Skip to contentSkip to conversation

media: uvcvideo: drop useless assignment in uvc_parse_format()

PATCH In review Sergey Shtylyov 4 participants 6 messages Aug 20 – Sep 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: uvcvideo: drop useless assignment in uvc_parse_format()

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
 drivers/media/usb/uvc/uvc_driver.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +0 -1
index e289cc71ba98..0e78e8bcd320 100644
@@ -520,7 +520,6 @@ static int uvc_parse_format(struct uvc_device *dev,
 		format->xfer_func = uvc_xfer_func(buffer[4]);
 		format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
 
-		buflen -= buffer[0];
 		buffer += buffer[0];
 	} else {
 		format->colorspace = V4L2_COLORSPACE_SRGB;
Signature · 1 line
2.55.0
#1 lore raw
Quoted 8 lines · Sergey Shtylyov

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Duh, forgot to add that the patch is against the next branch of the
linuxtv.org/media.git repo!

[...]

MBR, Sergey

#2 lore raw
In reply to Sergey Shtylyov

Hi Sergey

Quoted 4 lines · Sergey Shtylyov

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

The patch is correct, although I do not see a great benefit in removing it. As you say, the compiler will remove it anyway. If we modify the function to add logging or continue parsing the left over buffer, it is going to come back to haunt us....

I leave it to Laurent or HansG to decide if they want to merge it.

Thanks!

Quoted 22 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
 drivers/media/usb/uvc/uvc_driver.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +0 -2
index e289cc71ba98..0e78e8bcd320 100644
@@ -520,7 +520,6 @@ static int uvc_parse_format(struct uvc_device *dev,
                format->xfer_func = uvc_xfer_func(buffer[4]);
                format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
 
-               buflen -= buffer[0];
                buffer += buffer[0];
        } else {
                format->colorspace = V4L2_COLORSPACE_SRGB;
--
Quoted 2 lines

2.55.0

--
Ricardo Ribalda

maintainer
#3 lore raw
Quoted 8 lines · Ricardo Ribalda

Hi Sergey

Quoted 4 lines · Sergey Shtylyov

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

Quoted 6 lines

The patch is correct, although I do not see a great benefit in removing it. As you say, the compiler will remove it anyway. If we modify the function to add logging or continue parsing the left over buffer, it is going to come back to haunt us....

I leave it to Laurent or HansG to decide if they want to merge it.

I'd rather keep the buflen update in place for the reasons explained by Ricardo.

/me wishes for std::span<> in C

Quoted 20 lines
Quoted 20 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
 drivers/media/usb/uvc/uvc_driver.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +0 -1
index e289cc71ba98..0e78e8bcd320 100644
@@ -520,7 +520,6 @@ static int uvc_parse_format(struct uvc_device *dev,
                format->xfer_func = uvc_xfer_func(buffer[4]);
                format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
 
-               buflen -= buffer[0];
                buffer += buffer[0];
        } else {
                format->colorspace = V4L2_COLORSPACE_SRGB;
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#4 lore raw

Hi,

Quoted 14 lines · Laurent Pinchart
Quoted 13 lines · Ricardo Ribalda

Hi Sergey

Quoted 4 lines · Sergey Shtylyov

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

The patch is correct, although I do not see a great benefit in removing it. As you say, the compiler will remove it anyway. If we modify the function to add logging or continue parsing the left over buffer, it is going to come back to haunt us....

Quoted 6 lines
Quoted 1 line

I leave it to Laurent or HansG to decide if they want to merge it.

I'd rather keep the buflen update in place for the reasons explained by Ricardo.

/me wishes for std::span<> in C

Ack, I've dropped this patch from patchwork.

Regards,

Hans

Quoted 22 lines
Quoted 21 lines
Quoted 21 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
 drivers/media/usb/uvc/uvc_driver.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +0 -1
index e289cc71ba98..0e78e8bcd320 100644
@@ -520,7 +520,6 @@ static int uvc_parse_format(struct uvc_device *dev,
                format->xfer_func = uvc_xfer_func(buffer[4]);
                format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
 
-               buflen -= buffer[0];
                buffer += buffer[0];
        } else {
                format->colorspace = V4L2_COLORSPACE_SRGB;
#5 lore raw

On 9/29/26 12:16 PM, Hans de Goede wrote:

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

Close to the end of uvc_parse_format(), the parameter buflen is decremented (again) but that statement seems pointless as buflen isn't used afterwards. Drop the useless assignment (gcc doesn't generate any code for it anyways).

The patch is correct, although I do not see a great benefit in removing it. As you say, the compiler will remove it anyway. If we modify the function to add logging or continue parsing the left over buffer, it is going to come back to haunt us....

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I leave it to Laurent or HansG to decide if they want to merge it.

I'd rather keep the buflen update in place for the reasons explained by Ricardo.

/me wishes for std::span<> in C

Ack, I've dropped this patch from patchwork.

OK, but why "Not Applicable" and not "Rejected"? :-)

Quoted 3 lines

Regards,

Hans

[...]

MBR, Sergey