Message ID | b4a9369bf923c0a3b90cf0e8ccee8ee2178403fc.1696586632.git.hverkuil-cisco@xs4all.nl |
---|---|
State | Accepted |
Commit | f06acbe3398c4141939c6362301220d2fdfba805 |
Headers | show |
Series | media: fix smatch warnings | expand |
Hi Hans, On Fri, Oct 06, 2023 at 12:08:48PM +0200, Hans Verkuil wrote: > Check if the format was really found. > > Fixes smatch warning: > > drivers/media/i2c/tc358746.c:790 tc358746_set_fmt() error: 'fmt' dereferencing possible ERR_PTR() > > Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> > CC: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > drivers/media/i2c/tc358746.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/tc358746.c b/drivers/media/i2c/tc358746.c > index 566f5eaddd57..ce612a47ba84 100644 > --- a/drivers/media/i2c/tc358746.c > +++ b/drivers/media/i2c/tc358746.c > @@ -784,8 +784,12 @@ static int tc358746_set_fmt(struct v4l2_subdev *sd, > sink_fmt = v4l2_subdev_get_pad_format(sd, sd_state, TC358746_SINK); > > fmt = tc358746_get_format_by_code(format->pad, format->format.code); > - if (IS_ERR(fmt)) > + if (IS_ERR(fmt)) { > fmt = tc358746_get_format_by_code(format->pad, tc358746_def_fmt.code); > + // Can't happen, but just in case... /* ... */ Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> > + if (WARN_ON(IS_ERR(fmt))) > + return -EINVAL; > + } > > format->format.code = fmt->code; > format->format.field = V4L2_FIELD_NONE; > -- > 2.40.1 >
diff --git a/drivers/media/i2c/tc358746.c b/drivers/media/i2c/tc358746.c index 566f5eaddd57..ce612a47ba84 100644 --- a/drivers/media/i2c/tc358746.c +++ b/drivers/media/i2c/tc358746.c @@ -784,8 +784,12 @@ static int tc358746_set_fmt(struct v4l2_subdev *sd, sink_fmt = v4l2_subdev_get_pad_format(sd, sd_state, TC358746_SINK); fmt = tc358746_get_format_by_code(format->pad, format->format.code); - if (IS_ERR(fmt)) + if (IS_ERR(fmt)) { fmt = tc358746_get_format_by_code(format->pad, tc358746_def_fmt.code); + // Can't happen, but just in case... + if (WARN_ON(IS_ERR(fmt))) + return -EINVAL; + } format->format.code = fmt->code; format->format.field = V4L2_FIELD_NONE;
Check if the format was really found. Fixes smatch warning: drivers/media/i2c/tc358746.c:790 tc358746_set_fmt() error: 'fmt' dereferencing possible ERR_PTR() Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> CC: Sakari Ailus <sakari.ailus@linux.intel.com> --- drivers/media/i2c/tc358746.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)