linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: linux-media@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Stefan Riedmueller <s.riedmueller@phytec.de>
Subject: [PATCH] media: mt9p031: Check for non-null I2C ID match
Date: Sun, 19 Jun 2022 00:22:32 +0200	[thread overview]
Message-ID: <20220618222232.478138-1-marex@denx.de> (raw)

The const struct i2c_device_id *did passed to probe may be NULL e.g.
in case DT contains the following compatible string:
compatible = "aptina,mt9p006", "aptina,mt9p031";

Check the variable for non-NULL and fail gracefully instead of crashing
the kernel outright with NULL pointer dereference splat.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 drivers/media/i2c/mt9p031.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index e0f0d87d4cfe9..d0706723e493c 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -1106,6 +1106,11 @@ static int mt9p031_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
+	if (did == NULL) {
+		dev_err(&client->dev, "Invalid I2C device ID\n");
+		return -EINVAL;
+	}
+
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
 		dev_warn(&client->dev,
 			"I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
-- 
2.35.1


             reply	other threads:[~2022-06-18 22:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-18 22:22 Marek Vasut [this message]
2022-06-18 22:59 ` [PATCH] media: mt9p031: Check for non-null I2C ID match Laurent Pinchart

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=20220618222232.478138-1-marex@denx.de \
    --to=marex@denx.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=s.riedmueller@phytec.de \
    --cc=sakari.ailus@linux.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).