[PATCH v2] platform/x86: xo15-ebook: Use devres-based resource management

Rafael J. Wysocki posted 1 patch 3 weeks, 6 days ago
drivers/platform/x86/xo15-ebook.c |   43 ++++++++++++--------------------------
1 file changed, 14 insertions(+), 29 deletions(-)
[PATCH v2] platform/x86: xo15-ebook: Use devres-based resource management
Posted by Rafael J. Wysocki 3 weeks, 6 days ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

Use devm_kzalloc() and devm_input_allocate_device() in
ebook_switch_probe() for allocating the button object and the
input device, respectively, to simplify the rollback path in
that function and ebook_switch_remove().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2: Use dev_err_probe() after failing acpi_match_acpi_device() (Andy)

Applies on top of the driver conversion series

https://lore.kernel.org/linux-acpi/2420444.ElGaqSPkdT@rafael.j.wysocki/

---
 drivers/platform/x86/xo15-ebook.c |   43 ++++++++++++--------------------------
 1 file changed, 14 insertions(+), 29 deletions(-)

--- a/drivers/platform/x86/xo15-ebook.c
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -82,30 +82,28 @@ static SIMPLE_DEV_PM_OPS(ebook_switch_pm
 
 static int ebook_switch_probe(struct platform_device *pdev)
 {
-	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+	struct device *dev = &pdev->dev;
+	struct acpi_device *device = ACPI_COMPANION(dev);
 	const struct acpi_device_id *id;
 	struct ebook_switch *button;
 	struct input_dev *input;
 	int error;
 
-	button = kzalloc_obj(struct ebook_switch);
+	button = devm_kzalloc(dev, sizeof(*button), GFP_KERNEL);
 	if (!button)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, button);
 
-	button->input = input = input_allocate_device();
-	if (!input) {
-		error = -ENOMEM;
-		goto err_free_button;
-	}
+	input = devm_input_allocate_device(dev);
+	if (!input)
+		return -ENOMEM;
+
+	button->input = input;
 
 	id = acpi_match_acpi_device(ebook_device_ids, device);
-	if (!id) {
-		dev_err(&pdev->dev, "Unsupported hid\n");
-		error = -ENODEV;
-		goto err_free_input;
-	}
+	if (!id)
+		return dev_err_probe(dev, -ENODEV, "Unsupported hid\n");
 
 	strscpy(acpi_device_name(device), XO15_EBOOK_DEVICE_NAME);
 	strscpy(acpi_device_class(device), XO15_EBOOK_CLASS "/" XO15_EBOOK_SUBCLASS);
@@ -115,21 +113,20 @@ static int ebook_switch_probe(struct pla
 	input->name = acpi_device_name(device);
 	input->phys = button->phys;
 	input->id.bustype = BUS_HOST;
-	input->dev.parent = &pdev->dev;
 
 	input->evbit[0] = BIT_MASK(EV_SW);
 	set_bit(SW_TABLET_MODE, input->swbit);
 
 	error = input_register_device(input);
 	if (error)
-		goto err_free_input;
+		return error;
 
 	error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
-						ebook_switch_notify, &pdev->dev);
+						ebook_switch_notify, dev);
 	if (error)
-		goto err_unregister_input;
+		return error;
 
-	ebook_send_state(&pdev->dev);
+	ebook_send_state(dev);
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
@@ -139,16 +136,6 @@ static int ebook_switch_probe(struct pla
 	}
 
 	return 0;
-
-err_free_input:
-	input_free_device(input);
-err_free_button:
-	kfree(button);
-	return error;
-
-err_unregister_input:
-	input_unregister_device(input);
-	goto err_free_button;
 }
 
 static void ebook_switch_remove(struct platform_device *pdev)
@@ -162,8 +149,6 @@ static void ebook_switch_remove(struct p
 
 	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
 				       ebook_switch_notify);
-	input_unregister_device(button->input);
-	kfree(button);
 }
 
 static struct platform_driver xo15_ebook_driver = {
Re: [PATCH v2] platform/x86: xo15-ebook: Use devres-based resource management
Posted by Ilpo Järvinen 3 weeks, 2 days ago
On Fri, 15 May 2026 13:47:29 +0200, Rafael J. Wysocki wrote:

> Use devm_kzalloc() and devm_input_allocate_device() in
> ebook_switch_probe() for allocating the button object and the
> input device, respectively, to simplify the rollback path in
> that function and ebook_switch_remove().
> 
> 


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: xo15-ebook: Use devres-based resource management
      commit: a45c6d1a93d308552979e54d5d50b788d609b401

--
 i.
Re: [PATCH v2] platform/x86: xo15-ebook: Use devres-based resource management
Posted by Andy Shevchenko 3 weeks, 5 days ago
On Fri, May 15, 2026 at 01:47:29PM +0200, Rafael J. Wysocki wrote:

> Use devm_kzalloc() and devm_input_allocate_device() in
> ebook_switch_probe() for allocating the button object and the
> input device, respectively, to simplify the rollback path in
> that function and ebook_switch_remove().

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko