input: pwm-beeper: handle module unloading properly
Subsystems (2)
PATCH v7 5/5 input: pwm-beeper: handle module unloading properly
'input: pwm-beeper: add feature to set volume via sysfs' adds device attributes without removing them on error or if the module is unloaded.
This change removes the device attributes on module unloading or if registering on the input subsystem fails.
If the module will be unloaded and loaded again it fails:
[ 1007.918180] sysfs: cannot create duplicate filename '/devices/platform/buzzer/volume'
--- drivers/input/misc/pwm-beeper.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/input/misc/pwm-beeper.c +13 -0
@@ -300,6 +300,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; }
@@ -309,6 +310,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);
@@ -354,6 +366,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,
Signature · 1 line
2.39.0
Quoted 4 lines · Manuel Traut
'input: pwm-beeper: add feature to set volume via sysfs' adds device attributes without removing them on error or if the module is unloaded.
This change removes the device attributes on module unloading or if
Do not use "This commit/patch".
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95
Quoted 23 lines
registering on the input subsystem fails.
If the module will be unloaded and loaded again it fails:
[ 1007.918180] sysfs: cannot create duplicate filename '/devices/platform/buzzer/volume'Signed-off-by Manuel Traut <[email protected]>--- drivers/input/misc/pwm-beeper.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/input/misc/pwm-beeper.c +1
-0@@ -300,6 +300,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; }
drivers/input/misc/pwm-beeper.c static int pwm_beeper_probe(struct platform_device *pdev) · line 317
Quoted 8 lines
drivers/input/misc/pwm-beeper.c +5
-0@@ -309,6 +310,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);
Wrong indentation.
Please run scripts/checkpatch.pl and fix reported warnings.
drivers/input/misc/pwm-beeper.c static int pwm_beeper_probe(struct platform_device *pdev) · line 318
Quoted 1 line
drivers/input/misc/pwm-beeper.c +1
-0+input_unregister_device (beeper->input);
Best regards,
Krzysztof