LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] usb: gadget: mv_u3d: Change functon call in mv_u3d_probe()
@ 2021-08-18 13:01 Nadezda Lutovinova
2021-08-18 13:10 ` Felipe Balbi
0 siblings, 1 reply; 4+ messages in thread
From: Nadezda Lutovinova @ 2021-08-18 13:01 UTC (permalink / raw)
To: Felipe Balbi
Cc: Nadezda Lutovinova, Greg Kroah-Hartman, Johan Hovold, linux-usb,
linux-kernel, ldv-project
If IRQ occurs between calling request_irq() and mv_u3d_eps_init(),
then null pointer dereference occurs since u3d->eps[] wasn't
initialized yet but used in mv_u3d_nuke().
The patch puts registration of the interrupt handler after
initializing of neccesery data.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Nadezda Lutovinova <lutovinova@ispras.ru>
---
drivers/usb/gadget/udc/mv_u3d_core.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
index ce3d7a3eb7e3..a1057ddfbda3 100644
--- a/drivers/usb/gadget/udc/mv_u3d_core.c
+++ b/drivers/usb/gadget/udc/mv_u3d_core.c
@@ -1921,14 +1921,6 @@ static int mv_u3d_probe(struct platform_device *dev)
goto err_get_irq;
}
u3d->irq = r->start;
- if (request_irq(u3d->irq, mv_u3d_irq,
- IRQF_SHARED, driver_name, u3d)) {
- u3d->irq = 0;
- dev_err(&dev->dev, "Request irq %d for u3d failed\n",
- u3d->irq);
- retval = -ENODEV;
- goto err_request_irq;
- }
/* initialize gadget structure */
u3d->gadget.ops = &mv_u3d_ops; /* usb_gadget_ops */
@@ -1941,6 +1933,15 @@ static int mv_u3d_probe(struct platform_device *dev)
mv_u3d_eps_init(u3d);
+ if (request_irq(u3d->irq, mv_u3d_irq,
+ IRQF_SHARED, driver_name, u3d)) {
+ u3d->irq = 0;
+ dev_err(&dev->dev, "Request irq %d for u3d failed\n",
+ u3d->irq);
+ retval = -ENODEV;
+ goto err_request_irq;
+ }
+
/* external vbus detection */
if (u3d->vbus) {
u3d->clock_gating = 1;
@@ -1964,8 +1965,8 @@ static int mv_u3d_probe(struct platform_device *dev)
err_unregister:
free_irq(u3d->irq, u3d);
-err_request_irq:
err_get_irq:
+err_request_irq:
kfree(u3d->status_req);
err_alloc_status_req:
kfree(u3d->eps);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: gadget: mv_u3d: Change functon call in mv_u3d_probe()
2021-08-18 13:01 [PATCH] usb: gadget: mv_u3d: Change functon call in mv_u3d_probe() Nadezda Lutovinova
@ 2021-08-18 13:10 ` Felipe Balbi
2021-08-18 14:12 ` [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC Nadezda Lutovinova
0 siblings, 1 reply; 4+ messages in thread
From: Felipe Balbi @ 2021-08-18 13:10 UTC (permalink / raw)
To: Nadezda Lutovinova
Cc: Greg Kroah-Hartman, Johan Hovold, linux-usb, linux-kernel, ldv-project
Hi,
(first of all, your subject could be a little more descriptive,
something like:
usb: gadget: mv_u3d: request_irq() after initializing UDC
as that would better detail what you're doing)
Nadezda Lutovinova <lutovinova@ispras.ru> writes:
> If IRQ occurs between calling request_irq() and mv_u3d_eps_init(),
> then null pointer dereference occurs since u3d->eps[] wasn't
> initialized yet but used in mv_u3d_nuke().
>
> The patch puts registration of the interrupt handler after
> initializing of neccesery data.
>
> Found by Linux Driver Verification project (linuxtesting.org).
this looks like an important bug fix, it probably deserves a stable tag
here. Which commit introduce this problem? Otherr than that, commits
looks good.
--
balbi
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC
2021-08-18 13:10 ` Felipe Balbi
@ 2021-08-18 14:12 ` Nadezda Lutovinova
2021-08-18 14:33 ` Felipe Balbi
0 siblings, 1 reply; 4+ messages in thread
From: Nadezda Lutovinova @ 2021-08-18 14:12 UTC (permalink / raw)
To: Felipe Balbi
Cc: Nadezda Lutovinova, Greg Kroah-Hartman, Johan Hovold, linux-usb,
linux-kernel, ldv-project, stable
If IRQ occurs between calling request_irq() and mv_u3d_eps_init(),
then null pointer dereference occurs since u3d->eps[] wasn't
initialized yet but used in mv_u3d_nuke().
The patch puts registration of the interrupt handler after
initializing of neccesery data.
Found by Linux Driver Verification project (linuxtesting.org).
Fixes: 90fccb529d24 ("usb: gadget: Gadget directory cleanup - group UDC drivers")
Signed-off-by: Nadezda Lutovinova <lutovinova@ispras.ru>
---
v2: fix subject and add a stable tag
---
drivers/usb/gadget/udc/mv_u3d_core.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
index ce3d7a3eb7e3..a1057ddfbda3 100644
--- a/drivers/usb/gadget/udc/mv_u3d_core.c
+++ b/drivers/usb/gadget/udc/mv_u3d_core.c
@@ -1921,14 +1921,6 @@ static int mv_u3d_probe(struct platform_device *dev)
goto err_get_irq;
}
u3d->irq = r->start;
- if (request_irq(u3d->irq, mv_u3d_irq,
- IRQF_SHARED, driver_name, u3d)) {
- u3d->irq = 0;
- dev_err(&dev->dev, "Request irq %d for u3d failed\n",
- u3d->irq);
- retval = -ENODEV;
- goto err_request_irq;
- }
/* initialize gadget structure */
u3d->gadget.ops = &mv_u3d_ops; /* usb_gadget_ops */
@@ -1941,6 +1933,15 @@ static int mv_u3d_probe(struct platform_device *dev)
mv_u3d_eps_init(u3d);
+ if (request_irq(u3d->irq, mv_u3d_irq,
+ IRQF_SHARED, driver_name, u3d)) {
+ u3d->irq = 0;
+ dev_err(&dev->dev, "Request irq %d for u3d failed\n",
+ u3d->irq);
+ retval = -ENODEV;
+ goto err_request_irq;
+ }
+
/* external vbus detection */
if (u3d->vbus) {
u3d->clock_gating = 1;
@@ -1964,8 +1965,8 @@ static int mv_u3d_probe(struct platform_device *dev)
err_unregister:
free_irq(u3d->irq, u3d);
-err_request_irq:
err_get_irq:
+err_request_irq:
kfree(u3d->status_req);
err_alloc_status_req:
kfree(u3d->eps);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC
2021-08-18 14:12 ` [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC Nadezda Lutovinova
@ 2021-08-18 14:33 ` Felipe Balbi
0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2021-08-18 14:33 UTC (permalink / raw)
To: Nadezda Lutovinova
Cc: Greg Kroah-Hartman, Johan Hovold, linux-usb, linux-kernel,
ldv-project, stable
Nadezda Lutovinova <lutovinova@ispras.ru> writes:
> If IRQ occurs between calling request_irq() and mv_u3d_eps_init(),
> then null pointer dereference occurs since u3d->eps[] wasn't
> initialized yet but used in mv_u3d_nuke().
>
> The patch puts registration of the interrupt handler after
> initializing of neccesery data.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Fixes: 90fccb529d24 ("usb: gadget: Gadget directory cleanup - group UDC drivers")
> Signed-off-by: Nadezda Lutovinova <lutovinova@ispras.ru>
Thanks for updating so quickly:
Acked-by: Felipe Balbi <balbi@kernel.org>
--
balbi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-18 14:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 13:01 [PATCH] usb: gadget: mv_u3d: Change functon call in mv_u3d_probe() Nadezda Lutovinova
2021-08-18 13:10 ` Felipe Balbi
2021-08-18 14:12 ` [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC Nadezda Lutovinova
2021-08-18 14:33 ` Felipe Balbi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).