public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	loongarch@lists.linux.dev, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, WANG Xuerui <kernel@xen0n.name>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH v1 1/1] cpufreq: loongson: Check for error code from devm_mutex_init() call
Date: Thu, 31 Oct 2024 09:07:27 +0200	[thread overview]
Message-ID: <ZyMsr0JrXne-h4r8@smile.fi.intel.com> (raw)
In-Reply-To: <CAAhV-H6bOZLur8Eq2CyFaeQp7R1LwiRqf0ODqnftg6+zAbDoYg@mail.gmail.com>

On Thu, Oct 31, 2024 at 09:29:52AM +0800, Huacai Chen wrote:
> On Thu, Oct 31, 2024 at 12:29 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:

...

> > -       for (i = 0; i < MAX_PACKAGES; i++)
> > -               devm_mutex_init(&pdev->dev, &cpufreq_mutex[i]);
> > +       for (i = 0; i < MAX_PACKAGES; i++) {
> > +               ret = devm_mutex_init(&pdev->dev, &cpufreq_mutex[i]);
> > +               if (ret)
> Good catch, but I think "if (ret < 0)" is better? Sometimes a positive
> return value is legal, even if not in this case.

I disagree on this.

During a tons of reviews I have done in the past this kind of check is
impediment and always rises the Q "why?" It means that the author hasn't
fully thought through the code and most likely done something is a cargo cult.
On top of that, if the callee is changed at some point to actually return
a positive code(s), the caller most likely has to be at least aware of that
change. The proposed modification makes this silently compile and hides
possible important details from the caller(s).

> And it is better to use loongson3 rather than loongson because there
>  is another loongson2 driver.

Thanks, I will change that in v2 (I believe you are talking about Subject?).

> > +                       return ret;
> > +       }

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2024-10-31  7:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 16:29 [PATCH v1 1/1] cpufreq: loongson: Check for error code from devm_mutex_init() call Andy Shevchenko
2024-10-31  1:29 ` Huacai Chen
2024-10-31  7:07   ` Andy Shevchenko [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=ZyMsr0JrXne-h4r8@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.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