Re: [PATCH v1] PM: runtime: Avoid device usage count underflows

From: Rafael J. Wysocki
Date: Mon Apr 11 2022 - 14:07:42 EST


On Mon, Apr 11, 2022 at 6:53 PM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
>
> On Mon, Apr 11, 2022 at 6:17 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:
> > On Mon, Apr 11, 2022 at 5:09 PM Andy Shevchenko
> > <andy.shevchenko@xxxxxxxxx> wrote:
> > > On Wed, Apr 6, 2022 at 11:49 PM Rafael J. Wysocki <rjw@xxxxxxxxxxxxx> wrote:
>
> ...
>
> > > > + retval = rpm_drop_usage_count(dev);
> > > > + if (retval > 0) {
> > > > trace_rpm_usage_rcuidle(dev, rpmflags);
> > > > return 0;
> > > > + } else if (retval < 0) {
> > > > + return retval;
> > > > }
> > >
> > > Can be written in a form
> > >
> > > if (retval < 0)
> > > return retval;
> > > if (retval > 0) {
> > > trace_rpm_usage_rcuidle(dev, rpmflags);
> > > return 0;
> > > }
> > >
> >
> > I know.
> >
> > And why would it be better?
>
> Depends on the perception:

Well, exactly.

> a) less characters to parse (no 'else');

But to me, with the "else" it is clear that the conditionals are
related to each other which is not so clear otherwise at first sight.
YMMV

> b) checking for errors first, which seems more or less standard pattern.

So the checks can be reversed no problem, but this is such a minor point ,,,