gpio: mcp23s08: create default gpio base if neither device node nor platform data is defined
diff mbox

Message ID 1421744408-8837-1-git-send-email-sonic.adi@gmail.com
State New
Headers show

Commit Message

Sonic Zhang Jan. 20, 2015, 9 a.m. UTC
From: Sonic Zhang <sonic.zhang@analog.com>

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 drivers/gpio/gpio-mcp23s08.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Alexandre Courbot Jan. 20, 2015, 10:11 a.m. UTC | #1
On Tue, Jan 20, 2015 at 6:00 PM, Sonic Zhang <sonic.adi@gmail.com> wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>

Thanks!

Note: please always include a commit body even if the title is enough
to understand the patch.

Antonio, could you try this and give us your Tested-by if it succeeds?
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Antonio Fiol BonnĂ­n Jan. 20, 2015, 4:03 p.m. UTC | #2
On Tue, Jan 20, 2015 at 10:00 AM, Sonic Zhang <sonic.adi@gmail.com> wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
>
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>

Tested-by: Antonio Fiol <antonio@fiol.es>

> ---
>  drivers/gpio/gpio-mcp23s08.c |   17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
> index da9c316..eea5d7e 100644
> --- a/drivers/gpio/gpio-mcp23s08.c
> +++ b/drivers/gpio/gpio-mcp23s08.c
> @@ -801,9 +801,11 @@ static int mcp230xx_probe(struct i2c_client *client,
>                 client->irq = irq_of_parse_and_map(client->dev.of_node, 0);
>         } else {
>                 pdata = dev_get_platdata(&client->dev);
> -               if (!pdata || !gpio_is_valid(pdata->base)) {
> -                       dev_dbg(&client->dev, "invalid platform data\n");
> -                       return -EINVAL;
> +               if (!pdata) {
> +                       pdata = devm_kzalloc(&client->dev,
> +                                       sizeof(struct mcp23s08_platform_data),
> +                                       GFP_KERNEL);
> +                       pdata->base = -1;
>                 }
>         }
>
> @@ -924,10 +926,11 @@ static int mcp23s08_probe(struct spi_device *spi)
>         } else {
>                 type = spi_get_device_id(spi)->driver_data;
>                 pdata = dev_get_platdata(&spi->dev);
> -               if (!pdata || !gpio_is_valid(pdata->base)) {
> -                       dev_dbg(&spi->dev,
> -                                       "invalid or missing platform data\n");
> -                       return -EINVAL;
> +               if (!pdata) {
> +                       pdata = devm_kzalloc(&spi->dev,
> +                                       sizeof(struct mcp23s08_platform_data),
> +                                       GFP_KERNEL);
> +                       pdata->base = -1;
>                 }
>
>                 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
> --
> 1.7.9.5
>

Thank you Sonic for the patch, and Alexander for your patience,
understanding and guidance.

This patch is working in my scenario. It is assigning the same base as
it was on the version before the patch that broke the behavior in the
past.

If you wish me to test in other scenarios (e.g. creating a device tree
file, or using platform data), I'd appreciate pointers to learn the
basics, or some help preparing the kernel tree to build with the
needed definitions (if that's what needs to be done).

I am saying this because seeing the commit logs it appears that effort
is being put into the driver to work in scenarios that differ from
mine, and I definitely do not want to break them.

Kind regards,
Linus Walleij Jan. 21, 2015, 4:53 p.m. UTC | #3
On Tue, Jan 20, 2015 at 10:00 AM, Sonic Zhang <sonic.adi@gmail.com> wrote:

> From: Sonic Zhang <sonic.zhang@analog.com>
>
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>

Patch applied for fixes with the ACK and Tested-by tags.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Courbot Jan. 22, 2015, 3:15 a.m. UTC | #4
On Thu, Jan 22, 2015 at 1:53 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Tue, Jan 20, 2015 at 10:00 AM, Sonic Zhang <sonic.adi@gmail.com> wrote:
>
>> From: Sonic Zhang <sonic.zhang@analog.com>
>>
>> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
>
> Patch applied for fixes with the ACK and Tested-by tags.

This was a very nice example of how bug reports should go: a clear and
detailed initial report, quick answer from involved parties, and the
fix applied, all in 5 days. Wish we could see more resolutions like
this - thanks to everyone involved.
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index da9c316..eea5d7e 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -801,9 +801,11 @@  static int mcp230xx_probe(struct i2c_client *client,
 		client->irq = irq_of_parse_and_map(client->dev.of_node, 0);
 	} else {
 		pdata = dev_get_platdata(&client->dev);
-		if (!pdata || !gpio_is_valid(pdata->base)) {
-			dev_dbg(&client->dev, "invalid platform data\n");
-			return -EINVAL;
+		if (!pdata) {
+			pdata = devm_kzalloc(&client->dev,
+					sizeof(struct mcp23s08_platform_data),
+					GFP_KERNEL);
+			pdata->base = -1;
 		}
 	}
 
@@ -924,10 +926,11 @@  static int mcp23s08_probe(struct spi_device *spi)
 	} else {
 		type = spi_get_device_id(spi)->driver_data;
 		pdata = dev_get_platdata(&spi->dev);
-		if (!pdata || !gpio_is_valid(pdata->base)) {
-			dev_dbg(&spi->dev,
-					"invalid or missing platform data\n");
-			return -EINVAL;
+		if (!pdata) {
+			pdata = devm_kzalloc(&spi->dev,
+					sizeof(struct mcp23s08_platform_data),
+					GFP_KERNEL);
+			pdata->base = -1;
 		}
 
 		for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {