[PATCH net-next v2 09/12] dpll: Prevent duplicate registrations

Ivan Vecera posted 12 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH net-next v2 09/12] dpll: Prevent duplicate registrations
Posted by Ivan Vecera 3 weeks, 2 days ago
Modify the internal registration helpers dpll_xa_ref_{dpll,pin}_add()
to reject duplicate registration attempts.

Previously, if a caller attempted to register the same pin multiple
times (with the same ops, priv, and cookie) on the same device, the core
silently increments the reference count and return success. This behavior
is incorrect because if the caller makes these duplicate registrations
then for the first one dpll_pin_registration is allocated and for others
the associated dpll_pin_ref.refcount is incremented. During the first
unregistration the associated dpll_pin_registration is freed and for
others WARN is fired.

Fix this by updating the logic to return `-EEXIST` if a matching
registration is found to enforce a strict "register once" policy.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 drivers/dpll/dpll_core.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c
index f2a77eb1b9916..8616d6285c646 100644
--- a/drivers/dpll/dpll_core.c
+++ b/drivers/dpll/dpll_core.c
@@ -161,10 +161,8 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin,
 		if (ref->pin != pin)
 			continue;
 		reg = dpll_pin_registration_find(ref, ops, priv, cookie);
-		if (reg) {
-			refcount_inc(&ref->refcount);
-			return 0;
-		}
+		if (reg)
+			return -EEXIST;
 		ref_exists = true;
 		break;
 	}
@@ -244,10 +242,8 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct dpll_device *dpll,
 		if (ref->dpll != dpll)
 			continue;
 		reg = dpll_pin_registration_find(ref, ops, priv, cookie);
-		if (reg) {
-			refcount_inc(&ref->refcount);
-			return 0;
-		}
+		if (reg)
+			return -EEXIST;
 		ref_exists = true;
 		break;
 	}
-- 
2.52.0
RE: [Intel-wired-lan] [PATCH net-next v2 09/12] dpll: Prevent duplicate registrations
Posted by Loktionov, Aleksandr 2 weeks, 6 days ago

> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> Of Ivan Vecera
> Sent: Friday, January 16, 2026 7:46 PM
> To: netdev@vger.kernel.org
> Cc: Eric Dumazet <edumazet@google.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Rob Herring <robh@kernel.org>; Leon
> Romanovsky <leon@kernel.org>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; linux-rdma@vger.kernel.org; Kitszel,
> Przemyslaw <przemyslaw.kitszel@intel.com>; Kubalewski, Arkadiusz
> <arkadiusz.kubalewski@intel.com>; intel-wired-lan@lists.osuosl.org;
> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>;
> devicetree@vger.kernel.org; Conor Dooley <conor+dt@kernel.org>; Jiri
> Pirko <jiri@resnulli.us>; Richard Cochran <richardcochran@gmail.com>;
> Saravana Kannan <saravanak@kernel.org>; Prathosh Satish
> <Prathosh.Satish@microchip.com>; Vadim Fedorenko
> <vadim.fedorenko@linux.dev>; Mark Bloch <mbloch@nvidia.com>; linux-
> kernel@vger.kernel.org; Tariq Toukan <tariqt@nvidia.com>; Andrew Lunn
> <andrew+netdev@lunn.ch>; Jonathan Lemon <jonathan.lemon@gmail.com>;
> Krzysztof Kozlowski <krzk+dt@kernel.org>; Saeed Mahameed
> <saeedm@nvidia.com>; David S. Miller <davem@davemloft.net>
> Subject: [Intel-wired-lan] [PATCH net-next v2 09/12] dpll: Prevent
> duplicate registrations
> 
> Modify the internal registration helpers dpll_xa_ref_{dpll,pin}_add()
> to reject duplicate registration attempts.
> 
> Previously, if a caller attempted to register the same pin multiple
> times (with the same ops, priv, and cookie) on the same device, the
> core silently increments the reference count and return success. This
> behavior is incorrect because if the caller makes these duplicate
> registrations then for the first one dpll_pin_registration is
> allocated and for others the associated dpll_pin_ref.refcount is
> incremented. During the first unregistration the associated
> dpll_pin_registration is freed and for others WARN is fired.
> 
> Fix this by updating the logic to return `-EEXIST` if a matching
> registration is found to enforce a strict "register once" policy.
> 
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> ---
>  drivers/dpll/dpll_core.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index
> f2a77eb1b9916..8616d6285c646 100644
> --- a/drivers/dpll/dpll_core.c
> +++ b/drivers/dpll/dpll_core.c
> @@ -161,10 +161,8 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins,
> struct dpll_pin *pin,
>  		if (ref->pin != pin)
>  			continue;
>  		reg = dpll_pin_registration_find(ref, ops, priv,
> cookie);
> -		if (reg) {
> -			refcount_inc(&ref->refcount);
> -			return 0;
> -		}
> +		if (reg)
> +			return -EEXIST;
>  		ref_exists = true;
>  		break;
>  	}
> @@ -244,10 +242,8 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls,
> struct dpll_device *dpll,
>  		if (ref->dpll != dpll)
>  			continue;
>  		reg = dpll_pin_registration_find(ref, ops, priv,
> cookie);
> -		if (reg) {
> -			refcount_inc(&ref->refcount);
> -			return 0;
> -		}
> +		if (reg)
> +			return -EEXIST;
>  		ref_exists = true;
>  		break;
>  	}
> --
> 2.52.0

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>