diff options
| -rw-r--r-- | drivers/gpio/gpiolib.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ac5944b4e4d8..4efb92ca3463 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
| @@ -255,32 +255,29 @@ int gpiochip_add(struct gpio_chip *chip) | |||
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | status = gpiochip_add_to_list(chip); | 257 | status = gpiochip_add_to_list(chip); |
| 258 | if (status) { | ||
| 259 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
| 260 | goto err_free_descs; | ||
| 261 | } | ||
| 258 | 262 | ||
| 259 | if (status == 0) { | 263 | for (id = 0; id < chip->ngpio; id++) { |
| 260 | for (id = 0; id < chip->ngpio; id++) { | 264 | struct gpio_desc *desc = &descs[id]; |
| 261 | struct gpio_desc *desc = &descs[id]; | 265 | |
| 262 | desc->chip = chip; | 266 | desc->chip = chip; |
| 263 | 267 | ||
| 264 | /* REVISIT: most hardware initializes GPIOs as | 268 | /* REVISIT: most hardware initializes GPIOs as inputs (often |
| 265 | * inputs (often with pullups enabled) so power | 269 | * with pullups enabled) so power usage is minimized. Linux |
| 266 | * usage is minimized. Linux code should set the | 270 | * code should set the gpio direction first thing; but until |
| 267 | * gpio direction first thing; but until it does, | 271 | * it does, and in case chip->get_direction is not set, we may |
| 268 | * and in case chip->get_direction is not set, | 272 | * expose the wrong direction in sysfs. |
| 269 | * we may expose the wrong direction in sysfs. | 273 | */ |
| 270 | */ | 274 | desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; |
| 271 | desc->flags = !chip->direction_input | ||
| 272 | ? (1 << FLAG_IS_OUT) | ||
| 273 | : 0; | ||
| 274 | } | ||
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | chip->desc = descs; | 277 | chip->desc = descs; |
| 278 | 278 | ||
| 279 | spin_unlock_irqrestore(&gpio_lock, flags); | 279 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 280 | 280 | ||
| 281 | if (status) | ||
| 282 | goto fail; | ||
| 283 | |||
| 284 | #ifdef CONFIG_PINCTRL | 281 | #ifdef CONFIG_PINCTRL |
| 285 | INIT_LIST_HEAD(&chip->pin_ranges); | 282 | INIT_LIST_HEAD(&chip->pin_ranges); |
| 286 | #endif | 283 | #endif |
| @@ -304,10 +301,9 @@ err_remove_chip: | |||
| 304 | spin_lock_irqsave(&gpio_lock, flags); | 301 | spin_lock_irqsave(&gpio_lock, flags); |
| 305 | list_del(&chip->list); | 302 | list_del(&chip->list); |
| 306 | spin_unlock_irqrestore(&gpio_lock, flags); | 303 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 307 | fail: | 304 | chip->desc = NULL; |
| 308 | err_free_descs: | 305 | err_free_descs: |
| 309 | kfree(descs); | 306 | kfree(descs); |
| 310 | chip->desc = NULL; | ||
| 311 | 307 | ||
| 312 | /* failures here can mean systems won't boot... */ | 308 | /* failures here can mean systems won't boot... */ |
| 313 | pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, | 309 | pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, |
