media: uvcvideo: Fix memory leak of object map on error exit path

Currently when the allocation of map->name fails the error exit path
does not kfree the previously allocated object map. Fix this by
setting ret to -ENOMEM and taking the free_map exit error path to
ensure map is kfree'd.

Addresses-Coverity: ("Resource leak")

Fixes: 70fa906d6f ("media: uvcvideo: Use control names from framework")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
Colin Ian King 2021-09-17 13:49:30 +02:00 коммит произвёл Mauro Carvalho Chehab
Родитель 4383cfa18c
Коммит 4b06506055
1 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -44,8 +44,10 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
if (v4l2_ctrl_get_name(map->id) == NULL) {
map->name = kmemdup(xmap->name, sizeof(xmap->name),
GFP_KERNEL);
if (!map->name)
return -ENOMEM;
if (!map->name) {
ret = -ENOMEM;
goto free_map;
}
}
memcpy(map->entity, xmap->entity, sizeof(map->entity));
map->selector = xmap->selector;