mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Couple of cleanups in really_probe()
@ 2021-12-31  3:38 Lu Baolu
  2021-12-31  3:39 ` [PATCH v2 1/2] driver core: Move driver_sysfs_remove() after driver_sysfs_add() Lu Baolu
  2021-12-31  3:39 ` [PATCH v2 2/2] driver core: Make bus notifiers in right order in really_probe() Lu Baolu
  0 siblings, 2 replies; 3+ messages in thread
From: Lu Baolu @ 2021-12-31  3:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J . Wysocki, Kay Sievers, linux-kernel, Lu Baolu

Hi folks,

This series includes two cleanups in really_probe(). The purpose of
these cleanups are to make the sysfs add/remove and bus notification
events orderly when the driver can't bind to the device.

Best regards,
baolu

Change log:
v1: https://lore.kernel.org/all/20211229045159.1731943-1-baolu.lu@linux.intel.com/

v1->v2:
 - Split a single patch into two.
 - Remove the Fixes and Cc-stable tags as it doesn't fix any real
   bugs in practice. No need to back port. 

Lu Baolu (2):
  driver core: Move driver_sysfs_remove() after driver_sysfs_add()
  driver core: Make bus notifiers in right order in really_probe()

 drivers/base/dd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] driver core: Move driver_sysfs_remove() after driver_sysfs_add()
  2021-12-31  3:38 [PATCH v2 0/2] Couple of cleanups in really_probe() Lu Baolu
@ 2021-12-31  3:39 ` Lu Baolu
  2021-12-31  3:39 ` [PATCH v2 2/2] driver core: Make bus notifiers in right order in really_probe() Lu Baolu
  1 sibling, 0 replies; 3+ messages in thread
From: Lu Baolu @ 2021-12-31  3:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J . Wysocki, Kay Sievers, linux-kernel, Lu Baolu

The driver_sysfs_remove() should be called after driver_sysfs_add() in
really_probe(). The out-of-order driver_sysfs_remove() tries to remove
some nonexistent nodes under the device and driver sysfs nodes. This is
allowed, hence this change doesn't fix any problem, just a cleanup.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/base/dd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 68ea1f949daa..f6fac016b811 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -577,14 +577,14 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	if (dev->bus->dma_configure) {
 		ret = dev->bus->dma_configure(dev);
 		if (ret)
-			goto probe_failed;
+			goto sysfs_failed;
 	}
 
 	ret = driver_sysfs_add(dev);
 	if (ret) {
 		pr_err("%s: driver_sysfs_add(%s) failed\n",
 		       __func__, dev_name(dev));
-		goto probe_failed;
+		goto sysfs_failed;
 	}
 
 	if (dev->pm_domain && dev->pm_domain->activate) {
@@ -657,6 +657,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	else if (drv->remove)
 		drv->remove(dev);
 probe_failed:
+	driver_sysfs_remove(dev);
+sysfs_failed:
 	if (dev->bus)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
@@ -666,7 +668,6 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	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)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] driver core: Make bus notifiers in right order in really_probe()
  2021-12-31  3:38 [PATCH v2 0/2] Couple of cleanups in really_probe() Lu Baolu
  2021-12-31  3:39 ` [PATCH v2 1/2] driver core: Move driver_sysfs_remove() after driver_sysfs_add() Lu Baolu
@ 2021-12-31  3:39 ` Lu Baolu
  1 sibling, 0 replies; 3+ messages in thread
From: Lu Baolu @ 2021-12-31  3:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J . Wysocki, Kay Sievers, linux-kernel, Lu Baolu

If a driver cannot be bound to a device, the correct bus notifier order
should be:

 - BUS_NOTIFY_BIND_DRIVER: driver is about to be bound
 - BUS_NOTIFY_DRIVER_NOT_BOUND: driver failed to be bound

or no notifier if the failure happens before the actual binding.

The really_probe() notifies a BUS_NOTIFY_DRIVER_NOT_BOUND event without
a BUS_NOTIFY_BIND_DRIVER if .dma_configure() returns failure. This
change makes the notifiers in order.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/base/dd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index f6fac016b811..9eaaff2f556c 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -577,7 +577,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	if (dev->bus->dma_configure) {
 		ret = dev->bus->dma_configure(dev);
 		if (ret)
-			goto sysfs_failed;
+			goto pinctrl_bind_failed;
 	}
 
 	ret = driver_sysfs_add(dev);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-31  3:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31  3:38 [PATCH v2 0/2] Couple of cleanups in really_probe() Lu Baolu
2021-12-31  3:39 ` [PATCH v2 1/2] driver core: Move driver_sysfs_remove() after driver_sysfs_add() Lu Baolu
2021-12-31  3:39 ` [PATCH v2 2/2] driver core: Make bus notifiers in right order in really_probe() Lu Baolu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®