public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Srinivasa Rao Mandadapu <quic_srivasam@quicinc.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	linux-kernel@vger.kernel.org, Vinod Koul <vkoul@kernel.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: drivers/soundwire/qcom.c:1319 qcom_swrm_probe() warn: passing zero to 'PTR_ERR'
Date: Mon, 22 Aug 2022 10:56:19 +0300	[thread overview]
Message-ID: <202208202132.gxUTdHmB-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   50cd95ac46548429e5bba7ca75cc97d11a697947
commit: 1fd0d85affe4d64e54b81d04bf9577e57172a341 soundwire: qcom: Add flag for software clock gating check
config: riscv-randconfig-m031-20220819 (https://download.01.org/0day-ci/archive/20220820/202208202132.gxUTdHmB-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/soundwire/qcom.c:1319 qcom_swrm_probe() warn: passing zero to 'PTR_ERR'

Old smatch warnings:
arch/riscv/include/asm/atomic.h:204 arch_atomic_fetch_add_unless() warn: inconsistent indenting

vim +/PTR_ERR +1319 drivers/soundwire/qcom.c

02efb49aa805ce Srinivas Kandagatla     2020-01-13  1280  static int qcom_swrm_probe(struct platform_device *pdev)
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1281  {
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1282  	struct device *dev = &pdev->dev;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1283  	struct sdw_master_prop *prop;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1284  	struct sdw_bus_params *params;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1285  	struct qcom_swrm_ctrl *ctrl;
8cb3b4e74cd810 Srinivas Kandagatla     2020-09-17  1286  	const struct qcom_swrm_data *data;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1287  	int ret;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1288  	u32 val;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1289  
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1290  	ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1291  	if (!ctrl)
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1292  		return -ENOMEM;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1293  
8cb3b4e74cd810 Srinivas Kandagatla     2020-09-17  1294  	data = of_device_get_match_data(dev);
8cb3b4e74cd810 Srinivas Kandagatla     2020-09-17  1295  	ctrl->rows_index = sdw_find_row_index(data->default_rows);
8cb3b4e74cd810 Srinivas Kandagatla     2020-09-17  1296  	ctrl->cols_index = sdw_find_col_index(data->default_cols);
47edc0104c61d6 Vinod Koul              2020-11-25  1297  #if IS_REACHABLE(CONFIG_SLIMBUS)
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1298  	if (dev->parent->bus == &slimbus_bus) {
5bd773242f75da Jonathan Marek          2020-09-05  1299  #else
5bd773242f75da Jonathan Marek          2020-09-05  1300  	if (false) {
5bd773242f75da Jonathan Marek          2020-09-05  1301  #endif
d1df23fe688b58 Jonathan Marek          2020-09-05  1302  		ctrl->reg_read = qcom_swrm_ahb_reg_read;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1303  		ctrl->reg_write = qcom_swrm_ahb_reg_write;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1304  		ctrl->regmap = dev_get_regmap(dev->parent, NULL);
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1305  		if (!ctrl->regmap)
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1306  			return -EINVAL;
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1307  	} else {
82f5c70c26511b Jonathan Marek          2020-09-05  1308  		ctrl->reg_read = qcom_swrm_cpu_reg_read;
82f5c70c26511b Jonathan Marek          2020-09-05  1309  		ctrl->reg_write = qcom_swrm_cpu_reg_write;
82f5c70c26511b Jonathan Marek          2020-09-05  1310  		ctrl->mmio = devm_platform_ioremap_resource(pdev, 0);
82f5c70c26511b Jonathan Marek          2020-09-05  1311  		if (IS_ERR(ctrl->mmio))
82f5c70c26511b Jonathan Marek          2020-09-05  1312  			return PTR_ERR(ctrl->mmio);
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1313  	}
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1314  
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1315  	if (data->sw_clk_gate_required) {
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1316  		ctrl->audio_cgcr = devm_reset_control_get_exclusive(dev, "swr_audio_cgcr");
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1317  		if (IS_ERR_OR_NULL(ctrl->audio_cgcr)) {
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1318  			dev_err(dev, "Failed to get cgcr reset ctrl required for SW gating\n");
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01 @1319  			ret = PTR_ERR(ctrl->audio_cgcr);

I believe that the IS_ERR_OR_NULL() check is wrong because
devm_reset_control_get_exclusive() does not return NULL.  That means
that this bug is harmless.

I wrote a blog about this:
https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/

The TLDR; version is that when a function returns both error pointers
and NULLs then the NULL should be treated as a success path.  Do not
print an error message.  Continue probing the driver but add NULL checks
as necessary to support that the feature can be disabled.

The devm_reset_control_get_exclusive() function calls
__devm_reset_control_get() which *can* return NULL if we pass
"optional == true".  But devm_reset_control_get_exclusive() passes
"optional == false" so it is not optional and will either return a valid
pointer or an error pointer.

1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1320  			goto err_init;
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1321  		}
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1322  	}
1fd0d85affe4d6 Srinivasa Rao Mandadapu 2022-07-01  1323  
02efb49aa805ce Srinivas Kandagatla     2020-01-13  1324  	ctrl->irq = of_irq_get(dev->of_node, 0);
91b5cfc0209b63 Pierre-Louis Bossart    2020-04-30  1325  	if (ctrl->irq < 0) {

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


                 reply	other threads:[~2022-08-22  7:57 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=202208202132.gxUTdHmB-lkp@intel.com \
    --to=dan.carpenter@oracle.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=quic_srivasam@quicinc.com \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=vkoul@kernel.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