Message ID | 20200728112209.26207-2-hdegoede@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2,1/2] media: uvcvideo: Fix uvc_ctrl_fixup_xu_info() not having any effect | expand |
Hi Hans, Thank you for the patch. On Tue, Jul 28, 2020 at 01:22:09PM +0200, Hans de Goede wrote: > There is only 1 error exit in uvc_ctrl_add_info(), so using goto style > error handling is not necessary. Also the kfree(ctrl->uvc_data) on error > is not necessary, because the only error exit is for the kzalloc() of > ctrl->uvc_data failing. > > Remove all the error handling cruft and simply do "return -ENOMEM" on > kzalloc() failure. > > Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > Changes in v2: > - new patch in v2 of this series > --- > drivers/media/usb/uvc/uvc_ctrl.c | 13 +++---------- > 1 file changed, 3 insertions(+), 10 deletions(-) > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > index b78aba991212..dbebc6083e85 100644 > --- a/drivers/media/usb/uvc/uvc_ctrl.c > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > @@ -2011,18 +2011,14 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) > static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, > const struct uvc_control_info *info) > { > - int ret = 0; > - > ctrl->info = *info; > INIT_LIST_HEAD(&ctrl->info.mappings); > > /* Allocate an array to save control values (cur, def, max, etc.) */ > ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1, > GFP_KERNEL); > - if (ctrl->uvc_data == NULL) { > - ret = -ENOMEM; > - goto done; > - } > + if (!ctrl->uvc_data) > + return -ENOMEM; > > ctrl->initialized = 1; > > @@ -2030,10 +2026,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, > "entity %u\n", ctrl->info.entity, ctrl->info.selector, > dev->udev->devpath, ctrl->entity->id); > > -done: > - if (ret < 0) > - kfree(ctrl->uvc_data); > - return ret; > + return 0; > } > > /*
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b78aba991212..dbebc6083e85 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2011,18 +2011,14 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, const struct uvc_control_info *info) { - int ret = 0; - ctrl->info = *info; INIT_LIST_HEAD(&ctrl->info.mappings); /* Allocate an array to save control values (cur, def, max, etc.) */ ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1, GFP_KERNEL); - if (ctrl->uvc_data == NULL) { - ret = -ENOMEM; - goto done; - } + if (!ctrl->uvc_data) + return -ENOMEM; ctrl->initialized = 1; @@ -2030,10 +2026,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, "entity %u\n", ctrl->info.entity, ctrl->info.selector, dev->udev->devpath, ctrl->entity->id); -done: - if (ret < 0) - kfree(ctrl->uvc_data); - return ret; + return 0; } /*
There is only 1 error exit in uvc_ctrl_add_info(), so using goto style error handling is not necessary. Also the kfree(ctrl->uvc_data) on error is not necessary, because the only error exit is for the kzalloc() of ctrl->uvc_data failing. Remove all the error handling cruft and simply do "return -ENOMEM" on kzalloc() failure. Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- Changes in v2: - new patch in v2 of this series --- drivers/media/usb/uvc/uvc_ctrl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)