From: Rob Herring <robh@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] driver core: Refactor multiple copies of device cleanup
Date: Wed, 23 Feb 2022 16:52:56 -0600 [thread overview]
Message-ID: <20220223225257.1681968-2-robh@kernel.org> (raw)
In-Reply-To: <20220223225257.1681968-1-robh@kernel.org>
There are 3 copies of the same device cleanup code used for probe failure,
testing re-probing, and device unbinding. Changes to this code often miss
at least one of the copies of the code. See commits d0243bbd5dd3 ("drivers
core: Free dma_range_map when driver probe failed") and d8f7a5484f21
("driver core: Free DMA range map when device is released") for example.
Let's refactor the code to its own function.
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/base/dd.c | 46 ++++++++++++++++------------------------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index f47cab21430f..19bae32955c1 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -506,6 +506,19 @@ static ssize_t state_synced_show(struct device *dev,
}
static DEVICE_ATTR_RO(state_synced);
+static void device_unbind_cleanup(struct device *dev)
+{
+ devres_release_all(dev);
+ arch_teardown_dma_ops(dev);
+ kfree(dev->dma_range_map);
+ dev->dma_range_map = NULL;
+ dev->driver = NULL;
+ dev_set_drvdata(dev, NULL);
+ if (dev->pm_domain && dev->pm_domain->dismiss)
+ dev->pm_domain->dismiss(dev);
+ pm_runtime_reinit(dev);
+ dev_pm_set_driver_flags(dev, 0);
+}
static int call_driver_probe(struct device *dev, struct device_driver *drv)
{
@@ -628,16 +641,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
else if (drv->remove)
drv->remove(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);
- if (dev->pm_domain && dev->pm_domain->dismiss)
- dev->pm_domain->dismiss(dev);
- pm_runtime_reinit(dev);
+ device_unbind_cleanup(dev);
goto re_probe;
}
@@ -667,16 +672,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
pinctrl_bind_failed:
device_links_no_driver(dev);
- devres_release_all(dev);
- arch_teardown_dma_ops(dev);
- kfree(dev->dma_range_map);
- dev->dma_range_map = NULL;
- dev->driver = NULL;
- dev_set_drvdata(dev, NULL);
- if (dev->pm_domain && dev->pm_domain->dismiss)
- dev->pm_domain->dismiss(dev);
- pm_runtime_reinit(dev);
- dev_pm_set_driver_flags(dev, 0);
+ device_unbind_cleanup(dev);
done:
return ret;
}
@@ -1209,17 +1205,7 @@ static void __device_release_driver(struct device *dev, struct device *parent)
drv->remove(dev);
device_links_driver_cleanup(dev);
-
- devres_release_all(dev);
- arch_teardown_dma_ops(dev);
- kfree(dev->dma_range_map);
- dev->dma_range_map = NULL;
- dev->driver = NULL;
- dev_set_drvdata(dev, NULL);
- if (dev->pm_domain && dev->pm_domain->dismiss)
- dev->pm_domain->dismiss(dev);
- pm_runtime_reinit(dev);
- dev_pm_set_driver_flags(dev, 0);
+ device_unbind_cleanup(dev);
klist_remove(&dev->p->knode_driver);
device_pm_check_callbacks(dev);
--
2.32.0
next prev parent reply other threads:[~2022-02-23 22:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 22:52 [PATCH 0/2] driver core: Refactor device unbind/probe fail clean-ups Rob Herring
2022-02-23 22:52 ` Rob Herring [this message]
2022-02-23 22:52 ` [PATCH 2/2] driver core: Refactor sysfs and drv/bus remove hooks Rob Herring
2022-02-24 9:07 ` Greg Kroah-Hartman
2022-02-24 9:08 ` [PATCH 0/2] driver core: Refactor device unbind/probe fail clean-ups Greg Kroah-Hartman
2022-02-24 13:24 ` Rob Herring
2022-02-24 18:24 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223225257.1681968-2-robh@kernel.org \
--to=robh@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.