public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: Jean Delvare <jdelvare@suse.com>,
	Peter Korsgaard <peter.korsgaard@barco.com>,
	Peter Rosin <peda@axentia.se>
Cc: Serge Semin <Sergey.Semin@t-platforms.ru>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] i2c: mux-gpio: Use "mux" con_id to find channel GPIOs
Date: Sat, 15 Jun 2019 00:47:49 +0300	[thread overview]
Message-ID: <20190614214748.2389-1-fancer.lancer@gmail.com> (raw)

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@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
 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

             reply	other threads:[~2019-06-14 21:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 21:47 Serge Semin [this message]
2019-06-15 11:43 ` [PATCH] i2c: mux-gpio: Use "mux" con_id to find channel GPIOs Andy Shevchenko
2019-06-15 23:24   ` Serge Semin
2019-06-16  9:02     ` Peter Rosin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190614214748.2389-1-fancer.lancer@gmail.com \
    --to=fancer.lancer@gmail.com \
    --cc=Sergey.Semin@t-platforms.ru \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jdelvare@suse.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=peda@axentia.se \
    --cc=peter.korsgaard@barco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox