diff mbox series

[v2,04/22] usb: host: ehci-omap: deny IRQ0

Message ID 20211026173943.6829-5-s.shtylyov@omp.ru (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Sergey Shtylyov Oct. 26, 2021, 5:39 p.m. UTC
If platform_get_irq() returns IRQ0 (considered invalid according to Linus)
the driver blithely passes it to usb_add_hcd() that treats IRQ0 as no IRQ
at all. Deny IRQ0 right away, returning -EINVAL from the probe() method...

Fixes: b33f37064b74 ("USB: host: ehci: introduce omap ehci-hcd driver")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
---
Changes in version 2:
- added Alan's ACK.

 drivers/usb/host/ehci-omap.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

kernel test robot Oct. 30, 2021, 7:49 p.m. UTC | #1
Hi Sergey,

I love your patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on peter-chen-usb/for-usb-next balbi-usb/testing/next v5.15-rc7 next-20211029]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Sergey-Shtylyov/Explicitly-deny-IRQ0-in-the-USB-host-drivers/20211027-015925
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: arm-defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/99339edc4591ee2104acf45913d0dcb2a75bf1bf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Sergey-Shtylyov/Explicitly-deny-IRQ0-in-the-USB-host-drivers/20211027-015925
        git checkout 99339edc4591ee2104acf45913d0dcb2a75bf1bf
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arm SHELL=/bin/bash drivers/usb/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/usb/host/ehci-omap.c: In function 'ehci_hcd_omap_probe':
>> drivers/usb/host/ehci-omap.c:121:25: error: 'ENIVAL' undeclared (first use in this function); did you mean 'EINVAL'?
     121 |                 return -ENIVAL;
         |                         ^~~~~~
         |                         EINVAL
   drivers/usb/host/ehci-omap.c:121:25: note: each undeclared identifier is reported only once for each function it appears in


