All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kunwu Chan <chentao@kylinos.cn>
To: dmitry.torokhov@gmail.com, aduggan@synaptics.com, cheiny@synaptics.com
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe
Date: Tue, 16 Jan 2024 16:38:47 +0800	[thread overview]
Message-ID: <20240116083847.89934-1-chentao@kylinos.cn> (raw)

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


             reply	other threads:[~2024-01-16  8:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  8:38 Kunwu Chan [this message]
2024-01-16 19:11 ` [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe Dmitry Torokhov
2024-01-17  7:07   ` Kunwu Chan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116083847.89934-1-chentao@kylinos.cn \
    --to=chentao@kylinos.cn \
    --cc=aduggan@synaptics.com \
    --cc=cheiny@synaptics.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.