Commit ea9ef6c2 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Hans Verkuil

media: dvb-usb: m920x: Fix a potential memory leak in m920x_i2c_xfer()

'read' is freed when it is known to be NULL, but not when a read error
occurs.

Revert the logic to avoid a small leak, should a m920x_read() call fail.

Fixes: a2ab06d7 ("media: m920x: don't use stack on USB reads")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent fae4280e
...@@ -277,7 +277,6 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu ...@@ -277,7 +277,6 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu
char *read = kmalloc(1, GFP_KERNEL); char *read = kmalloc(1, GFP_KERNEL);
if (!read) { if (!read) {
ret = -ENOMEM; ret = -ENOMEM;
kfree(read);
goto unlock; goto unlock;
} }
...@@ -288,8 +287,10 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu ...@@ -288,8 +287,10 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu
if ((ret = m920x_read(d->udev, M9206_I2C, 0x0, if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
0x20 | stop, 0x20 | stop,
read, 1)) != 0) read, 1)) != 0) {
kfree(read);
goto unlock; goto unlock;
}
msg[i].buf[j] = read[0]; msg[i].buf[j] = read[0];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment