Skip to contentSkip to conversation

dpll: fix dpll_xa_ref_*_del() for multiple registrations

PATCH Applied Jiri Pirko 3 participants 4 messages Mar 6, 2024 – Mar 8, 2024

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

PATCH 1/1 dpll: fix dpll_xa_ref_*_del() for multiple registrations

From: Jiri Pirko <[email protected]>

Currently, if there are multiple registrations of the same pin on the same dpll device, following warnings are observed:

WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:143 dpll_xa_ref_pin_del.isra.0+0x21e/0x230
WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:223 __dpll_pin_unregister+0x2b3/0x2c0

The problem is, that in both dpll_xa_ref_dpll_del() and dpll_xa_ref_pin_del() registration is only removed from list in case the reference count drops to zero. That is wrong, the registration has to be removed always.

To fix this, remove the registration from the list and free it unconditionally, instead of doing it only when the ref reference counter reaches zero.

Fixes 9431063ad323 ("dpll: core: Add DPLL framework base functions")
---
 drivers/dpll/dpll_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dpll/dpll_core.c +4 -4
index 7f686d179fc9..c751a87c7a8e 100644
@@ -129,9 +129,9 @@ static int dpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return -EINVAL;
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_pins, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
@@ -209,9 +209,9 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return;
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_dplls, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
Signature · 1 line
2.43.2
#1 lore raw
Quoted 11 lines · On Wed, 06 Mar, 2024 16:12:40 +0100 Jiri Pirko <[email protected]> wrote:

From: Jiri Pirko <[email protected]>

Currently, if there are multiple registrations of the same pin on the same dpll device, following warnings are observed:

WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:143 dpll_xa_ref_pin_del.isra.0+0x21e/0x230
WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:223 __dpll_pin_unregister+0x2b3/0x2c0

The problem is, that in both dpll_xa_ref_dpll_del() and dpll_xa_ref_pin_del() registration is only removed from list in case the reference count drops to zero. That is wrong, the registration has to be removed always.

What about the case where you have two functions/netdevs that refer to the same DPLL device/pin and you only remove a single function? You have another function/netdev left that now refers to the unregistered DPLL device/pin.

Quoted 39 lines

To fix this, remove the registration from the list and free it unconditionally, instead of doing it only when the ref reference counter reaches zero.

Fixes 9431063ad323 ("dpll: core: Add DPLL framework base functions")
---
 drivers/dpll/dpll_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dpll/dpll_core.c +4 -4
index 7f686d179fc9..c751a87c7a8e 100644
@@ -129,9 +129,9 @@ static int dpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return -EINVAL;
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_pins, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
@@ -209,9 +209,9 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return;
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_dplls, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
Reviewed-by
#2 lore raw
Quoted 13 lines · On Wed, 06 Mar, 2024 07:18:35 -0800 Rahul Rameshbabu <[email protected]>…
Quoted 11 lines · On Wed, 06 Mar, 2024 16:12:40 +0100 Jiri Pirko <[email protected]> wrote:

From: Jiri Pirko <[email protected]>

Currently, if there are multiple registrations of the same pin on the same dpll device, following warnings are observed:

WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:143 dpll_xa_ref_pin_del.isra.0+0x21e/0x230
WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:223 __dpll_pin_unregister+0x2b3/0x2c0

The problem is, that in both dpll_xa_ref_dpll_del() and dpll_xa_ref_pin_del() registration is only removed from list in case the reference count drops to zero. That is wrong, the registration has to be removed always.

Quoted 5 lines

What about the case where you have two functions/netdevs that refer to the same DPLL device/pin and you only remove a single function? You have another function/netdev left that now refers to the unregistered DPLL device/pin.

Actually, I see that being registered or not does not impact the use of existing DPLL device/pin references in other functions. I agree with this change.

Quoted 31 lines
Quoted 31 lines

To fix this, remove the registration from the list and free it unconditionally, instead of doing it only when the ref reference counter reaches zero.

Fixes 9431063ad323 ("dpll: core: Add DPLL framework base functions")
---
 drivers/dpll/dpll_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dpll/dpll_core.c +2 -2
index 7f686d179fc9..c751a87c7a8e 100644
@@ -129,9 +129,9 @@ static int dpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return -EINVAL;
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_pins, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
@@ -209,9 +209,9 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll,
 		reg = dpll_pin_registration_find(ref, ops, priv);
 		if (WARN_ON(!reg))
 			return;
Quoted 8 lines

drivers/dpll/dpll_core.c dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll, · line 217

Quoted 8 lines
drivers/dpll/dpll_core.c +2 -2
+		list_del(&reg->list);
+		kfree(reg);
 		if (refcount_dec_and_test(&ref->refcount)) {
-			list_del(&reg->list);
-			kfree(reg);
 			xa_erase(xa_dplls, i);
 			WARN_ON(!list_empty(&ref->registration_list));
 			kfree(ref);
#3 lore raw
In reply to Jiri Pirko
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 8 lines · On Wed, 6 Mar 2024 16:12:40 +0100 you wrote:

From: Jiri Pirko <[email protected]>

Currently, if there are multiple registrations of the same pin on the same dpll device, following warnings are observed:

WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:143 dpll_xa_ref_pin_del.isra.0+0x21e/0x230
WARNING: CPU: 5 PID: 2212 at drivers/dpll/dpll_core.c:223 __dpll_pin_unregister+0x2b3/0x2c0

[...]

Here is the summary with links:
- [net] dpll: fix dpll_xa_ref_*_del() for multiple registrations

    https://git.kernel.org/netdev/net/c/b446631f355e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html