From: "Rafael J. Wysocki" <rafael@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux ACPI <linux-acpi@vger.kernel.org>,
Hans de Goede <hansg@kernel.org>,
platform-driver-x86@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1] platform/x86: xo15-ebook: Use devres-based resource management
Date: Wed, 13 May 2026 20:53:44 +0200 [thread overview]
Message-ID: <12913455.O9o76ZdvQC@rafael.j.wysocki> (raw)
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>
---
As promised, on top of
https://lore.kernel.org/linux-acpi/2420444.ElGaqSPkdT@rafael.j.wysocki/
---
drivers/platform/x86/xo15-ebook.c | 41 ++++++++++++--------------------------
1 file changed, 14 insertions(+), 27 deletions(-)
--- a/drivers/platform/x86/xo15-ebook.c
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -82,29 +82,29 @@ 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;
+ dev_err(dev, "Unsupported hid\n");
+ return -ENODEV;
}
strscpy(acpi_device_name(device), XO15_EBOOK_DEVICE_NAME);
@@ -115,21 +115,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 +138,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 +151,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 = {
next reply other threads:[~2026-05-13 18:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 18:53 Rafael J. Wysocki [this message]
2026-05-13 20:42 ` [PATCH v1] platform/x86: xo15-ebook: Use devres-based resource management Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12913455.O9o76ZdvQC@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox