[7/7] uvc_v4l2.c: avoid using iterator used outside loop

Message ID 20220509091553.2637089-8-hverkuil-cisco@xs4all.nl (mailing list archive)
State New
Delegated to: Laurent Pinchart
Headers
Series Various smatch fixes |

Commit Message

Hans Verkuil May 9, 2022, 9:15 a.m. UTC
  Fixes these two smatch warnings:

drivers/media/usb/uvc/uvc_v4l2.c:885 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'
drivers/media/usb/uvc/uvc_v4l2.c:896 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
  

Comments

sakari.ailus@iki.fi May 9, 2022, 10:04 a.m. UTC | #1
Hi Hans,

Thanks for the set.

On Mon, May 09, 2022 at 11:15:53AM +0200, Hans Verkuil wrote:
> Fixes these two smatch warnings:
> 
> drivers/media/usb/uvc/uvc_v4l2.c:885 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'
> drivers/media/usb/uvc/uvc_v4l2.c:896 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
>  drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 711556d13d03..ff3f04af4e21 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c

...

> @@ -879,21 +880,25 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
>  		if (index != 0)
>  			return -EINVAL;
>  		list_for_each_entry(iterm, &chain->entities, chain) {
> -			if (UVC_ENTITY_IS_ITERM(iterm))
> +			if (UVC_ENTITY_IS_ITERM(iterm)) {
> +				pin = iterm->id;
> +				found_pin = true;
>  				break;
> +			}
>  		}
> -		pin = iterm->id;
>  	} else if (index < selector->bNrInPins) {
>  		pin = selector->baSourceID[index];
>  		list_for_each_entry(iterm, &chain->entities, chain) {
>  			if (!UVC_ENTITY_IS_ITERM(iterm))
>  				continue;
> -			if (iterm->id == pin)
> +			if (iterm->id == pin) {
> +				found_pin = true;
>  				break;
> +			}
>  		}
>  	}
>  
> -	if (iterm == NULL || iterm->id != pin)
> +	if (!found_pin)
>  		return -EINVAL;
>  
>  	memset(input, 0, sizeof(*input));

iterm is used a few lines below, too, so this patch doesn't remove its use
outside the loop. Which btw. I don't think is a problem at all. Doing that
is relatively common IMO.

For the rest of the set:

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  
Laurent Pinchart May 9, 2022, 10:09 a.m. UTC | #2
Hi Hans,

Thank you for the patch.

On Mon, May 09, 2022 at 11:15:53AM +0200, Hans Verkuil wrote:
> Fixes these two smatch warnings:
> 
> drivers/media/usb/uvc/uvc_v4l2.c:885 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'
> drivers/media/usb/uvc/uvc_v4l2.c:896 uvc_ioctl_enum_input() warn: iterator used outside loop: 'iterm'
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

This conflicts with 261f33388c29 ("media: uvcvideo: Fix missing check to
determine if element is found in list").

> ---
>  drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 711556d13d03..ff3f04af4e21 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -871,6 +871,7 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
>  	struct uvc_video_chain *chain = handle->chain;
>  	const struct uvc_entity *selector = chain->selector;
>  	struct uvc_entity *iterm = NULL;
> +	bool found_pin = false;
>  	u32 index = input->index;
>  	int pin = 0;
>  
> @@ -879,21 +880,25 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
>  		if (index != 0)
>  			return -EINVAL;
>  		list_for_each_entry(iterm, &chain->entities, chain) {
> -			if (UVC_ENTITY_IS_ITERM(iterm))
> +			if (UVC_ENTITY_IS_ITERM(iterm)) {
> +				pin = iterm->id;
> +				found_pin = true;
>  				break;
> +			}
>  		}
> -		pin = iterm->id;
>  	} else if (index < selector->bNrInPins) {
>  		pin = selector->baSourceID[index];
>  		list_for_each_entry(iterm, &chain->entities, chain) {
>  			if (!UVC_ENTITY_IS_ITERM(iterm))
>  				continue;
> -			if (iterm->id == pin)
> +			if (iterm->id == pin) {
> +				found_pin = true;
>  				break;
> +			}
>  		}
>  	}
>  
> -	if (iterm == NULL || iterm->id != pin)
> +	if (!found_pin)
>  		return -EINVAL;
>  
>  	memset(input, 0, sizeof(*input));
  

Patch

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 711556d13d03..ff3f04af4e21 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -871,6 +871,7 @@  static int uvc_ioctl_enum_input(struct file *file, void *fh,
 	struct uvc_video_chain *chain = handle->chain;
 	const struct uvc_entity *selector = chain->selector;
 	struct uvc_entity *iterm = NULL;
+	bool found_pin = false;
 	u32 index = input->index;
 	int pin = 0;
 
@@ -879,21 +880,25 @@  static int uvc_ioctl_enum_input(struct file *file, void *fh,
 		if (index != 0)
 			return -EINVAL;
 		list_for_each_entry(iterm, &chain->entities, chain) {
-			if (UVC_ENTITY_IS_ITERM(iterm))
+			if (UVC_ENTITY_IS_ITERM(iterm)) {
+				pin = iterm->id;
+				found_pin = true;
 				break;
+			}
 		}
-		pin = iterm->id;
 	} else if (index < selector->bNrInPins) {
 		pin = selector->baSourceID[index];
 		list_for_each_entry(iterm, &chain->entities, chain) {
 			if (!UVC_ENTITY_IS_ITERM(iterm))
 				continue;
-			if (iterm->id == pin)
+			if (iterm->id == pin) {
+				found_pin = true;
 				break;
+			}
 		}
 	}
 
-	if (iterm == NULL || iterm->id != pin)
+	if (!found_pin)
 		return -EINVAL;
 
 	memset(input, 0, sizeof(*input));