Skip to contentSkip to conversation

drivers/usb/host/xhci-plat.c:378 xhci_generic_plat_probe() error: we previously assumed 'sysdev' could be null (see line 368)

PATCH New Dan Carpenter 1 participant 1 message Feb 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 30/208 drivers/usb/host/xhci-plat.c:378 xhci_generic_plat_probe() error: we previously assumed 'sysdev' could be null (see line 368)

[ This is a Long Term Support tree. The warning was fixed upstream.
I removed Arnd and Greg from the CC list because I don't think they want to track the CIP kernel.

I feel like if you're backporting patches, then you should look for Fixes tags which mention those patches.

Fixes 77191db5ba7b ("xhci: host: potential NULL dereference in xhci_generic_plat_probe()")

- dan ]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git linux-6.1.y-cip-rt-rebase
head:   c3f80d7eeb70a51f6e05a5ca8424af3780072f29
commit: e60d31e628503adf7418431d64d198d700748550 [30/208] xhci: split out rcar/rz support from xhci-plat.c
config: x86_64-randconfig-161-20240205 (https://download.01.org/0day-ci/archive/20240205/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

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

New smatch warnings:
drivers/usb/host/xhci-plat.c:378 xhci_generic_plat_probe() error: we previously assumed 'sysdev' could be null (see line 368)

vim +/sysdev +378 drivers/usb/host/xhci-plat.c

e60d31e628503a Arnd Bergmann             2023-01-31  355  static int xhci_generic_plat_probe(struct platform_device *pdev)
e60d31e628503a Arnd Bergmann             2023-01-31  356  {
e60d31e628503a Arnd Bergmann             2023-01-31  357  	const struct xhci_plat_priv *priv_match;
e60d31e628503a Arnd Bergmann             2023-01-31  358  	struct device *sysdev;
e60d31e628503a Arnd Bergmann             2023-01-31  359  	int ret;
e60d31e628503a Arnd Bergmann             2023-01-31  360  
e60d31e628503a Arnd Bergmann             2023-01-31  361  	/*
e60d31e628503a Arnd Bergmann             2023-01-31  362  	 * sysdev must point to a device that is known to the system firmware
e60d31e628503a Arnd Bergmann             2023-01-31  363  	 * or PCI hardware. We handle these three cases here:
e60d31e628503a Arnd Bergmann             2023-01-31  364  	 * 1. xhci_plat comes from firmware
e60d31e628503a Arnd Bergmann             2023-01-31  365  	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
e60d31e628503a Arnd Bergmann             2023-01-31  366  	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)
e60d31e628503a Arnd Bergmann             2023-01-31  367  	 */
e60d31e628503a Arnd Bergmann             2023-01-31 @368  	for (sysdev = &pdev->dev; sysdev; sysdev = sysdev->parent) {
                                                                                          ^^^^^^
e60d31e628503a Arnd Bergmann             2023-01-31  369  		if (is_of_node(sysdev->fwnode) ||
e60d31e628503a Arnd Bergmann             2023-01-31  370  			is_acpi_device_node(sysdev->fwnode))
e60d31e628503a Arnd Bergmann             2023-01-31  371  			break;
e60d31e628503a Arnd Bergmann             2023-01-31  372  #ifdef CONFIG_PCI
e60d31e628503a Arnd Bergmann             2023-01-31  373  		else if (sysdev->bus == &pci_bus_type)
e60d31e628503a Arnd Bergmann             2023-01-31  374  			break;
e60d31e628503a Arnd Bergmann             2023-01-31  375  #endif
e60d31e628503a Arnd Bergmann             2023-01-31  376  	}
e60d31e628503a Arnd Bergmann             2023-01-31  377  
e60d31e628503a Arnd Bergmann             2023-01-31 @378  	if (WARN_ON(!sysdev->dma_mask)) {
                                                                             ^^^^^^

Unchecked dereference

e60d31e628503a Arnd Bergmann             2023-01-31  379  		/* Platform did not initialize dma_mask */
e60d31e628503a Arnd Bergmann             2023-01-31  380  		ret = dma_coerce_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
e60d31e628503a Arnd Bergmann             2023-01-31  381  		if (ret)
e60d31e628503a Arnd Bergmann             2023-01-31  382  			return ret;
e60d31e628503a Arnd Bergmann             2023-01-31  383  	}
e60d31e628503a Arnd Bergmann             2023-01-31  384  
e60d31e628503a Arnd Bergmann             2023-01-31  385  	if (pdev->dev.of_node)
e60d31e628503a Arnd Bergmann             2023-01-31  386  		priv_match = of_device_get_match_data(&pdev->dev);
e60d31e628503a Arnd Bergmann             2023-01-31  387  	else
e60d31e628503a Arnd Bergmann             2023-01-31  388  		priv_match = dev_get_platdata(&pdev->dev);
e60d31e628503a Arnd Bergmann             2023-01-31  389  
e60d31e628503a Arnd Bergmann             2023-01-31  390  	return xhci_plat_probe(pdev, sysdev, priv_match);
e60d31e628503a Arnd Bergmann             2023-01-31  391  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki