]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
xhci: dbc: create and remove dbc structure in dbgtty driver.
authorMathias Nyman <mathias.nyman@linux.intel.com>
Wed, 16 Feb 2022 09:51:46 +0000 (11:51 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 16 Sep 2022 08:53:29 +0000 (10:53 +0200)
BugLink: https://bugs.launchpad.net/bugs/1988479
[ Upstream commit 5ce036b98dd3301fc43bb06a6383ef07b6c776bc ]

Turn the dbgtty closer to a device driver by allocating the dbc
structure in its own xhci_dbc_tty_probe() function, and freeing it
in xhci_dbc_tty_remove()

Remove xhci_do_dbc_exit() as its no longer needed.

allocate and create the dbc strcuture in xhci_dbc_tty_probe()

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20220216095153.1303105-3-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/usb/host/xhci-dbgcap.c
drivers/usb/host/xhci-dbgcap.h
drivers/usb/host/xhci-dbgtty.c

index 6a437862b4980a758474808de440f3715458f7c3..f4da5708a40f8a47aa6e78b01401425dac879f51 100644 (file)
@@ -914,16 +914,6 @@ static void xhci_dbc_handle_events(struct work_struct *work)
        mod_delayed_work(system_wq, &dbc->event_work, 1);
 }
 
-static void xhci_do_dbc_exit(struct xhci_hcd *xhci)
-{
-       unsigned long           flags;
-
-       spin_lock_irqsave(&xhci->lock, flags);
-       kfree(xhci->dbc);
-       xhci->dbc = NULL;
-       spin_unlock_irqrestore(&xhci->lock, flags);
-}
-
 static ssize_t dbc_show(struct device *dev,
                        struct device_attribute *attr,
                        char *buf)
@@ -984,7 +974,7 @@ static ssize_t dbc_store(struct device *dev,
 static DEVICE_ATTR_RW(dbc);
 
 struct xhci_dbc *
-xhci_alloc_dbc(struct device *dev, void __iomem *base)
+xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver)
 {
        struct xhci_dbc         *dbc;
        int                     ret;
@@ -995,6 +985,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base)
 
        dbc->regs = base;
        dbc->dev = dev;
+       dbc->driver = driver;
 
        if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE)
                return NULL;
@@ -1045,18 +1036,8 @@ int xhci_dbc_init(struct xhci_hcd *xhci)
        if (xhci->dbc)
                return -EBUSY;
 
-       xhci->dbc = xhci_alloc_dbc(dev, base);
-       if (!xhci->dbc)
-               return -ENOMEM;
-
-       ret = xhci_dbc_tty_probe(xhci);
-       if (ret)
-               goto init_err2;
-
-       return 0;
+       ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci);
 
-init_err2:
-       xhci_do_dbc_exit(xhci);
        return ret;
 }
 
@@ -1068,7 +1049,6 @@ void xhci_dbc_exit(struct xhci_hcd *xhci)
                return;
 
        xhci_dbc_tty_remove(xhci->dbc);
-       xhci_dbc_remove(xhci->dbc);
        spin_lock_irqsave(&xhci->lock, flags);
        xhci->dbc = NULL;
        spin_unlock_irqrestore(&xhci->lock, flags);
index c70b78d504eb5428d7c7910d315c145d47573262..5d8c7815491cbf0d1545a55e8950d24e9b44475e 100644 (file)
@@ -196,8 +196,11 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
 #ifdef CONFIG_USB_XHCI_DBGCAP
 int xhci_dbc_init(struct xhci_hcd *xhci);
 void xhci_dbc_exit(struct xhci_hcd *xhci);
-int xhci_dbc_tty_probe(struct xhci_hcd *xhci);
+int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci);
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
+struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res,
+                                const struct dbc_driver *driver);
+void xhci_dbc_remove(struct xhci_dbc *dbc);
 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
                                      unsigned int direction,
                                      gfp_t flags);
index eb46e642e87aa5fee70a912d970eb1b7264dcbb5..18bcc96853ae106f2fe4574ed256ae7beefa0cc8 100644 (file)
@@ -468,9 +468,9 @@ static const struct dbc_driver dbc_driver = {
        .disconnect             = xhci_dbc_tty_unregister_device,
 };
 
-int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
+int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd *xhci)
 {
-       struct xhci_dbc         *dbc = xhci->dbc;
+       struct xhci_dbc         *dbc;
        struct dbc_port         *port;
        int                     status;
 
@@ -485,13 +485,22 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
                goto out;
        }
 
-       dbc->driver = &dbc_driver;
-       dbc->priv = port;
+       dbc_tty_driver->driver_state = port;
+
+       dbc = xhci_alloc_dbc(dev, base, &dbc_driver);
+       if (!dbc) {
+               status = -ENOMEM;
+               goto out2;
+       }
 
+       dbc->priv = port;
 
-       dbc_tty_driver->driver_state = port;
+       /* get rid of xhci once this is a real driver binding to a device */
+       xhci->dbc = dbc;
 
        return 0;
+out2:
+       kfree(port);
 out:
        /* dbc_tty_exit will be called by module_exit() in the future */
        dbc_tty_exit();
@@ -506,8 +515,7 @@ void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
 {
        struct dbc_port         *port = dbc_to_port(dbc);
 
-       dbc->driver = NULL;
-       dbc->priv = NULL;
+       xhci_dbc_remove(dbc);
        kfree(port);
 
        /* dbc_tty_exit will be called by  module_exit() in the future */