Skip to contentSkip to conversation

drivers/usb/host/xhci-mem.c:2040 xhci_add_in_port() error: uninitialized symbol 'tmp_minor_revision'.

PATCH In review Dan Carpenter 3 participants 3 messages May 10, 2023 – May 11, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 10/11 drivers/usb/host/xhci-mem.c:2040 xhci_add_in_port() error: uninitialized symbol 'tmp_minor_revision'.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git for-usb-next
head:   de6fcb4b6f1c55298b3ed0dd3d43961f86aa1b12
commit: efcf3bab0767e057d8727b9a211fbb4fb4cdc81e [10/11] xhci: Show ZHAOXIN xHCI root hub speed correctly
config: loongarch-randconfig-m031-20230509 (https://download.01.org/0day-ci/archive/20230510/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Link: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/usb/host/xhci-mem.c:2040 xhci_add_in_port() error: uninitialized symbol 'tmp_minor_revision'.

vim +/tmp_minor_revision +2040 drivers/usb/host/xhci-mem.c

da6699ce4a889c Sarah Sharp      2010-10-26  1959  static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1960  		__le32 __iomem *addr, int max_caps)
da6699ce4a889c Sarah Sharp      2010-10-26  1961  {
da6699ce4a889c Sarah Sharp      2010-10-26  1962  	u32 temp, port_offset, port_count;
da6699ce4a889c Sarah Sharp      2010-10-26  1963  	int i;
efcf3bab0767e0 Weitao Wang      2023-05-09  1964  	u8 major_revision, minor_revision, tmp_minor_revision;
47189098f8bebe Mathias Nyman    2015-10-01  1965  	struct xhci_hub *rhub;
a965315e59f3cb Adam Wallis      2018-05-22  1966  	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  1967  	struct xhci_port_cap *port_cap;
da6699ce4a889c Sarah Sharp      2010-10-26  1968  
47189098f8bebe Mathias Nyman    2015-10-01  1969  	temp = readl(addr);
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1970  	major_revision = XHCI_EXT_PORT_MAJOR(temp);
b72eb8435b25be YD Tseng         2017-06-09  1971  	minor_revision = XHCI_EXT_PORT_MINOR(temp);
47189098f8bebe Mathias Nyman    2015-10-01  1972  
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1973  	if (major_revision == 0x03) {
47189098f8bebe Mathias Nyman    2015-10-01  1974  		rhub = &xhci->usb3_rhub;
64364bc912c01b Thinh Nguyen     2021-03-10  1975  		/*
64364bc912c01b Thinh Nguyen     2021-03-10  1976  		 * Some hosts incorrectly use sub-minor version for minor
64364bc912c01b Thinh Nguyen     2021-03-10  1977  		 * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01
64364bc912c01b Thinh Nguyen     2021-03-10  1978  		 * for bcdUSB 0x310). Since there is no USB release with sub
64364bc912c01b Thinh Nguyen     2021-03-10  1979  		 * minor version 0x301 to 0x309, we can assume that they are
64364bc912c01b Thinh Nguyen     2021-03-10  1980  		 * incorrect and fix it here.
64364bc912c01b Thinh Nguyen     2021-03-10  1981  		 */
64364bc912c01b Thinh Nguyen     2021-03-10  1982  		if (minor_revision > 0x00 && minor_revision < 0x10)
64364bc912c01b Thinh Nguyen     2021-03-10  1983  			minor_revision <<= 4;
efcf3bab0767e0 Weitao Wang      2023-05-09  1984  		/*
efcf3bab0767e0 Weitao Wang      2023-05-09  1985  		 * Some zhaoxin's xHCI controller that follow usb3.1 spec
efcf3bab0767e0 Weitao Wang      2023-05-09  1986  		 * but only support Gen1.
efcf3bab0767e0 Weitao Wang      2023-05-09  1987  		 */
efcf3bab0767e0 Weitao Wang      2023-05-09  1988  		if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
efcf3bab0767e0 Weitao Wang      2023-05-09  1989  			tmp_minor_revision = minor_revision;

tmp_minor_revision is only set for major_revision == 0x03 (also XHCI_ZHAOXIN_HOST).

efcf3bab0767e0 Weitao Wang      2023-05-09  1990  			minor_revision = 0;
efcf3bab0767e0 Weitao Wang      2023-05-09  1991  		}
efcf3bab0767e0 Weitao Wang      2023-05-09  1992  
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1993  	} else if (major_revision <= 0x02) {
47189098f8bebe Mathias Nyman    2015-10-01  1994  		rhub = &xhci->usb2_rhub;
47189098f8bebe Mathias Nyman    2015-10-01  1995  	} else {
4feb07d0ada339 Andy Shevchenko  2023-03-17  1996  		xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n",
da6699ce4a889c Sarah Sharp      2010-10-26  1997  				addr, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  1998  		/* Ignoring port protocol we can't understand. FIXME */
da6699ce4a889c Sarah Sharp      2010-10-26  1999  		return;
da6699ce4a889c Sarah Sharp      2010-10-26  2000  	}
da6699ce4a889c Sarah Sharp      2010-10-26  2001  
da6699ce4a889c Sarah Sharp      2010-10-26  2002  	/* Port offset and count in the third dword, see section 7.2 */
b0ba9720846c98 Xenia Ragiadakou 2013-11-15  2003  	temp = readl(addr + 2);
da6699ce4a889c Sarah Sharp      2010-10-26  2004  	port_offset = XHCI_EXT_PORT_OFF(temp);
da6699ce4a889c Sarah Sharp      2010-10-26  2005  	port_count = XHCI_EXT_PORT_COUNT(temp);
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2006  	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
4feb07d0ada339 Andy Shevchenko  2023-03-17  2007  		       "Ext Cap %p, port offset = %u, count = %u, revision = 0x%x",
da6699ce4a889c Sarah Sharp      2010-10-26  2008  		       addr, port_offset, port_count, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  2009  	/* Port count includes the current port offset */
da6699ce4a889c Sarah Sharp      2010-10-26  2010  	if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
da6699ce4a889c Sarah Sharp      2010-10-26  2011  		/* WTF? "Valid values are ‘1’ to MaxPorts" */
da6699ce4a889c Sarah Sharp      2010-10-26  2012  		return;
fc71ff7583b143 Andiry Xu        2011-09-23  2013  
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2014  	port_cap = &xhci->port_caps[xhci->num_port_caps++];
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2015  	if (xhci->num_port_caps > max_caps)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2016  		return;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2017  
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2018  	port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp);
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2019  
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2020  	if (port_cap->psi_count) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2021  		port_cap->psi = kcalloc_node(port_cap->psi_count,
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2022  					     sizeof(*port_cap->psi),
a965315e59f3cb Adam Wallis      2018-05-22  2023  					     GFP_KERNEL, dev_to_node(dev));
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2024  		if (!port_cap->psi)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2025  			port_cap->psi_count = 0;
47189098f8bebe Mathias Nyman    2015-10-01  2026  
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2027  		port_cap->psi_uid_count++;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2028  		for (i = 0; i < port_cap->psi_count; i++) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2029  			port_cap->psi[i] = readl(addr + 4 + i);
47189098f8bebe Mathias Nyman    2015-10-01  2030  
47189098f8bebe Mathias Nyman    2015-10-01  2031  			/* count unique ID values, two consecutive entries can
47189098f8bebe Mathias Nyman    2015-10-01  2032  			 * have the same ID if link is assymetric
47189098f8bebe Mathias Nyman    2015-10-01  2033  			 */
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2034  			if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) !=
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2035  				  XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1])))
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2036  				port_cap->psi_uid_count++;
47189098f8bebe Mathias Nyman    2015-10-01  2037  
efcf3bab0767e0 Weitao Wang      2023-05-09  2038  			if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
efcf3bab0767e0 Weitao Wang      2023-05-09  2039  					XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5)

