diff mbox series

iio: adc: adi-axi-adc: Fix refcount leak in adi_axi_adc_attach_client

Message ID 20220524074517.45268-1-linmq006@gmail.com (mailing list archive)
State Accepted
Headers show
Series iio: adc: adi-axi-adc: Fix refcount leak in adi_axi_adc_attach_client | expand

Commit Message

Miaoqian Lin May 24, 2022, 7:45 a.m. UTC
of_parse_phandle() returns a node pointer with refcount
incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes: ef04070692a2 ("iio: adc: adi-axi-adc: add support for AXI ADC IP core")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/iio/adc/adi-axi-adc.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jonathan Cameron June 3, 2022, 3:29 p.m. UTC | #1
On Tue, 24 May 2022 11:45:17 +0400
Miaoqian Lin <linmq006@gmail.com> wrote:

> of_parse_phandle() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when not need anymore.
> Add missing of_node_put() to avoid refcount leak.
> 
> Fixes: ef04070692a2 ("iio: adc: adi-axi-adc: add support for AXI ADC IP core")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Looks 'obviously correct to me' so applied to the fixes togreg branch of iio.git
and marked for stable.

Great if anyone more familiar with this driver than me has a chance
to take a quick look though.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/adi-axi-adc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index a73e3c2d212f..a9e655e69eaa 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -322,16 +322,19 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
>  
>  		if (!try_module_get(cl->dev->driver->owner)) {
>  			mutex_unlock(&registered_clients_lock);
> +			of_node_put(cln);
>  			return ERR_PTR(-ENODEV);
>  		}
>  
>  		get_device(cl->dev);
>  		cl->info = info;
>  		mutex_unlock(&registered_clients_lock);
> +		of_node_put(cln);
>  		return cl;
>  	}
>  
>  	mutex_unlock(&registered_clients_lock);
> +	of_node_put(cln);
>  
>  	return ERR_PTR(-EPROBE_DEFER);
>  }
diff mbox series

Patch

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index a73e3c2d212f..a9e655e69eaa 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -322,16 +322,19 @@  static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
 
 		if (!try_module_get(cl->dev->driver->owner)) {
 			mutex_unlock(&registered_clients_lock);
+			of_node_put(cln);
 			return ERR_PTR(-ENODEV);
 		}
 
 		get_device(cl->dev);
 		cl->info = info;
 		mutex_unlock(&registered_clients_lock);
+		of_node_put(cln);
 		return cl;
 	}
 
 	mutex_unlock(&registered_clients_lock);
+	of_node_put(cln);
 
 	return ERR_PTR(-EPROBE_DEFER);
 }