iio: adc: adi-axi-adc: Fix object reference counting
Subsystems (2)
Nuno Sá
maintainerPATCH 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.
--- drivers/iio/adc/adi-axi-adc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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 (®istered_clients_lock);return ERR_PTR (-ENODEV ); } -get_device (dev); +get_device (cl->dev); cl->info = info;mutex_unlock (®istered_clients_lock);return cl;
Signature · 1 line
2.25.1
Nuno Sá
maintainerPATCH 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
@@ -326,9 +326,6 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)mutex_lock (®istered_clients_lock);list_for_each_entry (cl, ®istered_clients, entry) { -if (!cl->dev) -continue ; -if (cl->dev->of_node != cln)continue ;
Signature · 1 line
2.25.1
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
devis NULL. Hence, we can drop this check and assume there's no way thatdevcan be NULL at this point.Signed-off-by Nuno Sá <[email protected]>--- 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
index86b6b65916ee..e216e37e8c8c100644
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 (®istered_clients_lock);list_for_each_entry (cl, ®istered_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
-0if (cl->dev->of_node != cln)continue ;
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 IPcore)
Signed-off-by Nuno Sá <[email protected]>--- 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
index63d926e86798..86b6b65916ee100644drivers/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 (®istered_clients_lock);return ERR_PTR (-ENODEV ); } -get_device (dev); +get_device (cl->dev); cl->info = info;mutex_unlock (®istered_clients_lock);return cl;
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 IPcore)
Signed-off-by Nuno Sá <[email protected]>--- 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
index63d926e86798..86b6b65916ee100644drivers/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 (®istered_clients_lock);return ERR_PTR (-ENODEV ); } -get_device (dev); +get_device (cl->dev); cl->info = info;mutex_unlock (®istered_clients_lock);return cl;