mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manuel Traut <manuel.traut@mt.com>
To: linux-kernel@vger.kernel.org
Cc: Manuel Traut <manuel.traut@mt.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Frieder Schrempf <frieder.schrempf@kontron.de>,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org
Subject: [PATCH v8 5/5] input: pwm-beeper: handle module unloading properly
Date: Thu, 26 Jan 2023 10:18:25 +0100	[thread overview]
Message-ID: <20230126091825.220646-6-manuel.traut@mt.com> (raw)
In-Reply-To: <20230126091825.220646-1-manuel.traut@mt.com>

'input: pwm-beeper: add feature to set volume via sysfs' adds device
attributes without removing them on error or if the module is unloaded.

If the module will be unloaded and loaded again it fails:
[ 1007.918180] sysfs: cannot create duplicate filename '/devices/platform/buzzer/volume'

Therefore remove device attributes on module unloading and in case
registration at the input subsystem fails.

Signed-off-by: Manuel Traut <manuel.traut@mt.com>
---
 drivers/input/misc/pwm-beeper.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index 82b05f7f4c70..736b89bd1b42 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -299,6 +299,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 
 	error = input_register_device(beeper->input);
 	if (error) {
+		sysfs_remove_group(&pdev->dev.kobj, &pwm_beeper_attribute_group);
 		dev_err(dev, "Failed to register input device: %d\n", error);
 		return error;
 	}
@@ -308,6 +309,17 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int pwm_beeper_remove(struct platform_device *pdev)
+{
+	struct pwm_beeper *beeper;
+
+	beeper = platform_get_drvdata(pdev);
+	input_unregister_device(beeper->input);
+	sysfs_remove_group(&pdev->dev.kobj, &pwm_beeper_attribute_group);
+
+	return 0;
+}
+
 static int __maybe_unused pwm_beeper_suspend(struct device *dev)
 {
 	struct pwm_beeper *beeper = dev_get_drvdata(dev);
@@ -353,6 +365,7 @@ MODULE_DEVICE_TABLE(of, pwm_beeper_match);
 
 static struct platform_driver pwm_beeper_driver = {
 	.probe	= pwm_beeper_probe,
+	.remove	= pwm_beeper_remove,
 	.driver = {
 		.name	= "pwm-beeper",
 		.pm	= &pwm_beeper_pm_ops,
-- 
2.39.0


  parent reply	other threads:[~2023-01-26  9:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26  9:18 [PATCH v8 0/5] input: pwm-beeper: add feature to set volume level Manuel Traut
2023-01-26  9:18 ` [PATCH v8 1/5] dt-bindings: input: pwm-beeper: Convert txt bindings to yaml Manuel Traut
2023-01-26 12:32   ` Krzysztof Kozlowski
2023-01-26 13:21   ` Rob Herring
2023-01-26  9:18 ` [PATCH v8 2/5] input: pwm-beeper: add feature to set volume via sysfs Manuel Traut
2023-01-26  9:18 ` [PATCH v8 3/5] input: pwm-beeper: set volume levels by devicetree Manuel Traut
2023-01-26  9:18 ` [PATCH v8 4/5] dt-bindings: input: pwm-beeper: add volume Manuel Traut
2023-01-26 12:36   ` Krzysztof Kozlowski
2023-01-26 15:11     ` Manuel Traut
2023-01-26 15:20       ` Krzysztof Kozlowski
2023-01-26 16:08         ` Manuel Traut
2023-01-26  9:18 ` Manuel Traut [this message]
2023-01-30  9:07   ` [PATCH v8 5/5] input: pwm-beeper: handle module unloading properly Frieder Schrempf

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=20230126091825.220646-6-manuel.traut@mt.com \
    --to=manuel.traut@mt.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@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

all inboxes | Powered by JetHome®