mirror of
https://github.com/torvalds/linux.git
synced 2026-06-07 14:04:54 +02:00
media: media/saa7164: fix saa7164_encoder_register() memory leak bugs
[ Upstream commit c759b2970c ]
Add a fix for the memory leak bugs that can occur when the
saa7164_encoder_register() function fails.
The function allocates memory without explicitly freeing
it when errors occur.
Add a better error handling that deallocate the unused buffers before the
function exits during a fail.
Signed-off-by: Daniel Niv <danielniv3@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
087c2bffb4
commit
6a3edc1a5e
|
|
@ -1008,7 +1008,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
|
||||||
printk(KERN_ERR "%s() failed (errno = %d), NO PCI configuration\n",
|
printk(KERN_ERR "%s() failed (errno = %d), NO PCI configuration\n",
|
||||||
__func__, result);
|
__func__, result);
|
||||||
result = -ENOMEM;
|
result = -ENOMEM;
|
||||||
goto failed;
|
goto fail_pci;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Establish encoder defaults here */
|
/* Establish encoder defaults here */
|
||||||
|
|
@ -1062,7 +1062,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
|
||||||
100000, ENCODER_DEF_BITRATE);
|
100000, ENCODER_DEF_BITRATE);
|
||||||
if (hdl->error) {
|
if (hdl->error) {
|
||||||
result = hdl->error;
|
result = hdl->error;
|
||||||
goto failed;
|
goto fail_hdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
port->std = V4L2_STD_NTSC_M;
|
port->std = V4L2_STD_NTSC_M;
|
||||||
|
|
@ -1080,7 +1080,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
|
||||||
printk(KERN_INFO "%s: can't allocate mpeg device\n",
|
printk(KERN_INFO "%s: can't allocate mpeg device\n",
|
||||||
dev->name);
|
dev->name);
|
||||||
result = -ENOMEM;
|
result = -ENOMEM;
|
||||||
goto failed;
|
goto fail_hdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
port->v4l_device->ctrl_handler = hdl;
|
port->v4l_device->ctrl_handler = hdl;
|
||||||
|
|
@ -1091,10 +1091,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
printk(KERN_INFO "%s: can't register mpeg device\n",
|
printk(KERN_INFO "%s: can't register mpeg device\n",
|
||||||
dev->name);
|
dev->name);
|
||||||
/* TODO: We're going to leak here if we don't dealloc
|
goto fail_reg;
|
||||||
The buffers above. The unreg function can't deal wit it.
|
|
||||||
*/
|
|
||||||
goto failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
|
printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
|
||||||
|
|
@ -1116,9 +1113,14 @@ int saa7164_encoder_register(struct saa7164_port *port)
|
||||||
|
|
||||||
saa7164_api_set_encoder(port);
|
saa7164_api_set_encoder(port);
|
||||||
saa7164_api_get_encoder(port);
|
saa7164_api_get_encoder(port);
|
||||||
|
return 0;
|
||||||
|
|
||||||
result = 0;
|
fail_reg:
|
||||||
failed:
|
video_device_release(port->v4l_device);
|
||||||
|
port->v4l_device = NULL;
|
||||||
|
fail_hdl:
|
||||||
|
v4l2_ctrl_handler_free(hdl);
|
||||||
|
fail_pci:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user