From: Haotian Zhang <vulab@iscas.ac.cn>
To: sebastian.reichel@collabora.co.uk, dmitry.torokhov@gmail.com
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH] Input: misc: pwm-vibra: fix resource leaks on start failure
Date: Wed, 26 Nov 2025 22:56:35 +0800 [thread overview]
Message-ID: <20251126145635.954-1-vulab@iscas.ac.cn> (raw)
The pwm_vibrator_start() function returns immediately if
pwm_apply_might_sleep() fails, neglecting to disable the
regulator or reset the enable GPIO. This results in a
potential resource leak.
Introduce a local flag to track regulator enablement
and implement an error handling path. Deassert the enable
GPIO and disable the regulator upon failure.
Fixes: 3e5b08518f6a ("Input: add a driver for PWM controllable vibrators")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/input/misc/pwm-vibra.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c
index 3e5ed685ed8f..d323a12596c3 100644
--- a/drivers/input/misc/pwm-vibra.c
+++ b/drivers/input/misc/pwm-vibra.c
@@ -40,6 +40,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
struct device *pdev = vibrator->input->dev.parent;
struct pwm_state state;
int err;
+ bool new_vcc_on = false;
if (!vibrator->vcc_on) {
err = regulator_enable(vibrator->vcc);
@@ -48,6 +49,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
return err;
}
vibrator->vcc_on = true;
+ new_vcc_on = true;
}
gpiod_set_value_cansleep(vibrator->enable_gpio, 1);
@@ -59,7 +61,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
err = pwm_apply_might_sleep(vibrator->pwm, &state);
if (err) {
dev_err(pdev, "failed to apply pwm state: %d\n", err);
- return err;
+ goto err_gpio;
}
if (vibrator->pwm_dir) {
@@ -71,11 +73,19 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
if (err) {
dev_err(pdev, "failed to apply dir-pwm state: %d\n", err);
pwm_disable(vibrator->pwm);
- return err;
+ goto err_gpio;
}
}
return 0;
+
+err_gpio:
+ gpiod_set_value_cansleep(vibrator->enable_gpio, 0);
+ if (new_vcc_on) {
+ regulator_disable(vibrator->vcc);
+ vibrator->vcc_on = false;
+ }
+ return err;
}
static void pwm_vibrator_stop(struct pwm_vibrator *vibrator)
--
2.50.1.windows.1
next reply other threads:[~2025-11-26 14:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 14:56 Haotian Zhang [this message]
2025-11-27 23:20 ` [PATCH] Input: misc: pwm-vibra: fix resource leaks on start failure Sebastian Reichel
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=20251126145635.954-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sebastian.reichel@collabora.co.uk \
/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).