efcf3bab0767e0 Weitao Wang 2023-05-09 @2040 minor_revision = tmp_minor_revision;

We know XHCI_ZHAOXIN_HOST, but we don't know if major_revision == 0x03.

efcf3bab0767e0 Weitao Wang      2023-05-09  2041  
47189098f8bebe Mathias Nyman    2015-10-01  2042  			xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n",
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2043  				  XHCI_EXT_PORT_PSIV(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2044  				  XHCI_EXT_PORT_PSIE(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2045  				  XHCI_EXT_PORT_PLT(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2046  				  XHCI_EXT_PORT_PFD(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2047  				  XHCI_EXT_PORT_LP(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2048  				  XHCI_EXT_PORT_PSIM(port_cap->psi[i]));
47189098f8bebe Mathias Nyman    2015-10-01  2049  		}
47189098f8bebe Mathias Nyman    2015-10-01  2050  	}
efcf3bab0767e0 Weitao Wang      2023-05-09  2051  
efcf3bab0767e0 Weitao Wang      2023-05-09  2052  	rhub->maj_rev = major_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2053  
efcf3bab0767e0 Weitao Wang      2023-05-09  2054  	if (rhub->min_rev < minor_revision)
efcf3bab0767e0 Weitao Wang      2023-05-09  2055  		rhub->min_rev = minor_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2056  
efcf3bab0767e0 Weitao Wang      2023-05-09  2057  	port_cap->maj_rev = major_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2058  	port_cap->min_rev = minor_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2059  
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2060  	/* cache usb2 port capabilities */
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2061  	if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2062  		xhci->ext_caps[xhci->num_ext_caps++] = temp;
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2063  
f1fd62a6b6c62e Zeng Tao         2018-12-07  2064  	if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
f1fd62a6b6c62e Zeng Tao         2018-12-07  2065  		 (temp & XHCI_HLC)) {
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2066  		xhci_dbg_trace(xhci, trace_xhci_dbg_init,
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2067  			       "xHCI 1.0: support USB2 hardware lpm");
fc71ff7583b143 Andiry Xu        2011-09-23  2068  		xhci->hw_lpm_support = 1;
fc71ff7583b143 Andiry Xu        2011-09-23  2069  	}
fc71ff7583b143 Andiry Xu        2011-09-23  2070  
da6699ce4a889c Sarah Sharp      2010-10-26  2071  	port_offset--;
da6699ce4a889c Sarah Sharp      2010-10-26  2072  	for (i = port_offset; i < (port_offset + port_count); i++) {
bcaa9d5c59005e Mathias Nyman    2018-05-21  2073  		struct xhci_port *hw_port = &xhci->hw_ports[i];
da6699ce4a889c Sarah Sharp      2010-10-26  2074  		/* Duplicate entry.  Ignore the port if the revisions differ. */
07f7619053874b Mathias Nyman    2018-05-21  2075  		if (hw_port->rhub) {
4feb07d0ada339 Andy Shevchenko  2023-03-17  2076  			xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i);
4feb07d0ada339 Andy Shevchenko  2023-03-17  2077  			xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n",
07f7619053874b Mathias Nyman    2018-05-21  2078  					hw_port->rhub->maj_rev, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  2079  			/* Only adjust the roothub port counts if we haven't
da6699ce4a889c Sarah Sharp      2010-10-26  2080  			 * found a similar duplicate.
da6699ce4a889c Sarah Sharp      2010-10-26  2081  			 */
bcaa9d5c59005e Mathias Nyman    2018-05-21  2082  			if (hw_port->rhub != rhub &&
bcaa9d5c59005e Mathias Nyman    2018-05-21  2083  				 hw_port->hcd_portnum != DUPLICATE_ENTRY) {
bcaa9d5c59005e Mathias Nyman    2018-05-21  2084  				hw_port->rhub->num_ports--;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2085  				hw_port->hcd_portnum = DUPLICATE_ENTRY;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2086  			}
f8bbeabc34aa94 Sarah Sharp      2010-12-09  2087  			continue;
da6699ce4a889c Sarah Sharp      2010-10-26  2088  		}
bcaa9d5c59005e Mathias Nyman    2018-05-21  2089  		hw_port->rhub = rhub;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2090  		hw_port->port_cap = port_cap;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2091  		rhub->num_ports++;
da6699ce4a889c Sarah Sharp      2010-10-26  2092  	}
da6699ce4a889c Sarah Sharp      2010-10-26  2093  	/* FIXME: Should we disable ports not in the Extended Capabilities? */
da6699ce4a889c Sarah Sharp      2010-10-26  2094  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#1 lore raw
Quoted 101 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git for-usb-next
head:   de6fcb4b6f1c55298b3ed0dd3d43961f86aa1b12
commit: efcf3bab0767e057d8727b9a211fbb4fb4cdc81e [10/11] xhci: Show ZHAOXIN xHCI root hub speed correctly
config: loongarch-randconfig-m031-20230509 (https://download.01.org/0day-ci/archive/20230510/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Link: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/usb/host/xhci-mem.c:2040 xhci_add_in_port() error: uninitialized symbol 'tmp_minor_revision'.

vim +/tmp_minor_revision +2040 drivers/usb/host/xhci-mem.c

da6699ce4a889c Sarah Sharp      2010-10-26  1959  static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1960  		__le32 __iomem *addr, int max_caps)
da6699ce4a889c Sarah Sharp      2010-10-26  1961  {
da6699ce4a889c Sarah Sharp      2010-10-26  1962  	u32 temp, port_offset, port_count;
da6699ce4a889c Sarah Sharp      2010-10-26  1963  	int i;
efcf3bab0767e0 Weitao Wang      2023-05-09  1964  	u8 major_revision, minor_revision, tmp_minor_revision;
47189098f8bebe Mathias Nyman    2015-10-01  1965  	struct xhci_hub *rhub;
a965315e59f3cb Adam Wallis      2018-05-22  1966  	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  1967  	struct xhci_port_cap *port_cap;
da6699ce4a889c Sarah Sharp      2010-10-26  1968
47189098f8bebe Mathias Nyman    2015-10-01  1969  	temp = readl(addr);
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1970  	major_revision = XHCI_EXT_PORT_MAJOR(temp);
b72eb8435b25be YD Tseng         2017-06-09  1971  	minor_revision = XHCI_EXT_PORT_MINOR(temp);
47189098f8bebe Mathias Nyman    2015-10-01  1972
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1973  	if (major_revision == 0x03) {
47189098f8bebe Mathias Nyman    2015-10-01  1974  		rhub = &xhci->usb3_rhub;
64364bc912c01b Thinh Nguyen     2021-03-10  1975  		/*
64364bc912c01b Thinh Nguyen     2021-03-10  1976  		 * Some hosts incorrectly use sub-minor version for minor
64364bc912c01b Thinh Nguyen     2021-03-10  1977  		 * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01
64364bc912c01b Thinh Nguyen     2021-03-10  1978  		 * for bcdUSB 0x310). Since there is no USB release with sub
64364bc912c01b Thinh Nguyen     2021-03-10  1979  		 * minor version 0x301 to 0x309, we can assume that they are
64364bc912c01b Thinh Nguyen     2021-03-10  1980  		 * incorrect and fix it here.
64364bc912c01b Thinh Nguyen     2021-03-10  1981  		 */
64364bc912c01b Thinh Nguyen     2021-03-10  1982  		if (minor_revision > 0x00 && minor_revision < 0x10)
64364bc912c01b Thinh Nguyen     2021-03-10  1983  			minor_revision <<= 4;
efcf3bab0767e0 Weitao Wang      2023-05-09  1984  		/*
efcf3bab0767e0 Weitao Wang      2023-05-09  1985  		 * Some zhaoxin's xHCI controller that follow usb3.1 spec
efcf3bab0767e0 Weitao Wang      2023-05-09  1986  		 * but only support Gen1.
efcf3bab0767e0 Weitao Wang      2023-05-09  1987  		 */
efcf3bab0767e0 Weitao Wang      2023-05-09  1988  		if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
efcf3bab0767e0 Weitao Wang      2023-05-09  1989  			tmp_minor_revision = minor_revision;

tmp_minor_revision is only set for major_revision == 0x03 (also XHCI_ZHAOXIN_HOST).

efcf3bab0767e0 Weitao Wang      2023-05-09  1990  			minor_revision = 0;
efcf3bab0767e0 Weitao Wang      2023-05-09  1991  		}
efcf3bab0767e0 Weitao Wang      2023-05-09  1992
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1993  	} else if (major_revision <= 0x02) {
47189098f8bebe Mathias Nyman    2015-10-01  1994  		rhub = &xhci->usb2_rhub;
47189098f8bebe Mathias Nyman    2015-10-01  1995  	} else {
4feb07d0ada339 Andy Shevchenko  2023-03-17  1996  		xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n",
da6699ce4a889c Sarah Sharp      2010-10-26  1997  				addr, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  1998  		/* Ignoring port protocol we can't understand. FIXME */
da6699ce4a889c Sarah Sharp      2010-10-26  1999  		return;
da6699ce4a889c Sarah Sharp      2010-10-26  2000  	}
da6699ce4a889c Sarah Sharp      2010-10-26  2001
da6699ce4a889c Sarah Sharp      2010-10-26  2002  	/* Port offset and count in the third dword, see section 7.2 */
b0ba9720846c98 Xenia Ragiadakou 2013-11-15  2003  	temp = readl(addr + 2);
da6699ce4a889c Sarah Sharp      2010-10-26  2004  	port_offset = XHCI_EXT_PORT_OFF(temp);
da6699ce4a889c Sarah Sharp      2010-10-26  2005  	port_count = XHCI_EXT_PORT_COUNT(temp);
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2006  	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
4feb07d0ada339 Andy Shevchenko  2023-03-17  2007  		       "Ext Cap %p, port offset = %u, count = %u, revision = 0x%x",
da6699ce4a889c Sarah Sharp      2010-10-26  2008  		       addr, port_offset, port_count, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  2009  	/* Port count includes the current port offset */
da6699ce4a889c Sarah Sharp      2010-10-26  2010  	if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
da6699ce4a889c Sarah Sharp      2010-10-26  2011  		/* WTF? "Valid values are ‘1’ to MaxPorts" */
da6699ce4a889c Sarah Sharp      2010-10-26  2012  		return;
fc71ff7583b143 Andiry Xu        2011-09-23  2013
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2014  	port_cap = &xhci->port_caps[xhci->num_port_caps++];
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2015  	if (xhci->num_port_caps > max_caps)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2016  		return;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2017
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2018  	port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp);
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2019
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2020  	if (port_cap->psi_count) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2021  		port_cap->psi = kcalloc_node(port_cap->psi_count,
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2022  					     sizeof(*port_cap->psi),
a965315e59f3cb Adam Wallis      2018-05-22  2023  					     GFP_KERNEL, dev_to_node(dev));
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2024  		if (!port_cap->psi)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2025  			port_cap->psi_count = 0;
47189098f8bebe Mathias Nyman    2015-10-01  2026
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2027  		port_cap->psi_uid_count++;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2028  		for (i = 0; i < port_cap->psi_count; i++) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2029  			port_cap->psi[i] = readl(addr + 4 + i);
47189098f8bebe Mathias Nyman    2015-10-01  2030
47189098f8bebe Mathias Nyman    2015-10-01  2031  			/* count unique ID values, two consecutive entries can
47189098f8bebe Mathias Nyman    2015-10-01  2032  			 * have the same ID if link is assymetric
47189098f8bebe Mathias Nyman    2015-10-01  2033  			 */
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2034  			if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) !=
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2035  				  XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1])))
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2036  				port_cap->psi_uid_count++;
47189098f8bebe Mathias Nyman    2015-10-01  2037
efcf3bab0767e0 Weitao Wang      2023-05-09  2038  			if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
efcf3bab0767e0 Weitao Wang      2023-05-09  2039  					XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5)
Quoted 3 lines

