public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [bug report] media: tvp5150: add FORMAT_TRY support for get/set selection handlers
@ 2022-10-12 12:00 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2022-10-12 12:00 UTC (permalink / raw)
  To: m.felsch; +Cc: linux-media

Hello Marco Felsch,

The patch 46fe6e7dcede: "media: tvp5150: add FORMAT_TRY support for
get/set selection handlers" from Mar 12, 2020, leads to the following
Smatch static checker warning:

	drivers/media/i2c/tvp5150.c:1153 tvp5150_set_selection()
	error: potential NULL/IS_ERR bug 'crop'

drivers/media/i2c/tvp5150.c
    1106 static int tvp5150_set_selection(struct v4l2_subdev *sd,
    1107                                  struct v4l2_subdev_state *sd_state,
    1108                                  struct v4l2_subdev_selection *sel)
    1109 {
    1110         struct tvp5150 *decoder = to_tvp5150(sd);
    1111         struct v4l2_rect *rect = &sel->r;
    1112         struct v4l2_rect *crop;
    1113         unsigned int hmax;
    1114 
    1115         if (sel->target != V4L2_SEL_TGT_CROP)
    1116                 return -EINVAL;
    1117 
    1118         dev_dbg_lvl(sd->dev, 1, debug, "%s left=%d, top=%d, width=%d, height=%d\n",
    1119                 __func__, rect->left, rect->top, rect->width, rect->height);
    1120 
    1121         /* tvp5150 has some special limits */
    1122         rect->left = clamp(rect->left, 0, TVP5150_MAX_CROP_LEFT);
    1123         rect->top = clamp(rect->top, 0, TVP5150_MAX_CROP_TOP);
    1124         hmax = tvp5150_get_hmax(sd);
    1125 
    1126         /*
    1127          * alignments:
    1128          *  - width = 2 due to UYVY colorspace
    1129          *  - height, image = no special alignment
    1130          */
    1131         v4l_bound_align_image(&rect->width,
    1132                               TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect->left,
    1133                               TVP5150_H_MAX - rect->left, 1, &rect->height,
    1134                               hmax - TVP5150_MAX_CROP_TOP - rect->top,
    1135                               hmax - rect->top, 0, 0);
    1136 
    1137         if (!IS_ENABLED(CONFIG_VIDEO_V4L2_SUBDEV_API) &&
    1138             sel->which == V4L2_SUBDEV_FORMAT_TRY)
    1139                 return 0;
    1140 
    1141         crop = tvp5150_get_pad_crop(decoder, sd_state, sel->pad, sel->which);

If "sd_state" is NULL then v4l2_subdev_get_try_crop() can return NULL.
It's probably best to convert tvp5150_get_pad_crop() to only return
error pointers or only return NULL on error.

    1142         if (IS_ERR(crop))
    1143                 return PTR_ERR(crop);
    1144 
    1145         /*
    1146          * Update output image size if the selection (crop) rectangle size or
    1147          * position has been modified.
    1148          */
    1149         if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
    1150             !v4l2_rect_equal(rect, crop))
    1151                 tvp5150_set_hw_selection(sd, rect);
    1152 
--> 1153         *crop = *rect;
    1154 
    1155         return 0;
    1156 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-12 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-12 12:00 [bug report] media: tvp5150: add FORMAT_TRY support for get/set selection handlers Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox