Skip to content

Commit 8d25e15

Browse files
Colin Ian Kingmchehab
authored andcommitted
media: lirc: don't kfree the uninitialized pointer txbuf
The current error exit path if ir_raw_encode_scancode fails is via the label out_kfree which kfree's an uninitialized pointer txbuf. Fix this by exiting via a new exit path that does not kfree txbuf. Also exit via this new exit path for a failed allocation of txbuf to avoid a redundant kfree on a NULL pointer (to save a bunch of CPU cycles). Detected by: CoverityScan, CID#1463070 ("Uninitialized pointer read") Fixes: f81a815 ("media: lirc: release lock before sleep") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent e3ee691 commit 8d25e15

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎drivers/media/rc/lirc_dev.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,14 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
295295
ret = ir_raw_encode_scancode(scan.rc_proto, scan.scancode,
296296
raw, LIRCBUF_SIZE);
297297
if (ret < 0)
298-
goto out_kfree;
298+
goto out_kfree_raw;
299299

300300
count = ret;
301301

302302
txbuf = kmalloc_array(count, sizeof(unsigned int), GFP_KERNEL);
303303
if (!txbuf) {
304304
ret = -ENOMEM;
305-
goto out_kfree;
305+
goto out_kfree_raw;
306306
}
307307

308308
for (i = 0; i < count; i++)
@@ -366,6 +366,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
366366
return n;
367367
out_kfree:
368368
kfree(txbuf);
369+
out_kfree_raw:
369370
kfree(raw);
370371
out_unlock:
371372
mutex_unlock(&dev->lock);

0 commit comments

Comments
 (0)