efcf3bab0767e0 Weitao Wang 2023-05-09 @2040 minor_revision = tmp_minor_revision;

We know XHCI_ZHAOXIN_HOST, but we don't know if major_revision == 0x03.

I'll add that check to make code more readable and silence smatch.

In practice we know that if PSIV >= 5, (port supports 10Gbps speed) it must be a USB 3 port (major_revision == 0x03) and not a USB 2 port.

Thanks
Mathias

#2 lore raw
In reply to Dan Carpenter
Quoted 101 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git for-usb-next
head:   de6fcb4b6f1c55298b3ed0dd3d43961f86aa1b12
commit: efcf3bab0767e057d8727b9a211fbb4fb4cdc81e [10/11] xhci: Show ZHAOXIN xHCI root hub speed correctly
config: loongarch-randconfig-m031-20230509 (https://download.01.org/0day-ci/archive/20230510/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Link: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/usb/host/xhci-mem.c:2040 xhci_add_in_port() error: uninitialized symbol 'tmp_minor_revision'.

vim +/tmp_minor_revision +2040 drivers/usb/host/xhci-mem.c

da6699ce4a889c Sarah Sharp      2010-10-26  1959  static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1960  		__le32 __iomem *addr, int max_caps)
da6699ce4a889c Sarah Sharp      2010-10-26  1961  {
da6699ce4a889c Sarah Sharp      2010-10-26  1962  	u32 temp, port_offset, port_count;
da6699ce4a889c Sarah Sharp      2010-10-26  1963  	int i;
efcf3bab0767e0 Weitao Wang      2023-05-09  1964  	u8 major_revision, minor_revision, tmp_minor_revision;
47189098f8bebe Mathias Nyman    2015-10-01  1965  	struct xhci_hub *rhub;
a965315e59f3cb Adam Wallis      2018-05-22  1966  	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  1967  	struct xhci_port_cap *port_cap;
da6699ce4a889c Sarah Sharp      2010-10-26  1968
47189098f8bebe Mathias Nyman    2015-10-01  1969  	temp = readl(addr);
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1970  	major_revision = XHCI_EXT_PORT_MAJOR(temp);
b72eb8435b25be YD Tseng         2017-06-09  1971  	minor_revision = XHCI_EXT_PORT_MINOR(temp);
47189098f8bebe Mathias Nyman    2015-10-01  1972
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1973  	if (major_revision == 0x03) {
47189098f8bebe Mathias Nyman    2015-10-01  1974  		rhub = &xhci->usb3_rhub;
64364bc912c01b Thinh Nguyen     2021-03-10  1975  		/*
64364bc912c01b Thinh Nguyen     2021-03-10  1976  		 * Some hosts incorrectly use sub-minor version for minor
64364bc912c01b Thinh Nguyen     2021-03-10  1977  		 * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01
64364bc912c01b Thinh Nguyen     2021-03-10  1978  		 * for bcdUSB 0x310). Since there is no USB release with sub
64364bc912c01b Thinh Nguyen     2021-03-10  1979  		 * minor version 0x301 to 0x309, we can assume that they are
64364bc912c01b Thinh Nguyen     2021-03-10  1980  		 * incorrect and fix it here.
64364bc912c01b Thinh Nguyen     2021-03-10  1981  		 */
64364bc912c01b Thinh Nguyen     2021-03-10  1982  		if (minor_revision > 0x00 && minor_revision < 0x10)
64364bc912c01b Thinh Nguyen     2021-03-10  1983  			minor_revision <<= 4;
efcf3bab0767e0 Weitao Wang      2023-05-09  1984  		/*
efcf3bab0767e0 Weitao Wang      2023-05-09  1985  		 * Some zhaoxin's xHCI controller that follow usb3.1 spec
efcf3bab0767e0 Weitao Wang      2023-05-09  1986  		 * but only support Gen1.
efcf3bab0767e0 Weitao Wang      2023-05-09  1987  		 */
efcf3bab0767e0 Weitao Wang      2023-05-09  1988  		if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
efcf3bab0767e0 Weitao Wang      2023-05-09  1989  			tmp_minor_revision = minor_revision;

tmp_minor_revision is only set for major_revision == 0x03 (also XHCI_ZHAOXIN_HOST).

efcf3bab0767e0 Weitao Wang      2023-05-09  1990  			minor_revision = 0;
efcf3bab0767e0 Weitao Wang      2023-05-09  1991  		}
efcf3bab0767e0 Weitao Wang      2023-05-09  1992
d5ddcdf4d672fd Mathias Nyman    2015-11-24  1993  	} else if (major_revision <= 0x02) {
47189098f8bebe Mathias Nyman    2015-10-01  1994  		rhub = &xhci->usb2_rhub;
47189098f8bebe Mathias Nyman    2015-10-01  1995  	} else {
4feb07d0ada339 Andy Shevchenko  2023-03-17  1996  		xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n",
da6699ce4a889c Sarah Sharp      2010-10-26  1997  				addr, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  1998  		/* Ignoring port protocol we can't understand. FIXME */
da6699ce4a889c Sarah Sharp      2010-10-26  1999  		return;
da6699ce4a889c Sarah Sharp      2010-10-26  2000  	}
da6699ce4a889c Sarah Sharp      2010-10-26  2001
da6699ce4a889c Sarah Sharp      2010-10-26  2002  	/* Port offset and count in the third dword, see section 7.2 */
b0ba9720846c98 Xenia Ragiadakou 2013-11-15  2003  	temp = readl(addr + 2);
da6699ce4a889c Sarah Sharp      2010-10-26  2004  	port_offset = XHCI_EXT_PORT_OFF(temp);
da6699ce4a889c Sarah Sharp      2010-10-26  2005  	port_count = XHCI_EXT_PORT_COUNT(temp);
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2006  	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
4feb07d0ada339 Andy Shevchenko  2023-03-17  2007  		       "Ext Cap %p, port offset = %u, count = %u, revision = 0x%x",
da6699ce4a889c Sarah Sharp      2010-10-26  2008  		       addr, port_offset, port_count, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  2009  	/* Port count includes the current port offset */
da6699ce4a889c Sarah Sharp      2010-10-26  2010  	if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
da6699ce4a889c Sarah Sharp      2010-10-26  2011  		/* WTF? "Valid values are ‘1’ to MaxPorts" */
da6699ce4a889c Sarah Sharp      2010-10-26  2012  		return;
fc71ff7583b143 Andiry Xu        2011-09-23  2013
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2014  	port_cap = &xhci->port_caps[xhci->num_port_caps++];
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2015  	if (xhci->num_port_caps > max_caps)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2016  		return;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2017
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2018  	port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp);
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2019
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2020  	if (port_cap->psi_count) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2021  		port_cap->psi = kcalloc_node(port_cap->psi_count,
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2022  					     sizeof(*port_cap->psi),
a965315e59f3cb Adam Wallis      2018-05-22  2023  					     GFP_KERNEL, dev_to_node(dev));
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2024  		if (!port_cap->psi)
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2025  			port_cap->psi_count = 0;
47189098f8bebe Mathias Nyman    2015-10-01  2026
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2027  		port_cap->psi_uid_count++;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2028  		for (i = 0; i < port_cap->psi_count; i++) {
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2029  			port_cap->psi[i] = readl(addr + 4 + i);
47189098f8bebe Mathias Nyman    2015-10-01  2030
47189098f8bebe Mathias Nyman    2015-10-01  2031  			/* count unique ID values, two consecutive entries can
47189098f8bebe Mathias Nyman    2015-10-01  2032  			 * have the same ID if link is assymetric
47189098f8bebe Mathias Nyman    2015-10-01  2033  			 */
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2034  			if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) !=
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2035  				  XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1])))
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2036  				port_cap->psi_uid_count++;
47189098f8bebe Mathias Nyman    2015-10-01  2037
efcf3bab0767e0 Weitao Wang      2023-05-09  2038  			if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
efcf3bab0767e0 Weitao Wang      2023-05-09  2039  					XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5)
Quoted 4 lines

