Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: fix probe() error return in gpio driver probes

A number of drivers in drivers/gpio return -ENODEV when confronted with
missing setup parameters such as the platform data. However, returning
-ENODEV causes the driver layer to silently ignore the driver as it
assumes the probe did not find anything and was only speculative.

To make life easier to discern why a driver is not being attached, change
to returning -EINVAL, which is a better description of the fact that the
driver data was not valid.

Also add a set of dev_dbg() statements to the error paths to provide an
better explanation of the error as there may be more that one point in the
driver.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ben Dooks and committed by
Linus Torvalds
a342d215 5b96f172

+24 -12
+4 -2
drivers/gpio/max7301.c
··· 217 217 int i, ret; 218 218 219 219 pdata = spi->dev.platform_data; 220 - if (!pdata || !pdata->base) 221 - return -ENODEV; 220 + if (!pdata || !pdata->base) { 221 + dev_dbg(&spi->dev, "incorrect or missing platform data\n"); 222 + return -EINVAL; 223 + } 222 224 223 225 /* 224 226 * bits_per_word cannot be configured in platform data
+4 -2
drivers/gpio/max732x.c
··· 267 267 int ret, nr_port; 268 268 269 269 pdata = client->dev.platform_data; 270 - if (pdata == NULL) 271 - return -ENODEV; 270 + if (pdata == NULL) { 271 + dev_dbg(&client->dev, "no platform data\n"); 272 + return -EINVAL; 273 + } 272 274 273 275 chip = kzalloc(sizeof(struct max732x_chip), GFP_KERNEL); 274 276 if (chip == NULL)
+4 -2
drivers/gpio/mcp23s08.c
··· 310 310 unsigned base; 311 311 312 312 pdata = spi->dev.platform_data; 313 - if (!pdata || !gpio_is_valid(pdata->base)) 314 - return -ENODEV; 313 + if (!pdata || !gpio_is_valid(pdata->base)) { 314 + dev_dbg(&spi->dev, "invalid or missing platform data\n"); 315 + return -EINVAL; 316 + } 315 317 316 318 for (addr = 0; addr < 4; addr++) { 317 319 if (!pdata->chip[addr].is_present)
+4 -2
drivers/gpio/pca953x.c
··· 202 202 int ret; 203 203 204 204 pdata = client->dev.platform_data; 205 - if (pdata == NULL) 206 - return -ENODEV; 205 + if (pdata == NULL) { 206 + dev_dbg(&client->dev, "no platform data\n"); 207 + return -EINVAL; 208 + } 207 209 208 210 chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); 209 211 if (chip == NULL)
+8 -4
drivers/gpio/pcf857x.c
··· 188 188 int status; 189 189 190 190 pdata = client->dev.platform_data; 191 - if (!pdata) 192 - return -ENODEV; 191 + if (!pdata) { 192 + dev_dbg(&client->dev, "no platform data\n"); 193 + return -EINVAL; 194 + } 193 195 194 196 /* Allocate, initialize, and register this gpio_chip. */ 195 197 gpio = kzalloc(sizeof *gpio, GFP_KERNEL); ··· 250 248 else 251 249 status = i2c_read_le16(client); 252 250 253 - } else 254 - status = -ENODEV; 251 + } else { 252 + dev_dbg(&client->dev, "unsupported number of gpios\n"); 253 + status = -EINVAL; 254 + } 255 255 256 256 if (status < 0) 257 257 goto fail;