Skip to contentSkip to conversation

media: uvcvideo: Fix assignment in if condition

PATCH In review Darshan Rathod 2 participants 2 messages Jul 15, 2025

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

PATCH 1/1 media: uvcvideo: Fix assignment in if condition

The function uvc_input_init() used an assignment of the return value of input_register_device() within the condition of an if statement.

This coding style is discouraged by the Linux kernel coding style guide as it can be confused with a comparison and hide potential bugs. The checkpatch.pl script flags this as an error:
"ERROR: do not use assignment in if condition"

Separate the assignment into its own statement before the conditional check to improve code readability and adhere to the kernel's coding standards.

---
 drivers/media/usb/uvc/uvc_status.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_status.c +2 -1
index ee01dce4b783..3c29c0bb3f7c 100644
@@ -62,7 +62,8 @@ static int uvc_input_init(struct uvc_device *dev)
 	__set_bit(EV_KEY, input->evbit);
 	__set_bit(KEY_CAMERA, input->keybit);
 
-	if ((ret = input_register_device(input)) < 0)
+	ret = input_register_device(input);
+	if (ret < 0)
 		goto error;
 
 	dev->input = input;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Darshan,

Thank you for the patch.

Quoted 1 line · Darshan Rathod

The function uvc_input_init() used an assignment of the return value

s/used/uses/

Quoted 7 lines

of input_register_device() within the condition of an if statement.

This coding style is discouraged by the Linux kernel coding style guide as it can be confused with a comparison and hide potential bugs. The checkpatch.pl script flags this as an error:
"ERROR: do not use assignment in if condition"

Quoted 5 lines

Separate the assignment into its own statement before the conditional check to improve code readability and adhere to the kernel's coding standards.

I'll update the commit message as mentioned above when applying, no need for a v2.

Quoted 18 lines
---
 drivers/media/usb/uvc/uvc_status.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_status.c +2 -1
index ee01dce4b783..3c29c0bb3f7c 100644
@@ -62,7 +62,8 @@ static int uvc_input_init(struct uvc_device *dev)
 	__set_bit(EV_KEY, input->evbit);
 	__set_bit(KEY_CAMERA, input->keybit);
 
-	if ((ret = input_register_device(input)) < 0)
+	ret = input_register_device(input);
+	if (ret < 0)
 		goto error;
 
 	dev->input = input;
Signature · 3 lines
Regards,

Laurent Pinchart