uvcvideo: Fine-tuning for some function implementations
Subsystems (3)
cover uvcvideo: Fine-tuning for some function implementations
From: Markus Elfring <[email protected]>
Date: Thu, 21 Sep 2017 21:20:12 +0200
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Use common error handling code in uvc_ioctl_g_ext_ctrls() Adjust 14 checks for null pointers
Add some spaces for better code readability
drivers/media/usb/uvc/uvc_v4l2.c | 53 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/3 uvcvideo: Use common error handling code in uvc_ioctl_g_ext_ctrls()
From: Markus Elfring <[email protected]>
Date: Thu, 21 Sep 2017 20:47:02 +0200
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +7 -6
@@ -998,10 +998,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,struct v4l2_queryctrl qc = { .id = ctrl->id }; ret =uvc_query_v4l2_ctrl (chain, &qc); -if (ret <0 ) { - ctrls->error_idx = i; -return ret; - } +if (ret <0 ) + goto set_index; ctrl->value = qc.default_value; }
@@ -1017,14 +1015,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, ret =uvc_ctrl_get (chain, ctrl);if (ret <0 ) {uvc_ctrl_rollback (handle); - ctrls->error_idx = i; -return ret; + goto set_index; } } ctrls->error_idx =0 ;return uvc_ctrl_rollback (handle); + +set_index: + ctrls->error_idx = i; +return ret; } static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
Signature · 1 line
2.14.1
PATCH 2/3 uvcvideo: Adjust 14 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 21 Sep 2017 21:00:21 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/media/usb/uvc/uvc_v4l2.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +13 -14
@@ -41,7 +41,7 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,int ret; map =kzalloc (sizeof *map,GFP_KERNEL ); -if (map =NULL ) +if (!map)return -ENOMEM ; map->id = xmap->id;
@@ -211,7 +211,7 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,break ; } -if (frame =NULL ) { +if (!frame) {uvc_trace (UVC_TRACE_FORMAT ,"Unsupported size %ux%u.\n" , fmt->fmt.pix.width, fmt->fmt.pix.height);return -EINVAL ;
@@ -260,9 +260,9 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream, fmt->fmt.pix.colorspace = format->colorspace; fmt->fmt.pix.priv =0 ; -if (uvc_format !=NULL ) +if (uvc_format) *uvc_format = format; -if (uvc_frame !=NULL ) +if (uvc_frame) *uvc_frame = frame; done:
@@ -282,8 +282,7 @@ static int uvc_v4l2_get_format(struct uvc_streaming *stream,mutex_lock (&stream->mutex); format = stream->cur_format; frame = stream->cur_frame; - -if (format =NULL || frame =NULL ) { +if (!format || !frame) { ret = -EINVAL ; goto done; }
@@ -499,7 +498,7 @@ static int uvc_v4l2_open(struct file *file)/* Create the device handle. */ handle =kzalloc (sizeof *handle,GFP_KERNEL ); -if (handle =NULL ) { +if (!handle) {usb_autopm_put_interface (stream->dev->intf);return -ENOMEM ; }
@@ -811,7 +810,7 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,u32 index = input->index;int pin =0 ; -if (selector =NULL || +if (!selector || (chain->dev->quirks &UVC_QUIRK_IGNORE_SELECTOR_UNIT )) {if (index !=0 )return -EINVAL ;
@@ -830,7 +829,7 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh, } } -if (iterm =NULL || iterm->id != pin) +if (!iterm || iterm->id != pin)return -EINVAL ;memset (input,0 ,sizeof (*input));
@@ -849,7 +848,7 @@ static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input)int ret;u8 i; -if (chain->selector =NULL || +if (!chain->selector || (chain->dev->quirks &UVC_QUIRK_IGNORE_SELECTOR_UNIT )) { *input =0 ;return 0 ;
@@ -876,7 +875,7 @@ static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input)if (ret <0 )return ret; -if (chain->selector =NULL || +if (!chain->selector || (chain->dev->quirks &UVC_QUIRK_IGNORE_SELECTOR_UNIT )) {if (input)return -EINVAL ;
@@ -1160,7 +1159,7 @@ static int uvc_ioctl_enum_framesizes(struct file *file, void *fh,break ; } } -if (format =NULL ) +if (!format)return -EINVAL ;if (fsize->index >= format->nframes)
@@ -1189,7 +1188,7 @@ static int uvc_ioctl_enum_frameintervals(struct file *file, void *fh,break ; } } -if (format =NULL ) +if (!format)return -EINVAL ;for (i =0 ; i < format->nframes; i++) {
@@ -1199,7 +1198,7 @@ static int uvc_ioctl_enum_frameintervals(struct file *file, void *fh,break ; } } -if (frame =NULL ) +if (!frame)return -EINVAL ;if (frame->bFrameIntervalType) {
Signature · 1 line
2.14.1
PATCH 3/3 uvcvideo: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 21 Sep 2017 21:12:29 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +7 -6
@@ -123,13 +123,13 @@ static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval) best = dist; } - interval = frame->dwFrameInterval[i-1 ]; + interval = frame->dwFrameInterval[i -1 ]; }else {const __u32 min = frame->dwFrameInterval[0 ];const __u32 max = frame->dwFrameInterval[1 ];const __u32 step = frame->dwFrameInterval[2 ]; - interval = min + (interval - min + step/2 ) / step * step; + interval = min + (interval - min + step /2 ) / step * step;if (interval > max) interval = max; }
@@ -201,7 +201,7 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,__u16 h = format->frame[i].wHeight; d =min (w, rw) *min (h, rh); - d = w*h + rw*rh -2 *d; + d = w * h + rw * rh -2 * d;if (d < maxd) { maxd = d; frame = &format->frame[i];
@@ -219,9 +219,10 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,/* Use the default frame interval. */ interval = frame->dwDefaultFrameInterval; -uvc_trace (UVC_TRACE_FORMAT ,"Using default frame interval %u.%u us " -"(%u.%u fps).\n" , interval/10 , interval%10 ,10000000 /interval, - (100000000 /interval)%10 ); +uvc_trace (UVC_TRACE_FORMAT , +"Using default frame interval %u.%u us (%u.%u fps).\n" , + interval /10 , interval %10 , +10000000 / interval, (100000000 / interval) %10 );/* Set the format index, frame index and frame interval. */ memset (probe,0 ,sizeof *probe);
Signature · 1 line
2.14.1