Input: twl4030 - convert to using managed resources
Sebastian Reichel
Tested-byQuoted 7 lines · Dmitry Torokhov
Signed-off-by Dmitry Torokhov <[email protected]>---
Compile-tested only.
drivers/input/keyboard/twl4030_keypad.c | 70 +++++++++++---------------------- 1 file changed, 22 insertions(+), 48 deletions(-)
I have successfully booted dtor/input.git:master with this patch on top and the addition of twl4030-keypad DT nodes in omap3-n900.dts on my N900.
-- Sebastian
Quoted 14 lines · Dmitry Torokhov
Signed-off-by Dmitry Torokhov <[email protected]>---
Compile-tested only.
drivers/input/keyboard/twl4030_keypad.c | 70 +++++++++++---------------------- 1 file changed, 22 insertions(+), 48 deletions(-)drivers/input/keyboard/twl4030_keypad.c +0
-0
[.....]
drivers/input/keyboard/twl4030_keypad.c
Quoted 6 lines
drivers/input/keyboard/twl4030_keypad.c +0
-6-static int twl4030_kp_remove (struct platform_device *pdev) -{ -struct twl4030_keypad *kp =platform_get_drvdata (pdev); - -free_irq (kp->irq, kp); -input_unregister_device (kp->input);
Hi Dmitry Torokhov,
IMHO, input_unregister_device() seems to be necessary, because input_register_device() is still used. If I am wrong, please let me know kindly.
Sebastian Reichel,
Would you repeat insmod & rmmod 'twl4030_keypad.ko'?
Happy New Year! :-)
Best regards,
Jingoo Han
Quoted 6 lines · Jingoo Han
IMHO,
input_unregister_device()seems to be necessary, becauseinput_register_device()is still used. If I am wrong, please let me know kindly.Sebastian Reichel,
Would you repeat insmod & rmmod 'twl4030_keypad.ko'?
mh. I only tested with twl4030-keypad compiled into the kernel. I will try building the driver as module and reloading it on the device when I find some time.
-- Sebastian
Quoted 11 lines · Sebastian Reichel
Quoted 6 lines · Jingoo Han
IMHO,
input_unregister_device()seems to be necessary, becauseinput_register_device()is still used. If I am wrong, please let me know kindly.Sebastian Reichel,
Would you repeat insmod & rmmod 'twl4030_keypad.ko'?mh. I only tested with twl4030-keypad compiled into the kernel. I will try building the driver as module and reloading it on the device when I find some time.
OK, I see. :-)
If you repeat at least twice insmod & rmmod 'twl4030_keypad.ko', it will be good. If there are some bugs, it will make the error messages or kernel panic.
In my case, Samsung Exynos SPI driver made kernel panic when Repeating insmod & rmmod twice, after the patch to covert to devm_* functions was applied. This was because there was a bug of devm_spi_register_master().
Thank you.
Best regards,
Jingoo Han
Quoted 3 lines · Jingoo Han
If you repeat at least twice insmod & rmmod 'twl4030_keypad.ko', it will be good. If there are some bugs, it will make the error messages or kernel panic.
I tried load & unloading the twl4030_keypad module multiple times. I didn't get any error messages or kernel panics. Everything seems to behave correctly.
-- Sebastian
Quoted 58 lines · Dmitry Torokhov
Quoted 27 lines · Jingoo Han
Quoted 14 lines · Dmitry Torokhov
Signed-off-by Dmitry Torokhov <[email protected]>---
Compile-tested only.
drivers/input/keyboard/twl4030_keypad.c | 70 +++++++++++---------------------- 1 file changed, 22 insertions(+), 48 deletions(-)drivers/input/keyboard/twl4030_keypad.c +0
-0[.....]
drivers/input/keyboard/twl4030_keypad.c
Quoted 6 lines
drivers/input/keyboard/twl4030_keypad.c +0
-6-static int twl4030_kp_remove (struct platform_device *pdev) -{ -struct twl4030_keypad *kp =platform_get_drvdata (pdev); - -free_irq (kp->irq, kp); -input_unregister_device (kp->input);Hi Dmitry Torokhov,
Quoted 3 lines
IMHO,
input_unregister_device()seems to be necessary, becauseinput_register_device()is still used. If I am wrong, please let me know kindly.No,
input_unregister_device()is not needed (although it can be used) with managed input devices (ones that are allocated withdevm_input_allocate_device()) becauseinput_register_device()will automatically insert devres entry for such devices. So for managed input devices that were registered with input subsystem there are 2 separate devres entries: one for unregistering the device and another is to finally release all resources. If you had a sequence:devm_kzalloc(...); devm_input_allocate_device(...); devm_devm_ioremap_resource(...); devm_request_irq(...); input_register_device(...);then unwind sequence will be:
unregister input device (but input device structure is still
present in memory andinput_event()can be called, but events won't be delivered anywhere - that is done so that we can survive releasing IRQs after unregistering managed input device)
free IRQ
release resources
free input device structure
free kzalloc memory
Quoted 1 line
Hope this helps.
Oh, I really appreciate your detailed and kind comments. :-)
I checked the following. As you said, input_register_device() automatically inserts devres entry.
./drivers/input/input.c
int input_register_device(struct input_dev *dev)
{
struct input_devres *devres = NULL;
struct input_handler *handler;
unsigned int packet_size;
const char *path;
int error;
if (dev->devres_managed) {
devres = devres_alloc(devm_input_device_unregister,
sizeof(struct input_devres), GFP_KERNEL);Thank you so much.
Best regards,
Jingoo Han
Quoted 8 lines · Sebastian Reichel
Quoted 3 lines · Jingoo Han
If you repeat at least twice insmod & rmmod 'twl4030_keypad.ko', it will be good. If there are some bugs, it will make the error messages or kernel panic.
I tried load & unloading the
twl4030_keypadmodule multiple times. I didn't get any error messages or kernel panics. Everything seems to behave correctly.
Thank you for your testing. :-)
I checked the sequence; it looks good.
See you later.
Best regards,
Jingoo Han
Jingoo Han
Reviewed-byQuoted 2 lines · Dmitry Torokhov
Signed-off-by Dmitry Torokhov <[email protected]>
It looks good.
Best regards,
Jingoo Han
Quoted 7 lines
---
Compile-tested only.
drivers/input/keyboard/twl4030_keypad.c | 70 +++++++++++---------------------- 1 file changed, 22 insertions(+), 48 deletions(-)