🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7598

[PATCH net v6 2/5] ptp: unwind partially completed virtual clock creation

#7598
From: James Hilliard
Date: Mon, 26 Oct 2026 18:11
51 lines
12810 bytes
n_vclocks_store() publishes the new clock count only after every child
has been registered. If a later registration fails, it returns without
unregistering the children already created by that request. Those clocks
are left out of n_vclocks, and a subsequent request can overwrite their
index entries without removing them.

Unregister the newly created children in reverse order and clear their
index entries on failure. Leave the previously installed clocks and
their count unchanged. The n_vclocks mutex serializes this rollback with
other sysfs changes, and parent removal drains the store before walking
the children.

This was found by code inspection while adding initial PHC sample error
handling to virtual clock registration.

Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 drivers/ptp/ptp_sysfs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index 53388b123198..fabc1c9b1752 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -225,7 +225,7 @@ static ssize_t n_vclocks_store(struct device *dev,
 		for (i = 0; i < num - ptp->n_vclocks; i++) {
 			vclock = ptp_vclock_register(ptp);
 			if (!vclock)
-				goto out;
+				goto err_register;
 
 			*(ptp->vclock_index + ptp->n_vclocks + i) =
 				vclock->clock->index;
@@ -257,6 +257,12 @@ static ssize_t n_vclocks_store(struct device *dev,
 	mutex_unlock(&ptp->n_vclocks_mux);
 
 	return count;
+err_register:
+	num = i;
+	if (num)
+		device_for_each_child_reverse(dev, &num, unregister_vclock);
+	for (num = 0; num < i; num++)
+		ptp->vclock_index[ptp->n_vclocks + num] = -1;
 out:
 	mutex_unlock(&ptp->n_vclocks_mux);
 	return err;

-- 
2.53.0
Technical Details
Message-ID: <20261026-ptp-vclock-sampling-v6-2-e705612541f1@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352033-linux-kernel-netdev=dewy.ru
References: <20261026-ptp-vclock-sampling-v6-0-e705612541f1@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352033-linux-kernel-netdev=dewy.ru
From: james.hilliard1@gmail.com (James Hilliard)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v6 2/5] ptp: unwind partially completed virtual clock
 creation
Date: Mon, 26 Oct 2026 12:11:28 -0600
Organization: Usenet Network
Message-ID: <20261026-ptp-vclock-sampling-v6-2-e705612541f1@gmail.com>
References: <20261026-ptp-vclock-sampling-v6-0-e705612541f1@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1367369"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7BgHpsG5hUyjXdkYkKmYaGdfDyA= sha256:hixKIpjtVlzw0Vhvt8spPugWBEIrZKzqYXqvUJJA0qk=
	sha1:ZlwcY9eDI15xspw2zQljFHTzulY= sha256:uj3ZVILG4sQ866K1B3y4jSAe5eGR6FDxHL2iV1Pt0DE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 65BEA125BB1; Mon, 26 Oct 2026 21:12:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id vZxX6kJatC-e;
	Mon, 26 Oct 2026 21:12:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352033-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 76407125BB0; Mon, 26 Oct 2026 21:12:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 68DAB27D27; Mon, 26 Oct 2026 18:11:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793038300;
	b=NCay17ngA+O2f3sFn6lK3Hn0pJok1bnG5Ya11ZTx+8prvuf+JnYwTpq1u2Fk4WGgHuCN
	 EAgqV9ph8skW4zw87JtwbOUVzjhLzqRQzE08slqqgLBsV0HGyJVOycSDI3qWXagte6CC5
	 fF40Py6GgsnkczsMhyQl+8jFkE2Xa9bwLneNTssOcAnR3qlEe95UkDsCL1a+FHBDELj9T
	 Fe+bvXhB+lOqqUgiQsjRpnoAkXwPVjB5/+6vcuRTDXsZdeFNWsTRK6O1V9yJO7imBXe3j
	 +VVYug1dXVqx+4jmNPW5hp2AjbXvShqeSS2uCS2l6gQv0dH3xgefxHDgYWNgk9JKqbQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793038300;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer;
	bh=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=;
	b=yxQcdnlKUn3N/HlCwevpUnunRMv67XUivOj4ASHe9g3T0YoWeAt5sJRVuNuEUAsBGeeP
	 ZVbYmCN0R5jXAVdhiCAR4BVYaA3Wkw9fqYD6zC5RdVKUuVkJHfK4BFTAmFXEA8Vh/yqvA
	 kReE7UhJXLXXgBf2+telQsD6DqX6BAfGYvh/HAcAWzBCqbiwRFjFsT3dNMPRIdaExJZ4y
	 foyKK+f1Y1bJbgtrc9bO6z4p4aNqb0ChAKGTwgSEenOmw73VGBREUsxzQ3n7/yTduH4rU
	 +Ay0BWNGnIt0Vyl89u67Q0iVVgNX9wK7Hs8fiPavPw9gPvoDmnFm7dsqaL/y/ClT4hg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=cmObIIJ1;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 40FCA606A31F;
	Mon, 26 Oct 2026 18:11:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=cmObIIJ1
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.41
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793038298;
	b=dTfACmQkGfCRKRy0aeHGDkq9imE/82NmuzX5fHdrwregxgZdJtyEIov8kzmpOTO7CHbj
	 tCmgdLgNHD2F8sVmC1uDc3g/+RBkz90qxL/srKLbqC5hX8GSsuyQ6oBvjQcSn0OI+8Nsp
	 9GY50eTx3HVrmWnPDduOXLbtlyjgjNXhnsG8E9a37n4f+h8ejlHHhwirUHCzII65nOTwg
	 y0PFQw4YQevOv9xQJNGK9B/axP9uBo8XYBkGyPaFRpBpdmnxeSJkr9IwIW4AkGm4nZmLk
	 NGi3uIuJxN3yfe1Xuof5YNvq/g+T2phJ6MFQMUlWlLY5klnWlgu5A4LP9W4VOxfVTqw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793038298;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:Date:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:
	 References:In-Reply-To:To:Cc:X-Mailer;
	bh=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=;
	b=ZRx9+IGaemrViIshNcurEQ3NMn+ihK1t++73BrTTdDsq8f4tk6uviM6PgRmTqQ+REsRQ
	 8DMqE9v1QEmNnQbxSKx+ljOXtvWta3UlXrXS2YEYMPKej+0Z3aQdTzS6EsuqsHfFds+j1
	 P6PkwTUiteaoHgK7n2wjfR3o8rOHGAxarJ6Ge11M0o+HhvTKo++USQ1zXVYqq924BSskQ
	 h6W9EO7VP9np9SZYR3ZXcLo+hk1ygHKEHJyKicLuPhnw1bfC37e5bNqirY2hNdSt9MZ2I
	 sll1Oh9gzSlUWgydLKKw3+NG1Op+K+eTtP61DKosl7waGTL6GA7vCQsSbD1dgbh8IXQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=cmObIIJ1;
	arc=none smtp.remote-ip=209.85.160.41
X-Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97E3B606A31D
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 18:11:37 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97E3B606A31D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-48e94879f02so975146fac.0
        for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 11:11:37 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1793038296; x=1793643096; darn=vger.kernel.org;
        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
         :content-type:mime-version:subject:date:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=;
        b=cmObIIJ1y5lLS+rOt1FJahAjY3FkSDXqyLEj08rkBVk/02Lg2RpA+LIB9s5doTjHP7
         sQ0accUQzwFFmiVjen6O89mfmJoBKgdr5jOUzqUS37vQBsT2j+HL9mRSX4Uean7WWMEm
         8oeNd6pUtZOdcnPMGxqIFfIesEX2xSIxnA96WxIIaS0Mw5+E+57V1N/aE/m+9bvkRK5/
         Webx4FIxOSHvthzyLx3P4Qt50w1GC8oiRoIW4U0ntfaBffBDret6RFfQa0wiacSy40Th
         X6jAScYzXyjLD0KYGrmympQ2WFiyw9E7vGI6ZnFhuPp2NfJe58rkhi9eSYOyspkhOOUz
         9rQw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793038296; x=1793643096;
        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
         :content-type:mime-version:subject:date:from:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=;
        b=pPPsFy+jpfNd1IOLK0oeLZsIccE6UUWIHXaJdXmKoJY/3NyvMAT6H2eG+3EYboszQZ
         /8vWnYGNsaOEzNWITZjviKTYBoSBbfmqifaDGabTdKdCgJIXhG1Kzd+faZxhmfEW9c9G
         80Pu1yt6ftkJ4I1nDTO55kN6ukuyMUmFnAtvSYemdACNOi5wdAwo2ftR+i7O/YutyQB1
         ZnmmYmr+CKgab6r1FkgUusl7zU0MnKRZdleWAbqP6cATeSMbNFtU/ORE2kEp20YK2AzV
         G6eBCgKrszFxYl22YctKz2zun8qhRaUxqvfPYwG+QzNkqhf3yVK2SKZMLJc5R2LMCmVY
         WeqA==
X-Gm-Message-State: AFq9FYJjEkZ/ubOSIi1V+Eu9feRShfijSnAaXYIvYcpujK1AWAm7Q9Rb
	eW4BnAANJPMNlsTt95QPZyWgirlTrWai4xuJkA/o67ZG+p+Iopbu4+bU
X-Gm-Gg: AYBFou35nLIB0WWlKc/XmCxiz8ac0orPDQy4CiuC04vN8DgdLAaR6cN0KGLQA+AoySZ
	qjFmq9qQ9BXXunU9Tqqkn7/3bdA/sWNRhS7vXqSpTg6TAUM5d5ZntkW0B4Y96Z2VPLxzj2Ge1GA
	6jeJLEmp6VsYljzX0qROpDc+vbhlnKvGY9gl/ltQSgmmkLRIoiSBoaL84Ko2QCMtmYIaCclKyDS
	t1T9cf0RAMPwqG2ZsjlOg4SJKB5RCzgwVaTRUOR9Qf04OyjHSlVcIybfr3mYijbBQkHvUh9TVvZ
	pC0O1BDFjlyECmP7l8ZbHdBsgfU0SDskzUw6QnCKtIMfzOPF80jc+2q5kIu7HHbcqX9FK662RhB
	m078K16clQOWYzXSo9C/9aE4XUPIg6vRAlL3vNze8Bcwa1MP0DxaoQV1KUSS7JW7hVgP+8PZs+X
	2JZ+3yZ2dsl0eQL0vx4zgPYtt/BgFWHb0JQfd29CTMzE774zA+Cfi9SRim994GK1igo5tXX8tBr
	LI3zIWUFIZtYtuAnpiiYZFVioqOiv1IBkzl7bVd4CQv5O0FT5CiFwKSgFGPeXcN8OfeH0eto2yb
	6IGUijM2kqa5lETJy727uhJdE04953ug+keUwRstctqHALt2InsaFcZgdwiV3JO+BG4amAN4jKw
	fOWOos/h5/DSEuHxZjTppK84Y+D2z3/OCfjlC6pvZ/CRwwOEblYOknGqTrQ5pKaFzxG2TV0EyTJ
	zhoPCedECkerYopBfJZMfj8kegDvcx3s7IuIH79YfTXMpwPathz3o=
X-Received: by 2002:a05:6808:19a5:b0:4d6:90f3:74b1 with SMTP id 5614622812f47-55c003aceacmr5817075b6e.49.1793038296382;
        Mon, 26 Oct 2026 11:11:36 -0700 (PDT)
X-Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49])
        by smtp.gmail.com with ESMTPSA id 5614622812f47-55c043115bcsm5795251b6e.15.2026.10.26.11.11.34
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 26 Oct 2026 11:11:35 -0700 (PDT)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261026-ptp-vclock-sampling-v6-0-e705612541f1@gmail.com>
X-Cc: Eric Dumazet <edumazet@kernel.org>, 
 "David S. Miller" <davem@davemloft.net>, linux-kernel@vger.kernel.org, 
 Vadim Fedorenko <vadim.fedorenko@linux.dev>, 
 James Hilliard <james.hilliard1@gmail.com>
X-Mailer: b4 0.15.2