linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: Fix a ref counting issue
@ 2020-11-29  8:45 Christophe JAILLET
  2020-11-29 19:49 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2020-11-29  8:45 UTC (permalink / raw)
  To: dmitry.torokhov, rydberg, tj
  Cc: linux-input, linux-kernel, kernel-janitors, Christophe JAILLET

In case of a managed resource, 'devm_input_device_release()' already has a
'input_put_device(dev)' call.

Avoid a double reference decrement by explicitly calling
'input_put_device()' only on non-managed input device.

Fixes: 2be975c6d920 ("Input: introduce managed input devices (add devres support)")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is completely speculative and compile tested only.
---
 drivers/input/input.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 3cfd2c18eebd..c09c9f020667 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1920,7 +1920,8 @@ void input_free_device(struct input_dev *dev)
 						devm_input_device_release,
 						devm_input_device_match,
 						dev));
-		input_put_device(dev);
+		else
+			input_put_device(dev);
 	}
 }
 EXPORT_SYMBOL(input_free_device);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: Fix a ref counting issue
  2020-11-29  8:45 [PATCH] Input: Fix a ref counting issue Christophe JAILLET
@ 2020-11-29 19:49 ` Dmitry Torokhov
  2020-11-29 20:14   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2020-11-29 19:49 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: rydberg, tj, linux-input, linux-kernel, kernel-janitors

Hi Christophe,

On Sun, Nov 29, 2020 at 09:45:16AM +0100, Christophe JAILLET wrote:
> In case of a managed resource, 'devm_input_device_release()' already has a
> 'input_put_device(dev)' call.
> 
> Avoid a double reference decrement by explicitly calling
> 'input_put_device()' only on non-managed input device.

This patch is incorrect, as devres_destroy() that is used in
input_free_device(), unlike devres_releasde(), does not actually call
the "release" function. It simply destroys the devres object, but does
not clear associated resources.

> 
> Fixes: 2be975c6d920 ("Input: introduce managed input devices (add devres support)")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is completely speculative and compile tested only.
> ---
>  drivers/input/input.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 3cfd2c18eebd..c09c9f020667 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -1920,7 +1920,8 @@ void input_free_device(struct input_dev *dev)
>  						devm_input_device_release,
>  						devm_input_device_match,
>  						dev));
> -		input_put_device(dev);
> +		else
> +			input_put_device(dev);
>  	}
>  }
>  EXPORT_SYMBOL(input_free_device);
> -- 
> 2.27.0
> 

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: Fix a ref counting issue
  2020-11-29 19:49 ` Dmitry Torokhov
@ 2020-11-29 20:14   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2020-11-29 20:14 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: rydberg, tj, linux-input, linux-kernel, kernel-janitors


Le 29/11/2020 à 20:49, Dmitry Torokhov a écrit :
> Hi Christophe,
>
> On Sun, Nov 29, 2020 at 09:45:16AM +0100, Christophe JAILLET wrote:
>> In case of a managed resource, 'devm_input_device_release()' already has a
>> 'input_put_device(dev)' call.
>>
>> Avoid a double reference decrement by explicitly calling
>> 'input_put_device()' only on non-managed input device.
> This patch is incorrect, as devres_destroy() that is used in
> input_free_device(), unlike devres_releasde(), does not actually call
> the "release" function. It simply destroys the devres object, but does
> not clear associated resources.

Crystal clear.
Thanks for the explanation and sorry for the noise.

CJ

>> Fixes: 2be975c6d920 ("Input: introduce managed input devices (add devres support)")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> This patch is completely speculative and compile tested only.
>> ---
>>   drivers/input/input.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>> index 3cfd2c18eebd..c09c9f020667 100644
>> --- a/drivers/input/input.c
>> +++ b/drivers/input/input.c
>> @@ -1920,7 +1920,8 @@ void input_free_device(struct input_dev *dev)
>>   						devm_input_device_release,
>>   						devm_input_device_match,
>>   						dev));
>> -		input_put_device(dev);
>> +		else
>> +			input_put_device(dev);
>>   	}
>>   }
>>   EXPORT_SYMBOL(input_free_device);
>> -- 
>> 2.27.0
>>
> Thanks.
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-29 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-29  8:45 [PATCH] Input: Fix a ref counting issue Christophe JAILLET
2020-11-29 19:49 ` Dmitry Torokhov
2020-11-29 20:14   ` Christophe JAILLET

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).