From: Dan Carpenter <error27@gmail.com>
To: rex-bc.chen@mediatek.com
Cc: linux-mediatek@lists.infradead.org
Subject: [bug report] cpufreq: mediatek: Link CCI device to CPU
Date: Mon, 27 Feb 2023 11:07:12 +0300 [thread overview]
Message-ID: <Y/xksGSXSefEJvyO@kili> (raw)
Hello Rex-BC Chen,
The patch 0daa47325bae: "cpufreq: mediatek: Link CCI device to CPU"
from May 5, 2022, leads to the following Smatch static checker
warning:
drivers/cpufreq/mediatek-cpufreq.c:405 mtk_cpu_dvfs_info_init()
warn: passing zero to 'PTR_ERR'
drivers/cpufreq/mediatek-cpufreq.c
387 static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
388 {
389 struct device *cpu_dev;
390 struct dev_pm_opp *opp;
391 unsigned long rate;
392 int ret;
393
394 cpu_dev = get_cpu_device(cpu);
395 if (!cpu_dev) {
396 dev_err(cpu_dev, "failed to get cpu%d device\n", cpu);
397 return -ENODEV;
398 }
399 info->cpu_dev = cpu_dev;
400
401 info->ccifreq_bound = false;
402 if (info->soc_data->ccifreq_supported) {
403 info->cci_dev = of_get_cci(info->cpu_dev);
404 if (IS_ERR_OR_NULL(info->cci_dev)) {
--> 405 ret = PTR_ERR(info->cci_dev);
406 dev_err(cpu_dev, "cpu%d: failed to get cci device\n", cpu);
407 return -ENODEV;
This code is "harmless" in terms of run time but it's also wrong. Linus
once complained about this Smatch check that actually passing zero to
PTR_ERR() is allowed but I explained to him that in real life 95% or
19 times out of 20 then when people have this warning there is something
wrong. Today I have seen many of these bugs and 1 non-bug.
[Btw, this code will also trigger another warning because the "ret = "
assignment is never used.]
This driver does a lot of checking for IS_ERR_OR_NULL() and in each case
the code is doing something wrong. I have explained this in my blog:
https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/
The existance of the IS_ERR_OR_NULL() function doesn't mean that we
don't have to care if the function returns NULL or if it returns error
pointers...
If a function returns NULL, then we have to check for NULL. If a
function returns error pointers we have to check for error pointers.
If a function returns a mix of error pointers and NULL the *most* of the
time the errors need to be handled differently from the NULL returns.
For these functions a NULL is *not* an error but is instead a special
kind of success where the feature is not enabled.
Q: Give me the feature
A: The feature is disables so here is a NULL. Success!
The driver then has to written to handle an optional feature which has
been disabled. Do not print an error message. Do not return an error
code.
408 }
409 }
regards,
dan carpenter
reply other threads:[~2023-02-27 8:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Y/xksGSXSefEJvyO@kili \
--to=error27@gmail.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=rex-bc.chen@mediatek.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.