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

From: Andy Shevchenko
Date: Mon Apr 11 2022 - 12:53:41 EST


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:
a) less characters to parse (no 'else');
b) checking for errors first, which seems more or less standard pattern.

--
With Best Regards,
Andy Shevchenko