Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: men_z188_adc: Fix a resource leak in an error handling path

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>
Link: https://lore.kernel.org/r/320fc777863880247c2aff4a9d1a54ba69abf080.1643445149.git.christophe.jaillet@wanadoo.fr
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Christophe JAILLET and committed by
Jonathan Cameron
e0a2e37f a1cba0e2

+8 -1
+8 -1
drivers/iio/adc/men_z188_adc.c
··· 103 103 struct z188_adc *adc; 104 104 struct iio_dev *indio_dev; 105 105 struct resource *mem; 106 + int ret; 106 107 107 108 indio_dev = devm_iio_device_alloc(&dev->dev, sizeof(struct z188_adc)); 108 109 if (!indio_dev) ··· 129 128 adc->mem = mem; 130 129 mcb_set_drvdata(dev, indio_dev); 131 130 132 - return iio_device_register(indio_dev); 131 + ret = iio_device_register(indio_dev); 132 + if (ret) 133 + goto err_unmap; 133 134 135 + return 0; 136 + 137 + err_unmap: 138 + iounmap(adc->base); 134 139 err: 135 140 mcb_release_mem(mem); 136 141 return -ENXIO;