diff mbox series

[v2] Input: synaptics-rmi4: Add a null pointer check to the rmi_driver_probe

Message ID 20240117073124.143636-1-chentao@kylinos.cn
State New
Headers show
Series [v2] Input: synaptics-rmi4: Add a null pointer check to the rmi_driver_probe | expand

Commit Message

Kunwu Chan Jan. 17, 2024, 7:31 a.m. UTC
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.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
v2: Change title and remove dev_err
---
 drivers/input/rmi4/rmi_driver.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Dmitry Torokhov Jan. 18, 2024, 10:32 p.m. UTC | #1
Hi Kunwu,

On Wed, Jan 17, 2024 at 03:31:24PM +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.
> 
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

I did not suggest the patch, I merely provided feedback on it, so I
dropped this tag, reworded commit message slightly, and applied.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 258d5fe3d395..8da104e99e7b 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -1197,6 +1197,10 @@  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) {
+			retval = -ENOMEM;
+			goto err;
+		}
 	}
 
 	retval = rmi_init_functions(data);