From: Alexander Kurz <akurz@blala.de>
To: "Lee Jones" <lee@kernel.org>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Dzmitry Sankouski" <dsankouski@gmail.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
"Heiko Stuebner" <heiko@sntech.de>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
devicetree@vger.kernel.org, linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Alexander Kurz <akurz@blala.de>
Subject: [PATCH v2 2/9] Input: mc13783-pwrbutton: use managed resources
Date: Sat, 23 Aug 2025 14:44:34 +0000 [thread overview]
Message-ID: <20250823144441.12654-3-akurz@blala.de> (raw)
In-Reply-To: <20250823144441.12654-1-akurz@blala.de>
Use devres functionality to simplify resource freeing, dev.parent will
be set by devm_input_allocate_device().
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/mc13783-pwrbutton.c | 28 ++++++++------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 4765b25bc9f6..9fd84b8d163d 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -21,6 +21,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/device.h>
#include <linux/errno.h>
#include <linux/input.h>
#include <linux/interrupt.h>
@@ -118,18 +119,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
return -ENODEV;
}
- pwr = input_allocate_device();
- if (!pwr) {
- dev_dbg(&pdev->dev, "Can't allocate power button\n");
+ pwr = devm_input_allocate_device(&pdev->dev);
+ if (!pwr)
return -ENOMEM;
- }
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (!priv) {
- err = -ENOMEM;
- dev_dbg(&pdev->dev, "Can't allocate power button\n");
- goto free_input_dev;
- }
+ priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
@@ -155,7 +151,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
button1_irq, "b1on", priv);
if (err) {
dev_dbg(&pdev->dev, "Can't request irq\n");
- goto free_priv;
+ goto free_mc13xxx_lock;
}
}
@@ -203,7 +199,6 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
pwr->name = "mc13783_pwrbutton";
pwr->phys = "mc13783_pwrbutton/input0";
- pwr->dev.parent = &pdev->dev;
pwr->keycode = priv->keymap;
pwr->keycodemax = ARRAY_SIZE(priv->keymap);
@@ -234,12 +229,8 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
-free_priv:
+free_mc13xxx_lock:
mc13xxx_unlock(mc13783);
- kfree(priv);
-
-free_input_dev:
- input_free_device(pwr);
return err;
}
@@ -261,9 +252,6 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
mc13xxx_unlock(priv->mc13783);
-
- input_unregister_device(priv->pwr);
- kfree(priv);
}
static struct platform_driver mc13783_pwrbutton_driver = {
--
2.39.5
next prev parent reply other threads:[~2025-08-23 14:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-23 14:44 [PATCH v2 0/9] Fix, extend and support OF to mc13xxx pwrbutton Alexander Kurz
2025-08-23 14:44 ` [PATCH v2 1/9] Input: mc13783-pwrbutton: fix irq mixup Alexander Kurz
2025-08-23 14:44 ` Alexander Kurz [this message]
2025-08-23 14:44 ` [PATCH v2 3/9] Input: mc13783-pwrbutton: convert pdata members to array Alexander Kurz
2025-08-23 14:44 ` [PATCH v2 4/9] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Alexander Kurz
2025-08-23 14:44 ` [PATCH v2 5/9] dt-bindings: mfd: fsl,mc13xxx: convert txt to DT schema Alexander Kurz
2025-08-26 23:03 ` Rob Herring
2025-08-23 14:44 ` [PATCH v2 6/9] dt-bindings: mfd: fsl,mc13xxx: add buttons node Alexander Kurz
2025-08-26 23:08 ` Rob Herring
2025-08-23 14:44 ` [PATCH v2 7/9] ARM: dts: imx: Use fsl,led-control as mc13xxx node name Alexander Kurz
2025-08-23 14:44 ` [PATCH v2 8/9] leds: mc13783: use fsl,led-control as " Alexander Kurz
2025-09-03 11:59 ` Lee Jones
2025-08-23 14:44 ` [PATCH v2 9/9] Input: mc13783-pwrbutton: add OF support Alexander Kurz
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=20250823144441.12654-3-akurz@blala.de \
--to=akurz@blala.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dsankouski@gmail.com \
--cc=heiko@sntech.de \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@treblig.org \
--cc=robh@kernel.org \
--cc=u.kleine-koenig@baylibre.com \
/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;
as well as URLs for NNTP newsgroup(s).