Skip to contentSkip to conversation

media: uvcvideo: avoid variable shadowing in uvc_ctrl_cleanup_fh

PATCH Superseded Desnes Nunes 4 participants 6 messages Jul 1, 2025 – Jul 8, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: uvcvideo: avoid variable shadowing in uvc_ctrl_cleanup_fh

This avoids a variable loop shadowing occurring between the local loop iterating through the uvc_entity's controls and the global one going through the pending async controls of the file handle

Fixes 10acb9101355 ("media: uvcvideo: Increase/decrease the PM counter per IOCTL")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
index 44b6513c5264..532615d8484b 100644
@@ -3260,7 +3260,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
 void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 {
 	struct uvc_entity *entity;
-	int i;
+	unsigned int i;
 
 	guard(mutex)(&handle->chain->ctrl_mutex);
 
@@ -3268,7 +3268,7 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 		return;
 
 	list_for_each_entry(entity, &handle->chain->dev->entities, list) {
-		for (unsigned int i = 0; i < entity->ncontrols; ++i) {
+		for (i = 0; i < entity->ncontrols; ++i) {
 			if (entity->controls[i].handle != handle)
 				continue;
 			uvc_ctrl_set_handle(handle, &entity->controls[i], NULL);
Signature · 1 line
2.49.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Desnes Nunes

This avoids a variable loop shadowing occurring between the local loop iterating through the uvc_entity's controls and the global one going through the pending async controls of the file handle

Fixes 10acb9101355 ("media: uvcvideo: Increase/decrease the PM counter per IOCTL")
Quoted 31 lines
---
 drivers/media/usb/uvc/uvc_ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -3
index 44b6513c5264..532615d8484b 100644
@@ -3260,7 +3260,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
 void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 {
        struct uvc_entity *entity;
-       int i;
+       unsigned int i;
 
        guard(mutex)(&handle->chain->ctrl_mutex);
 
@@ -3268,7 +3268,7 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
                return;
 
        list_for_each_entry(entity, &handle->chain->dev->entities, list) {
-               for (unsigned int i = 0; i < entity->ncontrols; ++i) {
+               for (i = 0; i < entity->ncontrols; ++i) {
                        if (entity->controls[i].handle != handle)
                                continue;
                        uvc_ctrl_set_handle(handle, &entity->controls[i], NULL);
--

2.49.0

Signature · 1 line
Ricardo Ribalda
maintainer
#2 lore raw
In reply to Desnes Nunes

Hi,

Quoted 7 lines · Desnes Nunes

This avoids a variable loop shadowing occurring between the local loop iterating through the uvc_entity's controls and the global one going through the pending async controls of the file handle

Fixes 10acb9101355 ("media: uvcvideo: Increase/decrease the PM counter per IOCTL")

Thank you for the new version.

I've pushed this to uvc/for-next now:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commits/for-next/

Note I had to manually apply the patch because of it conflicting with:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commit/2b1e8e9f7bb30204ddb42887c4e554c131f003c9

So if you want this backported to stable you will need to send the original version to stable your self.

I plan to send a pull-request with the changes from for-next this Thursday.

Regards,

Hans

Quoted 26 lines
---
 drivers/media/usb/uvc/uvc_ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
index 44b6513c5264..532615d8484b 100644
@@ -3260,7 +3260,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
 void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 {
 	struct uvc_entity *entity;
-	int i;
+	unsigned int i;
 
 	guard(mutex)(&handle->chain->ctrl_mutex);
 
@@ -3268,7 +3268,7 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 		return;
 
 	list_for_each_entry(entity, &handle->chain->dev->entities, list) {
-		for (unsigned int i = 0; i < entity->ncontrols; ++i) {
+		for (i = 0; i < entity->ncontrols; ++i) {
 			if (entity->controls[i].handle != handle)
 				continue;
 			uvc_ctrl_set_handle(handle, &entity->controls[i], NULL);
maintainer
#3 lore raw

Hi Hans,

Quoted 9 lines · Hans de Goede
Quoted 7 lines · Desnes Nunes

This avoids a variable loop shadowing occurring between the local loop iterating through the uvc_entity's controls and the global one going through the pending async controls of the file handle

Fixes 10acb9101355 ("media: uvcvideo: Increase/decrease the PM counter per IOCTL")
Quoted 5 lines

Thank you for the new version.

I've pushed this to uvc/for-next now:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commits/for-next/

As mentioned during the review (see [email protected]), I still prefer local loop variables. Can we use that please ?

Quoted 36 lines

Note I had to manually apply the patch because of it conflicting with:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commit/2b1e8e9f7bb30204ddb42887c4e554c131f003c9

So if you want this backported to stable you will need to send the original version to stable your self.

I plan to send a pull-request with the changes from for-next this Thursday.

Quoted 26 lines
---
 drivers/media/usb/uvc/uvc_ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
index 44b6513c5264..532615d8484b 100644
@@ -3260,7 +3260,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
 void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 {
 	struct uvc_entity *entity;
-	int i;
+	unsigned int i;
 
 	guard(mutex)(&handle->chain->ctrl_mutex);
 
@@ -3268,7 +3268,7 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 		return;
 
 	list_for_each_entry(entity, &handle->chain->dev->entities, list) {
-		for (unsigned int i = 0; i < entity->ncontrols; ++i) {
+		for (i = 0; i < entity->ncontrols; ++i) {
 			if (entity->controls[i].handle != handle)
 				continue;
 			uvc_ctrl_set_handle(handle, &entity->controls[i], NULL);
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#4 lore raw

Hi,

Quoted 14 lines · Laurent Pinchart

Hi Hans,

Quoted 11 lines · Hans de Goede
Quoted 7 lines · Desnes Nunes

This avoids a variable loop shadowing occurring between the local loop iterating through the uvc_entity's controls and the global one going through the pending async controls of the file handle

Fixes 10acb9101355 ("media: uvcvideo: Increase/decrease the PM counter per IOCTL")

Thank you for the new version.

Quoted 7 lines
Quoted 3 lines

I've pushed this to uvc/for-next now:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commits/for-next/

As mentioned during the review (see [email protected]), I still prefer local loop variables. Can we use that please ?

Ok, I'll drop this from for-next.

Desnes, can you prepare a v3 moving the toplevel declation inside the other loop please ?

Regards,

Hans

Quoted 37 lines
Quoted 36 lines

Note I had to manually apply the patch because of it conflicting with:

https://gitlab.freedesktop.org/linux-media/users/uvc/-/commit/2b1e8e9f7bb30204ddb42887c4e554c131f003c9

So if you want this backported to stable you will need to send the original version to stable your self.

I plan to send a pull-request with the changes from for-next this Thursday.

Quoted 26 lines
---
 drivers/media/usb/uvc/uvc_ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
index 44b6513c5264..532615d8484b 100644
@@ -3260,7 +3260,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
 void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 {
 	struct uvc_entity *entity;
-	int i;
+	unsigned int i;
 
 	guard(mutex)(&handle->chain->ctrl_mutex);
 
@@ -3268,7 +3268,7 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle)
 		return;
 
 	list_for_each_entry(entity, &handle->chain->dev->entities, list) {
-		for (unsigned int i = 0; i < entity->ncontrols; ++i) {
+		for (i = 0; i < entity->ncontrols; ++i) {
 			if (entity->controls[i].handle != handle)
 				continue;
 			uvc_ctrl_set_handle(handle, &entity->controls[i], NULL);
#5 lore raw

Hello Hans,

On Mon, Jul 7, 2025 at 10:01 AM Hans de Goede <[email protected]> wrote:
...

Quoted 8 lines
Quoted 3 lines

As mentioned during the review (see [email protected]), I still prefer local loop variables. Can we use that please ?

Ok, I'll drop this from for-next.

Desnes, can you prepare a v3 moving the toplevel declation inside the other loop please ?

Sure, I will send a v3 with the requested changes today.

Best Regards,

Signature · 1 line
Desnes Nunes