From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@xs4all.nl>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Hans Verkuil <hans.verkuil@cisco.com>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Subject: Re: [PATCH v3 7/8] media: uvcvideo: Refactor __uvc_ctrl_add_mapping
Date: Tue, 3 Jan 2023 22:22:01 +0200 [thread overview]
Message-ID: <Y7SOaXgUS/3G2s8M@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20220920-resend-v4l2-compliance-v3-7-598d33a15815@chromium.org>
Hi Ricardo,
Thank you for the patch.
On Tue, Jan 03, 2023 at 03:36:25PM +0100, Ricardo Ribalda wrote:
> Simplify the exit code with a common error tag freeing all the memory.
>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index aa7a668f60a7..4830120e6506 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -2296,32 +2296,30 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
> 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,
> * this could be optimized.
> */
> map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL);
> - if (map == NULL)
> + if (!map)
> return -ENOMEM;
>
> + map->name = NULL;
> + map->menu_info = NULL;
> +
> /* For UVCIOC_CTRL_MAP custom control */
> if (mapping->name) {
> map->name = kstrdup(mapping->name, GFP_KERNEL);
> - if (!map->name) {
> - kfree(map);
> - return -ENOMEM;
> - }
> + if (!map->name)
> + goto nomem;
> }
>
> INIT_LIST_HEAD(&map->ev_subs);
>
> size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask);
> map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL);
> - if (map->menu_info == NULL) {
> - kfree(map->name);
> - kfree(map);
> - return -ENOMEM;
> - }
> + if (!map->menu_info)
> + goto nomem;
>
> if (map->get == NULL)
> map->get = uvc_get_le_value;
> @@ -2342,6 +2340,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
> ctrl->info.selector);
>
> return 0;
> +
> +nomem:
As it's an error label, I'd name it err_nomem. I'll fix that when
applying.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + kfree(map->menu_info);
> + kfree(map->name);
> + kfree(map);
> + return -ENOMEM;
> }
>
> int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2023-01-03 20:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 14:36 [PATCH v3 0/8] Follow-up patches for uvc v4l2-compliance Ricardo Ribalda
2023-01-03 14:36 ` [PATCH v3 1/8] media: uvcvideo: Check for INACTIVE in uvc_ctrl_is_accessible() Ricardo Ribalda
2023-01-12 22:12 ` Laurent Pinchart
2023-01-03 14:36 ` [PATCH v3 2/8] media: uvcvideo: improve error logging in uvc_query_ctrl() Ricardo Ribalda
2023-01-03 20:13 ` Laurent Pinchart
2023-01-03 20:15 ` Ricardo Ribalda
2023-01-12 22:21 ` Laurent Pinchart
2023-01-03 14:36 ` [PATCH v3 3/8] media: uvcvideo: Return -EACCES for Wrong state error Ricardo Ribalda
2023-01-03 14:36 ` [PATCH v3 4/8] media: uvcvideo: Do not return positive errors in uvc_query_ctrl() Ricardo Ribalda
2023-01-03 14:36 ` [PATCH v3 5/8] media: uvcvideo: Fix handling on Bitmask controls Ricardo Ribalda
2023-01-03 20:17 ` Laurent Pinchart
2023-01-03 14:36 ` [PATCH v3 6/8] media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU Ricardo Ribalda
2023-01-05 11:17 ` Ricardo Ribalda
2023-01-03 14:36 ` [PATCH v3 7/8] media: uvcvideo: Refactor __uvc_ctrl_add_mapping Ricardo Ribalda
2023-01-03 20:22 ` Laurent Pinchart [this message]
2023-01-03 14:36 ` [PATCH v3 8/8] media: uvcvideo: Use standard names for menus Ricardo Ribalda
2023-01-03 20:46 ` Laurent Pinchart
2023-01-04 18:31 ` kernel test robot
2023-01-03 20:53 ` [PATCH v3 0/8] Follow-up patches for uvc v4l2-compliance Laurent Pinchart
2023-01-03 20:54 ` Ricardo Ribalda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7SOaXgUS/3G2s8M@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox