lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20201027085613.GN1042@kadam>
Date:   Tue, 27 Oct 2020 11:56:13 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     kbuild@...ts.01.org, Badhri Jagan Sridharan <badhri@...gle.com>
Cc:     lkp@...el.com, Dan Carpenter <error27@...il.com>,
        kbuild-all@...ts.01.org, linux-kernel@...r.kernel.org,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Subject: drivers/usb/typec/tcpm/tcpci_maxim.c:324 max_tcpci_irq() error:
 uninitialized symbol 'irq_return'.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   9ff9b0d392ea08090cd1780fb196f36dbb586529
commit: 6f413b559f86a2894188e082e389ff95ee428345 usb: typec: tcpci_maxim: Chip level TCPC driver
config: nios2-randconfig-m031-20201016 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@...el.com>
Reported-by: Dan Carpenter <dan.carpenter@...cle.com>

New smatch warnings:
drivers/usb/typec/tcpm/tcpci_maxim.c:324 max_tcpci_irq() error: uninitialized symbol 'irq_return'.
drivers/usb/typec/tcpm/tcpci_maxim.c:407 max_tcpci_probe() warn: passing zero to 'PTR_ERR'

Old smatch warnings:
drivers/usb/typec/tcpm/tcpci_maxim.c:408 max_tcpci_probe() warn: passing zero to 'PTR_ERR'

vim +/irq_return +324 drivers/usb/typec/tcpm/tcpci_maxim.c

6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  301  static irqreturn_t max_tcpci_irq(int irq, void *dev_id)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  302  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  303  	struct max_tcpci_chip *chip = dev_id;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  304  	u16 status;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  305  	irqreturn_t irq_return;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  306  	int ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  307  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  308  	if (!chip->port)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  309  		return IRQ_HANDLED;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  310  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  311  	ret = max_tcpci_read16(chip, TCPC_ALERT, &status);

Can status be zero?  If it is then then "irq_return" is uninitialized.

6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  312  	if (ret < 0) {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  313  		dev_err(chip->dev, "ALERT read failed\n");
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  314  		return ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  315  	}
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  316  	while (status) {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  317  		irq_return = _max_tcpci_irq(chip, status);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  318  		/* Do not return if the ALERT is already set. */
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  319  		ret = max_tcpci_read16(chip, TCPC_ALERT, &status);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  320  		if (ret < 0)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  321  			break;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  322  	}
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  323  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07 @324  	return irq_return;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  325  }
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  326  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  327  static irqreturn_t max_tcpci_isr(int irq, void *dev_id)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  328  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  329  	struct max_tcpci_chip *chip = dev_id;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  330  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  331  	pm_wakeup_event(chip->dev, PD_ACTIVITY_TIMEOUT_MS);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  332  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  333  	if (!chip->port)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  334  		return IRQ_HANDLED;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  335  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  336  	return IRQ_WAKE_THREAD;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  337  }
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  338  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  339  static int max_tcpci_init_alert(struct max_tcpci_chip *chip, struct i2c_client *client)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  340  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  341  	int ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  342  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  343  	ret = devm_request_threaded_irq(chip->dev, client->irq, max_tcpci_isr, max_tcpci_irq,
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  344  					(IRQF_TRIGGER_LOW | IRQF_ONESHOT), dev_name(chip->dev),
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  345  					chip);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  346  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  347  	if (ret < 0)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  348  		return ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  349  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  350  	enable_irq_wake(client->irq);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  351  	return 0;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  352  }
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  353  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  354  static int max_tcpci_start_toggling(struct tcpci *tcpci, struct tcpci_data *tdata,
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  355  				    enum typec_cc_status cc)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  356  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  357  	struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  358  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  359  	max_tcpci_init_regs(chip);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  360  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  361  	return 0;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  362  }
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  363  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  364  static int tcpci_init(struct tcpci *tcpci, struct tcpci_data *data)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  365  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  366  	/*
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  367  	 * Generic TCPCI overwrites the regs once this driver initializes
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  368  	 * them. Prevent this by returning -1.
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  369  	 */
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  370  	return -1;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  371  }
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  372  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  373  static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  374  {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  375  	int ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  376  	struct max_tcpci_chip *chip;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  377  	u8 power_status;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  378  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  379  	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  380  	if (!chip)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  381  		return -ENOMEM;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  382  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  383  	chip->client = client;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  384  	chip->data.regmap = devm_regmap_init_i2c(client, &max_tcpci_regmap_config);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  385  	if (IS_ERR(chip->data.regmap)) {
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  386  		dev_err(&client->dev, "Regmap init failed\n");
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  387  		return PTR_ERR(chip->data.regmap);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  388  	}
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  389  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  390  	chip->dev = &client->dev;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  391  	i2c_set_clientdata(client, chip);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  392  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  393  	ret = max_tcpci_read8(chip, TCPC_POWER_STATUS, &power_status);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  394  	if (ret < 0)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  395  		return ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  396  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  397  	/* Chip level tcpci callbacks */
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  398  	chip->data.set_vbus = max_tcpci_set_vbus;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  399  	chip->data.start_drp_toggling = max_tcpci_start_toggling;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  400  	chip->data.TX_BUF_BYTE_x_hidden = true;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  401  	chip->data.init = tcpci_init;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  402  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  403  	max_tcpci_init_regs(chip);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  404  	chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  405  	if (IS_ERR_OR_NULL(chip->tcpci)) {

When a function returns both NULL and error pointers that means that
it is an optional feature and it has been deliberately disabled.  In
that case we cannot return a pointer to the feature (it is turned off)
but it's also not an error so we don't want to return an error pointer
so we return NULL.

So probe should handle the NULL return and continue.

But actually in this case tcpci_register_port() is not optional and
never returns NULL.  Just replace IS_ERR_OR_NULL() with IS_ERR().

6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  406  		dev_err(&client->dev, "TCPCI port registration failed");
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07 @407  		ret = PTR_ERR(chip->tcpci);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  408  		return PTR_ERR(chip->tcpci);

returning NULL would mean returning success here.

6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  409  	}
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  410  	chip->port = tcpci_get_tcpm_port(chip->tcpci);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  411  	ret = max_tcpci_init_alert(chip, client);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  412  	if (ret < 0)
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  413  		goto unreg_port;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  414  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  415  	device_init_wakeup(chip->dev, true);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  416  	return 0;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  417  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  418  unreg_port:
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  419  	tcpci_unregister_port(chip->tcpci);
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  420  
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  421  	return ret;
6f413b559f86a28 Badhri Jagan Sridharan 2020-10-07  422  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Download attachment ".config.gz" of type "application/gzip" (26926 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