Commit 252d50da authored by Ricardo Ribalda's avatar Ricardo Ribalda Committed by Laurent Pinchart

media: uvcvideo: Refactor __uvc_ctrl_add_mapping

Simplify the exit code with a common error tag freeing all the memory.
Suggested-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
parent 7faf8ae4
...@@ -2286,32 +2286,30 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, ...@@ -2286,32 +2286,30 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
unsigned int i; unsigned int i;
/* /*
* Most mappings come from static kernel data and need to be duplicated. * Most mappings come from static kernel data, and need to be duplicated.
* Mappings that come from userspace will be unnecessarily duplicated, * Mappings that come from userspace will be unnecessarily duplicated,
* this could be optimized. * this could be optimized.
*/ */
map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL); map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL);
if (map == NULL) if (!map)
return -ENOMEM; return -ENOMEM;
map->name = NULL;
map->menu_info = NULL;
/* For UVCIOC_CTRL_MAP custom control */ /* For UVCIOC_CTRL_MAP custom control */
if (mapping->name) { if (mapping->name) {
map->name = kstrdup(mapping->name, GFP_KERNEL); map->name = kstrdup(mapping->name, GFP_KERNEL);
if (!map->name) { if (!map->name)
kfree(map); goto err_nomem;
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)
kfree(map->name); goto err_nomem;
kfree(map);
return -ENOMEM;
}
if (map->get == NULL) if (map->get == NULL)
map->get = uvc_get_le_value; map->get = uvc_get_le_value;
...@@ -2332,6 +2330,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, ...@@ -2332,6 +2330,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
ctrl->info.selector); ctrl->info.selector);
return 0; return 0;
err_nomem:
kfree(map->menu_info);
kfree(map->name);
kfree(map);
return -ENOMEM;
} }
int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
......
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