USB Video Class driver: Fine-tuning for several function implementations
Subsystems (3)
cover USB Video Class driver: Fine-tuning for several function implementations
From: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 19:23:32 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (19):
uvc_driver: Use kmalloc_array() in uvc_simplify_fraction()
uvc_driver: Combine substrings for 48 messages
uvc_driver: Adjust three function calls together with a variable assignment
uvc_driver: Adjust 28 checks for null pointers
uvc_driver: Enclose 24 expressions for the sizeof operator by parentheses
uvc_driver: Add some spaces for better code readability
uvc_driver: Rename a jump label in uvc_probe()
uvc_driver: Rename a jump label in uvc_scan_fallback()
uvc_driver: Less function calls in uvc_parse_streaming() after error detection
uvc_driver: Return -ENOMEM after a failed kzalloc() call in uvc_parse_streaming()
uvc_driver: Delete an unnecessary variable initialisation in uvc_parse_streaming()
uvc_driver: Move six assignments in uvc_parse_streaming()
uvc_video: Use kmalloc_array() in uvc_video_clock_init()
uvc_video: Combine substrings for 22 messages
uvc_video: Adjust one function call together with a variable assignment
uvc_video: Adjust 18 checks for null pointers
uvc_video: Fix a typo in a comment line
uvc_video: Enclose an expression for the sizeof operator by parentheses
uvc_video: Add some spaces for better code readability
drivers/media/usb/uvc/uvc_driver.c | 532 +++++++++++++++++++------------------ drivers/media/usb/uvc/uvc_video.c | 162 +++++------ 2 files changed, 363 insertions(+), 331 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/19 uvc_driver: Use kmalloc_array() in uvc_simplify_fraction()
From: Markus Elfring <[email protected]>
Date: Sat, 24 Dec 2016 21:10:16 +0100
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -253,7 +253,7 @@ void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,uint32_t x, y, r;unsigned int i, n; - an =kmalloc (n_terms *sizeof *an,GFP_KERNEL ); + an =kmalloc_array (n_terms,sizeof (*an),GFP_KERNEL );if (an =NULL )return ;
Signature · 1 line
2.11.0
PATCH 2/19 uvc_driver: Combine substrings for 48 messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 07:41:29 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
* Thus fix the affected source code places.
* Improve indentation for passed parameters.
--- drivers/media/usb/uvc/uvc_driver.c | 290 ++++++++++++++++++++----------------- 1 file changed, 156 insertions(+), 134 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +156 -134
@@ -390,10 +390,10 @@ static int uvc_parse_format(struct uvc_device *dev,case UVC_VS_FORMAT_FRAME_BASED : n = buffer[2 ] =UVC_VS_FORMAT_UNCOMPRESSED ?27 :28 ;if (buflen < n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d FORMAT error\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d FORMAT error\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -438,10 +438,10 @@ static int uvc_parse_format(struct uvc_device *dev,case UVC_VS_FORMAT_MJPEG :if (buflen <11 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d FORMAT error\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d FORMAT error\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -454,10 +454,10 @@ static int uvc_parse_format(struct uvc_device *dev,case UVC_VS_FORMAT_DV :if (buflen <9 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d FORMAT error\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d FORMAT error\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -472,10 +472,10 @@ static int uvc_parse_format(struct uvc_device *dev,strlcpy (format->name,"HD-DV" ,sizeof format->name);break ;default : -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d: unknown DV format %u\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber, buffer[8 ]); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d: unknown DV format %u\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber, buffer[8 ]);return -EINVAL ; }
@@ -501,10 +501,11 @@ static int uvc_parse_format(struct uvc_device *dev,case UVC_VS_FORMAT_STREAM_BASED :/* Not supported yet. */ default : -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d unsupported format %u\n" , - dev->udev->devnum, alts->desc.bInterfaceNumber, - buffer[2 ]); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d unsupported format %u\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber, + buffer[2 ]);return -EINVAL ; }
@@ -527,9 +528,10 @@ static int uvc_parse_format(struct uvc_device *dev, n = n ? n :3 ;if (buflen <26 +4 *n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d FRAME error\n" , dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d FRAME error\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -610,10 +612,10 @@ static int uvc_parse_format(struct uvc_device *dev,if (buflen >2 && buffer[1 ] =USB_DT_CS_INTERFACE && buffer[2 ] =UVC_VS_COLORFORMAT ) {if (buflen <6 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d COLORFORMAT error\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d COLORFORMAT error\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -643,16 +645,18 @@ static int uvc_parse_streaming(struct uvc_device *dev,if (intf->cur_altsetting->desc.bInterfaceSubClass !=UVC_SC_VIDEOSTREAMING ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d interface %d isn't a " -"video streaming interface\n" , dev->udev->devnum, - intf->altsetting[0 ].desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d interface %d isn't a video streaming interface\n" , + dev->udev->devnum, + intf->altsetting[0 ].desc.bInterfaceNumber);return -EINVAL ; }if (usb_driver_claim_interface (&uvc_driver.driver, intf, dev)) { -uvc_trace (UVC_TRACE_DESCR ,"device %d interface %d is already " -"claimed\n" , dev->udev->devnum, - intf->altsetting[0 ].desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d interface %d is already claimed\n" , + dev->udev->devnum, + intf->altsetting[0 ].desc.bInterfaceNumber);return -EINVAL ; }
@@ -679,8 +683,9 @@ static int uvc_parse_streaming(struct uvc_device *dev,if (ep->extralen >2 && ep->extra[1 ] =USB_DT_CS_INTERFACE ) { -uvc_trace (UVC_TRACE_DESCR ,"trying extra data " -"from endpoint %u.\n" , i); +uvc_trace (UVC_TRACE_DESCR , +"trying extra data from endpoint %u.\n" , + i); buffer = alts->endpoint[i].extra; buflen = alts->endpoint[i].extralen;break ;
@@ -695,8 +700,8 @@ static int uvc_parse_streaming(struct uvc_device *dev, }if (buflen <=2 ) { -uvc_trace (UVC_TRACE_DESCR ,"no class-specific streaming " -"interface descriptors found.\n" ); +uvc_trace (UVC_TRACE_DESCR , +"no class-specific streaming interface descriptors found.\n" ); goto error; }
@@ -713,9 +718,9 @@ static int uvc_parse_streaming(struct uvc_device *dev,break ;default : -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface " -"%d HEADER descriptor not found.\n" , dev->udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d HEADER descriptor not found.\n" , + dev->udev->devnum, alts->desc.bInterfaceNumber); goto error; }
@@ -723,9 +728,9 @@ static int uvc_parse_streaming(struct uvc_device *dev, n = buflen >= size ? buffer[size-1 ] :0 ;if (buflen < size + p*n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d HEADER descriptor is invalid.\n" , - dev->udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d HEADER descriptor is invalid.\n" , + dev->udev->devnum, alts->desc.bInterfaceNumber); goto error; }
@@ -775,10 +780,11 @@ static int uvc_parse_streaming(struct uvc_device *dev,case UVC_VS_FORMAT_MPEG2TS :case UVC_VS_FORMAT_STREAM_BASED : -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming " -"interface %d FORMAT %u is not supported.\n" , - dev->udev->devnum, - alts->desc.bInterfaceNumber, _buffer[2 ]); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d FORMAT %u is not supported.\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber, + _buffer[2 ]);break ;case UVC_VS_FRAME_UNCOMPRESSED :
@@ -800,9 +806,9 @@ static int uvc_parse_streaming(struct uvc_device *dev, }if (nformats =0 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface " -"%d has no supported formats defined.\n" , - dev->udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d has no supported formats defined.\n" , + dev->udev->devnum, alts->desc.bInterfaceNumber); goto error; }
@@ -849,9 +855,11 @@ static int uvc_parse_streaming(struct uvc_device *dev, }if (buflen) -uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface " -"%d has %u bytes of trailing descriptor garbage.\n" , - dev->udev->devnum, alts->desc.bInterfaceNumber, buflen); +uvc_trace (UVC_TRACE_DESCR , +"device %d videostreaming interface %d has %u bytes of trailing descriptor garbage.\n" , + dev->udev->devnum, + alts->desc.bInterfaceNumber, + buflen);/* Parse the alternate settings to find the maximum bandwidth. */ for (i =0 ; i < intf->num_altsetting; ++i) {
@@ -959,9 +967,9 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, n = buflen >=25 + p ? buffer[22 +p] :0 ;if (buflen <25 + p +2 *n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d EXTENSION_UNIT error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d EXTENSION_UNIT error\n" , + udev->devnum, alts->desc.bInterfaceNumber);break ; }
@@ -1008,9 +1016,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev, n = buflen >=12 ? buffer[11 ] :0 ;if (buflen <12 + n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d HEADER error\n" , udev->devnum, - alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d HEADER error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1021,9 +1029,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,for (i =0 ; i < n; ++i) { intf =usb_ifnum_to_if (udev, buffer[12 +i]);if (intf =NULL ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d " -"interface %d doesn't exists\n" , - udev->devnum, i); +uvc_trace (UVC_TRACE_DESCR , +"device %d interface %d doesn't exists\n" , + udev->devnum, i);continue ; }
@@ -1033,9 +1041,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,case UVC_VC_INPUT_TERMINAL :if (buflen <8 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d INPUT_TERMINAL error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d INPUT_TERMINAL error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1044,11 +1052,12 @@ static int uvc_parse_standard_control(struct uvc_device *dev,*/ type =get_unaligned_le16 (&buffer[4 ]);if ((type &0xff00 ) =0 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d INPUT_TERMINAL %d has invalid " -"type 0x%04x, skipping\n" , udev->devnum, - alts->desc.bInterfaceNumber, - buffer[3 ], type); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n" , + udev->devnum, + alts->desc.bInterfaceNumber, + buffer[3 ], + type);return 0 ; }
@@ -1067,9 +1076,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev, }if (buflen < len + n + p) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d INPUT_TERMINAL error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d INPUT_TERMINAL error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1114,9 +1123,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,case UVC_VC_OUTPUT_TERMINAL :if (buflen <9 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d OUTPUT_TERMINAL error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d OUTPUT_TERMINAL error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1125,10 +1134,12 @@ static int uvc_parse_standard_control(struct uvc_device *dev,*/ type =get_unaligned_le16 (&buffer[4 ]);if ((type &0xff00 ) =0 ) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d OUTPUT_TERMINAL %d has invalid " -"type 0x%04x, skipping\n" , udev->devnum, - alts->desc.bInterfaceNumber, buffer[3 ], type); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n" , + udev->devnum, + alts->desc.bInterfaceNumber, + buffer[3 ], + type);return 0 ; }
@@ -1152,9 +1163,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev, p = buflen >=5 ? buffer[4 ] :0 ;if (buflen <5 || buflen <6 + p) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d SELECTOR_UNIT error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d SELECTOR_UNIT error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1178,9 +1189,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev, p = dev->uvc_version >=0x0110 ?10 :9 ;if (buflen < p + n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d PROCESSING_UNIT error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d PROCESSING_UNIT error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1211,9 +1222,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev, n = buflen >=24 + p ? buffer[22 +p] :0 ;if (buflen <24 + p + n) { -uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol " -"interface %d EXTENSION_UNIT error\n" , - udev->devnum, alts->desc.bInterfaceNumber); +uvc_trace (UVC_TRACE_DESCR , +"device %d videocontrol interface %d EXTENSION_UNIT error\n" , + udev->devnum, alts->desc.bInterfaceNumber);return -EINVAL ; }
@@ -1238,8 +1249,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,break ;default : -uvc_trace (UVC_TRACE_DESCR ,"Found an unknown CS_INTERFACE " -"descriptor (%u)\n" , buffer[2 ]); +uvc_trace (UVC_TRACE_DESCR , +"Found an unknown CS_INTERFACE descriptor (%u)\n" , + buffer[2 ]);break ; }
@@ -1284,8 +1296,9 @@ static int uvc_parse_control(struct uvc_device *dev)if (usb_endpoint_is_int_in (desc) &&le16_to_cpu (desc->wMaxPacketSize) >=8 && desc->bInterval !=0 ) { -uvc_trace (UVC_TRACE_DESCR ,"Found a Status endpoint " -"(addr %02x).\n" , desc->bEndpointAddress); +uvc_trace (UVC_TRACE_DESCR , +"Found a Status endpoint (addr %02x).\n" , + desc->bEndpointAddress); dev->int_ep = ep; } }
@@ -1332,8 +1345,9 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,printk (KERN_CONT " <- XU %d" , entity->id);if (entity->bNrInPins !=1 ) { -uvc_trace (UVC_TRACE_DESCR ,"Extension unit %d has more " -"than 1 input pin.\n" , entity->id); +uvc_trace (UVC_TRACE_DESCR , +"Extension unit %d has more than 1 input pin.\n" , + entity->id);return -1 ; }
@@ -1344,8 +1358,8 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,printk (KERN_CONT " <- PU %d" , entity->id);if (chain->processing !=NULL ) { -uvc_trace (UVC_TRACE_DESCR ,"Found multiple " -"Processing Units in chain.\n" ); +uvc_trace (UVC_TRACE_DESCR , +"Found multiple Processing Units in chain.\n" );return -1 ; }
@@ -1361,8 +1375,8 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,break ;if (chain->selector !=NULL ) { -uvc_trace (UVC_TRACE_DESCR ,"Found multiple Selector " -"Units in chain.\n" ); +uvc_trace (UVC_TRACE_DESCR , +"Found multiple Selector Units in chain.\n" );return -1 ; }
@@ -1397,8 +1411,9 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,break ;default : -uvc_trace (UVC_TRACE_DESCR ,"Unsupported entity type " -"0x%04x found in chain.\n" ,UVC_ENTITY_TYPE (entity)); +uvc_trace (UVC_TRACE_DESCR , +"Unsupported entity type 0x%04x found in chain.\n" , +UVC_ENTITY_TYPE (entity));return -1 ; }
@@ -1427,8 +1442,8 @@ static int uvc_scan_chain_forward(struct uvc_video_chain *chain,switch (UVC_ENTITY_TYPE (forward)) {case UVC_VC_EXTENSION_UNIT :if (forward->bNrInPins !=1 ) { -uvc_trace (UVC_TRACE_DESCR ,"Extension unit %d " -"has more than 1 input pin.\n" , +uvc_trace (UVC_TRACE_DESCR , +"Extension unit %d has more than 1 input pin.\n" , entity->id);return -EINVAL ; }
@@ -1448,8 +1463,9 @@ static int uvc_scan_chain_forward(struct uvc_video_chain *chain,case UVC_OTT_MEDIA_TRANSPORT_OUTPUT :case UVC_TT_STREAMING :if (UVC_ENTITY_IS_ITERM (forward)) { -uvc_trace (UVC_TRACE_DESCR ,"Unsupported input " -"terminal %u.\n" , forward->id); +uvc_trace (UVC_TRACE_DESCR , +"Unsupported input terminal %u.\n" , + forward->id);return -EINVAL ; }
@@ -1498,9 +1514,9 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain, id = entity->baSourceID[i]; term =uvc_entity_by_id (chain->dev, id);if (term =NULL || !UVC_ENTITY_IS_ITERM (term)) { -uvc_trace (UVC_TRACE_DESCR ,"Selector unit %d " -"input %d isn't connected to an " -"input terminal\n" , entity->id, i); +uvc_trace (UVC_TRACE_DESCR , +"Selector unit %d input %d isn't connected to an input terminal\n" , + entity->id, i);return -1 ; }
@@ -1535,8 +1551,9 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain, entity =uvc_entity_by_id (chain->dev, id);if (entity =NULL ) { -uvc_trace (UVC_TRACE_DESCR ,"Found reference to " -"unknown entity %d.\n" , id); +uvc_trace (UVC_TRACE_DESCR , +"Found reference to unknown entity %d.\n" , + id);return -EINVAL ; }
@@ -1557,8 +1574,9 @@ static int uvc_scan_chain(struct uvc_video_chain *chain,while (entity !=NULL ) {/* Entity must not be part of an existing chain */ if (entity->chain.next || entity->chain.prev) { -uvc_trace (UVC_TRACE_DESCR ,"Found reference to " -"entity %d already in chain.\n" , entity->id); +uvc_trace (UVC_TRACE_DESCR , +"Found reference to entity %d already in chain.\n" , + entity->id);return -EINVAL ; }
@@ -1892,8 +1910,9 @@ static int uvc_register_video(struct uvc_device *dev,*/ ret =uvc_video_init (stream);if (ret <0 ) { -uvc_printk (KERN_ERR ,"Failed to initialize the device " -"(%d).\n" , ret); +uvc_printk (KERN_ERR , +"Failed to initialize the device (%d).\n" , + ret);return ret; }
@@ -1951,8 +1970,9 @@ static int uvc_register_terms(struct uvc_device *dev, stream =uvc_stream_by_id (dev, term->id);if (stream =NULL ) { -uvc_printk (KERN_INFO ,"No streaming interface found " -"for terminal %u." , term->id); +uvc_printk (KERN_INFO , +"No streaming interface found for terminal %u." , + term->id);continue ; }
@@ -1980,8 +2000,9 @@ static int uvc_register_chains(struct uvc_device *dev)#ifdef CONFIG_MEDIA_CONTROLLER ret =uvc_mc_register_entities (chain);if (ret <0 ) { -uvc_printk (KERN_INFO ,"Failed to register entites " -"(%d).\n" , ret); +uvc_printk (KERN_INFO , +"Failed to register entities (%d).\n" , + ret); }#endif }
@@ -2001,9 +2022,9 @@ static int uvc_probe(struct usb_interface *intf,int ret;if (id->idVendor && id->idProduct) -uvc_trace (UVC_TRACE_PROBE ,"Probing known UVC device %s " -"(%04x:%04x)\n" , udev->devpath, id->idVendor, - id->idProduct); +uvc_trace (UVC_TRACE_PROBE , +"Probing known UVC device %s (%04x:%04x)\n" , + udev->devpath, id->idVendor, id->idProduct);else uvc_trace (UVC_TRACE_PROBE ,"Probing generic UVC device %s\n" , udev->devpath);
@@ -2035,8 +2056,8 @@ static int uvc_probe(struct usb_interface *intf,/* Parse the Video Class control descriptor. */ if (uvc_parse_control (dev) <0 ) { -uvc_trace (UVC_TRACE_PROBE ,"Unable to parse UVC " -"descriptors.\n" ); +uvc_trace (UVC_TRACE_PROBE , +"Unable to parse UVC descriptors.\n" ); goto error; }
@@ -2047,10 +2068,11 @@ static int uvc_probe(struct usb_interface *intf, le16_to_cpu(udev->descriptor.idProduct));if (dev->quirks != id->driver_info) { -uvc_printk (KERN_INFO ,"Forcing device quirks to 0x%x by module " -"parameter for testing purpose.\n" , dev->quirks); -uvc_printk (KERN_INFO ,"Please report required quirks to the " -"linux-uvc-devel mailing list.\n" ); +uvc_printk (KERN_INFO , +"Forcing device quirks to 0x%x by module parameter for testing purpose.\n" , + dev->quirks); +uvc_printk (KERN_INFO , +"Please report required quirks to the linux-uvc-devel mailing list.\n" ); }/* Initialize the media device and register the V4L2 device. */
@@ -2092,9 +2114,9 @@ static int uvc_probe(struct usb_interface *intf,/* Initialize the interrupt URB. */ if ((ret =uvc_status_init (dev)) <0 ) { -uvc_printk (KERN_INFO ,"Unable to initialize the status " -"endpoint (%d), status interrupt will not be " -"supported.\n" , ret); +uvc_printk (KERN_INFO , +"Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n" , + ret); }uvc_trace (UVC_TRACE_PROBE ,"UVC device initialized.\n" );
@@ -2145,8 +2167,8 @@ static int uvc_suspend(struct usb_interface *intf, pm_message_t message)return uvc_video_suspend (stream); } -uvc_trace (UVC_TRACE_SUSPEND ,"Suspend: video streaming USB interface " -"mismatch.\n" ); +uvc_trace (UVC_TRACE_SUSPEND , +"Suspend: video streaming USB interface mismatch.\n" );return -EINVAL ; }
@@ -2185,8 +2207,8 @@ static int __uvc_resume(struct usb_interface *intf, int reset) } } -uvc_trace (UVC_TRACE_SUSPEND ,"Resume: video streaming USB interface " -"mismatch.\n" ); +uvc_trace (UVC_TRACE_SUSPEND , +"Resume: video streaming USB interface mismatch.\n" );return -EINVAL ; }
Signature · 1 line
2.11.0
PATCH 3/19 uvc_driver: Adjust three function calls together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 08:05:58 +0100
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
--- drivers/media/usb/uvc/uvc_driver.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +6 -4
@@ -1275,7 +1275,8 @@ static int uvc_parse_control(struct uvc_device *dev) buffer[1] != USB_DT_CS_INTERFACE) goto next_descriptor; -if ((ret =uvc_parse_standard_control (dev, buffer, buflen)) <0 ) + ret =uvc_parse_standard_control (dev, buffer, buflen); +if (ret <0 )return ret; next_descriptor:
@@ -2030,7 +2031,8 @@ static int uvc_probe(struct usb_interface *intf, udev->devpath);/* Allocate memory for the device and initialize it. */ -if ((dev =kzalloc (sizeof *dev,GFP_KERNEL )) =NULL ) + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (!dev)return -ENOMEM ;INIT_LIST_HEAD (&dev->entities);
@@ -2113,11 +2115,11 @@ static int uvc_probe(struct usb_interface *intf,usb_set_intfdata (intf, dev);/* Initialize the interrupt URB. */ -if ((ret =uvc_status_init (dev)) <0 ) { + ret =uvc_status_init (dev); +if (ret <0 )uvc_printk (KERN_INFO ,"Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n" , ret); - }uvc_trace (UVC_TRACE_PROBE ,"UVC device initialized.\n" );usb_enable_autosuspend (udev);
Signature · 1 line
2.11.0
PATCH 4/19 uvc_driver: Adjust 28 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 09:40:21 +0100
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_driver.c | 54 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +27 -27
@@ -254,7 +254,7 @@ void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,unsigned int i, n; an =kmalloc_array (n_terms,sizeof (*an),GFP_KERNEL ); -if (an =NULL ) +if (!an)return ;/* Convert the fraction to a simple continued fraction. See
@@ -340,7 +340,7 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev, {unsigned int i; -if (entity =NULL ) +if (!entity) entity = list_entry(&dev->entities, struct uvc_entity, list);list_for_each_entry_continue (entity, &dev->entities, list) {
@@ -400,7 +400,7 @@ static int uvc_parse_format(struct uvc_device *dev,/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]); -if (fmtdesc !=NULL ) { +if (fmtdesc) {strlcpy (format->name, fmtdesc->name,sizeof format->name); format->fcc = fmtdesc->fcc;
@@ -661,7 +661,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, } streaming =kzalloc (sizeof *streaming,GFP_KERNEL ); -if (streaming =NULL ) { +if (!streaming) {usb_driver_release_interface (&uvc_driver.driver, intf);return -EINVAL ; }
@@ -749,7 +749,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, streaming->header.bmaControls =kmemdup (&buffer[size], p * n,GFP_KERNEL ); -if (streaming->header.bmaControls =NULL ) { +if (!streaming->header.bmaControls) { ret = -ENOMEM ; goto error; }
@@ -815,7 +815,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, size = nformats *sizeof *format + nframes *sizeof *frame + nintervals *sizeof *interval; format =kzalloc (size,GFP_KERNEL ); -if (format =NULL ) { +if (!format) { ret = -ENOMEM ; goto error; }
@@ -867,7 +867,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, alts = &intf->altsetting[i]; ep =uvc_find_endpoint (alts, streaming->header.bEndpointAddress); -if (ep =NULL ) +if (!ep)continue ; psize =le16_to_cpu (ep->desc.wMaxPacketSize);
@@ -901,7 +901,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, size =sizeof (*entity) + extra_size +sizeof (*entity->pads) * num_pads + num_inputs; entity =kzalloc (size,GFP_KERNEL ); -if (entity =NULL ) +if (!entity)return NULL ; entity->id = id;
@@ -975,7 +975,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], p +1 ,2 *n); -if (unit =NULL ) +if (!unit)return -ENOMEM ;memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 );
@@ -1028,7 +1028,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,/* Parse all USB Video Streaming interfaces. */ for (i =0 ; i < n; ++i) { intf =usb_ifnum_to_if (udev, buffer[12 +i]); -if (intf =NULL ) { +if (!intf) {uvc_trace (UVC_TRACE_DESCR ,"device %d interface %d doesn't exists\n" , udev->devnum, i);
@@ -1084,7 +1084,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, term =uvc_alloc_entity (type |UVC_TERM_INPUT , buffer[3 ],1 , n + p); -if (term =NULL ) +if (!term)return -ENOMEM ;if (UVC_ENTITY_TYPE (term) =UVC_ITT_CAMERA ) {
@@ -1145,7 +1145,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, term =uvc_alloc_entity (type |UVC_TERM_OUTPUT , buffer[3 ],1 ,0 ); -if (term =NULL ) +if (!term)return -ENOMEM ;memcpy (term->baSourceID, &buffer[7 ],1 );
@@ -1170,7 +1170,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, } unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 ,0 ); -if (unit =NULL ) +if (!unit)return -ENOMEM ;memcpy (unit->baSourceID, &buffer[5 ], p);
@@ -1196,7 +1196,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, } unit =uvc_alloc_entity (buffer[2 ], buffer[3 ],2 , n); -if (unit =NULL ) +if (!unit)return -ENOMEM ;memcpy (unit->baSourceID, &buffer[4 ],1 );
@@ -1229,7 +1229,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, } unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 , n); -if (unit =NULL ) +if (!unit)return -ENOMEM ;memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 );
@@ -1358,7 +1358,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,if (uvc_trace_param &UVC_TRACE_PROBE )printk (KERN_CONT " <- PU %d" , entity->id); -if (chain->processing !=NULL ) { +if (chain->processing) {uvc_trace (UVC_TRACE_DESCR ,"Found multiple Processing Units in chain.\n" );return -1 ;
@@ -1375,7 +1375,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain,if (entity->bNrInPins =1 )break ; -if (chain->selector !=NULL ) { +if (chain->selector) {uvc_trace (UVC_TRACE_DESCR ,"Found multiple Selector Units in chain.\n" );return -1 ;
@@ -1435,7 +1435,7 @@ static int uvc_scan_chain_forward(struct uvc_video_chain *chain,while (1 ) { forward =uvc_entity_by_reference (chain->dev, entity->id, forward); -if (forward =NULL ) +if (!forward)break ;if (forward = prev)continue ;
@@ -1514,7 +1514,7 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain,for (i =0 ; i < entity->bNrInPins; ++i) { id = entity->baSourceID[i]; term =uvc_entity_by_id (chain->dev, id); -if (term =NULL || !UVC_ENTITY_IS_ITERM (term)) { +if (!term || !UVC_ENTITY_IS_ITERM (term)) {uvc_trace (UVC_TRACE_DESCR ,"Selector unit %d input %d isn't connected to an input terminal\n" , entity->id, i);
@@ -1551,7 +1551,7 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain, } entity =uvc_entity_by_id (chain->dev, id); -if (entity =NULL ) { +if (!entity) {uvc_trace (UVC_TRACE_DESCR ,"Found reference to unknown entity %d.\n" , id);
@@ -1572,7 +1572,7 @@ static int uvc_scan_chain(struct uvc_video_chain *chain, entity = term; prev =NULL ; -while (entity !=NULL ) { +while (entity) {/* Entity must not be part of an existing chain */ if (entity->chain.next || entity->chain.prev) { uvc_trace(UVC_TRACE_DESCR,
@@ -1639,7 +1639,7 @@ static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)struct uvc_video_chain *chain; chain =kzalloc (sizeof (*chain),GFP_KERNEL ); -if (chain =NULL ) +if (!chain)return NULL ;INIT_LIST_HEAD (&chain->entities);
@@ -1689,12 +1689,12 @@ static int uvc_scan_fallback(struct uvc_device *dev) } } -if (iterm =NULL || oterm =NULL ) +if (!iterm || !oterm)return -EINVAL ;/* Allocate the chain and fill it. */ chain =uvc_alloc_chain (dev); -if (chain =NULL ) +if (!chain)return -ENOMEM ;if (uvc_scan_chain_entity (chain, oterm) <0 )
@@ -1765,7 +1765,7 @@ static int uvc_scan_device(struct uvc_device *dev)continue ; chain =uvc_alloc_chain (dev); -if (chain =NULL ) +if (!chain)return -ENOMEM ; term->flags |=UVC_ENTITY_FLAG_DEFAULT ;
@@ -1970,7 +1970,7 @@ static int uvc_register_terms(struct uvc_device *dev,continue ; stream =uvc_stream_by_id (dev, term->id); -if (stream =NULL ) { +if (!stream) {uvc_printk (KERN_INFO ,"No streaming interface found for terminal %u." , term->id);
@@ -2048,7 +2048,7 @@ static int uvc_probe(struct usb_interface *intf, dev->quirks = (uvc_quirks_param =-1 ) ? id->driver_info : uvc_quirks_param; -if (udev->product !=NULL ) +if (udev->product)strlcpy (dev->name, udev->product,sizeof dev->name);else snprintf(dev->name, sizeof dev->name,
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/19 uvc_driver: Enclose 24 expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 10:05:05 +0100
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.
WARNING: sizeof … should be sizeof(…)
Thus fix the affected source code places.
--- drivers/media/usb/uvc/uvc_driver.c | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +12 -12
@@ -402,7 +402,7 @@ static int uvc_parse_format(struct uvc_device *dev,if (fmtdesc) {strlcpy (format->name, fmtdesc->name, -sizeof format->name); +sizeof (format->name)); format->fcc = fmtdesc->fcc; }else { uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
@@ -445,7 +445,7 @@ static int uvc_parse_format(struct uvc_device *dev,return -EINVAL ; } -strlcpy (format->name,"MJPEG" ,sizeof format->name); +strlcpy (format->name,"MJPEG" ,sizeof (format->name)); format->fcc =V4L2_PIX_FMT_MJPEG ; format->flags =UVC_FMT_FLAG_COMPRESSED ; format->bpp =0 ;
@@ -463,13 +463,13 @@ static int uvc_parse_format(struct uvc_device *dev,switch (buffer[8 ] &0x7f ) {case 0 : -strlcpy (format->name,"SD-DV" ,sizeof format->name); +strlcpy (format->name,"SD-DV" ,sizeof (format->name));break ;case 1 : -strlcpy (format->name,"SDL-DV" ,sizeof format->name); +strlcpy (format->name,"SDL-DV" ,sizeof (format->name));break ;case 2 : -strlcpy (format->name,"HD-DV" ,sizeof format->name); +strlcpy (format->name,"HD-DV" ,sizeof (format->name));break ;default : uvc_trace(UVC_TRACE_DESCR,
@@ -480,7 +480,7 @@ static int uvc_parse_format(struct uvc_device *dev, }strlcat (format->name, buffer[8 ] & (1 <<7 ) ?" 60Hz" :" 50Hz" , -sizeof format->name); +sizeof (format->name)); format->fcc =V4L2_PIX_FMT_DV ; format->flags =UVC_FMT_FLAG_COMPRESSED |UVC_FMT_FLAG_STREAM ;
@@ -489,7 +489,7 @@ static int uvc_parse_format(struct uvc_device *dev,/* Create a dummy frame descriptor. */ frame = &format->frame[0 ]; -memset (&format->frame[0 ],0 ,sizeof format->frame[0 ]); +memset (&format->frame[0 ],0 ,sizeof (format->frame[0 ])); frame->bFrameIntervalType =1 ; frame->dwDefaultFrameInterval =1 ; frame->dwFrameInterval = *intervals;
@@ -660,7 +660,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,return -EINVAL ; } - streaming =kzalloc (sizeof *streaming,GFP_KERNEL ); + streaming =kzalloc (sizeof (*streaming),GFP_KERNEL );if (!streaming) {usb_driver_release_interface (&uvc_driver.driver, intf);return -EINVAL ;
@@ -812,8 +812,8 @@ static int uvc_parse_streaming(struct uvc_device *dev, goto error; } - size = nformats *sizeof *format + nframes *sizeof *frame - + nintervals *sizeof *interval; + size = nformats *sizeof (*format) + nframes *sizeof (*frame) + + nintervals *sizeof (*interval); format =kzalloc (size,GFP_KERNEL );if (!format) { ret = -ENOMEM ;
@@ -989,7 +989,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,if (buffer[24 +p+2 *n] !=0 )usb_string (udev, buffer[24 +p+2 *n], unit->name, -sizeof unit->name); +sizeof (unit->name));else sprintf (unit->name,"Extension %u" , buffer[3 ]);
@@ -1089,7 +1089,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,if (UVC_ENTITY_TYPE (term) =UVC_ITT_CAMERA ) { term->camera.bControlSize = n; - term->camera.bmControls = (__u8 *)term +sizeof *term; + term->camera.bmControls = (__u8 *)term +sizeof (*term); term->camera.wObjectiveFocalLengthMin get_unaligned_le16(&buffer[8]); term->camera.wObjectiveFocalLengthMax @@ -1100,17 +1100,17 @@ static int uvc_parse_standard_control(struct uvc_device *dev, } else if (UVC_ENTITY_TYPE(term) =
UVC_ITT_MEDIA_TRANSPORT_INPUT) {
term->media.bControlSize = n;
- term->media.bmControls = (__u8 *)term + sizeof *term;
+ term->media.bmControls = (__u8 *)term + sizeof(*term);
term->media.bTransportModeSize = p; term->media.bmTransportModes = (__u8 *)term
- + sizeof *term + n;
+ + sizeof(*term) + n;
memcpy(term->media.bmControls, &buffer[9], n); memcpy(term->media.bmTransportModes, &buffer[10+n], p);
}
if (buffer[7] != 0)
usb_string(udev, buffer[7], term->name,
- sizeof term->name);
+ sizeof(term->name));
else if (UVC_ENTITY_TYPE(term) = UVC_ITT_CAMERA)
sprintf(term->name, "Camera %u", buffer[3]);
else if (UVC_ENTITY_TYPE(term) = UVC_ITT_MEDIA_TRANSPORT_INPUT)
@@ -1152,7 +1152,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
if (buffer[8] != 0)
usb_string(udev, buffer[8], term->name,
- sizeof term->name);
+ sizeof(term->name));
else
sprintf(term->name, "Output %u", buffer[3]);
@@ -1177,7 +1177,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
if (buffer[5+p] != 0)
usb_string(udev, buffer[5+p], unit->name,
- sizeof unit->name);
+ sizeof(unit->name));
else
sprintf(unit->name, "Selector %u", buffer[3]);
@@ -1203,14 +1203,14 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
unit->processing.wMaxMultiplier get_unaligned_le16(&buffer[5]);
unit->processing.bControlSize = buffer[7];
- unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
+ unit->processing.bmControls = (__u8 *)unit + sizeof(*unit);
memcpy(unit->processing.bmControls, &buffer[8], n);
if (dev->uvc_version >= 0x0110)
unit->processing.bmVideoStandards = buffer[9+n];
if (buffer[8+n] != 0)
usb_string(udev, buffer[8+n], unit->name,
- sizeof unit->name);
+ sizeof(unit->name));
else
sprintf(unit->name, "Processing %u", buffer[3]);
@@ -1236,12 +1236,12 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
unit->extension.bNumControls = buffer[20]; memcpy(unit->baSourceID, &buffer[22], p); unit->extension.bControlSize = buffer[22+p];
- unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
+ unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
memcpy(unit->extension.bmControls, &buffer[23+p], n);
if (buffer[23+p+n] != 0)
usb_string(udev, buffer[23+p+n], unit->name,
- sizeof unit->name);
+ sizeof(unit->name));
else
sprintf(unit->name, "Extension %u", buffer[3]);
@@ -1932,7 +1932,7 @@ static int uvc_register_video(struct uvc_device *dev,
vdev->prio = &stream->chain->prio;
if (stream->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
vdev->vfl_dir = VFL_DIR_TX;
- strlcpy(vdev->name, dev->name, sizeof vdev->name);
+ strlcpy(vdev->name, dev->name, sizeof(vdev->name));
/* Set the driver data before calling video_register_device, otherwise
* uvc_v4l2_open might race us.
@@ -2049,9 +2049,9 @@ static int uvc_probe(struct usb_interface *intf,
? id->driver_info : uvc_quirks_param;
if (udev->product)
- strlcpy(dev->name, udev->product, sizeof dev->name);
+ strlcpy(dev->name, udev->product, sizeof(dev->name));
else
- snprintf(dev->name, sizeof dev->name,
+ snprintf(dev->name, sizeof(dev->name),
"UVC Camera (%04x:%04x)", le16_to_cpu(udev->descriptor.idVendor), le16_to_cpu(udev->descriptor.idProduct));
Signature · 1 line
2.11.0
PATCH 6/19 uvc_driver: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 10:37:17 +0100
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_driver.c | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +31 -31
@@ -284,7 +284,7 @@ void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,for (i = n; i >0 ; --i) { r = y; - y = an[i-1 ] * y + x; + y = an[i -1 ] * y + x; x = r; }
@@ -303,7 +303,7 @@ uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)/* Saturate the result if the operation would overflow. */ if (denominator =0 || - numerator/denominator >= ((uint32_t )-1 )/10000000 ) + numerator / denominator >= ((uint32_t )-1 ) /10000000 )return (uint32_t )-1 ;/* Divide both the denominator and the multiplier by two until
@@ -311,7 +311,7 @@ uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)* algorithm please let me know. */ multiplier =10000000 ; -while (numerator > ((uint32_t )-1 )/multiplier) { +while (numerator > ((uint32_t )-1 ) / multiplier) { multiplier /=2 ; denominator /=2 ; }
@@ -527,7 +527,7 @@ static int uvc_parse_format(struct uvc_device *dev, n = n ? n :3 ; -if (buflen <26 +4 *n) { +if (buflen <26 +4 * n) { uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d FRAME error\n", dev->udev->devnum,
@@ -574,7 +574,7 @@ static int uvc_parse_format(struct uvc_device *dev,* some other divisions by zero that could happen. */ for (i =0 ; i < n; ++i) { - interval =get_unaligned_le32 (&buffer[26 +4 *i]); + interval =get_unaligned_le32 (&buffer[26 +4 * i]); *(*intervals)++ = interval ? interval :1 ; }
@@ -594,9 +594,9 @@ static int uvc_parse_format(struct uvc_device *dev, }uvc_trace (UVC_TRACE_DESCR ,"- %ux%u (%u.%u fps)\n" , - frame->wWidth, frame->wHeight, -10000000 /frame->dwDefaultFrameInterval, - (100000000 /frame->dwDefaultFrameInterval)%10 ); + frame->wWidth, frame->wHeight, +10000000 / frame->dwDefaultFrameInterval, + (100000000 / frame->dwDefaultFrameInterval) %10 ); format->nframes++; buflen -= buffer[0 ];
@@ -725,9 +725,9 @@ static int uvc_parse_streaming(struct uvc_device *dev, } p = buflen >=4 ? buffer[3 ] :0 ; - n = buflen >= size ? buffer[size-1 ] :0 ; + n = buflen >= size ? buffer[size -1 ] :0 ; -if (buflen < size + p*n) { +if (buflen < size + p * n) {uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface %d HEADER descriptor is invalid.\n" , dev->udev->devnum, alts->desc.bInterfaceNumber);
@@ -914,7 +914,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,for (i =0 ; i < num_inputs; ++i) entity->pads[i].flags =MEDIA_PAD_FL_SINK ;if (!UVC_ENTITY_IS_OTERM (entity)) - entity->pads[num_pads-1 ].flags =MEDIA_PAD_FL_SOURCE ; + entity->pads[num_pads -1 ].flags =MEDIA_PAD_FL_SOURCE ; entity->bNrInPins = num_inputs; entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
@@ -964,9 +964,9 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,* ---------------------------------------------------------- */ p = buflen >=22 ? buffer[21 ] :0 ; - n = buflen >=25 + p ? buffer[22 +p] :0 ; + n = buflen >=25 + p ? buffer[22 + p] :0 ; -if (buflen <25 + p +2 *n) { +if (buflen <25 + p +2 * n) {uvc_trace (UVC_TRACE_DESCR ,"device %d videocontrol interface %d EXTENSION_UNIT error\n" , udev->devnum, alts->desc.bInterfaceNumber);
@@ -974,21 +974,21 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, } unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], - p +1 ,2 *n); + p +1 ,2 * n);if (!unit)return -ENOMEM ;memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];memcpy (unit->baSourceID, &buffer[22 ], p); - unit->extension.bControlSize = buffer[22 +p]; + unit->extension.bControlSize = buffer[22 + p]; unit->extension.bmControls = (__u8 *)unit +sizeof (*unit); unit->extension.bmControlsType = (__u8 *)unit +sizeof (*unit) + n; -memcpy (unit->extension.bmControls, &buffer[23 +p],2 *n); +memcpy (unit->extension.bmControls, &buffer[23 + p],2 * n); -if (buffer[24 +p+2 *n] !=0 ) -usb_string (udev, buffer[24 +p+2 *n], unit->name, +if (buffer[24 + p +2 * n] !=0 ) +usb_string (udev, buffer[24 + p +2 * n], unit->name,sizeof (unit->name));else sprintf (unit->name,"Extension %u" , buffer[3 ]);
@@ -1027,7 +1027,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,/* Parse all USB Video Streaming interfaces. */ for (i =0 ; i < n; ++i) { - intf =usb_ifnum_to_if (udev, buffer[12 +i]); + intf =usb_ifnum_to_if (udev, buffer[12 + i]);if (!intf) { uvc_trace(UVC_TRACE_DESCR, "device %d interface %d doesn't exists\n",
@@ -1071,7 +1071,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, }else if (type =UVC_ITT_MEDIA_TRANSPORT_INPUT ) { n = buflen >=9 ? buffer[8 ] :0 ; - p = buflen >=10 + n ? buffer[9 +n] :0 ; + p = buflen >=10 + n ? buffer[9 + n] :0 ; len =10 ; }
@@ -1105,7 +1105,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, term->media.bmTransportModes = (__u8 *)term +sizeof (*term) + n;memcpy (term->media.bmControls, &buffer[9 ], n); -memcpy (term->media.bmTransportModes, &buffer[10 +n], p); +memcpy (term->media.bmTransportModes, &buffer[10 + n], p); }if (buffer[7 ] !=0 )
@@ -1175,8 +1175,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev,memcpy (unit->baSourceID, &buffer[5 ], p); -if (buffer[5 +p] !=0 ) -usb_string (udev, buffer[5 +p], unit->name, +if (buffer[5 + p] !=0 ) +usb_string (udev, buffer[5 + p], unit->name,sizeof (unit->name));else sprintf (unit->name,"Selector %u" , buffer[3 ]);
@@ -1206,10 +1206,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev, unit->processing.bmControls = (__u8 *)unit +sizeof (*unit);memcpy (unit->processing.bmControls, &buffer[8 ], n);if (dev->uvc_version >=0x0110 ) - unit->processing.bmVideoStandards = buffer[9 +n]; + unit->processing.bmVideoStandards = buffer[9 + n]; -if (buffer[8 +n] !=0 ) -usb_string (udev, buffer[8 +n], unit->name, +if (buffer[8 + n] !=0 ) +usb_string (udev, buffer[8 + n], unit->name,sizeof (unit->name));else sprintf (unit->name,"Processing %u" , buffer[3 ]);
@@ -1219,7 +1219,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,case UVC_VC_EXTENSION_UNIT : p = buflen >=22 ? buffer[21 ] :0 ; - n = buflen >=24 + p ? buffer[22 +p] :0 ; + n = buflen >=24 + p ? buffer[22 + p] :0 ;if (buflen <24 + p + n) { uvc_trace(UVC_TRACE_DESCR,
@@ -1235,12 +1235,12 @@ static int uvc_parse_standard_control(struct uvc_device *dev,memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];memcpy (unit->baSourceID, &buffer[22 ], p); - unit->extension.bControlSize = buffer[22 +p]; + unit->extension.bControlSize = buffer[22 + p]; unit->extension.bmControls = (__u8 *)unit +sizeof (*unit); -memcpy (unit->extension.bmControls, &buffer[23 +p], n); +memcpy (unit->extension.bmControls, &buffer[23 + p], n); -if (buffer[23 +p+n] !=0 ) -usb_string (udev, buffer[23 +p+n], unit->name, +if (buffer[23 + p + n] !=0 ) +usb_string (udev, buffer[23 + p + n], unit->name,sizeof (unit->name));else sprintf (unit->name,"Extension %u" , buffer[3 ]);
Signature · 1 line
2.11.0
PATCH 7/19 uvc_driver: Rename a jump label in uvc_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 10:54:15 +0100
Adjust jump labels according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_driver.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +7 -8
@@ -2060,7 +2060,7 @@ static int uvc_probe(struct usb_interface *intf,if (uvc_parse_control (dev) <0 ) {uvc_trace (UVC_TRACE_PROBE ,"Unable to parse UVC descriptors.\n" ); - goto error; + goto unregister_video; } uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
@@ -2092,24 +2092,24 @@ static int uvc_probe(struct usb_interface *intf, dev->vdev.mdev = &dev->mdev;#endif if (v4l2_device_register (&intf->dev, &dev->vdev) <0 ) - goto error; + goto unregister_video;/* Initialize controls. */ if (uvc_ctrl_init_device (dev) <0 ) - goto error; + goto unregister_video;/* Scan the device for video chains. */ if (uvc_scan_device (dev) <0 ) - goto error; + goto unregister_video;/* Register video device nodes. */ if (uvc_register_chains (dev) <0 ) - goto error; + goto unregister_video;#ifdef CONFIG_MEDIA_CONTROLLER /* Register the media device node */ if (media_device_register (&dev->mdev) <0 ) - goto error; + goto unregister_video;#endif /* Save our data pointer in the interface data. */ usb_set_intfdata (intf, dev);
@@ -2124,8 +2124,7 @@ static int uvc_probe(struct usb_interface *intf,uvc_trace (UVC_TRACE_PROBE ,"UVC device initialized.\n" );usb_enable_autosuspend (udev);return 0 ; - -error: +unregister_video:uvc_unregister_video (dev);return -ENODEV ; }
Signature · 1 line
2.11.0
PATCH 8/19 uvc_driver: Rename a jump label in uvc_scan_fallback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 10:57:12 +0100
Adjust jump labels according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_driver.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +4 -5
@@ -1698,7 +1698,7 @@ static int uvc_scan_fallback(struct uvc_device *dev)return -ENOMEM ;if (uvc_scan_chain_entity (chain, oterm) <0 ) - goto error; + goto free_chain; prev = oterm;
@@ -1718,14 +1718,14 @@ static int uvc_scan_fallback(struct uvc_device *dev)continue ;if (uvc_scan_chain_entity (chain, entity) <0 ) - goto error; + goto free_chain; prev->baSourceID[0 ] = entity->id; prev = entity; }if (uvc_scan_chain_entity (chain, iterm) <0 ) - goto error; + goto free_chain; prev->baSourceID[0 ] = iterm->id;
@@ -1736,8 +1736,7 @@ static int uvc_scan_fallback(struct uvc_device *dev) uvc_print_chain(chain));return 0 ; - -error: +free_chain:kfree (chain);return -EINVAL ; }
Signature · 1 line
2.11.0
PATCH 9/19 uvc_driver: Less function calls in uvc_parse_streaming() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 15:45:31 +0100
The kfree() function was called in a few cases by the uvc_parse_streaming() function during error handling even if the passed data structure member contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_driver.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +12 -11
@@ -702,7 +702,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,if (buflen <=2 ) {uvc_trace (UVC_TRACE_DESCR ,"no class-specific streaming interface descriptors found.\n" ); - goto error; + goto release_interface; }/* Parse the header descriptor. */
@@ -721,7 +721,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface %d HEADER descriptor not found.\n" , dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } p = buflen >=4 ? buffer[3 ] :0 ;
@@ -731,7 +731,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface %d HEADER descriptor is invalid.\n" , dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } streaming->header.bNumFormats = p;
@@ -751,7 +751,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, GFP_KERNEL);if (!streaming->header.bmaControls) { ret = -ENOMEM ; - goto error; + goto release_interface; } buflen -= buffer[0 ];
@@ -809,7 +809,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,uvc_trace (UVC_TRACE_DESCR ,"device %d videostreaming interface %d has no supported formats defined.\n" , dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } size = nformats *sizeof (*format) + nframes *sizeof (*frame)
@@ -817,7 +817,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, format =kzalloc (size,GFP_KERNEL );if (!format) { ret = -ENOMEM ; - goto error; + goto free_controls; } frame = (struct uvc_frame *)&format[nformats];
@@ -837,7 +837,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, ret =uvc_parse_format (dev, streaming, format, &interval, buffer, buflen);if (ret <0 ) - goto error; + goto free_format; frame += format->nframes; format++;
@@ -878,12 +878,13 @@ static int uvc_parse_streaming(struct uvc_device *dev,list_add_tail (&streaming->list, &dev->streams);return 0 ; - -error: -usb_driver_release_interface (&uvc_driver.driver, intf); -usb_put_intf (intf); +free_format:kfree (streaming->format); +free_controls:kfree (streaming->header.bmaControls); +release_interface: +usb_driver_release_interface (&uvc_driver.driver, intf); +usb_put_intf (intf);kfree (streaming);return ret; }
Signature · 1 line
2.11.0
PATCH 10/19 uvc_driver: Return -ENOMEM after a failed kzalloc() call in uvc_parse_streaming()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 16:00:17 +0100
Use the return code "-ENOMEM" (instead of "-EINVAL") after a call of the function "kzalloc" failed here.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -663,7 +663,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, streaming =kzalloc (sizeof (*streaming),GFP_KERNEL );if (!streaming) {usb_driver_release_interface (&uvc_driver.driver, intf); -return -EINVAL ; +return -ENOMEM ; }mutex_init (&streaming->mutex);
Signature · 1 line
2.11.0
PATCH 11/19 uvc_driver: Delete an unnecessary variable initialisation in uvc_parse_streaming()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 16:02:46 +0100
The local variable "streaming" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -631,7 +631,7 @@ static int uvc_parse_format(struct uvc_device *dev,static int uvc_parse_streaming (struct uvc_device *dev,struct usb_interface *intf) { -struct uvc_streaming *streaming =NULL ; +struct uvc_streaming *streaming;struct uvc_format *format;struct uvc_frame *frame;struct usb_host_interface *alts = &intf->altsetting[0 ];
Signature · 1 line
2.11.0
PATCH 12/19 uvc_driver: Move six assignments in uvc_parse_streaming()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 16:25:57 +0100
Move the assignments for six local variables so that these statements will only be executed if memory allocations succeeded by this function.
--- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +10 -5
@@ -634,11 +634,10 @@ static int uvc_parse_streaming(struct uvc_device *dev,struct uvc_streaming *streaming;struct uvc_format *format;struct uvc_frame *frame; -struct usb_host_interface *alts = &intf->altsetting[0 ]; -unsigned char *_buffer, *buffer = alts->extra; -int _buflen, buflen = alts->extralen; -unsigned int nformats =0 , nframes =0 , nintervals =0 ; -unsigned int size, i, n, p; +struct usb_host_interface *alts; +unsigned char *_buffer, *buffer; +int _buflen, buflen; +unsigned int nformats, nframes, nintervals, size, i, n, p;__u32 *interval;__u16 psize;int ret = -EINVAL ;
@@ -670,6 +669,9 @@ static int uvc_parse_streaming(struct uvc_device *dev, streaming->dev = dev; streaming->intf =usb_get_intf (intf); streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; + alts = &intf->altsetting[0 ]; + buffer = alts->extra; + buflen = alts->extralen;/* The Pico iMage webcam has its class-specific interface descriptors * after the endpoint descriptors.
@@ -759,6 +761,9 @@ static int uvc_parse_streaming(struct uvc_device *dev, _buffer = buffer; _buflen = buflen; + nformats =0 ; + nframes =0 ; + nintervals =0 ;/* Count the format and frame descriptors. */ while (_buflen >2 && _buffer[1 ] =USB_DT_CS_INTERFACE ) {
Signature · 1 line
2.11.0
PATCH 13/19 uvc_video: Use kmalloc_array() in uvc_video_clock_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 16:45:21 +0100
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/uvc/uvc_video.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_video.c +3 -3
@@ -500,9 +500,9 @@ static int uvc_video_clock_init(struct uvc_streaming *stream)spin_lock_init (&clock->lock); clock->size =32 ; - - clock->samples =kmalloc (clock->size *sizeof (*clock->samples), -GFP_KERNEL ); + clock->samples =kmalloc_array (clock->size, +sizeof (*clock->samples), +GFP_KERNEL );if (clock->samples =NULL )return -ENOMEM ;
Signature · 1 line
2.11.0
PATCH 14/19 uvc_video: Combine substrings for 22 messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 17:54:05 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
* Thus fix the affected source code places.
* Improve indentation for passed parameters.
--- drivers/media/usb/uvc/uvc_video.c | 108 ++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 52 deletions(-)
drivers/media/usb/uvc/uvc_video.c +56 -52
@@ -77,9 +77,9 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, ret =__uvc_query_ctrl (dev, query, unit, intfnum, cs, data, size,UVC_CTRL_CONTROL_TIMEOUT );if (ret != size) { -uvc_printk (KERN_ERR ,"Failed to query (%s) UVC control %u on " -"unit %u: %d (exp. %u).\n" ,uvc_query_name (query), cs, - unit, ret, size); +uvc_printk (KERN_ERR , +"Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n" , +uvc_query_name (query), cs, unit, ret, size);return -EIO ; }
@@ -188,9 +188,9 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,* answer a GET_MIN or GET_MAX request with the wCompQuality * field only. */ -uvc_warn_once (stream->dev,UVC_WARN_MINMAX ,"UVC non " -"compliance - GET_MIN/MAX(PROBE) incorrectly " -"supported. Enabling workaround.\n" ); +uvc_warn_once (stream->dev, +UVC_WARN_MINMAX , +"UVC non compliance - GET_MIN/MAX(PROBE) incorrectly supported. Enabling workaround.\n" );memset (ctrl,0 ,sizeof *ctrl); ctrl->wCompQuality =le16_to_cpup ((__le16 *)data); ret =0 ;
@@ -200,15 +200,15 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,* video probe control. Warn once and return, the caller will * fall back to GET_CUR. */ -uvc_warn_once (stream->dev,UVC_WARN_PROBE_DEF ,"UVC non " -"compliance - GET_DEF(PROBE) not supported. " -"Enabling workaround.\n" ); +uvc_warn_once (stream->dev, +UVC_WARN_PROBE_DEF , +"UVC non compliance - GET_DEF(PROBE) not supported. Enabling workaround.\n" ); ret = -EIO ; goto out; }else if (ret != size) { -uvc_printk (KERN_ERR ,"Failed to query (%u) UVC %s control : " -"%d (exp. %u).\n" , query, probe ?"probe" :"commit" , - ret, size); +uvc_printk (KERN_ERR , +"Failed to query (%u) UVC %s control : %d (exp. %u).\n" , + query, probe ?"probe" :"commit" , ret, size); ret = -EIO ; goto out; }
@@ -287,9 +287,9 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream, probe ?UVC_VS_PROBE_CONTROL :UVC_VS_COMMIT_CONTROL , data, size, uvc_timeout_param);if (ret != size) { -uvc_printk (KERN_ERR ,"Failed to set UVC %s control : " -"%d (exp. %u).\n" , probe ?"probe" :"commit" , - ret, size); +uvc_printk (KERN_ERR , +"Failed to set UVC %s control : %d (exp. %u).\n" , + probe ?"probe" :"commit" , ret, size); ret = -EIO ; }
@@ -652,8 +652,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream, sof = y; - uvc_trace(UVC_TRACE_CLOCK, "%s: PTS %u y %llu.%06llu SOF %u.%06llu " - "(x1 %u x2 %u y1 %u y2 %u SOF offset %u)\n", + uvc_trace(UVC_TRACE_CLOCK, + "%s: PTS %u y %llu.%06llu SOF %u.%06llu (x1 %u x2 %u y1 %u y2 %u SOF offset %u)\n", stream->dev->name, buf->pts, y >> 16, div_u64((y & 0xffff) * 1000000, 65536), sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536),
@@ -694,8 +694,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream, ts.tv_nsec -=NSEC_PER_SEC ; } - uvc_trace(UVC_TRACE_CLOCK, "%s: SOF %u.%06llu y %llu ts %llu " - "buf ts %llu (x1 %u/%u/%u x2 %u/%u/%u y1 %u y2 %u)\n", + uvc_trace(UVC_TRACE_CLOCK, + "%s: SOF %u.%06llu y %llu ts %llu buf ts %llu (x1 %u/%u/%u x2 %u/%u/%u y1 %u y2 %u)\n", stream->dev->name, sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536), y, timespec_to_ns(&ts), vbuf->vb2_buf.timestamp,
@@ -829,9 +829,8 @@ static void uvc_video_stats_update(struct uvc_streaming *stream) {struct uvc_stats_frame *frame = &stream->stats.frame; - uvc_trace(UVC_TRACE_STATS, "frame %u stats: %u/%u/%u packets, " - "%u/%u/%u pts (%searly %sinitial), %u/%u scr, " - "last pts/stc/sof %u/%u/%u\n", + uvc_trace(UVC_TRACE_STATS, + "frame %u stats: %u/%u/%u packets, %u/%u/%u pts (%searly %sinitial), %u/%u scr, last pts/stc/sof %u/%u/%u\n", stream->sequence, frame->first_data, frame->nb_packets - frame->nb_empty, frame->nb_packets, frame->nb_pts_diffs, frame->last_pts_diff, frame->nb_pts,
@@ -1002,8 +1001,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,/* Mark the buffer as bad if the error bit is set. */ if (data[1 ] &UVC_STREAM_ERR ) { -uvc_trace (UVC_TRACE_FRAME ,"Marking buffer as bad (error bit " -"set).\n" ); +uvc_trace (UVC_TRACE_FRAME , +"Marking buffer as bad (error bit set).\n" ); buf->error =1 ; }
@@ -1019,8 +1018,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,struct timespec ts;if (fid = stream->last_fid) { -uvc_trace (UVC_TRACE_FRAME ,"Dropping payload (out of " -"sync).\n" ); +uvc_trace (UVC_TRACE_FRAME , +"Dropping payload (out of sync).\n" );if ((stream->dev->quirks &UVC_QUIRK_STREAM_NO_FID ) && (data[1 ] &UVC_STREAM_EOF )) stream->last_fid ^=UVC_STREAM_FID ;
@@ -1053,8 +1052,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,* previous payload had the EOF bit set. */ if (fid != stream->last_fid && buf->bytesused !=0 ) { -uvc_trace (UVC_TRACE_FRAME ,"Frame complete (FID bit " -"toggled).\n" ); +uvc_trace (UVC_TRACE_FRAME , +"Frame complete (FID bit toggled).\n" ); buf->state =UVC_BUF_STATE_READY ;return -EAGAIN ; }
@@ -1166,8 +1165,9 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,for (i =0 ; i < urb->number_of_packets; ++i) {if (urb->iso_frame_desc[i].status <0 ) { -uvc_trace (UVC_TRACE_FRAME ,"USB isochronous frame " -"lost (%d).\n" , urb->iso_frame_desc[i].status); +uvc_trace (UVC_TRACE_FRAME , +"USB isochronous frame lost (%d).\n" , + urb->iso_frame_desc[i].status);/* Mark the buffer as faulty. */ if (buf !=NULL ) buf->error =1 ;
@@ -1328,8 +1328,9 @@ static void uvc_video_complete(struct urb *urb)break ;default : -uvc_printk (KERN_WARNING ,"Non-zero status (%d) in video " -"completion handler.\n" , urb->status); +uvc_printk (KERN_WARNING , +"Non-zero status (%d) in video completion handler.\n" , + urb->status);case -ENOENT :/* usb_kill_urb() called. */ if (stream->frozen)
@@ -1424,15 +1425,16 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, }if (i =UVC_URBS ) { -uvc_trace (UVC_TRACE_VIDEO ,"Allocated %u URB buffers " -"of %ux%u bytes each.\n" ,UVC_URBS , npackets, - psize); +uvc_trace (UVC_TRACE_VIDEO , +"Allocated %u URB buffers of %ux%u bytes each.\n" , +UVC_URBS , npackets, psize);return npackets; } } -uvc_trace (UVC_TRACE_VIDEO ,"Failed to allocate URB buffers (%u bytes " -"per packet).\n" , psize); +uvc_trace (UVC_TRACE_VIDEO , +"Failed to allocate URB buffers (%u bytes per packet).\n" , + psize);return 0 ; }
@@ -1623,12 +1625,13 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) bandwidth = stream->ctrl.dwMaxPayloadTransferSize;if (bandwidth =0 ) { -uvc_trace (UVC_TRACE_VIDEO ,"Device requested null " -"bandwidth, defaulting to lowest.\n" ); +uvc_trace (UVC_TRACE_VIDEO , +"Device requested null bandwidth, defaulting to lowest.\n" ); bandwidth =1 ; }else { -uvc_trace (UVC_TRACE_VIDEO ,"Device requested %u " -"B/frame bandwidth.\n" , bandwidth); +uvc_trace (UVC_TRACE_VIDEO , +"Device requested %u B/frame bandwidth.\n" , + bandwidth); }for (i =0 ; i < intf->num_altsetting; ++i) {
@@ -1651,14 +1654,14 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) }if (best_ep =NULL ) { -uvc_trace (UVC_TRACE_VIDEO ,"No fast enough alt setting " -"for requested bandwidth.\n" ); +uvc_trace (UVC_TRACE_VIDEO , +"No fast enough alt setting for requested bandwidth.\n" );return -EIO ; } -uvc_trace (UVC_TRACE_VIDEO ,"Selecting alternate setting %u " -"(%u B/frame bandwidth).\n" , altsetting, best_psize); - +uvc_trace (UVC_TRACE_VIDEO , +"Selecting alternate setting %u (%u B/frame bandwidth).\n" , + altsetting, best_psize); ret =usb_set_interface (stream->dev->udev, intfnum, altsetting);if (ret <0 )return ret;
@@ -1681,8 +1684,9 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)for (i =0 ; i <UVC_URBS ; ++i) { ret =usb_submit_urb (stream->urb[i], gfp_flags);if (ret <0 ) { -uvc_printk (KERN_ERR ,"Failed to submit URB %u " -"(%d).\n" , i, ret); +uvc_printk (KERN_ERR , +"Failed to submit URB %u (%d).\n" , + i, ret);uvc_uninit_video (stream,1 );return ret; }
@@ -1816,8 +1820,8 @@ int uvc_video_init(struct uvc_streaming *stream) }if (format->nframes =0 ) { -uvc_printk (KERN_INFO ,"No frame descriptor found for the " -"default format.\n" ); +uvc_printk (KERN_INFO , +"No frame descriptor found for the default format.\n" );return -EINVAL ; }
@@ -1851,8 +1855,8 @@ int uvc_video_init(struct uvc_streaming *stream)if (stream->intf->num_altsetting =1 ) stream->decode = uvc_video_encode_bulk;else { -uvc_printk (KERN_INFO ,"Isochronous endpoints are not " -"supported for video output devices.\n" ); +uvc_printk (KERN_INFO , +"Isochronous endpoints are not supported for video output devices.\n" );return -EINVAL ; } }
Signature · 1 line
2.11.0
PATCH 15/19 uvc_video: Adjust one function call together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 18:00:39 +0100
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
--- drivers/media/usb/uvc/uvc_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +2 -2
@@ -1350,10 +1350,10 @@ static void uvc_video_complete(struct urb *urb) stream->decode (urb, stream, buf); -if ((ret =usb_submit_urb (urb,GFP_ATOMIC )) <0 ) { + ret =usb_submit_urb (urb,GFP_ATOMIC ); +if (ret <0 )uvc_printk (KERN_ERR ,"Failed to resubmit video URB (%d).\n" , ret); - } }/*
Signature · 1 line
2.11.0
PATCH 16/19 uvc_video: Adjust 18 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 18:26:21 +0100
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_video.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/media/usb/uvc/uvc_video.c +18 -18
@@ -100,7 +100,7 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, } } -if (format =NULL ) +if (!format)return ;for (i =0 ; i < format->nframes; ++i) {
@@ -110,7 +110,7 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, } } -if (frame =NULL ) +if (!frame)return ; if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
@@ -176,7 +176,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,return -EIO ; data =kmalloc (size,GFP_KERNEL ); -if (data =NULL ) +if (!data)return -ENOMEM ; ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum,
@@ -260,7 +260,7 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream, size = stream->dev->uvc_version >=0x0110 ?34 :26 ; data =kzalloc (size,GFP_KERNEL ); -if (data =NULL ) +if (!data)return -ENOMEM ; *(__le16 *)&data[0 ] =cpu_to_le16 (ctrl->bmHint);
@@ -420,7 +420,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,* kernel timestamps and store them with the SCR STC and SOF fields * in the ring buffer */ -if (has_pts && buf !=NULL ) +if (has_pts && buf) buf->pts =get_unaligned_le32 (&data[2 ]);if (!has_scr)
@@ -503,7 +503,7 @@ static int uvc_video_clock_init(struct uvc_streaming *stream) clock->samples =kmalloc_array (clock->size,sizeof (*clock->samples),GFP_KERNEL ); -if (clock->samples =NULL ) +if (!clock->samples)return -ENOMEM ;uvc_video_clock_reset (stream);
@@ -994,7 +994,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,/* Store the payload FID bit and return immediately when the buffer is * NULL. */ -if (buf =NULL ) { +if (!buf) { stream->last_fid = fid;return -ENODATA ; }
@@ -1169,7 +1169,7 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,"USB isochronous frame lost (%d).\n" , urb->iso_frame_desc[i].status);/* Mark the buffer as faulty. */ -if (buf !=NULL ) +if (buf) buf->error =1 ;continue ; }
@@ -1233,7 +1233,7 @@ static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream, }while (ret = -EAGAIN );/* If an error occurred skip the rest of the payload. */ -if (ret <0 || buf =NULL ) { +if (ret <0 || !buf) { stream->bulk.skip_payload =1 ; }else {memcpy (stream->bulk.header, mem, ret);
@@ -1250,7 +1250,7 @@ static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream,*/ /* Process video data. */ -if (!stream->bulk.skip_payload && buf !=NULL ) +if (!stream->bulk.skip_payload && buf)uvc_video_decode_data (stream, buf, mem, len);/* Detect the payload end by a URB smaller than the maximum size (or
@@ -1258,7 +1258,7 @@ static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream,*/ if (urb->actual_length < urb->transfer_buffer_length || stream->bulk.payload_size >= stream->bulk.max_payload_size) { -if (!stream->bulk.skip_payload && buf !=NULL ) { +if (!stream->bulk.skip_payload && buf) {uvc_video_decode_end (stream, buf, stream->bulk.header, stream->bulk.payload_size);if (buf->state =UVC_BUF_STATE_READY )
@@ -1278,7 +1278,7 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream,u8 *mem = urb->transfer_buffer;int len = stream->urb_size, ret; -if (buf =NULL ) { +if (!buf) { urb->transfer_buffer_length =0 ;return ; }
@@ -1450,7 +1450,7 @@ static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers)for (i =0 ; i <UVC_URBS ; ++i) { urb = stream->urb[i]; -if (urb =NULL ) +if (!urb)continue ;usb_kill_urb (urb);
@@ -1511,7 +1511,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,for (i =0 ; i <UVC_URBS ; ++i) { urb =usb_alloc_urb (npackets, gfp_flags); -if (urb =NULL ) { +if (!urb) {uvc_uninit_video (stream,1 );return -ENOMEM ; }
@@ -1577,7 +1577,7 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream,for (i =0 ; i <UVC_URBS ; ++i) { urb =usb_alloc_urb (0 , gfp_flags); -if (urb =NULL ) { +if (!urb) {uvc_uninit_video (stream,1 );return -ENOMEM ; }
@@ -1641,7 +1641,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) alts = &intf->altsetting[i]; ep =uvc_find_endpoint (alts, stream->header.bEndpointAddress); -if (ep =NULL ) +if (!ep)continue ;/* Check if the bandwidth is high enough. */
@@ -1653,7 +1653,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) } } -if (best_ep =NULL ) { +if (!best_ep) {uvc_trace (UVC_TRACE_VIDEO ,"No fast enough alt setting for requested bandwidth.\n" );return -EIO ;
@@ -1671,7 +1671,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)/* Bulk endpoint, proceed to URB initialization. */ ep =uvc_find_endpoint (&intf->altsetting[0 ], stream->header.bEndpointAddress); -if (ep =NULL ) +if (!ep)return -EIO ; ret =uvc_init_video_bulk (stream, ep, gfp_flags);
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 17/19 uvc_video: Fix a typo in a comment line
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 18:42:58 +0100
The script "checkpatch.pl" pointed out that a word may be misspelled.
Add a missing character there.
--- drivers/media/usb/uvc/uvc_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_video.c +1 -1
@@ -1794,7 +1794,7 @@ int uvc_video_init(struct uvc_streaming *stream)usb_set_interface (stream->dev->udev, stream->intfnum,0 );/* Set the streaming probe control with default streaming parameters -* retrieved from the device. Webcams that don't suport GET_DEF +* retrieved from the device. Webcams that don't support GET_DEF * requests on the probe control will just keep their current streaming * parameters. */
Signature · 1 line
2.11.0
PATCH 18/19 uvc_video: Enclose an expression for the sizeof operator by parentheses
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 18:50:35 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: sizeof *ctrl should be sizeof(*ctrl)
Thus fix the affected source code place.
--- drivers/media/usb/uvc/uvc_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_video.c +1 -1
@@ -191,7 +191,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,uvc_warn_once (stream->dev,UVC_WARN_MINMAX ,"UVC non compliance - GET_MIN/MAX(PROBE) incorrectly supported. Enabling workaround.\n" ); -memset (ctrl,0 ,sizeof *ctrl); +memset (ctrl,0 ,sizeof (*ctrl)); ctrl->wCompQuality =le16_to_cpup ((__le16 *)data); ret =0 ; goto out;
Signature · 1 line
2.11.0
PATCH 19/19 uvc_video: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Dec 2016 19:00:29 +0100
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/media/usb/uvc/uvc_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +2 -2
@@ -1814,7 +1814,7 @@ int uvc_video_init(struct uvc_streaming *stream)* available format otherwise. */ for (i = stream->nformats; i >0 ; --i) { - format = &stream->format[i-1 ]; + format = &stream->format[i -1 ];if (format->index = probe->bFormatIndex)break ; }
@@ -1831,7 +1831,7 @@ int uvc_video_init(struct uvc_streaming *stream)* descriptor is not found, use the first available frame. */ for (i = format->nframes; i >0 ; --i) { - frame = &format->frame[i-1 ]; + frame = &format->frame[i -1 ];if (frame->bFrameIndex = probe->bFrameIndex)break ; }
Signature · 1 line
2.11.0