From: Dan Carpenter <dan.carpenter@oracle.com>
To: m.felsch@pengutronix.de
Cc: linux-media@vger.kernel.org
Subject: [bug report] media: tvp5150: add FORMAT_TRY support for get/set selection handlers
Date: Wed, 12 Oct 2022 15:00:01 +0300 [thread overview]
Message-ID: <Y0asQSuTaFU45YFy@kili> (raw)
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
reply other threads:[~2022-10-12 12:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0asQSuTaFU45YFy@kili \
--to=dan.carpenter@oracle.com \
--cc=linux-media@vger.kernel.org \
--cc=m.felsch@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox