diff options
author | Anti Sullin <anti.sullin@artecdesign.ee> | 2007-09-26 00:01:03 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2007-09-26 00:01:03 -0400 |
commit | 006df3024431a50262d4a2898d25924f84fb697a (patch) | |
tree | 556a42e2e3bc47e947e509fff0ae6613db531628 /drivers | |
parent | 2a8281d72da5dd8da025e6822dadd23a35383895 (diff) |
Input: gpio_keys - verify that supplied GPIO numbers are valid
As David Brownell pointed out, gpio_keys driver does not check
return code of gpio_to_irq().
This patch adds the gpio_to_irq return code check to gpio_keys
and moves the IRQ edge type setting to request_irq flags to avoid
changing the irq type before we have confirmed we can use it.
Signed-off-by: Anti Sullin <anti.sullin@artecdesign.ee>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/keyboard/gpio_keys.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 739212252b09..b3069bc00f03 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
@@ -78,12 +78,24 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) | |||
78 | int irq = gpio_to_irq(button->gpio); | 78 | int irq = gpio_to_irq(button->gpio); |
79 | unsigned int type = button->type ?: EV_KEY; | 79 | unsigned int type = button->type ?: EV_KEY; |
80 | 80 | ||
81 | set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); | 81 | if (irq < 0) { |
82 | error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM, | 82 | error = irq; |
83 | button->desc ? button->desc : "gpio_keys", | 83 | printk(KERN_ERR |
84 | pdev); | 84 | "gpio-keys: " |
85 | "Unable to get irq number for GPIO %d," | ||
86 | "error %d\n", | ||
87 | button->gpio, error); | ||
88 | goto fail; | ||
89 | } | ||
90 | |||
91 | error = request_irq(irq, gpio_keys_isr, | ||
92 | IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_RISING | | ||
93 | IRQF_TRIGGER_FALLING, | ||
94 | button->desc ? button->desc : "gpio_keys", | ||
95 | pdev); | ||
85 | if (error) { | 96 | if (error) { |
86 | printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n", | 97 | printk(KERN_ERR |
98 | "gpio-keys: Unable to claim irq %d; error %d\n", | ||
87 | irq, error); | 99 | irq, error); |
88 | goto fail; | 100 | goto fail; |
89 | } | 101 | } |
@@ -93,16 +105,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) | |||
93 | 105 | ||
94 | error = input_register_device(input); | 106 | error = input_register_device(input); |
95 | if (error) { | 107 | if (error) { |
96 | printk(KERN_ERR "Unable to register gpio-keys input device\n"); | 108 | printk(KERN_ERR |
109 | "gpio-keys: Unable to register input device, " | ||
110 | "error: %d\n", error); | ||
97 | goto fail; | 111 | goto fail; |
98 | } | 112 | } |
99 | 113 | ||
100 | return 0; | 114 | return 0; |
101 | 115 | ||
102 | fail: | 116 | fail: |
103 | for (i = i - 1; i >= 0; i--) | 117 | while (--i >= 0) |
104 | free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev); | 118 | free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev); |
105 | 119 | ||
120 | platform_set_drvdata(pdev, NULL); | ||
106 | input_free_device(input); | 121 | input_free_device(input); |
107 | 122 | ||
108 | return error; | 123 | return error; |