Skip to content

Commit c8930ed

Browse files
Jinjie Ruanwsakernel
authored andcommitted
i2c: Make return value check more accurate and explicit for devm_pinctrl_get()
If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then recovery can't work, because we can't switch the I2C pins between the I2C controller and GPIO. So, it is quite correct to print "can't get pinctrl, bus recovery not supported" because the I2C bus can't be recovered without pinctrl. The PTR_ERR() is also fine - because if pinctrl is not present and returns NULL, we'll end up returning zero, which is exactly what we want. However, open code that with a more accurate message will be more explicit for NULL case when CONFIG_PINCTRL is not defined. Signed-off-by: Jinjie Ruan <[email protected]> Acked-by: Oleksij Rempel <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Suggested-by: Russell King (Oracle) <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 4ba6386 commit c8930ed

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

drivers/i2c/busses/i2c-at91-master.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,11 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
831831
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
832832

833833
rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
834-
if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
834+
if (!rinfo->pinctrl) {
835+
dev_info(dev->dev, "pinctrl unavailable, bus recovery not supported\n");
836+
return 0;
837+
}
838+
if (IS_ERR(rinfo->pinctrl)) {
835839
dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
836840
return PTR_ERR(rinfo->pinctrl);
837841
}

drivers/i2c/busses/i2c-imx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,11 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
13881388
struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
13891389

13901390
i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
1391-
if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
1391+
if (!i2c_imx->pinctrl) {
1392+
dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n");
1393+
return 0;
1394+
}
1395+
if (IS_ERR(i2c_imx->pinctrl)) {
13921396
dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
13931397
return PTR_ERR(i2c_imx->pinctrl);
13941398
}

0 commit comments

Comments
 (0)