Skip to contentSkip to conversation

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

PATCH In review Sonic Zhang 4 participants 5 messages Jan 20, 2015 – Jan 22, 2015 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: mcp23s08: create default gpio base if neither device node nor platform data is defined

From: Sonic Zhang <[email protected]>

---
 drivers/gpio/gpio-mcp23s08.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mcp23s08.c +10 -7
index da9c316..eea5d7e 100644
@@ -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++) {
Signature · 1 line
1.7.9.5
Tested-by on v1 1/1
#2 lore raw
In reply to Sonic Zhang
Quoted 3 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

Quoted 40 lines
---
 drivers/gpio/gpio-mcp23s08.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mcp23s08.c +10 -8
index da9c316..eea5d7e 100644
@@ -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++) {
--
Quoted 2 lines

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,

Signature · 1 line
Antonio
#4 lore raw
Quoted 7 lines · Linus Walleij
Quoted 3 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

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.