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 <tdey@codeaurora.org>
This commit is contained in:
Tapas Dey 2021-07-20 16:53:25 +05:30 • committed by Gerrit - the friendly Code Review server
commit 30e5a66dad

View file

@ -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);