archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <>
Cc: Marek Vasut <>,
	Laurent Pinchart <>,
	Mauro Carvalho Chehab <>,
	Sakari Ailus <>,
	Stefan Riedmueller <>
Subject: [PATCH] media: mt9p031: Check for non-null I2C ID match
Date: Sun, 19 Jun 2022 00:22:32 +0200	[thread overview]
Message-ID: <> (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 <>
Cc: Laurent Pinchart <>
Cc: Mauro Carvalho Chehab <>
Cc: Sakari Ailus <>
Cc: Stefan Riedmueller <>
 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)) {
 			"I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");

             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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* 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).