vim +121 drivers/usb/host/ehci-omap.c

    77	
    78	/**
    79	 * ehci_hcd_omap_probe - initialize TI-based HCDs
    80	 * @pdev: Pointer to this platform device's information
    81	 *
    82	 * Allocates basic resources for this USB host controller, and
    83	 * then invokes the start() method for the HCD associated with it
    84	 * through the hotplug entry's driver_data.
    85	 */
    86	static int ehci_hcd_omap_probe(struct platform_device *pdev)
    87	{
    88		struct device *dev = &pdev->dev;
    89		struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
    90		struct resource	*res;
    91		struct usb_hcd	*hcd;
    92		void __iomem *regs;
    93		int ret;
    94		int irq;
    95		int i;
    96		struct omap_hcd	*omap;
    97	
    98		if (usb_disabled())
    99			return -ENODEV;
   100	
   101		if (!dev->parent) {
   102			dev_err(dev, "Missing parent device\n");
   103			return -ENODEV;
   104		}
   105	
   106		/* For DT boot, get platform data from parent. i.e. usbhshost */
   107		if (dev->of_node) {
   108			pdata = dev_get_platdata(dev->parent);
   109			dev->platform_data = pdata;
   110		}
   111	
   112		if (!pdata) {
   113			dev_err(dev, "Missing platform data\n");
   114			return -ENODEV;
   115		}
   116	
   117		irq = platform_get_irq(pdev, 0);
   118		if (irq < 0)
   119			return irq;
   120		if (!irq)
 > 121			return -ENIVAL;
   122	
   123		res =  platform_get_resource(pdev, IORESOURCE_MEM, 0);
   124		regs = devm_ioremap_resource(dev, res);
   125		if (IS_ERR(regs))
   126			return PTR_ERR(regs);
   127	
   128		/*
   129		 * Right now device-tree probed devices don't get dma_mask set.
   130		 * Since shared usb code relies on it, set it here for now.
   131		 * Once we have dma capability bindings this can go away.
   132		 */
   133		ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
   134		if (ret)
   135			return ret;
   136	
   137		ret = -ENODEV;
   138		hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
   139				dev_name(dev));
   140		if (!hcd) {
   141			dev_err(dev, "Failed to create HCD\n");
   142			return -ENOMEM;
   143		}
   144	
   145		hcd->rsrc_start = res->start;
   146		hcd->rsrc_len = resource_size(res);
   147		hcd->regs = regs;
   148		hcd_to_ehci(hcd)->caps = regs;
   149	
   150		omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
   151		omap->nports = pdata->nports;
   152	
   153		platform_set_drvdata(pdev, hcd);
   154	
   155		/* get the PHY devices if needed */
   156		for (i = 0 ; i < omap->nports ; i++) {
   157			struct usb_phy *phy;
   158	
   159			/* get the PHY device */
   160			phy = devm_usb_get_phy_by_phandle(dev, "phys", i);
   161			if (IS_ERR(phy)) {
   162				ret = PTR_ERR(phy);
   163				if (ret == -ENODEV) { /* no PHY */
   164					phy = NULL;
   165					continue;
   166				}
   167	
   168				if (ret != -EPROBE_DEFER)
   169					dev_err(dev, "Can't get PHY for port %d: %d\n",
   170						i, ret);
   171				goto err_phy;
   172			}
   173	
   174			omap->phy[i] = phy;
   175	
   176			if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
   177				usb_phy_init(omap->phy[i]);
   178				/* bring PHY out of suspend */
   179				usb_phy_set_suspend(omap->phy[i], 0);
   180			}
   181		}
   182	
   183		pm_runtime_enable(dev);
   184		pm_runtime_get_sync(dev);
   185	
   186		/*
   187		 * An undocumented "feature" in the OMAP3 EHCI controller,
   188		 * causes suspended ports to be taken out of suspend when
   189		 * the USBCMD.Run/Stop bit is cleared (for example when
   190		 * we do ehci_bus_suspend).
   191		 * This breaks suspend-resume if the root-hub is allowed
   192		 * to suspend. Writing 1 to this undocumented register bit
   193		 * disables this feature and restores normal behavior.
   194		 */
   195		ehci_write(regs, EHCI_INSNREG04,
   196					EHCI_INSNREG04_DISABLE_UNSUSPEND);
   197	
   198		ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
   199		if (ret) {
   200			dev_err(dev, "failed to add hcd with err %d\n", ret);
   201			goto err_pm_runtime;
   202		}
   203		device_wakeup_enable(hcd->self.controller);
   204	
   205		/*
   206		 * Bring PHYs out of reset for non PHY modes.
   207		 * Even though HSIC mode is a PHY-less mode, the reset
   208		 * line exists between the chips and can be modelled
   209		 * as a PHY device for reset control.
   210		 */
   211		for (i = 0; i < omap->nports; i++) {
   212			if (!omap->phy[i] ||
   213			     pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
   214				continue;
   215	
   216			usb_phy_init(omap->phy[i]);
   217			/* bring PHY out of suspend */
   218			usb_phy_set_suspend(omap->phy[i], 0);
   219		}
   220	
   221		return 0;
   222	
   223	err_pm_runtime:
   224		pm_runtime_put_sync(dev);
   225		pm_runtime_disable(dev);
   226	
   227	err_phy:
   228		for (i = 0; i < omap->nports; i++) {
   229			if (omap->phy[i])
   230				usb_phy_shutdown(omap->phy[i]);
   231		}
   232	
   233		usb_put_hcd(hcd);
   234	
   235		return ret;
   236	}
   237	

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

Patch

diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 7f4a03e8647a..79cec242c025 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -117,6 +117,8 @@  static int ehci_hcd_omap_probe(struct platform_device *pdev)
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
+	if (!irq)
+		return -ENIVAL;
 
 	res =  platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	regs = devm_ioremap_resource(dev, res);