[PATCH v2] platform/x86: adv_swbutton: use devm_add_action_or_reset() for cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Current code leaves the device's wakeup enabled in the error path of
.probe() and .remove(). Also, the registered input device is not
unregistered. Add a devm_add_action_or_reset() call and cleanup these
resources in the callback.

Fixes: 3d904005f686 ("platform/x86: add support for Advantech software defined button")
Signed-off-by: Joe Hattori <joe@xxxxxxxxxxxxxxxxxxxxx>
---
Changes in V2:
- Use devm_add_action_or_reset().
- Call input_unregister_device().
---
 drivers/platform/x86/adv_swbutton.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/platform/x86/adv_swbutton.c b/drivers/platform/x86/adv_swbutton.c
index 6fa60f3fc53c..5b07c42adfad 100644
--- a/drivers/platform/x86/adv_swbutton.c
+++ b/drivers/platform/x86/adv_swbutton.c
@@ -44,6 +44,14 @@ static void adv_swbutton_notify(acpi_handle handle, u32 event, void *context)
 	}
 }
 
+static void adv_swbutton_release(void *__input)
+{
+	struct input_dev *input = __input;
+
+	input_unregister_device(input);
+	device_init_wakeup(input->dev.parent, false);
+}
+
 static int adv_swbutton_probe(struct platform_device *device)
 {
 	struct adv_swbutton *button;
@@ -78,6 +86,9 @@ static int adv_swbutton_probe(struct platform_device *device)
 
 	device_init_wakeup(&device->dev, true);
 
+	if (devm_add_action_or_reset(&device->dev, adv_swbutton_release, input))
+		return -ENOMEM;
+
 	status = acpi_install_notify_handler(handle,
 					     ACPI_DEVICE_NOTIFY,
 					     adv_swbutton_notify,
-- 
2.34.1





[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux