diff mbox series

input: touchscreen: Add NULL pointer check before dereference

Message ID 20190901182309.GA5574@ahmlpt0706 (mailing list archive)
State New, archived
Delegated to: Dmitry Torokhov
Headers show
Series input: touchscreen: Add NULL pointer check before dereference | expand

Commit Message

Saiyam Doshi Sept. 1, 2019, 6:23 p.m. UTC
In sx8654_probe function, if call to device_get_match_data()
return NULL, it dereferences driver_data from 'id'.

To avoid NULL pointer dereference, add check to make sure
'id' is not NULL.

Signed-off-by: Saiyam Doshi <saiyamdoshi.in@gmail.com>
---
 drivers/input/touchscreen/sx8654.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Saiyam Doshi Oct. 24, 2019, 6:08 p.m. UTC | #1
On Sun, Sep 01, 2019 at 11:53:09PM +0530, Saiyam Doshi wrote:
> In sx8654_probe function, if call to device_get_match_data()
> return NULL, it dereferences driver_data from 'id'.
> 
> To avoid NULL pointer dereference, add check to make sure
> 'id' is not NULL.

Any review / update on this?

-Saiyam
Dmitry Torokhov Oct. 25, 2019, 9:17 p.m. UTC | #2
Hi Saiyam,

On Thu, Oct 24, 2019 at 11:38:22PM +0530, Saiyam Doshi wrote:
> On Sun, Sep 01, 2019 at 11:53:09PM +0530, Saiyam Doshi wrote:
> > In sx8654_probe function, if call to device_get_match_data()
> > return NULL, it dereferences driver_data from 'id'.
> > 
> > To avoid NULL pointer dereference, add check to make sure
> > 'id' is not NULL.
> 
> Any review / update on this?

Can you please explain under what circumstances we can get NULL from
device_get_match_data() in this driver?

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c
index de85e57b2486..7121a3d41555 100644
--- a/drivers/input/touchscreen/sx8654.c
+++ b/drivers/input/touchscreen/sx8654.c
@@ -333,7 +333,7 @@  static int sx8654_probe(struct i2c_client *client,
 	dev_dbg(&client->dev, "got GPIO reset pin\n");
 
 	sx8654->data = device_get_match_data(&client->dev);
-	if (!sx8654->data)
+	if (!sx8654->data && id)
 		sx8654->data = (const struct sx865x_data *)id->driver_data;
 	if (!sx8654->data) {
 		dev_err(&client->dev, "invalid or missing device data\n");