From 30e5a66dad0be2cbae0654900caa7fb59e0599e0 Mon Sep 17 00:00:00 2001 From: Tapas Dey Date: Tue, 20 Jul 2021 16:53:25 +0530 Subject: [PATCH] NFC: Fix NULL pointer dereference issue Modify code and add proper NULL check to avoid NULL pointer dereference. Change-Id: I09c6a74b653b12e60c48fc5f63cca9148e117ee9 Signed-off-by: Tapas Dey --- drivers/nfc/qti/nfc_i2c_drv.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/nfc/qti/nfc_i2c_drv.c b/drivers/nfc/qti/nfc_i2c_drv.c index 989471be9d2e..fee83a9f9a2e 100644 --- a/drivers/nfc/qti/nfc_i2c_drv.c +++ b/drivers/nfc/qti/nfc_i2c_drv.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved. */ #include "nfc_common.h" @@ -452,7 +452,14 @@ int nfc_i2c_dev_suspend(struct device *device) { struct i2c_client *client = to_i2c_client(device); struct nfc_dev *nfc_dev = i2c_get_clientdata(client); - struct i2c_dev *i2c_dev = &nfc_dev->i2c_dev; + struct i2c_dev *i2c_dev = NULL; + + if (!nfc_dev) { + pr_err("%s: device doesn't exist anymore\n", __func__); + return -ENODEV; + } + + i2c_dev = &nfc_dev->i2c_dev; NFCLOG_IPC(nfc_dev, false, "%s: irq_enabled = %d", __func__, i2c_dev->irq_enabled); @@ -468,7 +475,14 @@ int nfc_i2c_dev_resume(struct device *device) { struct i2c_client *client = to_i2c_client(device); struct nfc_dev *nfc_dev = i2c_get_clientdata(client); - struct i2c_dev *i2c_dev = &nfc_dev->i2c_dev; + struct i2c_dev *i2c_dev = NULL; + + if (!nfc_dev) { + pr_err("%s: device doesn't exist anymore\n", __func__); + return -ENODEV; + } + + i2c_dev = &nfc_dev->i2c_dev; NFCLOG_IPC(nfc_dev, false, "%s: irq_wake_up = %d", __func__, i2c_dev->irq_wake_up);