Re: [PATCH] media: mt9p031: Check for non-null I2C ID match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Marek,

(CC'ing Wolfram)

Thank you for the patch.

On Sun, Jun 19, 2022 at 12:22:32AM +0200, Marek Vasut wrote:
> 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@xxxxxxx>
> Cc: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> Cc: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
> Cc: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
> Cc: Stefan Riedmueller <s.riedmueller@xxxxxxxxx>
> ---
>  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;
> +	}
> +

Is there a way we could fix this in the I2C core ? See
https://lore.kernel.org/all/20210723183114.26017-1-laurent.pinchart@xxxxxxxxxxxxxxxx/

>  	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
>  		dev_warn(&client->dev,
>  			"I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");

-- 
Regards,

Laurent Pinchart



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux