linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe
@ 2024-01-16  8:38 Kunwu Chan
  2024-01-16 19:11 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Kunwu Chan @ 2024-01-16  8:38 UTC (permalink / raw)
  To: dmitry.torokhov, aduggan, cheiny; +Cc: linux-input, linux-kernel, Kunwu Chan

devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/input/rmi4/rmi_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 258d5fe3d395..d3a601ff51e6 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev)
 		rmi_driver_set_input_params(rmi_dev, data->input);
 		data->input->phys = devm_kasprintf(dev, GFP_KERNEL,
 						"%s/input0", dev_name(dev));
+		if (!data->input->phys) {
+			dev_err(dev, "%s: Failed to allocate memory.\n",
+					__func__);
+			retval = -ENOMEM;
+			goto err;
+		}
 	}
 
 	retval = rmi_init_functions(data);
-- 
2.39.2


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

* Re: [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe
  2024-01-16  8:38 [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe Kunwu Chan
@ 2024-01-16 19:11 ` Dmitry Torokhov
  2024-01-17  7:07   ` Kunwu Chan
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2024-01-16 19:11 UTC (permalink / raw)
  To: Kunwu Chan; +Cc: aduggan, cheiny, linux-input, linux-kernel

On Tue, Jan 16, 2024 at 04:38:47PM +0800, Kunwu Chan wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.

It is perfectly valid to not set "input->phys" and leave it at NULL. So
while I agree that having error handling is good I do not believe
there's chance for NULL pointer dereference, so please adjust your patch
title.

> 
> Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices")
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
>  drivers/input/rmi4/rmi_driver.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
> index 258d5fe3d395..d3a601ff51e6 100644
> --- a/drivers/input/rmi4/rmi_driver.c
> +++ b/drivers/input/rmi4/rmi_driver.c
> @@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev)
>  		rmi_driver_set_input_params(rmi_dev, data->input);
>  		data->input->phys = devm_kasprintf(dev, GFP_KERNEL,
>  						"%s/input0", dev_name(dev));
> +		if (!data->input->phys) {
> +			dev_err(dev, "%s: Failed to allocate memory.\n",

No need to log the error here, memory allocation will already log the
failure.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe
  2024-01-16 19:11 ` Dmitry Torokhov
@ 2024-01-17  7:07   ` Kunwu Chan
  0 siblings, 0 replies; 3+ messages in thread
From: Kunwu Chan @ 2024-01-17  7:07 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: aduggan, cheiny, linux-input, linux-kernel

On 2024/1/17 03:11, Dmitry Torokhov wrote:
> On Tue, Jan 16, 2024 at 04:38:47PM +0800, Kunwu Chan wrote:
>> devm_kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure. Ensure the allocation was successful
>> by checking the pointer validity.
> 
> It is perfectly valid to not set "input->phys" and leave it at NULL. So
> while I agree that having error handling is good I do not believe
> there's chance for NULL pointer dereference, so please adjust your patch
> title.

Thanks for your suggestions.
I'll change patch title to "Input: synaptics-rmi4: Add a null pointer 
check to the rmi_driver_probe".

>>
>> Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices")
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> ---
>>   drivers/input/rmi4/rmi_driver.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
>> index 258d5fe3d395..d3a601ff51e6 100644
>> --- a/drivers/input/rmi4/rmi_driver.c
>> +++ b/drivers/input/rmi4/rmi_driver.c
>> @@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev)
>>   		rmi_driver_set_input_params(rmi_dev, data->input);
>>   		data->input->phys = devm_kasprintf(dev, GFP_KERNEL,
>>   						"%s/input0", dev_name(dev));
>> +		if (!data->input->phys) {
>> +			dev_err(dev, "%s: Failed to allocate memory.\n",
> 
> No need to log the error here, memory allocation will already log the
> failure.
Thanks, I'll remove the dev_err.
> 
> Thanks.
> 
-- 
Thanks,
   Kunwu


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

end of thread, other threads:[~2024-01-17  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16  8:38 [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe Kunwu Chan
2024-01-16 19:11 ` Dmitry Torokhov
2024-01-17  7:07   ` Kunwu Chan

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