Skip to content

Commit 413c5f7

Browse files
matnymangregkh
authored andcommitted
xhci: dbc: create and remove dbc structure in dbgtty driver.
[ Upstream commit 5ce036b ] 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d7afb4a commit 413c5f7

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

drivers/usb/host/xhci-dbgcap.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -914,16 +914,6 @@ static void xhci_dbc_handle_events(struct work_struct *work)
914914
mod_delayed_work(system_wq, &dbc->event_work, 1);
915915
}
916916

917-
static void xhci_do_dbc_exit(struct xhci_hcd *xhci)
918-
{
919-
unsigned long flags;
920-
921-
spin_lock_irqsave(&xhci->lock, flags);
922-
kfree(xhci->dbc);
923-
xhci->dbc = NULL;
924-
spin_unlock_irqrestore(&xhci->lock, flags);
925-
}
926-
927917
static ssize_t dbc_show(struct device *dev,
928918
struct device_attribute *attr,
929919
char *buf)
@@ -984,7 +974,7 @@ static ssize_t dbc_store(struct device *dev,
984974
static DEVICE_ATTR_RW(dbc);
985975

986976
struct xhci_dbc *
987-
xhci_alloc_dbc(struct device *dev, void __iomem *base)
977+
xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver)
988978
{
989979
struct xhci_dbc *dbc;
990980
int ret;
@@ -995,6 +985,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base)
995985

996986
dbc->regs = base;
997987
dbc->dev = dev;
988+
dbc->driver = driver;
998989

999990
if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE)
1000991
return NULL;
@@ -1045,18 +1036,8 @@ int xhci_dbc_init(struct xhci_hcd *xhci)
10451036
if (xhci->dbc)
10461037
return -EBUSY;
10471038

1048-
xhci->dbc = xhci_alloc_dbc(dev, base);
1049-
if (!xhci->dbc)
1050-
return -ENOMEM;
1051-
1052-
ret = xhci_dbc_tty_probe(xhci);
1053-
if (ret)
1054-
goto init_err2;
1055-
1056-
return 0;
1039+
ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci);
10571040

1058-
init_err2:
1059-
xhci_do_dbc_exit(xhci);
10601041
return ret;
10611042
}
10621043

@@ -1068,7 +1049,6 @@ void xhci_dbc_exit(struct xhci_hcd *xhci)
10681049
return;
10691050

10701051
xhci_dbc_tty_remove(xhci->dbc);
1071-
xhci_dbc_remove(xhci->dbc);
10721052
spin_lock_irqsave(&xhci->lock, flags);
10731053
xhci->dbc = NULL;
10741054
spin_unlock_irqrestore(&xhci->lock, flags);

drivers/usb/host/xhci-dbgcap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
196196
#ifdef CONFIG_USB_XHCI_DBGCAP
197197
int xhci_dbc_init(struct xhci_hcd *xhci);
198198
void xhci_dbc_exit(struct xhci_hcd *xhci);
199-
int xhci_dbc_tty_probe(struct xhci_hcd *xhci);
199+
int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci);
200200
void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
201+
struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res,
202+
const struct dbc_driver *driver);
203+
void xhci_dbc_remove(struct xhci_dbc *dbc);
201204
struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
202205
unsigned int direction,
203206
gfp_t flags);

drivers/usb/host/xhci-dbgtty.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ static const struct dbc_driver dbc_driver = {
468468
.disconnect = xhci_dbc_tty_unregister_device,
469469
};
470470

471-
int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
471+
int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd *xhci)
472472
{
473-
struct xhci_dbc *dbc = xhci->dbc;
473+
struct xhci_dbc *dbc;
474474
struct dbc_port *port;
475475
int status;
476476

@@ -485,13 +485,22 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
485485
goto out;
486486
}
487487

488-
dbc->driver = &dbc_driver;
489-
dbc->priv = port;
488+
dbc_tty_driver->driver_state = port;
489+
490+
dbc = xhci_alloc_dbc(dev, base, &dbc_driver);
491+
if (!dbc) {
492+
status = -ENOMEM;
493+
goto out2;
494+
}
490495

496+
dbc->priv = port;
491497

492-
dbc_tty_driver->driver_state = port;
498+
/* get rid of xhci once this is a real driver binding to a device */
499+
xhci->dbc = dbc;
493500

494501
return 0;
502+
out2:
503+
kfree(port);
495504
out:
496505
/* dbc_tty_exit will be called by module_exit() in the future */
497506
dbc_tty_exit();
@@ -506,8 +515,7 @@ void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
506515
{
507516
struct dbc_port *port = dbc_to_port(dbc);
508517

509-
dbc->driver = NULL;
510-
dbc->priv = NULL;
518+
xhci_dbc_remove(dbc);
511519
kfree(port);
512520

513521
/* dbc_tty_exit will be called by module_exit() in the future */

0 commit comments

Comments
 (0)