diff options
author | Guenter Roeck <linux@roeck-us.net> | 2016-03-31 11:11:29 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-04-08 04:10:09 -0400 |
commit | 476e2fc5cd430bbe17598833e79f8e8b9e4bbbc7 (patch) | |
tree | 89d991aa2df44ae4cbb2917ef4dda6ff55c57745 /drivers/gpio | |
parent | c4e5ffb6f224c1a4a9eaad82b19645ec22d1b24f (diff) |
gpiolib: Do not use devm functions when registering gpio chip
It is possible that a gpio chip is registered before the gpiolib
initialization code has run. This means we can not use devm_ functions
to allocate memory at that time. Do it the old fashioned way.
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: Greg Ungerer <gerg@uclinux.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpiolib.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4a0e66b2b357..5ca7c9aa4fab 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -440,6 +440,8 @@ static void gpiodevice_release(struct device *dev) | |||
440 | cdev_del(&gdev->chrdev); | 440 | cdev_del(&gdev->chrdev); |
441 | list_del(&gdev->list); | 441 | list_del(&gdev->list); |
442 | ida_simple_remove(&gpio_ida, gdev->id); | 442 | ida_simple_remove(&gpio_ida, gdev->id); |
443 | kfree(gdev->label); | ||
444 | kfree(gdev->descs); | ||
443 | kfree(gdev); | 445 | kfree(gdev); |
444 | } | 446 | } |
445 | 447 | ||
@@ -504,8 +506,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
504 | else | 506 | else |
505 | gdev->owner = THIS_MODULE; | 507 | gdev->owner = THIS_MODULE; |
506 | 508 | ||
507 | gdev->descs = devm_kcalloc(&gdev->dev, chip->ngpio, | 509 | gdev->descs = kcalloc(chip->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); |
508 | sizeof(gdev->descs[0]), GFP_KERNEL); | ||
509 | if (!gdev->descs) { | 510 | if (!gdev->descs) { |
510 | status = -ENOMEM; | 511 | status = -ENOMEM; |
511 | goto err_free_gdev; | 512 | goto err_free_gdev; |
@@ -518,12 +519,12 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
518 | } | 519 | } |
519 | 520 | ||
520 | if (chip->label) | 521 | if (chip->label) |
521 | gdev->label = devm_kstrdup(&gdev->dev, chip->label, GFP_KERNEL); | 522 | gdev->label = kstrdup(chip->label, GFP_KERNEL); |
522 | else | 523 | else |
523 | gdev->label = devm_kstrdup(&gdev->dev, "unknown", GFP_KERNEL); | 524 | gdev->label = kstrdup("unknown", GFP_KERNEL); |
524 | if (!gdev->label) { | 525 | if (!gdev->label) { |
525 | status = -ENOMEM; | 526 | status = -ENOMEM; |
526 | goto err_free_gdev; | 527 | goto err_free_descs; |
527 | } | 528 | } |
528 | 529 | ||
529 | gdev->ngpio = chip->ngpio; | 530 | gdev->ngpio = chip->ngpio; |
@@ -543,7 +544,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
543 | if (base < 0) { | 544 | if (base < 0) { |
544 | status = base; | 545 | status = base; |
545 | spin_unlock_irqrestore(&gpio_lock, flags); | 546 | spin_unlock_irqrestore(&gpio_lock, flags); |
546 | goto err_free_gdev; | 547 | goto err_free_label; |
547 | } | 548 | } |
548 | /* | 549 | /* |
549 | * TODO: it should not be necessary to reflect the assigned | 550 | * TODO: it should not be necessary to reflect the assigned |
@@ -558,7 +559,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
558 | status = gpiodev_add_to_list(gdev); | 559 | status = gpiodev_add_to_list(gdev); |
559 | if (status) { | 560 | if (status) { |
560 | spin_unlock_irqrestore(&gpio_lock, flags); | 561 | spin_unlock_irqrestore(&gpio_lock, flags); |
561 | goto err_free_gdev; | 562 | goto err_free_label; |
562 | } | 563 | } |
563 | 564 | ||
564 | for (i = 0; i < chip->ngpio; i++) { | 565 | for (i = 0; i < chip->ngpio; i++) { |
@@ -637,6 +638,10 @@ err_remove_from_list: | |||
637 | spin_lock_irqsave(&gpio_lock, flags); | 638 | spin_lock_irqsave(&gpio_lock, flags); |
638 | list_del(&gdev->list); | 639 | list_del(&gdev->list); |
639 | spin_unlock_irqrestore(&gpio_lock, flags); | 640 | spin_unlock_irqrestore(&gpio_lock, flags); |
641 | err_free_label: | ||
642 | kfree(gdev->label); | ||
643 | err_free_descs: | ||
644 | kfree(gdev->descs); | ||
640 | err_free_gdev: | 645 | err_free_gdev: |
641 | ida_simple_remove(&gpio_ida, gdev->id); | 646 | ida_simple_remove(&gpio_ida, gdev->id); |
642 | /* failures here can mean systems won't boot... */ | 647 | /* failures here can mean systems won't boot... */ |