forked from Minki/linux
Input: samsung-keypad - switch to using managed resources
devm_* functions are device managed and make error handling and code simpler. While at it also fix error exit paths. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
9336648978
commit
a57da34795
@ -309,7 +309,7 @@ static void samsung_keypad_parse_dt_gpio(struct device *dev,
|
|||||||
struct samsung_keypad *keypad)
|
struct samsung_keypad *keypad)
|
||||||
{
|
{
|
||||||
struct device_node *np = dev->of_node;
|
struct device_node *np = dev->of_node;
|
||||||
int gpio, ret, row, col;
|
int gpio, error, row, col;
|
||||||
|
|
||||||
for (row = 0; row < keypad->rows; row++) {
|
for (row = 0; row < keypad->rows; row++) {
|
||||||
gpio = of_get_named_gpio(np, "row-gpios", row);
|
gpio = of_get_named_gpio(np, "row-gpios", row);
|
||||||
@ -320,10 +320,11 @@ static void samsung_keypad_parse_dt_gpio(struct device *dev,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gpio_request(gpio, "keypad-row");
|
error = devm_gpio_request(dev, gpio, "keypad-row");
|
||||||
if (ret)
|
if (error)
|
||||||
dev_err(dev, "keypad row[%d] gpio request failed\n",
|
dev_err(dev,
|
||||||
row);
|
"keypad row[%d] gpio request failed: %d\n",
|
||||||
|
row, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (col = 0; col < keypad->cols; col++) {
|
for (col = 0; col < keypad->cols; col++) {
|
||||||
@ -335,35 +336,19 @@ static void samsung_keypad_parse_dt_gpio(struct device *dev,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gpio_request(gpio, "keypad-col");
|
error = devm_gpio_request(dev, gpio, "keypad-col");
|
||||||
if (ret)
|
if (error)
|
||||||
dev_err(dev, "keypad column[%d] gpio request failed\n",
|
dev_err(dev,
|
||||||
col);
|
"keypad column[%d] gpio request failed: %d\n",
|
||||||
|
col, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void samsung_keypad_dt_gpio_free(struct samsung_keypad *keypad)
|
|
||||||
{
|
|
||||||
int cnt;
|
|
||||||
|
|
||||||
for (cnt = 0; cnt < keypad->rows; cnt++)
|
|
||||||
if (gpio_is_valid(keypad->row_gpios[cnt]))
|
|
||||||
gpio_free(keypad->row_gpios[cnt]);
|
|
||||||
|
|
||||||
for (cnt = 0; cnt < keypad->cols; cnt++)
|
|
||||||
if (gpio_is_valid(keypad->col_gpios[cnt]))
|
|
||||||
gpio_free(keypad->col_gpios[cnt]);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
static
|
static
|
||||||
struct samsung_keypad_platdata *samsung_keypad_parse_dt(struct device *dev)
|
struct samsung_keypad_platdata *samsung_keypad_parse_dt(struct device *dev)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void samsung_keypad_dt_gpio_free(struct samsung_keypad *keypad)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int samsung_keypad_probe(struct platform_device *pdev)
|
static int samsung_keypad_probe(struct platform_device *pdev)
|
||||||
@ -405,36 +390,30 @@ static int samsung_keypad_probe(struct platform_device *pdev)
|
|||||||
row_shift = get_count_order(pdata->cols);
|
row_shift = get_count_order(pdata->cols);
|
||||||
keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
|
keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
|
||||||
|
|
||||||
keypad = kzalloc(sizeof(*keypad) + keymap_size, GFP_KERNEL);
|
keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size,
|
||||||
input_dev = input_allocate_device();
|
GFP_KERNEL);
|
||||||
if (!keypad || !input_dev) {
|
input_dev = devm_input_allocate_device(&pdev->dev);
|
||||||
error = -ENOMEM;
|
if (!keypad || !input_dev)
|
||||||
goto err_free_mem;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!res) {
|
if (!res)
|
||||||
error = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_free_mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
keypad->base = ioremap(res->start, resource_size(res));
|
keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
|
||||||
if (!keypad->base) {
|
if (!keypad->base)
|
||||||
error = -EBUSY;
|
return -EBUSY;
|
||||||
goto err_free_mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
keypad->clk = clk_get(&pdev->dev, "keypad");
|
keypad->clk = devm_clk_get(&pdev->dev, "keypad");
|
||||||
if (IS_ERR(keypad->clk)) {
|
if (IS_ERR(keypad->clk)) {
|
||||||
dev_err(&pdev->dev, "failed to get keypad clk\n");
|
dev_err(&pdev->dev, "failed to get keypad clk\n");
|
||||||
error = PTR_ERR(keypad->clk);
|
return PTR_ERR(keypad->clk);
|
||||||
goto err_unmap_base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error = clk_prepare(keypad->clk);
|
error = clk_prepare(keypad->clk);
|
||||||
if (error) {
|
if (error) {
|
||||||
dev_err(&pdev->dev, "keypad clock prepare failed\n");
|
dev_err(&pdev->dev, "keypad clock prepare failed\n");
|
||||||
goto err_put_clk;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
keypad->input_dev = input_dev;
|
keypad->input_dev = input_dev;
|
||||||
@ -479,14 +458,15 @@ static int samsung_keypad_probe(struct platform_device *pdev)
|
|||||||
keypad->irq = platform_get_irq(pdev, 0);
|
keypad->irq = platform_get_irq(pdev, 0);
|
||||||
if (keypad->irq < 0) {
|
if (keypad->irq < 0) {
|
||||||
error = keypad->irq;
|
error = keypad->irq;
|
||||||
goto err_put_clk;
|
goto err_unprepare_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = request_threaded_irq(keypad->irq, NULL, samsung_keypad_irq,
|
error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL,
|
||||||
IRQF_ONESHOT, dev_name(&pdev->dev), keypad);
|
samsung_keypad_irq, IRQF_ONESHOT,
|
||||||
|
dev_name(&pdev->dev), keypad);
|
||||||
if (error) {
|
if (error) {
|
||||||
dev_err(&pdev->dev, "failed to register keypad interrupt\n");
|
dev_err(&pdev->dev, "failed to register keypad interrupt\n");
|
||||||
goto err_put_clk;
|
goto err_unprepare_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_init_wakeup(&pdev->dev, pdata->wakeup);
|
device_init_wakeup(&pdev->dev, pdata->wakeup);
|
||||||
@ -495,7 +475,7 @@ static int samsung_keypad_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
error = input_register_device(keypad->input_dev);
|
error = input_register_device(keypad->input_dev);
|
||||||
if (error)
|
if (error)
|
||||||
goto err_free_irq;
|
goto err_disable_runtime_pm;
|
||||||
|
|
||||||
if (pdev->dev.of_node) {
|
if (pdev->dev.of_node) {
|
||||||
devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
|
devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
|
||||||
@ -504,22 +484,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free_irq:
|
err_disable_runtime_pm:
|
||||||
free_irq(keypad->irq, keypad);
|
|
||||||
pm_runtime_disable(&pdev->dev);
|
pm_runtime_disable(&pdev->dev);
|
||||||
device_init_wakeup(&pdev->dev, 0);
|
device_init_wakeup(&pdev->dev, 0);
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
err_unprepare_clk:
|
err_unprepare_clk:
|
||||||
clk_unprepare(keypad->clk);
|
clk_unprepare(keypad->clk);
|
||||||
err_put_clk:
|
|
||||||
clk_put(keypad->clk);
|
|
||||||
samsung_keypad_dt_gpio_free(keypad);
|
|
||||||
err_unmap_base:
|
|
||||||
iounmap(keypad->base);
|
|
||||||
err_free_mem:
|
|
||||||
input_free_device(input_dev);
|
|
||||||
kfree(keypad);
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,18 +503,7 @@ static int samsung_keypad_remove(struct platform_device *pdev)
|
|||||||
|
|
||||||
input_unregister_device(keypad->input_dev);
|
input_unregister_device(keypad->input_dev);
|
||||||
|
|
||||||
/*
|
|
||||||
* It is safe to free IRQ after unregistering device because
|
|
||||||
* samsung_keypad_close will shut off interrupts.
|
|
||||||
*/
|
|
||||||
free_irq(keypad->irq, keypad);
|
|
||||||
|
|
||||||
clk_unprepare(keypad->clk);
|
clk_unprepare(keypad->clk);
|
||||||
clk_put(keypad->clk);
|
|
||||||
samsung_keypad_dt_gpio_free(keypad);
|
|
||||||
|
|
||||||
iounmap(keypad->base);
|
|
||||||
kfree(keypad);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user