diff mbox series

[1/2] Input: spear-keyboard - Fix a double put in spear_kbd_remove()

Message ID a39197be6248ebe5385e4f352241b4ba5e857c42.1721939824.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New
Headers show
Series Input: spear-keyboard - Fix an issue and clean-up code | expand

Commit Message

Christophe JAILLET July 25, 2024, 8:46 p.m. UTC
The 'input_dev' is a managed resource allocated with
devm_input_allocate_device(), so there is no need to call
input_unregister_device() in the remove function.

In fact, this call was correctly removed in commit 6102752eb354 ("Input:
spear-keyboard - switch to using managed resources"), but silently
re-introduced later in the commit in Fixes.

Fixes: 9336648978c2 ("Input: spear-keyboard - add clk_{un}prepare() support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested-only
---
 drivers/input/keyboard/spear-keyboard.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Dmitry Torokhov July 25, 2024, 8:52 p.m. UTC | #1
Hi Christophe,

On Thu, Jul 25, 2024 at 10:46:49PM +0200, Christophe JAILLET wrote:
> The 'input_dev' is a managed resource allocated with
> devm_input_allocate_device(), so there is no need to call
> input_unregister_device() in the remove function.
> 
> In fact, this call was correctly removed in commit 6102752eb354 ("Input:
> spear-keyboard - switch to using managed resources"), but silently
> re-introduced later in the commit in Fixes.

This change is incorrect as it leads to an active and enabled clock
being unprepared to early. We need to unregister input device which in
turn will call spear_kbd_close() if needed which will disable the clock
in question. Only after that we can unprepare it.

There is also no double put as input core will recognize that input
device was unregistered explicitly and will not attempt to unregister it
2nd time through devm:

void input_unregister_device(struct input_dev *dev)
{
	if (dev->devres_managed) {
		WARN_ON(devres_destroy(dev->dev.parent,
					devm_input_device_unregister,
					devm_input_device_match,
					dev));
		__input_unregister_device(dev);
		/*
		 * We do not do input_put_device() here because it will be done
		 * when 2nd devres fires up.
		 */
	} else {
		__input_unregister_device(dev);
		input_put_device(dev);
	}
}

> 
> Fixes: 9336648978c2 ("Input: spear-keyboard - add clk_{un}prepare() support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested-only
> ---
>  drivers/input/keyboard/spear-keyboard.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
> index 557d00a667ce..5d9fc8dc9433 100644
> --- a/drivers/input/keyboard/spear-keyboard.c
> +++ b/drivers/input/keyboard/spear-keyboard.c
> @@ -276,7 +276,6 @@ static void spear_kbd_remove(struct platform_device *pdev)
>  {
>  	struct spear_kbd *kbd = platform_get_drvdata(pdev);
>  
> -	input_unregister_device(kbd->input);
>  	clk_unprepare(kbd->clk);
>  }
>  
> -- 
> 2.45.2
> 

Thanks.
Christophe JAILLET July 25, 2024, 9:34 p.m. UTC | #2
Le 25/07/2024 à 22:52, Dmitry Torokhov a écrit :
> Hi Christophe,
> 
> On Thu, Jul 25, 2024 at 10:46:49PM +0200, Christophe JAILLET wrote:
>> The 'input_dev' is a managed resource allocated with
>> devm_input_allocate_device(), so there is no need to call
>> input_unregister_device() in the remove function.
>>
>> In fact, this call was correctly removed in commit 6102752eb354 ("Input:
>> spear-keyboard - switch to using managed resources"), but silently
>> re-introduced later in the commit in Fixes.
> 
> This change is incorrect as it leads to an active and enabled clock
> being unprepared to early. We need to unregister input device which in
> turn will call spear_kbd_close() if needed which will disable the clock
> in question. Only after that we can unprepare it.
> 
> There is also no double put as input core will recognize that input
> device was unregistered explicitly and will not attempt to unregister it
> 2nd time through devm:

Got it.

Thanks for the review and the detailed explanation.
Sorry for the noise.

I'll resend as asked in patch 2/2, if saving some lines of code makes 
enough sense for you.
But as said in the cover letter, if there is no issue, I'm not sure it 
worth the time for an old driver.

CJ

> 
> void input_unregister_device(struct input_dev *dev)
> {
> 	if (dev->devres_managed) {
> 		WARN_ON(devres_destroy(dev->dev.parent,
> 					devm_input_device_unregister,
> 					devm_input_device_match,
> 					dev));
> 		__input_unregister_device(dev);
> 		/*
> 		 * We do not do input_put_device() here because it will be done
> 		 * when 2nd devres fires up.
> 		 */
> 	} else {
> 		__input_unregister_device(dev);
> 		input_put_device(dev);
> 	}
> }
> 
>>
>> Fixes: 9336648978c2 ("Input: spear-keyboard - add clk_{un}prepare() support")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Compile tested-only
>> ---
>>   drivers/input/keyboard/spear-keyboard.c | 1 -
>>   1 file changed, 1 deletion(-)
>>
>> diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
>> index 557d00a667ce..5d9fc8dc9433 100644
>> --- a/drivers/input/keyboard/spear-keyboard.c
>> +++ b/drivers/input/keyboard/spear-keyboard.c
>> @@ -276,7 +276,6 @@ static void spear_kbd_remove(struct platform_device *pdev)
>>   {
>>   	struct spear_kbd *kbd = platform_get_drvdata(pdev);
>>   
>> -	input_unregister_device(kbd->input);
>>   	clk_unprepare(kbd->clk);
>>   }
>>   
>> -- 
>> 2.45.2
>>
> 
> Thanks.
>
Dmitry Torokhov July 25, 2024, 9:55 p.m. UTC | #3
On Thu, Jul 25, 2024 at 11:34:14PM +0200, Christophe JAILLET wrote:
> Le 25/07/2024 à 22:52, Dmitry Torokhov a écrit :
> > Hi Christophe,
> > 
> > On Thu, Jul 25, 2024 at 10:46:49PM +0200, Christophe JAILLET wrote:
> > > The 'input_dev' is a managed resource allocated with
> > > devm_input_allocate_device(), so there is no need to call
> > > input_unregister_device() in the remove function.
> > > 
> > > In fact, this call was correctly removed in commit 6102752eb354 ("Input:
> > > spear-keyboard - switch to using managed resources"), but silently
> > > re-introduced later in the commit in Fixes.
> > 
> > This change is incorrect as it leads to an active and enabled clock
> > being unprepared to early. We need to unregister input device which in
> > turn will call spear_kbd_close() if needed which will disable the clock
> > in question. Only after that we can unprepare it.
> > 
> > There is also no double put as input core will recognize that input
> > device was unregistered explicitly and will not attempt to unregister it
> > 2nd time through devm:
> 
> Got it.
> 
> Thanks for the review and the detailed explanation.
> Sorry for the noise.
> 
> I'll resend as asked in patch 2/2, if saving some lines of code makes enough
> sense for you.
> But as said in the cover letter, if there is no issue, I'm not sure it worth
> the time for an old driver.

I generally like infrastructure cleanups, unless it is too much trouble.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 557d00a667ce..5d9fc8dc9433 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -276,7 +276,6 @@  static void spear_kbd_remove(struct platform_device *pdev)
 {
 	struct spear_kbd *kbd = platform_get_drvdata(pdev);
 
-	input_unregister_device(kbd->input);
 	clk_unprepare(kbd->clk);
 }