mirror of https://gitee.com/openkylin/linux.git
Input: omap4-keypad - fix runtime PM error handling
In omap4_keypad_probe, the patch fix several bugs. 1) pm_runtime_get_sync will increment pm usage counter even it failed. Forgetting to pm_runtime_put_noidle will result in reference leak. 2) In err_unmap, forget to disable runtime of device, pm_runtime_enable will increase power disable depth. Thus a pairing decrement is needed on the error handling path to keep it balanced. 3) In err_pm_disable, it will call pm_runtime_put_sync twice not one time. To fix this we factor out code reading revision and disabling touchpad, and drop PM reference once we are done talking to the device. Fixes:f77621cc64
("Input: omap-keypad - dynamically handle register offsets") Fixes:5ad567ffba
("Input: omap4-keypad - wire up runtime PM handling") Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> Link: https://lore.kernel.org/r/20201120133918.2559681-1-zhangqilong3@huawei.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
3aa40a1ad3
commit
59bbf83835
|
@ -186,12 +186,8 @@ static int omap4_keypad_open(struct input_dev *input)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void omap4_keypad_close(struct input_dev *input)
|
static void omap4_keypad_stop(struct omap4_keypad *keypad_data)
|
||||||
{
|
{
|
||||||
struct omap4_keypad *keypad_data = input_get_drvdata(input);
|
|
||||||
|
|
||||||
disable_irq(keypad_data->irq);
|
|
||||||
|
|
||||||
/* Disable interrupts and wake-up events */
|
/* Disable interrupts and wake-up events */
|
||||||
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
|
||||||
OMAP4_VAL_IRQDISABLE);
|
OMAP4_VAL_IRQDISABLE);
|
||||||
|
@ -200,7 +196,15 @@ static void omap4_keypad_close(struct input_dev *input)
|
||||||
/* clear pending interrupts */
|
/* clear pending interrupts */
|
||||||
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
|
||||||
kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
|
kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void omap4_keypad_close(struct input_dev *input)
|
||||||
|
{
|
||||||
|
struct omap4_keypad *keypad_data;
|
||||||
|
|
||||||
|
keypad_data = input_get_drvdata(input);
|
||||||
|
disable_irq(keypad_data->irq);
|
||||||
|
omap4_keypad_stop(keypad_data);
|
||||||
enable_irq(keypad_data->irq);
|
enable_irq(keypad_data->irq);
|
||||||
|
|
||||||
pm_runtime_put_sync(input->dev.parent);
|
pm_runtime_put_sync(input->dev.parent);
|
||||||
|
@ -223,13 +227,37 @@ static int omap4_keypad_parse_dt(struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int omap4_keypad_check_revision(struct device *dev,
|
||||||
|
struct omap4_keypad *keypad_data)
|
||||||
|
{
|
||||||
|
unsigned int rev;
|
||||||
|
|
||||||
|
rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
|
||||||
|
rev &= 0x03 << 30;
|
||||||
|
rev >>= 30;
|
||||||
|
switch (rev) {
|
||||||
|
case KBD_REVISION_OMAP4:
|
||||||
|
keypad_data->reg_offset = 0x00;
|
||||||
|
keypad_data->irqreg_offset = 0x00;
|
||||||
|
break;
|
||||||
|
case KBD_REVISION_OMAP5:
|
||||||
|
keypad_data->reg_offset = 0x10;
|
||||||
|
keypad_data->irqreg_offset = 0x0c;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(dev, "Keypad reports unsupported revision %d", rev);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int omap4_keypad_probe(struct platform_device *pdev)
|
static int omap4_keypad_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct omap4_keypad *keypad_data;
|
struct omap4_keypad *keypad_data;
|
||||||
struct input_dev *input_dev;
|
struct input_dev *input_dev;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
unsigned int max_keys;
|
unsigned int max_keys;
|
||||||
int rev;
|
|
||||||
int irq;
|
int irq;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
@ -269,41 +297,33 @@ static int omap4_keypad_probe(struct platform_device *pdev)
|
||||||
goto err_release_mem;
|
goto err_release_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pm_runtime_enable(&pdev->dev);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enable clocks for the keypad module so that we can read
|
* Enable clocks for the keypad module so that we can read
|
||||||
* revision register.
|
* revision register.
|
||||||
*/
|
*/
|
||||||
pm_runtime_enable(&pdev->dev);
|
|
||||||
error = pm_runtime_get_sync(&pdev->dev);
|
error = pm_runtime_get_sync(&pdev->dev);
|
||||||
if (error) {
|
if (error) {
|
||||||
dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
|
dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
|
||||||
goto err_unmap;
|
pm_runtime_put_noidle(&pdev->dev);
|
||||||
}
|
} else {
|
||||||
rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
|
error = omap4_keypad_check_revision(&pdev->dev,
|
||||||
rev &= 0x03 << 30;
|
keypad_data);
|
||||||
rev >>= 30;
|
if (!error) {
|
||||||
switch (rev) {
|
/* Ensure device does not raise interrupts */
|
||||||
case KBD_REVISION_OMAP4:
|
omap4_keypad_stop(keypad_data);
|
||||||
keypad_data->reg_offset = 0x00;
|
}
|
||||||
keypad_data->irqreg_offset = 0x00;
|
pm_runtime_put_sync(&pdev->dev);
|
||||||
break;
|
|
||||||
case KBD_REVISION_OMAP5:
|
|
||||||
keypad_data->reg_offset = 0x10;
|
|
||||||
keypad_data->irqreg_offset = 0x0c;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dev_err(&pdev->dev,
|
|
||||||
"Keypad reports unsupported revision %d", rev);
|
|
||||||
error = -EINVAL;
|
|
||||||
goto err_pm_put_sync;
|
|
||||||
}
|
}
|
||||||
|
if (error)
|
||||||
|
goto err_pm_disable;
|
||||||
|
|
||||||
/* input device allocation */
|
/* input device allocation */
|
||||||
keypad_data->input = input_dev = input_allocate_device();
|
keypad_data->input = input_dev = input_allocate_device();
|
||||||
if (!input_dev) {
|
if (!input_dev) {
|
||||||
error = -ENOMEM;
|
error = -ENOMEM;
|
||||||
goto err_pm_put_sync;
|
goto err_pm_disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_dev->name = pdev->name;
|
input_dev->name = pdev->name;
|
||||||
|
@ -349,28 +369,25 @@ static int omap4_keypad_probe(struct platform_device *pdev)
|
||||||
goto err_free_keymap;
|
goto err_free_keymap;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_init_wakeup(&pdev->dev, true);
|
|
||||||
pm_runtime_put_sync(&pdev->dev);
|
|
||||||
|
|
||||||
error = input_register_device(keypad_data->input);
|
error = input_register_device(keypad_data->input);
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
dev_err(&pdev->dev, "failed to register input device\n");
|
dev_err(&pdev->dev, "failed to register input device\n");
|
||||||
goto err_pm_disable;
|
goto err_free_irq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device_init_wakeup(&pdev->dev, true);
|
||||||
platform_set_drvdata(pdev, keypad_data);
|
platform_set_drvdata(pdev, keypad_data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_pm_disable:
|
err_free_irq:
|
||||||
pm_runtime_disable(&pdev->dev);
|
|
||||||
free_irq(keypad_data->irq, keypad_data);
|
free_irq(keypad_data->irq, keypad_data);
|
||||||
err_free_keymap:
|
err_free_keymap:
|
||||||
kfree(keypad_data->keymap);
|
kfree(keypad_data->keymap);
|
||||||
err_free_input:
|
err_free_input:
|
||||||
input_free_device(input_dev);
|
input_free_device(input_dev);
|
||||||
err_pm_put_sync:
|
err_pm_disable:
|
||||||
pm_runtime_put_sync(&pdev->dev);
|
pm_runtime_disable(&pdev->dev);
|
||||||
err_unmap:
|
|
||||||
iounmap(keypad_data->base);
|
iounmap(keypad_data->base);
|
||||||
err_release_mem:
|
err_release_mem:
|
||||||
release_mem_region(res->start, resource_size(res));
|
release_mem_region(res->start, resource_size(res));
|
||||||
|
|
Loading…
Reference in New Issue