[PATCH] i2c: mux-gpio: Use "mux" con_id to find channel GPIOs

From: Serge Semin
Date: Fri Jun 14 2019 - 17:54:20 EST


Recent patch - ("i2c: mux/i801: Switch to use descriptor passing")
altered the i2c-mux-gpio driver to use the GPIO-descriptor
based interface to find and request the GPIOs then being utilized
to select and deselect the channels of GPIO-driven i2c-muxes. Even
though the proposed modification was correct for the platform_data-based
systems, it was invalid for the OF-based ones and caused the kernel
to crash at the driver probe procedure. There were two problems with
that modification. First of all the gpiod_count() and gpiod_get_index()
were called with NULL con_id. Due to this the methods couldn't find
the "mux-gpios" OF-properties and returned the -ENOENT error. Secondly
the return value of gpiod_count() wasn't checked for being negative,
which in case of an error caused the driver to crash. This patch
is intended to fix the described problems.

Fixes: - ("i2c: mux/i801: Switch to use descriptor passing")
Cc: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Cc: Peter Rosin <peda@xxxxxxxxxx>
Cc: Jean Delvare <jdelvare@xxxxxxxx>
Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
---
drivers/i2c/busses/i2c-i801.c | 2 +-
drivers/i2c/muxes/i2c-mux-gpio.c | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index a377d94968af..ec54b5b4f1a1 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1276,7 +1276,7 @@ static int i801_add_mux(struct i801_priv *priv)
for (i = 0; i < mux_config->n_gpios; i++) {
lookup->table[i].chip_label = mux_config->gpio_chip;
lookup->table[i].chip_hwnum = mux_config->gpios[i];
- lookup->table[i].con_id = NULL;
+ lookup->table[i].con_id = "mux";
}
gpiod_add_lookup_table(lookup);
priv->lookup = lookup;
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index b9578f668fb2..1ea097dc8d5d 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -130,10 +130,10 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
sizeof(mux->data));
}

- ngpios = gpiod_count(&pdev->dev, NULL);
- if (!ngpios) {
- dev_err(&pdev->dev, "no gpios provided\n");
- return -EINVAL;
+ ngpios = gpiod_count(&pdev->dev, "mux");
+ if (ngpios <= 0) {
+ dev_err(&pdev->dev, "no valid gpios provided\n");
+ return ngpios ?: -EINVAL;
}
mux->ngpios = ngpios;

@@ -173,7 +173,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
flag = GPIOD_OUT_HIGH;
else
flag = GPIOD_OUT_LOW;
- gpiod = devm_gpiod_get_index(&pdev->dev, NULL, i, flag);
+ gpiod = devm_gpiod_get_index(&pdev->dev, "mux", i, flag);
if (IS_ERR(gpiod)) {
ret = PTR_ERR(gpiod);
goto alloc_failed;
--
2.21.0