diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 487afe6f22fc..568aa2b6bdb0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -248,29 +248,30 @@ int gpiochip_add(struct gpio_chip *chip) | |||
248 | base = gpiochip_find_base(chip->ngpio); | 248 | base = gpiochip_find_base(chip->ngpio); |
249 | if (base < 0) { | 249 | if (base < 0) { |
250 | status = base; | 250 | status = base; |
251 | goto unlock; | 251 | spin_unlock_irqrestore(&gpio_lock, flags); |
252 | goto err_free_descs; | ||
252 | } | 253 | } |
253 | chip->base = base; | 254 | chip->base = base; |
254 | } | 255 | } |
255 | 256 | ||
256 | 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 | } | ||
257 | 262 | ||
258 | if (status == 0) { | 263 | for (id = 0; id < chip->ngpio; id++) { |
259 | for (id = 0; id < chip->ngpio; id++) { | 264 | struct gpio_desc *desc = &descs[id]; |
260 | struct gpio_desc *desc = &descs[id]; | 265 | |
261 | desc->chip = chip; | 266 | desc->chip = chip; |
262 | 267 | ||
263 | /* REVISIT: most hardware initializes GPIOs as | 268 | /* REVISIT: most hardware initializes GPIOs as inputs (often |
264 | * inputs (often with pullups enabled) so power | 269 | * with pullups enabled) so power usage is minimized. Linux |
265 | * usage is minimized. Linux code should set the | 270 | * code should set the gpio direction first thing; but until |
266 | * gpio direction first thing; but until it does, | 271 | * it does, and in case chip->get_direction is not set, we may |
267 | * and in case chip->get_direction is not set, | 272 | * expose the wrong direction in sysfs. |
268 | * we may expose the wrong direction in sysfs. | 273 | */ |
269 | */ | 274 | desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; |
270 | desc->flags = !chip->direction_input | ||
271 | ? (1 << FLAG_IS_OUT) | ||
272 | : 0; | ||
273 | } | ||
274 | } | 275 | } |
275 | 276 | ||
276 | chip->desc = descs; | 277 | chip->desc = descs; |
@@ -284,12 +285,9 @@ int gpiochip_add(struct gpio_chip *chip) | |||
284 | of_gpiochip_add(chip); | 285 | of_gpiochip_add(chip); |
285 | acpi_gpiochip_add(chip); | 286 | acpi_gpiochip_add(chip); |
286 | 287 | ||
287 | if (status) | ||
288 | goto fail; | ||
289 | |||
290 | status = gpiochip_export(chip); | 288 | status = gpiochip_export(chip); |
291 | if (status) | 289 | if (status) |
292 | goto fail; | 290 | goto err_remove_chip; |
293 | 291 | ||
294 | pr_debug("%s: registered GPIOs %d to %d on device: %s\n", __func__, | 292 | pr_debug("%s: registered GPIOs %d to %d on device: %s\n", __func__, |
295 | chip->base, chip->base + chip->ngpio - 1, | 293 | chip->base, chip->base + chip->ngpio - 1, |
@@ -297,11 +295,15 @@ int gpiochip_add(struct gpio_chip *chip) | |||
297 | 295 | ||
298 | return 0; | 296 | return 0; |
299 | 297 | ||
300 | unlock: | 298 | err_remove_chip: |
299 | acpi_gpiochip_remove(chip); | ||
300 | of_gpiochip_remove(chip); | ||
301 | spin_lock_irqsave(&gpio_lock, flags); | ||
302 | list_del(&chip->list); | ||
301 | spin_unlock_irqrestore(&gpio_lock, flags); | 303 | spin_unlock_irqrestore(&gpio_lock, flags); |
302 | fail: | ||
303 | kfree(descs); | ||
304 | chip->desc = NULL; | 304 | chip->desc = NULL; |
305 | err_free_descs: | ||
306 | kfree(descs); | ||
305 | 307 | ||
306 | /* failures here can mean systems won't boot... */ | 308 | /* failures here can mean systems won't boot... */ |
307 | 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__, |
@@ -325,14 +327,15 @@ void gpiochip_remove(struct gpio_chip *chip) | |||
325 | unsigned long flags; | 327 | unsigned long flags; |
326 | unsigned id; | 328 | unsigned id; |
327 | 329 | ||
328 | acpi_gpiochip_remove(chip); | 330 | gpiochip_unexport(chip); |
329 | |||
330 | spin_lock_irqsave(&gpio_lock, flags); | ||
331 | 331 | ||
332 | gpiochip_irqchip_remove(chip); | 332 | gpiochip_irqchip_remove(chip); |
333 | |||
334 | acpi_gpiochip_remove(chip); | ||
333 | gpiochip_remove_pin_ranges(chip); | 335 | gpiochip_remove_pin_ranges(chip); |
334 | of_gpiochip_remove(chip); | 336 | of_gpiochip_remove(chip); |
335 | 337 | ||
338 | spin_lock_irqsave(&gpio_lock, flags); | ||
336 | for (id = 0; id < chip->ngpio; id++) { | 339 | for (id = 0; id < chip->ngpio; id++) { |
337 | if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) | 340 | if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) |
338 | dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); | 341 | dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); |
@@ -342,7 +345,6 @@ void gpiochip_remove(struct gpio_chip *chip) | |||
342 | 345 | ||
343 | list_del(&chip->list); | 346 | list_del(&chip->list); |
344 | spin_unlock_irqrestore(&gpio_lock, flags); | 347 | spin_unlock_irqrestore(&gpio_lock, flags); |
345 | gpiochip_unexport(chip); | ||
346 | 348 | ||
347 | kfree(chip->desc); | 349 | kfree(chip->desc); |
348 | chip->desc = NULL; | 350 | chip->desc = NULL; |