efcf3bab0767e0 Weitao Wang 2023-05-09 @2040 minor_revision = tmp_minor_revision;

We know XHCI_ZHAOXIN_HOST, but we don't know if major_revision == 0x03.

Thanks for your report. I would link to explain it.
This condition "XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5" implies that major_revision is equal to 0x03 in xHCI spec.

Best Regards,
Weitao

Quoted 55 lines
efcf3bab0767e0 Weitao Wang      2023-05-09  2041
47189098f8bebe Mathias Nyman    2015-10-01  2042  			xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n",
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2043  				  XHCI_EXT_PORT_PSIV(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2044  				  XHCI_EXT_PORT_PSIE(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2045  				  XHCI_EXT_PORT_PLT(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2046  				  XHCI_EXT_PORT_PFD(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2047  				  XHCI_EXT_PORT_LP(port_cap->psi[i]),
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2048  				  XHCI_EXT_PORT_PSIM(port_cap->psi[i]));
47189098f8bebe Mathias Nyman    2015-10-01  2049  		}
47189098f8bebe Mathias Nyman    2015-10-01  2050  	}
efcf3bab0767e0 Weitao Wang      2023-05-09  2051
efcf3bab0767e0 Weitao Wang      2023-05-09  2052  	rhub->maj_rev = major_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2053
efcf3bab0767e0 Weitao Wang      2023-05-09  2054  	if (rhub->min_rev < minor_revision)
efcf3bab0767e0 Weitao Wang      2023-05-09  2055  		rhub->min_rev = minor_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2056
efcf3bab0767e0 Weitao Wang      2023-05-09  2057  	port_cap->maj_rev = major_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2058  	port_cap->min_rev = minor_revision;
efcf3bab0767e0 Weitao Wang      2023-05-09  2059
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2060  	/* cache usb2 port capabilities */
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2061  	if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2062  		xhci->ext_caps[xhci->num_ext_caps++] = temp;
b630d4b9d05ba2 Mathias Nyman    2013-05-23  2063
f1fd62a6b6c62e Zeng Tao         2018-12-07  2064  	if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
f1fd62a6b6c62e Zeng Tao         2018-12-07  2065  		 (temp & XHCI_HLC)) {
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2066  		xhci_dbg_trace(xhci, trace_xhci_dbg_init,
d195fcffe4c82c Xenia Ragiadakou 2013-08-14  2067  			       "xHCI 1.0: support USB2 hardware lpm");
fc71ff7583b143 Andiry Xu        2011-09-23  2068  		xhci->hw_lpm_support = 1;
fc71ff7583b143 Andiry Xu        2011-09-23  2069  	}
fc71ff7583b143 Andiry Xu        2011-09-23  2070
da6699ce4a889c Sarah Sharp      2010-10-26  2071  	port_offset--;
da6699ce4a889c Sarah Sharp      2010-10-26  2072  	for (i = port_offset; i < (port_offset + port_count); i++) {
bcaa9d5c59005e Mathias Nyman    2018-05-21  2073  		struct xhci_port *hw_port = &xhci->hw_ports[i];
da6699ce4a889c Sarah Sharp      2010-10-26  2074  		/* Duplicate entry.  Ignore the port if the revisions differ. */
07f7619053874b Mathias Nyman    2018-05-21  2075  		if (hw_port->rhub) {
4feb07d0ada339 Andy Shevchenko  2023-03-17  2076  			xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i);
4feb07d0ada339 Andy Shevchenko  2023-03-17  2077  			xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n",
07f7619053874b Mathias Nyman    2018-05-21  2078  					hw_port->rhub->maj_rev, major_revision);
da6699ce4a889c Sarah Sharp      2010-10-26  2079  			/* Only adjust the roothub port counts if we haven't
da6699ce4a889c Sarah Sharp      2010-10-26  2080  			 * found a similar duplicate.
da6699ce4a889c Sarah Sharp      2010-10-26  2081  			 */
bcaa9d5c59005e Mathias Nyman    2018-05-21  2082  			if (hw_port->rhub != rhub &&
bcaa9d5c59005e Mathias Nyman    2018-05-21  2083  				 hw_port->hcd_portnum != DUPLICATE_ENTRY) {
bcaa9d5c59005e Mathias Nyman    2018-05-21  2084  				hw_port->rhub->num_ports--;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2085  				hw_port->hcd_portnum = DUPLICATE_ENTRY;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2086  			}
f8bbeabc34aa94 Sarah Sharp      2010-12-09  2087  			continue;
da6699ce4a889c Sarah Sharp      2010-10-26  2088  		}
bcaa9d5c59005e Mathias Nyman    2018-05-21  2089  		hw_port->rhub = rhub;
cf0ee7c60c8964 Mathias Nyman    2020-02-11  2090  		hw_port->port_cap = port_cap;
bcaa9d5c59005e Mathias Nyman    2018-05-21  2091  		rhub->num_ports++;
da6699ce4a889c Sarah Sharp      2010-10-26  2092  	}
da6699ce4a889c Sarah Sharp      2010-10-26  2093  	/* FIXME: Should we disable ports not in the Extended Capabilities? */
da6699ce4a889c Sarah Sharp      2010-10-26  2094  }