usbvision: don't return an uninitialized value
Commit c5f48367fe54c46805774eeea8e828de54a5ad7b introduced this return of an uninitialized variable.
Spotted by the Coverity checker.
---
drivers/media/video/usbvision/usbvision-video.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/video/usbvision/usbvision-video.c renamed from drivers/media/video/usbvision/usbvision-video.c.old +2 -3
@@ -525,18 +525,17 @@ static int vidioc_s_register (struct fil {struct video_device *dev =video_devdata (file);struct usb_usbvision *usbvision = (struct usb_usbvision *)video_get_drvdata (dev); -int errCode;if (!v4l2_chip_match_host (reg->match_type, reg->match_chip))return -EINVAL ;/* NT100x has a 8-bit register space */ reg->val = (u8 )usbvision_write_reg (usbvision, reg->reg&0xff , reg->val);if (reg->val <0 ) {err ("%s: VIDIOC_DBG_S_REGISTER failed: error %d" , - __FUNCTION__, errCode); -return errCode; + __FUNCTION__, reg->val); +return reg->val; }return 0 ; }#endif
Quoted 4 lines · Adrian Bunk
Commit
c5f48367fe54c46805774eeea8e828de54a5ad7bintroduced this return of an uninitialized variable.Spotted by the Coverity checker.
It spotted that, but it seems it missed the bigger bug, reg->val is unsigned. Since reg->val can't be less than 0, it will never actually return the unitialized variable.
This patch should fix it correctly. The vidioc_g_register function was broken too, it wasn't actually setting reg->val to the register value it read.
--------------------------------------------------------------------
usbvision: fix bugs in vidioc_[sg]_register functions
From: Trent Piepho <[email protected]>
s_register was assigning the return code to (unsigned)reg->val, rather than errCode, which it what it would return. Except reg->val can't be < 0, so it would never actually return an error.
g_register never actually put the value it read into reg->val.
linux/drivers/media/video/usbvision/usbvision-video.c +3 -2
@@ -550,6 +550,7 @@ static int vidioc_g_register (struct fil __FUNCTION__, errCode);return errCode; } + reg->val = errCode;return 0 ; }
@@ -564,8 +565,8 @@ static int vidioc_s_register (struct filif (!v4l2_chip_match_host (reg->match_type, reg->match_chip))return -EINVAL ;/* NT100x has a 8-bit register space */ - reg->val = (u8 )usbvision_write_reg (usbvision, reg->reg&0xff , reg->val); -if (reg->val <0 ) { + errCode =usbvision_write_reg (usbvision, reg->reg&0xff , reg->val); +if (errCode <0 ) {err ("%s: VIDIOC_DBG_S_REGISTER failed: error %d" , __FUNCTION__, errCode);return errCode;