Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2035511ybv; Fri, 21 Feb 2020 07:44:14 -0800 (PST) X-Google-Smtp-Source: APXvYqyL95OPqYWcHaOhVdVxh/Q16/XgVS/dljgZCtXA4LvZnqNRfdixtbq/wnyZqV1o0+4GpwaW X-Received: by 2002:a05:6830:1e5c:: with SMTP id e28mr28120303otj.163.1582299853715; Fri, 21 Feb 2020 07:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582299853; cv=none; d=google.com; s=arc-20160816; b=KTd9wQ9G/LyXplsDO7+Et8c2/c/SjpWJHHCaBmdPog1wXlOtn/MvzKo6KKMGF9/3eJ X7aate9gU8w8acZH+6QbV6STOt/2VXIW+bb/0alDaU2E9jNtbQ8YGeH06VqXSDfvVsPb AD8JQ7DaefnKzefJQ5cnLA2k9aUVqO5CytAGX60/tIT4ZHiy+N7WvQdH2CkgP6CoaMha aX2XWrWwiNnnTxhnolwOrWWOJf/dHoSIJ7iv1BtLtKQgIyz6R03wfB9TZdaCC0/2FiVO dhaIe/JkQpW8L1qUxYwpo7cAiTXcEpGoEa+DP4qc3b1jg1BdGWYIjXM7PUvYA5xqpv3U 9DZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Qj3MEvc0Pfr2daoaV+Vt9+l6tQjH1iCPX1J3VZ4pKtY=; b=0EO3a8RepYt1XnT39YTL0dP+1chVf7Tnul58lhtRIUgM0/PNDq/f7+hV53ezi64yRJ urd3TTslh+/5yZFIOM7pEeyz1IuB9MBQtv9sBf1SlfkzMyeHqB3BtQq5iL/bi1fKlDZK TlOuiAsbkdR5n9B95lVGdvAm83HsQ4aQucCI4nc/7pOSaNQULhswIfz/y+bf3DNYgd2A xQ/kpm1kMrrkr/xPIJqTSAg5aIkrz8r9KIRdGkdC5Gakg5WyUrEM9non33Sl7FartuOO bbjxCH0TwWHzgriqliW9M7H0QmBjMsjHvDjs8+TQo0q4UUw8nKPj0iMX73lPLOtYKL5s akOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b126si906091oii.72.2020.02.21.07.44.01; Fri, 21 Feb 2020 07:44:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728777AbgBUPne (ORCPT + 99 others); Fri, 21 Feb 2020 10:43:34 -0500 Received: from mga05.intel.com ([192.55.52.43]:42653 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728177AbgBUPnd (ORCPT ); Fri, 21 Feb 2020 10:43:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2020 07:43:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,468,1574150400"; d="scan'208";a="236603814" Received: from mdiamon1-mobl.amr.corp.intel.com (HELO [10.252.143.193]) ([10.252.143.193]) by orsmga003.jf.intel.com with ESMTP; 21 Feb 2020 07:43:30 -0800 Subject: Re: [PATCH] Intel: Skylake: Fix inconsistent IS_ERR and PTR_ERR To: Joe Perches , Xu Wang , perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, "Rojewski, Cezary" , "Slawinski, AmadeuszX" References: <20200221101112.3104-1-vulab@iscas.ac.cn> <1247da797bc0a860e845989241385e124e589063.camel@perches.com> From: Pierre-Louis Bossart Message-ID: <8e96c207-cdf8-2d1f-755e-be60555c8728@linux.intel.com> Date: Fri, 21 Feb 2020 09:40:13 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <1247da797bc0a860e845989241385e124e589063.camel@perches.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?