Re: [PATCH] media: v4l2-subdev: fix some NULL vs IS_ERR() checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Dan,

Thank you for the patch.

On Tue, Jun 22, 2021 at 05:31:53PM +0300, Dan Carpenter wrote:
> The v4l2_subdev_alloc_state() function returns error pointers, it
> doesn't return NULL.

It's funny you send this patch today, I've been thinking about the exact
same issue yesterday, albeit more globally, when trying to figure out if
a function I called returned NULL or an error pointer on error.

Would it make to create an __err_ptr annotation to mark functions that
return an error pointer ? This would both give a simple indication to
the user and allow tools such as smatch to detect errors.

> Fixes: 0d346d2a6f54 ("media: v4l2-subdev: add subdev-wide state struct")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

Reviewed-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>

Mauro, can you pick this patch up ?

> ---
>  drivers/media/platform/vsp1/vsp1_entity.c | 4 ++--
>  drivers/staging/media/tegra-video/vi.c | 4 ++--
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 4 ++--
>  3 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/vsp1/vsp1_entity.c b/drivers/media/platform/vsp1/vsp1_entity.c
> index 6f51e5c75543..823c15facd1b 100644
> --- a/drivers/media/platform/vsp1/vsp1_entity.c
> +++ b/drivers/media/platform/vsp1/vsp1_entity.c
> @@ -676,9 +676,9 @@ int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
>  	 * rectangles.
>  	 */
>  	entity->config = v4l2_subdev_alloc_state(&entity->subdev);
> -	if (entity->config == NULL) {
> +	if (IS_ERR(entity->config)) {
>  		media_entity_cleanup(&entity->subdev.entity);
> -		return -ENOMEM;
> +		return PTR_ERR(entity->config);
>  	}
>  
>  	return 0;
> diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
> index 89709cd06d4d..d321790b07d9 100644
> --- a/drivers/staging/media/tegra-video/vi.c
> +++ b/drivers/staging/media/tegra-video/vi.c
> @@ -508,8 +508,8 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
>  		return -ENODEV;
>  
>  	sd_state = v4l2_subdev_alloc_state(subdev);
> -	if (!sd_state)
> -		return -ENOMEM;
> +	if (IS_ERR(sd_state))
> +		return PTR_ERR(sd_state);
>  	/*
>  	 * Retrieve the format information and if requested format isn't
>  	 * supported, keep the current format.
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index cca15a10c0b3..0d141155f0e3 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -253,8 +253,8 @@ static int rvin_try_format(struct rvin_dev *vin, u32 which,
>  	int ret;
>  
>  	sd_state = v4l2_subdev_alloc_state(sd);
> -	if (sd_state == NULL)
> -		return -ENOMEM;
> +	if (IS_ERR(sd_state))
> +		return PTR_ERR(sd_state);
>  
>  	if (!rvin_format_from_pixel(vin, pix->pixelformat))
>  		pix->pixelformat = RVIN_DEFAULT_FORMAT;

-- 
Regards,

Laurent Pinchart



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux