From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Joe Perches <joe@perches.com>, Xu Wang <vulab@iscas.ac.cn>,
perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org
Cc: "Rojewski, Cezary" <cezary.rojewski@intel.com>,
linux-kernel@vger.kernel.org, "Slawinski,
AmadeuszX" <amadeuszx.slawinski@intel.com>
Subject: Re: [PATCH] Intel: Skylake: Fix inconsistent IS_ERR and PTR_ERR
Date: Fri, 21 Feb 2020 09:40:13 -0600 [thread overview]
Message-ID: <8e96c207-cdf8-2d1f-755e-be60555c8728@linux.intel.com> (raw)
In-Reply-To: <1247da797bc0a860e845989241385e124e589063.camel@perches.com>
On 2/21/20 8:41 AM, Joe Perches wrote:
> On Fri, 2020-02-21 at 18:11 +0800, Xu Wang wrote:
>> PTR_ERR should access the value just tested by IS_ERR.
>> In skl_clk_dev_probe(),it is inconsistent.
> []
>> diff --git a/sound/soc/intel/skylake/skl-ssp-clk.c b/sound/soc/intel/skylake/skl-ssp-clk.c
> []
>> @@ -384,7 +384,7 @@ static int skl_clk_dev_probe(struct platform_device *pdev)
>> &clks[i], clk_pdata, i);
>>
>> if (IS_ERR(data->clk[data->avail_clk_cnt])) {
>> - ret = PTR_ERR(data->clk[data->avail_clk_cnt++]);
>> + ret = PTR_ERR(data->clk[data->avail_clk_cnt]);
>
> NAK.
>
> This is not inconsistent and you are removing the ++
> which is a post increment. Likely that is necessary.
>
> You could write the access and the increment as two
> separate statements if it confuses you.
Well to be fair the code is far from clear.
the post-increment is likely needed because of the error handling in
unregister_src_clk 1
data->clk[data->avail_clk_cnt] = register_skl_clk(dev,
&clks[i], clk_pdata, i);
if (IS_ERR(data->clk[data->avail_clk_cnt])) {
ret = PTR_ERR(data->clk[data->avail_clk_cnt++]);
goto err_unreg_skl_clk;
}
}
platform_set_drvdata(pdev, data);
return 0;
err_unreg_skl_clk:
unregister_src_clk(data);
static void unregister_src_clk(struct skl_clk_data *dclk)
{
while (dclk->avail_clk_cnt--)
clkdev_drop(dclk->clk[dclk->avail_clk_cnt]->lookup);
}
So the post-increment is cancelled in the while().
That said, the avail_clk_cnt field is never initialized or incremented
in normal usages so the code looks quite suspicious indeed.
gitk tells me this patch is likely the culprit:
6ee927f2f01466 ('ASoC: Intel: Skylake: Fix NULL ptr dereference when
unloading clk dev')
- data->clk[i] = register_skl_clk(dev, &clks[i], clk_pdata, i);
- if (IS_ERR(data->clk[i])) {
- ret = PTR_ERR(data->clk[i]);
+ data->clk[data->avail_clk_cnt] = register_skl_clk(dev,
+ &clks[i], clk_pdata, i);
+
+ if (IS_ERR(data->clk[data->avail_clk_cnt])) {
+ ret = PTR_ERR(data->clk[data->avail_clk_cnt++]);
goto err_unreg_skl_clk;
}
-
- data->avail_clk_cnt++;
That last removal is probably wrong. Cezary and Amadeusz, you may want
to look at this?
next prev parent reply other threads:[~2020-02-21 15:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200221101112.3104-1-vulab@iscas.ac.cn>
2020-02-21 14:41 ` [PATCH] Intel: Skylake: Fix inconsistent IS_ERR and PTR_ERR Joe Perches
2020-02-21 15:40 ` Pierre-Louis Bossart [this message]
2020-02-23 15:59 ` Cezary Rojewski
2020-02-24 10:42 ` Amadeusz Sławiński
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=8e96c207-cdf8-2d1f-755e-be60555c8728@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@intel.com \
--cc=cezary.rojewski@intel.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=vulab@iscas.ac.cn \
/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