Skip to content

Commit d21daf1

Browse files
pinchartlFelipe Balbi
authored andcommitted
usb: isp1760: Fix USB disabled check
The isp1760 driver registration function returns an error if USB is disabled. This made sense when the driver only supported host controllers, but now that it supports peripheral controllers host support isn't mandatory anymore. Fix this by returning an error only when both the HCD and UDC functions are disabled, either through the kernel configuration or at runtime. Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 1f8d9b9 commit d21daf1

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

drivers/usb/isp1760/isp1760-core.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
112112
struct device *dev, unsigned int devflags)
113113
{
114114
struct isp1760_device *isp;
115+
bool udc_disabled = !(devflags & ISP1760_FLAG_ISP1761);
115116
int ret;
116117

117-
if (usb_disabled())
118+
/*
119+
* If neither the HCD not the UDC is enabled return an error, as no
120+
* device would be registered.
121+
*/
122+
if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) &&
123+
(!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled))
118124
return -ENODEV;
119125

120126
/* prevent usb-core allocating DMA pages */
@@ -137,12 +143,14 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
137143

138144
isp1760_init_core(isp);
139145

140-
ret = isp1760_hcd_register(&isp->hcd, isp->regs, mem, irq,
141-
irqflags | IRQF_SHARED, dev);
142-
if (ret < 0)
143-
return ret;
146+
if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) {
147+
ret = isp1760_hcd_register(&isp->hcd, isp->regs, mem, irq,
148+
irqflags | IRQF_SHARED, dev);
149+
if (ret < 0)
150+
return ret;
151+
}
144152

145-
if (devflags & ISP1760_FLAG_ISP1761) {
153+
if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && !udc_disabled) {
146154
ret = isp1760_udc_register(isp, irq, irqflags | IRQF_SHARED |
147155
IRQF_DISABLED);
148156
if (ret < 0) {
@@ -160,9 +168,7 @@ void isp1760_unregister(struct device *dev)
160168
{
161169
struct isp1760_device *isp = dev_get_drvdata(dev);
162170

163-
if (isp->devflags & ISP1760_FLAG_ISP1761)
164-
isp1760_udc_unregister(isp);
165-
171+
isp1760_udc_unregister(isp);
166172
isp1760_hcd_unregister(&isp->hcd);
167173
}
168174

drivers/usb/isp1760/isp1760-hcd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,9 @@ int isp1760_hcd_register(struct isp1760_hcd *priv, void __iomem *regs,
22262226

22272227
void isp1760_hcd_unregister(struct isp1760_hcd *priv)
22282228
{
2229+
if (!priv->hcd)
2230+
return;
2231+
22292232
usb_remove_hcd(priv->hcd);
22302233
usb_put_hcd(priv->hcd);
22312234
}

drivers/usb/isp1760/isp1760-udc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,9 @@ void isp1760_udc_unregister(struct isp1760_device *isp)
14881488
{
14891489
struct isp1760_udc *udc = &isp->udc;
14901490

1491+
if (!udc->isp)
1492+
return;
1493+
14911494
usb_del_gadget_udc(&udc->gadget);
14921495

14931496
free_irq(udc->irq, udc);

0 commit comments

Comments
 (0)