Skip to content

Commit e641757

Browse files
krzkWolfram Sang
authored andcommitted
i2c: iop3xx: Fix memory leak in probe error path
When handling devm_gpiod_get_optional() errors, free the memory already allocated. This fixes Smatch warnings: drivers/i2c/busses/i2c-iop3xx.c:437 iop3xx_i2c_probe() warn: possible memory leak of 'new_adapter' drivers/i2c/busses/i2c-iop3xx.c:442 iop3xx_i2c_probe() warn: possible memory leak of 'new_adapter' Fixes: fdb7e88 ("i2c: iop: Use GPIO descriptors") Reported-by: kbuild test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 24a4967 commit e641757

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/i2c/busses/i2c-iop3xx.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,17 @@ iop3xx_i2c_probe(struct platform_device *pdev)
433433
adapter_data->gpio_scl = devm_gpiod_get_optional(&pdev->dev,
434434
"scl",
435435
GPIOD_ASIS);
436-
if (IS_ERR(adapter_data->gpio_scl))
437-
return PTR_ERR(adapter_data->gpio_scl);
436+
if (IS_ERR(adapter_data->gpio_scl)) {
437+
ret = PTR_ERR(adapter_data->gpio_scl);
438+
goto free_both;
439+
}
438440
adapter_data->gpio_sda = devm_gpiod_get_optional(&pdev->dev,
439441
"sda",
440442
GPIOD_ASIS);
441-
if (IS_ERR(adapter_data->gpio_sda))
442-
return PTR_ERR(adapter_data->gpio_sda);
443+
if (IS_ERR(adapter_data->gpio_sda)) {
444+
ret = PTR_ERR(adapter_data->gpio_sda);
445+
goto free_both;
446+
}
443447

444448
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
445449
if (!res) {

0 commit comments

Comments
 (0)