All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: men_z188_adc: Fix a resource leak in an error handling path
@ 2022-01-29  8:32 Christophe JAILLET
  2022-01-30 13:51 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-01-29  8:32 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Greg Kroah-Hartman,
	Johannes Thumshirn
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-iio

If iio_device_register() fails, a previous ioremap() is left unbalanced.

Update the error handling path and add the missing iounmap() call, as
already done in the remove function.

Fixes: 74aeac4da66f ("iio: adc: Add MEN 16z188 ADC driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/iio/adc/men_z188_adc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/men_z188_adc.c b/drivers/iio/adc/men_z188_adc.c
index 42ea8bc7e780..adc5ceaef8c9 100644
--- a/drivers/iio/adc/men_z188_adc.c
+++ b/drivers/iio/adc/men_z188_adc.c
@@ -103,6 +103,7 @@ static int men_z188_probe(struct mcb_device *dev,
 	struct z188_adc *adc;
 	struct iio_dev *indio_dev;
 	struct resource *mem;
+	int ret;
 
 	indio_dev = devm_iio_device_alloc(&dev->dev, sizeof(struct z188_adc));
 	if (!indio_dev)
@@ -128,8 +129,14 @@ static int men_z188_probe(struct mcb_device *dev,
 	adc->mem = mem;
 	mcb_set_drvdata(dev, indio_dev);
 
-	return iio_device_register(indio_dev);
+	ret = iio_device_register(indio_dev);
+	if (ret)
+		goto err_unmap;
+
+	return 0;
 
+err_unmap:
+	iounmap(adc->base);
 err:
 	mcb_release_mem(mem);
 	return -ENXIO;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: adc: men_z188_adc: Fix a resource leak in an error handling path
  2022-01-29  8:32 [PATCH] iio: adc: men_z188_adc: Fix a resource leak in an error handling path Christophe JAILLET
@ 2022-01-30 13:51 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2022-01-30 13:51 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Lars-Peter Clausen, Greg Kroah-Hartman, Johannes Thumshirn,
	linux-kernel, kernel-janitors, linux-iio

On Sat, 29 Jan 2022 09:32:47 +0100
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> If iio_device_register() fails, a previous ioremap() is left unbalanced.
> 
> Update the error handling path and add the missing iounmap() call, as
> already done in the remove function.
> 
> Fixes: 74aeac4da66f ("iio: adc: Add MEN 16z188 ADC driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
This is a good target for a devm_ conversion at somepoint, but this
is indeed the minimal fix so we should do this first.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/men_z188_adc.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/men_z188_adc.c b/drivers/iio/adc/men_z188_adc.c
> index 42ea8bc7e780..adc5ceaef8c9 100644
> --- a/drivers/iio/adc/men_z188_adc.c
> +++ b/drivers/iio/adc/men_z188_adc.c
> @@ -103,6 +103,7 @@ static int men_z188_probe(struct mcb_device *dev,
>  	struct z188_adc *adc;
>  	struct iio_dev *indio_dev;
>  	struct resource *mem;
> +	int ret;
>  
>  	indio_dev = devm_iio_device_alloc(&dev->dev, sizeof(struct z188_adc));
>  	if (!indio_dev)
> @@ -128,8 +129,14 @@ static int men_z188_probe(struct mcb_device *dev,
>  	adc->mem = mem;
>  	mcb_set_drvdata(dev, indio_dev);
>  
> -	return iio_device_register(indio_dev);
> +	ret = iio_device_register(indio_dev);
> +	if (ret)
> +		goto err_unmap;
> +
> +	return 0;
>  
> +err_unmap:
> +	iounmap(adc->base);
>  err:
>  	mcb_release_mem(mem);
>  	return -ENXIO;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-30 13:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29  8:32 [PATCH] iio: adc: men_z188_adc: Fix a resource leak in an error handling path Christophe JAILLET
2022-01-30 13:51 ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.