* [PATCH] drivers core: Fix oops when driver probe fails
@ 2021-07-27 10:40 Filip Schauer
2021-07-27 10:57 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Filip Schauer @ 2021-07-27 10:40 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1875 bytes --]
dma_range_map is freed to early, which might cause an oops when
a driver probe fails.
Call trace:
is_free_buddy_page+0xe4/0x1d4
__free_pages+0x2c/0x88
dma_free_contiguous+0x64/0x80
dma_direct_free+0x38/0xb4
dma_free_attrs+0x88/0xa0
dmam_release+0x28/0x34
release_nodes+0x78/0x8c
devres_release_all+0xa8/0x110
really_probe+0x118/0x2d0
__driver_probe_device+0xc8/0xe0
driver_probe_device+0x54/0xec
__driver_attach+0xe0/0xf0
bus_for_each_dev+0x7c/0xc8
driver_attach+0x30/0x3c
bus_add_driver+0x17c/0x1c4
driver_register+0xc0/0xf8
__platform_driver_register+0x34/0x40
...
This issue is introduced by commit d0243bbd5dd3 ("drivers core:
Free dma_range_map when driver probe failed"). It frees
dma_range_map before the call to devres_release_all, which is too
early. The solution is to free dma_range_map only after
devres_release_all.
Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe
failed")
Signed-off-by: Filip Schauer <filip@mg6.at>
---
drivers/base/dd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index daeb9b5763ae..437cd61343b2 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -653,8 +653,6 @@ static int really_probe(struct device *dev, struct
device_driver *drv)
else if (drv->remove)
drv->remove(dev);
probe_failed:
- kfree(dev->dma_range_map);
- dev->dma_range_map = NULL;
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
@@ -662,6 +660,8 @@ static int really_probe(struct device *dev, struct
device_driver *drv)
device_links_no_driver(dev);
devres_release_all(dev);
arch_teardown_dma_ops(dev);
+ kfree(dev->dma_range_map);
+ dev->dma_range_map = NULL;
driver_sysfs_remove(dev);
dev->driver = NULL;
dev_set_drvdata(dev, NULL);
--
2.25.1
[-- Attachment #2: unknown --]
[-- Type: text/x-diff, Size: 1875 bytes --]
dma_range_map is freed to early, which might cause an oops when
a driver probe fails.
Call trace:
is_free_buddy_page+0xe4/0x1d4
__free_pages+0x2c/0x88
dma_free_contiguous+0x64/0x80
dma_direct_free+0x38/0xb4
dma_free_attrs+0x88/0xa0
dmam_release+0x28/0x34
release_nodes+0x78/0x8c
devres_release_all+0xa8/0x110
really_probe+0x118/0x2d0
__driver_probe_device+0xc8/0xe0
driver_probe_device+0x54/0xec
__driver_attach+0xe0/0xf0
bus_for_each_dev+0x7c/0xc8
driver_attach+0x30/0x3c
bus_add_driver+0x17c/0x1c4
driver_register+0xc0/0xf8
__platform_driver_register+0x34/0x40
...
This issue is introduced by commit d0243bbd5dd3 ("drivers core:
Free dma_range_map when driver probe failed"). It frees
dma_range_map before the call to devres_release_all, which is too
early. The solution is to free dma_range_map only after
devres_release_all.
Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed")
Signed-off-by: Filip Schauer <filip@mg6.at>
---
drivers/base/dd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index daeb9b5763ae..437cd61343b2 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -653,8 +653,6 @@ static int really_probe(struct device *dev, struct device_driver *drv)
else if (drv->remove)
drv->remove(dev);
probe_failed:
- kfree(dev->dma_range_map);
- dev->dma_range_map = NULL;
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
@@ -662,6 +660,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
device_links_no_driver(dev);
devres_release_all(dev);
arch_teardown_dma_ops(dev);
+ kfree(dev->dma_range_map);
+ dev->dma_range_map = NULL;
driver_sysfs_remove(dev);
dev->driver = NULL;
dev_set_drvdata(dev, NULL);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers core: Fix oops when driver probe fails
2021-07-27 10:40 [PATCH] drivers core: Fix oops when driver probe fails Filip Schauer
@ 2021-07-27 10:57 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-07-27 10:57 UTC (permalink / raw)
To: Filip Schauer; +Cc: linux-kernel
On Tue, Jul 27, 2021 at 12:40:35PM +0200, Filip Schauer wrote:
> dma_range_map is freed to early, which might cause an oops when
> a driver probe fails.
> Call trace:
> is_free_buddy_page+0xe4/0x1d4
> __free_pages+0x2c/0x88
> dma_free_contiguous+0x64/0x80
> dma_direct_free+0x38/0xb4
> dma_free_attrs+0x88/0xa0
> dmam_release+0x28/0x34
> release_nodes+0x78/0x8c
> devres_release_all+0xa8/0x110
> really_probe+0x118/0x2d0
> __driver_probe_device+0xc8/0xe0
> driver_probe_device+0x54/0xec
> __driver_attach+0xe0/0xf0
> bus_for_each_dev+0x7c/0xc8
> driver_attach+0x30/0x3c
> bus_add_driver+0x17c/0x1c4
> driver_register+0xc0/0xf8
> __platform_driver_register+0x34/0x40
> ...
>
> This issue is introduced by commit d0243bbd5dd3 ("drivers core:
> Free dma_range_map when driver probe failed"). It frees
> dma_range_map before the call to devres_release_all, which is too
> early. The solution is to free dma_range_map only after
> devres_release_all.
>
> Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe
> failed")
> Signed-off-by: Filip Schauer <filip@mg6.at>
> ---
> drivers/base/dd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index daeb9b5763ae..437cd61343b2 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -653,8 +653,6 @@ static int really_probe(struct device *dev, struct
> device_driver *drv)
> else if (drv->remove)
> drv->remove(dev);
> probe_failed:
> - kfree(dev->dma_range_map);
> - dev->dma_range_map = NULL;
> if (dev->bus)
> blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
> BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
> @@ -662,6 +660,8 @@ static int really_probe(struct device *dev, struct
> device_driver *drv)
> device_links_no_driver(dev);
> devres_release_all(dev);
> arch_teardown_dma_ops(dev);
> + kfree(dev->dma_range_map);
> + dev->dma_range_map = NULL;
> driver_sysfs_remove(dev);
> dev->driver = NULL;
> dev_set_drvdata(dev, NULL);
> --
> 2.25.1
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- Your patch is malformed (tabs converted to spaces, linewrapped, etc.)
and can not be applied. Please read the file,
Documentation/email-clients.txt in order to fix this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] drivers core: Fix oops when driver probe fails
@ 2021-07-27 11:23 Filip Schauer
2021-07-27 12:31 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Filip Schauer @ 2021-07-27 11:23 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel
dma_range_map is freed to early, which might cause an oops when
a driver probe fails.
Call trace:
is_free_buddy_page+0xe4/0x1d4
__free_pages+0x2c/0x88
dma_free_contiguous+0x64/0x80
dma_direct_free+0x38/0xb4
dma_free_attrs+0x88/0xa0
dmam_release+0x28/0x34
release_nodes+0x78/0x8c
devres_release_all+0xa8/0x110
really_probe+0x118/0x2d0
__driver_probe_device+0xc8/0xe0
driver_probe_device+0x54/0xec
__driver_attach+0xe0/0xf0
bus_for_each_dev+0x7c/0xc8
driver_attach+0x30/0x3c
bus_add_driver+0x17c/0x1c4
driver_register+0xc0/0xf8
__platform_driver_register+0x34/0x40
...
This issue is introduced by commit d0243bbd5dd3 ("drivers core:
Free dma_range_map when driver probe failed"). It frees
dma_range_map before the call to devres_release_all, which is too
early. The solution is to free dma_range_map only after
devres_release_all.
Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed")
Signed-off-by: Filip Schauer <filip@mg6.at>
---
drivers/base/dd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index daeb9b5763ae..437cd61343b2 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -653,8 +653,6 @@ static int really_probe(struct device *dev, struct device_driver *drv)
else if (drv->remove)
drv->remove(dev);
probe_failed:
- kfree(dev->dma_range_map);
- dev->dma_range_map = NULL;
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
@@ -662,6 +660,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
device_links_no_driver(dev);
devres_release_all(dev);
arch_teardown_dma_ops(dev);
+ kfree(dev->dma_range_map);
+ dev->dma_range_map = NULL;
driver_sysfs_remove(dev);
dev->driver = NULL;
dev_set_drvdata(dev, NULL);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers core: Fix oops when driver probe fails
2021-07-27 11:23 Filip Schauer
@ 2021-07-27 12:31 ` Greg KH
2021-07-27 16:01 ` Filip Schauer
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2021-07-27 12:31 UTC (permalink / raw)
To: Filip Schauer; +Cc: linux-kernel
On Tue, Jul 27, 2021 at 01:23:11PM +0200, Filip Schauer wrote:
> dma_range_map is freed to early, which might cause an oops when
> a driver probe fails.
> Call trace:
> is_free_buddy_page+0xe4/0x1d4
> __free_pages+0x2c/0x88
> dma_free_contiguous+0x64/0x80
> dma_direct_free+0x38/0xb4
> dma_free_attrs+0x88/0xa0
> dmam_release+0x28/0x34
> release_nodes+0x78/0x8c
> devres_release_all+0xa8/0x110
> really_probe+0x118/0x2d0
> __driver_probe_device+0xc8/0xe0
> driver_probe_device+0x54/0xec
> __driver_attach+0xe0/0xf0
> bus_for_each_dev+0x7c/0xc8
> driver_attach+0x30/0x3c
> bus_add_driver+0x17c/0x1c4
> driver_register+0xc0/0xf8
> __platform_driver_register+0x34/0x40
> ...
>
> This issue is introduced by commit d0243bbd5dd3 ("drivers core:
> Free dma_range_map when driver probe failed"). It frees
> dma_range_map before the call to devres_release_all, which is too
> early. The solution is to free dma_range_map only after
> devres_release_all.
>
> Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed")
> Signed-off-by: Filip Schauer <filip@mg6.at>
> ---
> drivers/base/dd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Oh, nice catch! This is a v2, right? Next time please be explicit :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers core: Fix oops when driver probe fails
2021-07-27 12:31 ` Greg KH
@ 2021-07-27 16:01 ` Filip Schauer
0 siblings, 0 replies; 5+ messages in thread
From: Filip Schauer @ 2021-07-27 16:01 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Tue, Jul 27, 2021 at 02:31:10PM +0200, Greg KH wrote:
> On Tue, Jul 27, 2021 at 01:23:11PM +0200, Filip Schauer wrote:
> > dma_range_map is freed to early, which might cause an oops when
> > a driver probe fails.
> > Call trace:
> > is_free_buddy_page+0xe4/0x1d4
> > __free_pages+0x2c/0x88
> > dma_free_contiguous+0x64/0x80
> > dma_direct_free+0x38/0xb4
> > dma_free_attrs+0x88/0xa0
> > dmam_release+0x28/0x34
> > release_nodes+0x78/0x8c
> > devres_release_all+0xa8/0x110
> > really_probe+0x118/0x2d0
> > __driver_probe_device+0xc8/0xe0
> > driver_probe_device+0x54/0xec
> > __driver_attach+0xe0/0xf0
> > bus_for_each_dev+0x7c/0xc8
> > driver_attach+0x30/0x3c
> > bus_add_driver+0x17c/0x1c4
> > driver_register+0xc0/0xf8
> > __platform_driver_register+0x34/0x40
> > ...
> >
> > This issue is introduced by commit d0243bbd5dd3 ("drivers core:
> > Free dma_range_map when driver probe failed"). It frees
> > dma_range_map before the call to devres_release_all, which is too
> > early. The solution is to free dma_range_map only after
> > devres_release_all.
> >
> > Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed")
> > Signed-off-by: Filip Schauer <filip@mg6.at>
> > ---
> > drivers/base/dd.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Oh, nice catch! This is a v2, right? Next time please be explicit :)
>
> thanks,
>
> greg k-h
>
Thank you for adding the patch.
And my bad, this is indeed a PATCH v2.
I didn't know about the patch revisioning convention.
I'll be more explicit next time.
Thanks,
Filip Schauer
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-27 16:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-27 10:40 [PATCH] drivers core: Fix oops when driver probe fails Filip Schauer
2021-07-27 10:57 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2021-07-27 11:23 Filip Schauer
2021-07-27 12:31 ` Greg KH
2021-07-27 16:01 ` Filip Schauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox