Commit 18a9b21f authored by Ricardo Ribalda's avatar Ricardo Ribalda Committed by Mauro Carvalho Chehab

media: uvcvideo: Fix memory leak if uvc_ctrl_add_mapping fails

Move all the life cycle of the name to add_mapping. This simplifies
the error handling inside uvc_ioctl_ctrl_map and solves a memory leak
when kemmdup fails.

Also make sure that for custom controls, the user provides a valid name.

Fixes: 07adedb5c606 ("media: uvcvideo: Use control names from framework")
Signed-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 1c8af8e9
...@@ -2188,11 +2188,21 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, ...@@ -2188,11 +2188,21 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
if (map == NULL) if (map == NULL)
return -ENOMEM; return -ENOMEM;
/* For UVCIOC_CTRL_MAP custom control */
if (mapping->name) {
map->name = kstrdup(mapping->name, GFP_KERNEL);
if (!map->name) {
kfree(map);
return -ENOMEM;
}
}
INIT_LIST_HEAD(&map->ev_subs); INIT_LIST_HEAD(&map->ev_subs);
size = sizeof(*mapping->menu_info) * mapping->menu_count; size = sizeof(*mapping->menu_info) * mapping->menu_count;
map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL);
if (map->menu_info == NULL) { if (map->menu_info == NULL) {
kfree(map->name);
kfree(map); kfree(map);
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -42,12 +42,12 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, ...@@ -42,12 +42,12 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
map->id = xmap->id; map->id = xmap->id;
/* Non standard control id. */ /* Non standard control id. */
if (v4l2_ctrl_get_name(map->id) == NULL) { if (v4l2_ctrl_get_name(map->id) == NULL) {
map->name = kmemdup(xmap->name, sizeof(xmap->name), if (xmap->name[0] == '\0') {
GFP_KERNEL); ret = -EINVAL;
if (!map->name) {
ret = -ENOMEM;
goto free_map; goto free_map;
} }
xmap->name[sizeof(xmap->name) - 1] = '\0';
map->name = xmap->name;
} }
memcpy(map->entity, xmap->entity, sizeof(map->entity)); memcpy(map->entity, xmap->entity, sizeof(map->entity));
map->selector = xmap->selector; map->selector = xmap->selector;
......
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