From: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: "linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [PATCH] media: sunxi: sun6i_mipi_csi2.c/sun8i_a83t_mipi_csi2.c: clarify error handling
Date: Tue, 19 Jul 2022 14:20:48 +0200 [thread overview]
Message-ID: <YtahoElfO/l/Msfm@aptenodytes> (raw)
In-Reply-To: <600d543a-7445-3634-dbf7-cf3b01c6a2a4@xs4all.nl>
[-- Attachment #1: Type: text/plain, Size: 5997 bytes --]
Hans,
On Tue 19 Jul 22, 12:04, Hans Verkuil wrote:
> On 7/19/22 11:54, Paul Kocialkowski wrote:
> > Hi Hans,
> >
> > On Mon 18 Jul 22, 18:08, Hans Verkuil wrote:
> >> Both sun6i_mipi_csi2.c and sun8i_a83t_mipi_csi2.c have the same issue:
> >> the comment before the ret = 0 assignment is incorrect, drop it and
> >> always assign the result of the v4l2_subdev_call(..., 0) to ret.
> >
> > Not sure what is incorrect about it. I agree that it's good to return the
> > return code of v4l2_subdev_call instead of always 0 on the !on path though.
> >
> >> In the disable label check for !on and set ret to 0 in that case.
> >>
> >> This fixes two smatch warnings:
> >>
> >> drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c:193 sun6i_mipi_csi2_s_stream() warn: missing error code 'ret'
> >
> > I don't think this is legit: the initialization of ret is specifically there
> > to avoid an undefined ret there.
>
> I believe so as well, but I need to get rid of the smatch warning.
Yes fair enough, I was just a bit confused by the commit message.
> >> drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c:225 sun8i_a83t_mipi_csi2_s_stream() warn: missing error code 'ret'
> >>
> >> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> >> ---
> >> .../media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c | 7 ++++---
> >> .../sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c | 7 ++++---
> >> 2 files changed, 8 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c b/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
> >> index 31e12f1506cb..a4e3f9a6b2ff 100644
> >> --- a/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
> >> +++ b/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
> >> @@ -182,14 +182,13 @@ static int sun6i_mipi_csi2_s_stream(struct v4l2_subdev *subdev, int on)
> >> unsigned int lanes_count =
> >> csi2_dev->bridge.endpoint.bus.mipi_csi2.num_data_lanes;
> >> unsigned long pixel_rate;
> >> - /* Initialize to 0 to use both in disable label (ret != 0) and off. */
> >> - int ret = 0;
> >> + int ret;
> >>
> >> if (!source_subdev)
> >> return -ENODEV;
> >>
> >> if (!on) {
> >> - v4l2_subdev_call(source_subdev, video, s_stream, 0);
> >> + ret = v4l2_subdev_call(source_subdev, video, s_stream, 0);
> >> goto disable;
> >> }
> >>
> >> @@ -281,6 +280,8 @@ static int sun6i_mipi_csi2_s_stream(struct v4l2_subdev *subdev, int on)
> >> return 0;
> >>
> >> disable:
> >> + if (!on)
> >> + ret = 0;
> >
> > Then this will always overwrite the ret value from v4l2_subdev_call with the
> > !on disable path. Looks like this can be removed.
>
> Returning an error when stopping streaming is kind of pointless, since
> what are you going to do with that error?
Yeah that's true and it's probably safer to pretend that things went well
just in case returning != 0 somehow ends up halting the turn-off sequence.
> I assumed that's why the original code did this, and I didn't want to
> change the behavior.
Yeah I think it was my initial intent to discard the v4l2_subdev_call return
code for this reason.
> If you think it is better to just return the error, then that can be a
> patch on top.
Nah I'm fine with returning zero after all. But instead of assigning ret from
v4l2_subdev_call and then overwriting it conditionally in the disable label,
you could just as well set ret = 0; before goto disable; which seems less
confusing to me. I think this should also satisfy the smatch warning.
Otherwise it would be nice to at least have a comment about it or to reflect
the ret overwrite in the commit message (and maybe add a blank like after the
conditional block while at it).
> BTW, I think it would have been better to have separate streamon and streamoff
> ops instead of a single s_stream. Starting streaming would return an int, while
> stopping streaming would be a void function. In general when you stop, release,
> close, etc. something there is no point in an error code since there is nothing
> you can do with it.
Agreed, maybe this can be somehow helpful in sensor drivers where you just have
one common bit to start/halt the stream but for more complex subdevs it's not
very helpful to have a single op.
Cheers,
Paul
> Regards,
>
> Hans
>
> >
> > What do you think?
> >
> > Paul
> >
> >> phy_power_off(dphy);
> >> sun6i_mipi_csi2_disable(csi2_dev);
> >>
> >> diff --git a/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c b/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
> >> index c82ede3ca0ff..d052ee77ef0a 100644
> >> --- a/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
> >> +++ b/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
> >> @@ -214,14 +214,13 @@ static int sun8i_a83t_mipi_csi2_s_stream(struct v4l2_subdev *subdev, int on)
> >> unsigned int lanes_count =
> >> csi2_dev->bridge.endpoint.bus.mipi_csi2.num_data_lanes;
> >> unsigned long pixel_rate;
> >> - /* Initialize to 0 to use both in disable label (ret != 0) and off. */
> >> - int ret = 0;
> >> + int ret;
> >>
> >> if (!source_subdev)
> >> return -ENODEV;
> >>
> >> if (!on) {
> >> - v4l2_subdev_call(source_subdev, video, s_stream, 0);
> >> + ret = v4l2_subdev_call(source_subdev, video, s_stream, 0);
> >> goto disable;
> >> }
> >>
> >> @@ -313,6 +312,8 @@ static int sun8i_a83t_mipi_csi2_s_stream(struct v4l2_subdev *subdev, int on)
> >> return 0;
> >>
> >> disable:
> >> + if (!on)
> >> + ret = 0;
> >> phy_power_off(dphy);
> >> sun8i_a83t_mipi_csi2_disable(csi2_dev);
> >>
> >> --
> >> 2.35.1
> >>
> >
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2022-07-19 12:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 16:08 [PATCH] media: sunxi: sun6i_mipi_csi2.c/sun8i_a83t_mipi_csi2.c: clarify error handling Hans Verkuil
2022-07-19 9:54 ` Paul Kocialkowski
2022-07-19 10:04 ` Hans Verkuil
2022-07-19 12:20 ` Paul Kocialkowski [this message]
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=YtahoElfO/l/Msfm@aptenodytes \
--to=paul.kocialkowski@bootlin.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/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