diff options
Diffstat (limited to 'drivers/input/keyboard/gpio_keys.c')
-rw-r--r-- | drivers/input/keyboard/gpio_keys.c | 74 |
1 files changed, 25 insertions, 49 deletions
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 2db13246eb8e..52dc872c23c0 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
@@ -578,23 +578,18 @@ gpio_keys_get_devtree_pdata(struct device *dev) | |||
578 | int i; | 578 | int i; |
579 | 579 | ||
580 | node = dev->of_node; | 580 | node = dev->of_node; |
581 | if (!node) { | 581 | if (!node) |
582 | error = -ENODEV; | 582 | return ERR_PTR(-ENODEV); |
583 | goto err_out; | ||
584 | } | ||
585 | 583 | ||
586 | nbuttons = of_get_child_count(node); | 584 | nbuttons = of_get_child_count(node); |
587 | if (nbuttons == 0) { | 585 | if (nbuttons == 0) |
588 | error = -ENODEV; | 586 | return ERR_PTR(-ENODEV); |
589 | goto err_out; | ||
590 | } | ||
591 | 587 | ||
592 | pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), | 588 | pdata = devm_kzalloc(dev, |
593 | GFP_KERNEL); | 589 | sizeof(*pdata) + nbuttons * sizeof(*button), |
594 | if (!pdata) { | 590 | GFP_KERNEL); |
595 | error = -ENOMEM; | 591 | if (!pdata) |
596 | goto err_out; | 592 | return ERR_PTR(-ENOMEM); |
597 | } | ||
598 | 593 | ||
599 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); | 594 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); |
600 | pdata->nbuttons = nbuttons; | 595 | pdata->nbuttons = nbuttons; |
@@ -619,7 +614,7 @@ gpio_keys_get_devtree_pdata(struct device *dev) | |||
619 | dev_err(dev, | 614 | dev_err(dev, |
620 | "Failed to get gpio flags, error: %d\n", | 615 | "Failed to get gpio flags, error: %d\n", |
621 | error); | 616 | error); |
622 | goto err_free_pdata; | 617 | return ERR_PTR(error); |
623 | } | 618 | } |
624 | 619 | ||
625 | button = &pdata->buttons[i++]; | 620 | button = &pdata->buttons[i++]; |
@@ -630,8 +625,7 @@ gpio_keys_get_devtree_pdata(struct device *dev) | |||
630 | if (of_property_read_u32(pp, "linux,code", &button->code)) { | 625 | if (of_property_read_u32(pp, "linux,code", &button->code)) { |
631 | dev_err(dev, "Button without keycode: 0x%x\n", | 626 | dev_err(dev, "Button without keycode: 0x%x\n", |
632 | button->gpio); | 627 | button->gpio); |
633 | error = -EINVAL; | 628 | return ERR_PTR(-EINVAL); |
634 | goto err_free_pdata; | ||
635 | } | 629 | } |
636 | 630 | ||
637 | button->desc = of_get_property(pp, "label", NULL); | 631 | button->desc = of_get_property(pp, "label", NULL); |
@@ -646,17 +640,10 @@ gpio_keys_get_devtree_pdata(struct device *dev) | |||
646 | button->debounce_interval = 5; | 640 | button->debounce_interval = 5; |
647 | } | 641 | } |
648 | 642 | ||
649 | if (pdata->nbuttons == 0) { | 643 | if (pdata->nbuttons == 0) |
650 | error = -EINVAL; | 644 | return ERR_PTR(-EINVAL); |
651 | goto err_free_pdata; | ||
652 | } | ||
653 | 645 | ||
654 | return pdata; | 646 | return pdata; |
655 | |||
656 | err_free_pdata: | ||
657 | kfree(pdata); | ||
658 | err_out: | ||
659 | return ERR_PTR(error); | ||
660 | } | 647 | } |
661 | 648 | ||
662 | static struct of_device_id gpio_keys_of_match[] = { | 649 | static struct of_device_id gpio_keys_of_match[] = { |
@@ -691,6 +678,7 @@ static int gpio_keys_probe(struct platform_device *pdev) | |||
691 | const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); | 678 | const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); |
692 | struct gpio_keys_drvdata *ddata; | 679 | struct gpio_keys_drvdata *ddata; |
693 | struct input_dev *input; | 680 | struct input_dev *input; |
681 | size_t size; | ||
694 | int i, error; | 682 | int i, error; |
695 | int wakeup = 0; | 683 | int wakeup = 0; |
696 | 684 | ||
@@ -700,14 +688,18 @@ static int gpio_keys_probe(struct platform_device *pdev) | |||
700 | return PTR_ERR(pdata); | 688 | return PTR_ERR(pdata); |
701 | } | 689 | } |
702 | 690 | ||
703 | ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + | 691 | size = sizeof(struct gpio_keys_drvdata) + |
704 | pdata->nbuttons * sizeof(struct gpio_button_data), | 692 | pdata->nbuttons * sizeof(struct gpio_button_data); |
705 | GFP_KERNEL); | 693 | ddata = devm_kzalloc(dev, size, GFP_KERNEL); |
706 | input = input_allocate_device(); | 694 | if (!ddata) { |
707 | if (!ddata || !input) { | ||
708 | dev_err(dev, "failed to allocate state\n"); | 695 | dev_err(dev, "failed to allocate state\n"); |
709 | error = -ENOMEM; | 696 | return -ENOMEM; |
710 | goto fail1; | 697 | } |
698 | |||
699 | input = devm_input_allocate_device(dev); | ||
700 | if (!input) { | ||
701 | dev_err(dev, "failed to allocate input device\n"); | ||
702 | return -ENOMEM; | ||
711 | } | 703 | } |
712 | 704 | ||
713 | ddata->pdata = pdata; | 705 | ddata->pdata = pdata; |
@@ -768,20 +760,12 @@ static int gpio_keys_probe(struct platform_device *pdev) | |||
768 | while (--i >= 0) | 760 | while (--i >= 0) |
769 | gpio_remove_key(&ddata->data[i]); | 761 | gpio_remove_key(&ddata->data[i]); |
770 | 762 | ||
771 | fail1: | ||
772 | input_free_device(input); | ||
773 | kfree(ddata); | ||
774 | /* If we have no platform data, we allocated pdata dynamically. */ | ||
775 | if (!dev_get_platdata(&pdev->dev)) | ||
776 | kfree(pdata); | ||
777 | |||
778 | return error; | 763 | return error; |
779 | } | 764 | } |
780 | 765 | ||
781 | static int gpio_keys_remove(struct platform_device *pdev) | 766 | static int gpio_keys_remove(struct platform_device *pdev) |
782 | { | 767 | { |
783 | struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); | 768 | struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); |
784 | struct input_dev *input = ddata->input; | ||
785 | int i; | 769 | int i; |
786 | 770 | ||
787 | sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); | 771 | sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); |
@@ -791,14 +775,6 @@ static int gpio_keys_remove(struct platform_device *pdev) | |||
791 | for (i = 0; i < ddata->pdata->nbuttons; i++) | 775 | for (i = 0; i < ddata->pdata->nbuttons; i++) |
792 | gpio_remove_key(&ddata->data[i]); | 776 | gpio_remove_key(&ddata->data[i]); |
793 | 777 | ||
794 | input_unregister_device(input); | ||
795 | |||
796 | /* If we have no platform data, we allocated pdata dynamically. */ | ||
797 | if (!dev_get_platdata(&pdev->dev)) | ||
798 | kfree(ddata->pdata); | ||
799 | |||
800 | kfree(ddata); | ||
801 | |||
802 | return 0; | 778 | return 0; |
803 | } | 779 | } |
804 | 780 | ||