Skip to contentSkip to conversation

iio: adc: adi-axi-adc: Fix object reference counting

PATCH Applied Nuno Sá 3 participants 5 messages Jul 1, 2020 – Jul 4, 2020

Subsystems (2)
lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

PATCH 1/2 iio: adc: adi-axi-adc: Fix object reference counting

When looking for a registered client to attach with, the wrong reference counters are being grabbed. The idea is to increment the module and device counters of the client device and not the counters of the axi device being probed.

Fixes ef04070692a2 (iio: adc: adi-axi-adc: add support for AXI ADC IP core)
---
 drivers/iio/adc/adi-axi-adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/adi-axi-adc.c +2 -2
index 63d926e86798..86b6b65916ee 100644
@@ -332,12 +332,12 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
 		if (cl->dev->of_node != cln)
 			continue;
 
-		if (!try_module_get(dev->driver->owner)) {
+		if (!try_module_get(cl->dev->driver->owner)) {
 			mutex_unlock(&registered_clients_lock);
 			return ERR_PTR(-ENODEV);
 		}
 
-		get_device(dev);
+		get_device(cl->dev);
 		cl->info = info;
 		mutex_unlock(&registered_clients_lock);
 		return cl;
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 2/2 iio: adc: adi-axi-adc: Remove unneeded check

Looking at the register path, there will be bigger issues if dev is NULL. Hence, we can drop this check and assume there's no way that dev can be NULL at this point.

---
 drivers/iio/adc/adi-axi-adc.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/adc/adi-axi-adc.c +0 -3
index 86b6b65916ee..e216e37e8c8c 100644
@@ -326,9 +326,6 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
 	mutex_lock(&registered_clients_lock);
 
 	list_for_each_entry(cl, &registered_clients, entry) {
-		if (!cl->dev)
-			continue;
-
 		if (cl->dev->of_node != cln)
 			continue;
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] iio: adc: adi-axi-adc: Remove unneeded check

Quoted 17 lines · Nuno Sá

[External]

Looking at the register path, there will be bigger issues if dev is NULL. Hence, we can drop this check and assume there's no way that dev can be NULL at this point.

---
 drivers/iio/adc/adi-axi-adc.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/adc/adi-axi- renamed from drivers/iio/adc/adi-axi-adc.c +0 -0

adc.c
index 86b6b65916ee..e216e37e8c8c 100644

drivers/iio/adc/adi-axi-adc.c static struct adi_axi_adc_client · line 332

Quoted 7 lines
drivers/iio/adc/adi-axi-adc.c +0 -3
@@ -326,9 +326,6 @@ static struct adi_axi_adc_client
 *adi_axi_adc_attach_client(struct device *dev)
 	mutex_lock(&registered_clients_lock);
 
 	list_for_each_entry(cl, &registered_clients, entry) {
-		if (!cl->dev)
-			continue;
-

I may need to check this again.
I think this may be a left-over, of when there was un-managed adi_axi_adc_conv_register()

Quoted 3 lines
drivers/iio/adc/adi-axi-adc.c +0 -0
 		if (cl->dev->of_node != cln)
 			continue;
Acked-by on v1 1/2
#3 lore raw
In reply to Nuno Sá
Quoted 9 lines · Nuno Sá

[External]

When looking for a registered client to attach with, the wrong reference counters are being grabbed. The idea is to increment the module and device
counters of the client device and not the counters of the axi device being
probed.

Yep.
Good catch here.

Quoted 29 lines
Fixes ef04070692a2 (iio: adc: adi-axi-adc: add support for AXI ADC IP

core)

---
 drivers/iio/adc/adi-axi-adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/adi-axi- renamed from drivers/iio/adc/adi-axi-adc.c +0 -0

adc.c
index 63d926e86798..86b6b65916ee 100644

drivers/iio/adc/adi-axi-adc.c +2 -2
@@ -332,12 +332,12 @@ static struct adi_axi_adc_client
 *adi_axi_adc_attach_client(struct device *dev)
 		if (cl->dev->of_node != cln)
 			continue;
 
-		if (!try_module_get(dev->driver->owner)) {
+		if (!try_module_get(cl->dev->driver->owner)) {
 			mutex_unlock(&registered_clients_lock);
 			return ERR_PTR(-ENODEV);
 		}
 
-		get_device(dev);
+		get_device(cl->dev);
 		cl->info = info;
 		mutex_unlock(&registered_clients_lock);

return cl;

maintainer Applied
#4 lore raw
Quoted 11 lines · Alexandru
Quoted 9 lines · Nuno Sá

[External]

When looking for a registered client to attach with, the wrong reference counters are being grabbed. The idea is to increment the module and device
counters of the client device and not the counters of the axi device being
probed.

Quoted 4 lines

Yep.
Good catch here.

Applied to the fixes-togreg branch of iio.git

Thanks,

Jonathan

Quoted 30 lines
Quoted 30 lines
Fixes ef04070692a2 (iio: adc: adi-axi-adc: add support for AXI ADC IP

core)

---
 drivers/iio/adc/adi-axi-adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/adi-axi- renamed from drivers/iio/adc/adi-axi-adc.c +0 -0

adc.c
index 63d926e86798..86b6b65916ee 100644

drivers/iio/adc/adi-axi-adc.c +2 -2
@@ -332,12 +332,12 @@ static struct adi_axi_adc_client
 *adi_axi_adc_attach_client(struct device *dev)
 		if (cl->dev->of_node != cln)
 			continue;
 
-		if (!try_module_get(dev->driver->owner)) {
+		if (!try_module_get(cl->dev->driver->owner)) {
 			mutex_unlock(&registered_clients_lock);
 			return ERR_PTR(-ENODEV);
 		}
 
-		get_device(dev);
+		get_device(cl->dev);
 		cl->info = info;
 		mutex_unlock(&registered_clients_lock);

return cl;