linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin King <colin.king@canonical.com>
To: Tianshu Qiu <tian.shu.qiu@intel.com>,
	Shawn Tu <shawnx.tu@intel.com>, Bingbu Cao <bingbu.cao@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Tomasz Figa <tfiga@chromium.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Qingwu Zhang <qingwu.zhang@intel.com>,
	linux-media@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH][next] media: ov2740: fix dereference before null check on pointer nvm
Date: Thu, 26 Nov 2020 11:49:32 +0000	[thread overview]
Message-ID: <20201126114932.1984730-1-colin.king@canonical.com> (raw)

From: Colin Ian King <colin.king@canonical.com>

Currently pointer nvm is being dereferenced before it is being null
checked.  Fix this by moving the assignments of pointers client and
ov2740 so that are after the null check hence avoiding any potential
null pointer dereferences on pointer nvm.

Fixes: 5e6fd339b68d ("media: ov2740: allow OTP data access during streaming")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/media/i2c/ov2740.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 99016546cbec..b41a90c2aed5 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -600,8 +600,8 @@ static void ov2740_update_pad_format(const struct ov2740_mode *mode,
 
 static int ov2740_load_otp_data(struct nvm_data *nvm)
 {
-	struct i2c_client *client = nvm->client;
-	struct ov2740 *ov2740 = to_ov2740(i2c_get_clientdata(client));
+	struct i2c_client *client;
+	struct ov2740 *ov2740;
 	u32 isp_ctrl00 = 0;
 	u32 isp_ctrl01 = 0;
 	int ret;
@@ -612,6 +612,9 @@ static int ov2740_load_otp_data(struct nvm_data *nvm)
 	if (nvm->nvm_buffer)
 		return 0;
 
+	client = nvm->client;
+	ov2740 = to_ov2740(i2c_get_clientdata(client));
+
 	nvm->nvm_buffer = kzalloc(CUSTOMER_USE_OTP_SIZE, GFP_KERNEL);
 	if (!nvm->nvm_buffer)
 		return -ENOMEM;
-- 
2.29.2


             reply	other threads:[~2020-11-26 11:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 11:49 Colin King [this message]
2020-12-03  2:43 ` [PATCH][next] media: ov2740: fix dereference before null check on pointer nvm Bingbu Cao

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=20201126114932.1984730-1-colin.king@canonical.com \
    --to=colin.king@canonical.com \
    --cc=bingbu.cao@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=qingwu.zhang@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=shawnx.tu@intel.com \
    --cc=tfiga@chromium.org \
    --cc=tian.shu.qiu@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).