diff mbox series

[7/7] media: ngene: don't try to memcpy from NULL

Message ID 11ef5297a62a8c3cc812495b69398b316e80ad73.1566502743.git.mchehab+samsung@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/7] media: remove include stdarg.h from some drivers | expand

Commit Message

Mauro Carvalho Chehab Aug. 22, 2019, 7:39 p.m. UTC
[drivers/media/pci/ngene/ngene-i2c.c:122] -> [drivers/media/pci/ngene/ngene-i2c.c:39]: (error) Null pointer dereference: out

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
 drivers/media/pci/ngene/ngene-i2c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Mauro Carvalho Chehab Aug. 22, 2019, 7:43 p.m. UTC | #1
Em Thu, 22 Aug 2019 16:39:34 -0300
Mauro Carvalho Chehab <mchehab+samsung@kernel.org> escreveu:

> [drivers/media/pci/ngene/ngene-i2c.c:122] -> [drivers/media/pci/ngene/ngene-i2c.c:39]: (error) Null pointer dereference: out
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> ---
>  drivers/media/pci/ngene/ngene-i2c.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/pci/ngene/ngene-i2c.c b/drivers/media/pci/ngene/ngene-i2c.c
> index 2e9e9774dc6f..bfdb7286f6f0 100644
> --- a/drivers/media/pci/ngene/ngene-i2c.c
> +++ b/drivers/media/pci/ngene/ngene-i2c.c
> @@ -36,7 +36,10 @@ static int ngene_command_i2c_read(struct ngene *dev, u8 adr,
>  	com.cmd.hdr.Opcode = CMD_I2C_READ;
>  	com.cmd.hdr.Length = outlen + 3;
>  	com.cmd.I2CRead.Device = adr << 1;
> -	memcpy(com.cmd.I2CRead.Data, out, outlen);
> +
> +	if (out)
> +		memcpy(com.cmd.I2CRead.Data, out, outlen);
> +

Hmm... I actually forgot to drop this one from this series, as I guess it
is safe to do:

	memcpy(out, NULL, 0);

>  	com.cmd.I2CRead.Data[outlen] = inlen;
>  	com.cmd.I2CRead.Data[outlen + 1] = 0;
>  	com.in_len = outlen + 3;



Thanks,
Mauro
diff mbox series

Patch

diff --git a/drivers/media/pci/ngene/ngene-i2c.c b/drivers/media/pci/ngene/ngene-i2c.c
index 2e9e9774dc6f..bfdb7286f6f0 100644
--- a/drivers/media/pci/ngene/ngene-i2c.c
+++ b/drivers/media/pci/ngene/ngene-i2c.c
@@ -36,7 +36,10 @@  static int ngene_command_i2c_read(struct ngene *dev, u8 adr,
 	com.cmd.hdr.Opcode = CMD_I2C_READ;
 	com.cmd.hdr.Length = outlen + 3;
 	com.cmd.I2CRead.Device = adr << 1;
-	memcpy(com.cmd.I2CRead.Data, out, outlen);
+
+	if (out)
+		memcpy(com.cmd.I2CRead.Data, out, outlen);
+
 	com.cmd.I2CRead.Data[outlen] = inlen;
 	com.cmd.I2CRead.Data[outlen + 1] = 0;
 	com.in_len = outlen + 3;