Skip to contentSkip to conversation

drivercore: Revert "deferral race condition fix"

PATCH In review Andy Shevchenko 13 participants 32 messages Nov 10, 2018 – Nov 15, 2018

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 drivercore: Revert "deferral race condition fix"

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
---
 drivers/base/dd.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/base/dd.c +2 -25
index 169412ee4ae8..9a966e45fda5 100644
@@ -53,7 +53,6 @@
 static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
-static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
 static struct dentry *deferred_devices;
 static bool initcalls_done;
 
@@ -143,17 +142,6 @@ static bool driver_deferred_probe_enable = false;
  * This functions moves all devices from the pending list to the active
  * list and schedules the deferred probe workqueue to process them.  It
  * should be called anytime a driver is successfully bound to a device.
- *
- * Note, there is a race condition in multi-threaded probe. In the case where
- * more than one device is probing at the same time, it is possible for one
- * probe to complete successfully while another is about to defer. If the second
- * depends on the first, then it will get put on the pending list after the
- * trigger event has already occurred and will be stuck there.
- *
- * The atomic 'deferred_trigger_count' is used to determine if a successful
- * trigger has occurred in the midst of probing a driver. If the trigger count
- * changes in the midst of a probe, then deferred processing should be triggered
- * again.
  */
 static void driver_deferred_probe_trigger(void)
 {
@@ -166,7 +154,6 @@ static void driver_deferred_probe_trigger(void)
 	 * into the active list so they can be retried by the workqueue
 	 */
 	mutex_lock(&deferred_probe_mutex);
-	atomic_inc(&deferred_trigger_count);
 	list_splice_tail_init(&deferred_probe_pending_list,
 			      &deferred_probe_active_list);
 	mutex_unlock(&deferred_probe_mutex);
@@ -434,19 +421,9 @@ EXPORT_SYMBOL_GPL(device_bind_driver);
 static atomic_t probe_count = ATOMIC_INIT(0);
 static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
 
-static void driver_deferred_probe_add_trigger(struct device *dev,
-					      int local_trigger_count)
-{
-	driver_deferred_probe_add(dev);
-	/* Did a trigger occur while probing? Need to re-trigger if yes */
-	if (local_trigger_count != atomic_read(&deferred_trigger_count))
-		driver_deferred_probe_trigger();
-}
-
 static int really_probe(struct device *dev, struct device_driver *drv)
 {
 	int ret = -EPROBE_DEFER;
-	int local_trigger_count = atomic_read(&deferred_trigger_count);
 	bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
 			   !drv->suppress_bind_attrs;
 
@@ -463,7 +440,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 
 	ret = device_links_check_suppliers(dev);
 	if (ret == -EPROBE_DEFER)
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
+		driver_deferred_probe_add(dev);
 	if (ret)
 		return ret;
 
@@ -559,7 +536,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	case -EPROBE_DEFER:
 		/* Driver requested deferred probing */
 		dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
+		driver_deferred_probe_add(dev);
 		break;
 	case -ENODEV:
 	case -ENXIO:
Signature · 1 line
2.19.1
#1 lore raw

PATCH 2/5 extcon: Return -EPROBE_DEFER when extcon device is not found

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

---
 drivers/extcon/extcon-axp288.c        | 4 ++--
 drivers/extcon/extcon.c               | 2 +-
 drivers/power/supply/axp288_charger.c | 8 ++++----
 drivers/usb/phy/phy-omap-otg.c        | 6 +++---
 drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
 		if (name) {
 			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
 			dev_info(dev, "controlling USB role\n");
 		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
 		if (!strcmp(sd->name, extcon_name))
 			goto out;
 	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);
 out:
 	mutex_unlock(&extcon_dev_list_lock);
 	return sd;
drivers/power/supply/axp288_charger.c +4 -4
index 735658ee1c60..8558577fccf5 100644
@@ -768,17 +768,17 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	info->regmap_irqc = axp20x->regmap_irqc;
 
 	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
-	if (info->cable.edev == NULL) {
+	if (IS_ERR(info->cable.edev)) {
 		dev_dbg(&pdev->dev, "%s is not ready, probe deferred\n",
 			AXP288_EXTCON_DEV_NAME);
-		return -EPROBE_DEFER;
+		return PTR_ERR(info->cable.edev);
 	}
 
 	if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) {
 		info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME);
-		if (info->otg.cable == NULL) {
+		if (IS_ERR(info->otg.cable)) {
 			dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n");
-			return -EPROBE_DEFER;
+			return PTR_ERR(info->otg.cable);
 		}
 		dev_info(&pdev->dev,
 			 "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n");
drivers/usb/phy/phy-omap-otg.c +3 -3
index ee0863c6553e..605314ddcd3d 100644
@@ -91,12 +91,12 @@ static int omap_otg_probe(struct platform_device *pdev)
 	int ret;
 	u32 rev;
 
-	if (!config || !config->extcon)
+	if (!config)
 		return -ENODEV;
 
 	extcon = extcon_get_extcon_dev(config->extcon);
-	if (!extcon)
-		return -EPROBE_DEFER;
+	if (IS_ERR(extcon))
+		return PTR_ERR(extcon);
 
 	otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
 	if (!otg_dev)
drivers/usb/typec/tcpm/fusb302.c +2 -2
index 43b64d9309d0..6d332066202b 100644
@@ -1767,8 +1767,8 @@ static int fusb302_probe(struct i2c_client *client,
 	 */
 	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
 		chip->extcon = extcon_get_extcon_dev(name);
-		if (!chip->extcon)
-			return -EPROBE_DEFER;
+		if (IS_ERR(chip->extcon))
+			return PTR_ERR(chip->extcon);
 	}
 
 	chip->vbus = devm_regulator_get(chip->dev, "vbus");
Signature · 1 line
2.19.1
Acked-by on v1 2/5
#2 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 10 lines · Andy Shevchenko

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Quoted 98 lines
---
  drivers/extcon/extcon-axp288.c        | 4 ++--
  drivers/extcon/extcon.c               | 2 +-
  drivers/power/supply/axp288_charger.c | 8 ++++----
  drivers/usb/phy/phy-omap-otg.c        | 6 +++---
  drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
  5 files changed, 12 insertions(+), 12 deletions(-)
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
  		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
  		if (name) {
  			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
  			dev_info(dev, "controlling USB role\n");
  		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
  		if (!strcmp(sd->name, extcon_name))
  			goto out;
  	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);
  out:
  	mutex_unlock(&extcon_dev_list_lock);
  	return sd;
drivers/power/supply/axp288_charger.c +4 -4
index 735658ee1c60..8558577fccf5 100644
@@ -768,17 +768,17 @@ static int axp288_charger_probe(struct platform_device *pdev)
  	info->regmap_irqc = axp20x->regmap_irqc;
 
  	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
-	if (info->cable.edev == NULL) {
+	if (IS_ERR(info->cable.edev)) {
  		dev_dbg(&pdev->dev, "%s is not ready, probe deferred\n",
  			AXP288_EXTCON_DEV_NAME);
-		return -EPROBE_DEFER;
+		return PTR_ERR(info->cable.edev);
  	}
 
  	if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) {
  		info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME);
-		if (info->otg.cable == NULL) {
+		if (IS_ERR(info->otg.cable)) {
  			dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n");
-			return -EPROBE_DEFER;
+			return PTR_ERR(info->otg.cable);
  		}
  		dev_info(&pdev->dev,
  			 "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n");
drivers/usb/phy/phy-omap-otg.c +3 -3
index ee0863c6553e..605314ddcd3d 100644
@@ -91,12 +91,12 @@ static int omap_otg_probe(struct platform_device *pdev)
  	int ret;
  	u32 rev;
 
-	if (!config || !config->extcon)
+	if (!config)
  		return -ENODEV;
 
  	extcon = extcon_get_extcon_dev(config->extcon);
-	if (!extcon)
-		return -EPROBE_DEFER;
+	if (IS_ERR(extcon))
+		return PTR_ERR(extcon);
 
  	otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
  	if (!otg_dev)
drivers/usb/typec/tcpm/fusb302.c +2 -2
index 43b64d9309d0..6d332066202b 100644
@@ -1767,8 +1767,8 @@ static int fusb302_probe(struct i2c_client *client,
  	 */
  	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
  		chip->extcon = extcon_get_extcon_dev(name);
-		if (!chip->extcon)
-			return -EPROBE_DEFER;
+		if (IS_ERR(chip->extcon))
+			return PTR_ERR(chip->extcon);
  	}
 
  	chip->vbus = devm_regulator_get(chip->dev, "vbus");
maintainer Acked-by on v1 2/5
#3 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

In reply to Andy Shevchenko

Hi,

Quoted 11 lines · Andy Shevchenko

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

---

-- Sebastian

Quoted 99 lines
 drivers/extcon/extcon-axp288.c        | 4 ++--
 drivers/extcon/extcon.c               | 2 +-
 drivers/power/supply/axp288_charger.c | 8 ++++----
 drivers/usb/phy/phy-omap-otg.c        | 6 +++---
 drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
 		if (name) {
 			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
 			dev_info(dev, "controlling USB role\n");
 		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
 		if (!strcmp(sd->name, extcon_name))
 			goto out;
 	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);
 out:
 	mutex_unlock(&extcon_dev_list_lock);
 	return sd;
drivers/power/supply/axp288_charger.c +4 -4
index 735658ee1c60..8558577fccf5 100644
@@ -768,17 +768,17 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	info->regmap_irqc = axp20x->regmap_irqc;
 
 	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
-	if (info->cable.edev == NULL) {
+	if (IS_ERR(info->cable.edev)) {
 		dev_dbg(&pdev->dev, "%s is not ready, probe deferred\n",
 			AXP288_EXTCON_DEV_NAME);
-		return -EPROBE_DEFER;
+		return PTR_ERR(info->cable.edev);
 	}
 
 	if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) {
 		info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME);
-		if (info->otg.cable == NULL) {
+		if (IS_ERR(info->otg.cable)) {
 			dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n");
-			return -EPROBE_DEFER;
+			return PTR_ERR(info->otg.cable);
 		}
 		dev_info(&pdev->dev,
 			 "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n");
drivers/usb/phy/phy-omap-otg.c +3 -3
index ee0863c6553e..605314ddcd3d 100644
@@ -91,12 +91,12 @@ static int omap_otg_probe(struct platform_device *pdev)
 	int ret;
 	u32 rev;
 
-	if (!config || !config->extcon)
+	if (!config)
 		return -ENODEV;
 
 	extcon = extcon_get_extcon_dev(config->extcon);
-	if (!extcon)
-		return -EPROBE_DEFER;
+	if (IS_ERR(extcon))
+		return PTR_ERR(extcon);
 
 	otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
 	if (!otg_dev)
drivers/usb/typec/tcpm/fusb302.c +2 -2
index 43b64d9309d0..6d332066202b 100644
@@ -1767,8 +1767,8 @@ static int fusb302_probe(struct i2c_client *client,
 	 */
 	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
 		chip->extcon = extcon_get_extcon_dev(name);
-		if (!chip->extcon)
-			return -EPROBE_DEFER;
+		if (IS_ERR(chip->extcon))
+			return PTR_ERR(chip->extcon);
 	}
 
 	chip->vbus = devm_regulator_get(chip->dev, "vbus");
Signature · 1 line
2.19.1
maintainer Acked-by on v1 2/5
#4 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

In reply to Andy Shevchenko

Hi Andy,

Quoted 9 lines · Andy Shevchenko

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Quoted 8 lines
---
 drivers/extcon/extcon-axp288.c        | 4 ++--
 drivers/extcon/extcon.c               | 2 +-
 drivers/power/supply/axp288_charger.c | 8 ++++----
 drivers/usb/phy/phy-omap-otg.c        | 6 +++---
 drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)

Best Regards,
Chanwoo Choi

Quoted 91 lines
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
 		if (name) {
 			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
 			dev_info(dev, "controlling USB role\n");
 		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
 		if (!strcmp(sd->name, extcon_name))
 			goto out;
 	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);
 out:
 	mutex_unlock(&extcon_dev_list_lock);
 	return sd;
drivers/power/supply/axp288_charger.c +4 -4
index 735658ee1c60..8558577fccf5 100644
@@ -768,17 +768,17 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	info->regmap_irqc = axp20x->regmap_irqc;
 
 	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
-	if (info->cable.edev == NULL) {
+	if (IS_ERR(info->cable.edev)) {
 		dev_dbg(&pdev->dev, "%s is not ready, probe deferred\n",
 			AXP288_EXTCON_DEV_NAME);
-		return -EPROBE_DEFER;
+		return PTR_ERR(info->cable.edev);
 	}
 
 	if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) {
 		info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME);
-		if (info->otg.cable == NULL) {
+		if (IS_ERR(info->otg.cable)) {
 			dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n");
-			return -EPROBE_DEFER;
+			return PTR_ERR(info->otg.cable);
 		}
 		dev_info(&pdev->dev,
 			 "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n");
drivers/usb/phy/phy-omap-otg.c +3 -3
index ee0863c6553e..605314ddcd3d 100644
@@ -91,12 +91,12 @@ static int omap_otg_probe(struct platform_device *pdev)
 	int ret;
 	u32 rev;
 
-	if (!config || !config->extcon)
+	if (!config)
 		return -ENODEV;
 
 	extcon = extcon_get_extcon_dev(config->extcon);
-	if (!extcon)
-		return -EPROBE_DEFER;
+	if (IS_ERR(extcon))
+		return PTR_ERR(extcon);
 
 	otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
 	if (!otg_dev)
drivers/usb/typec/tcpm/fusb302.c +2 -2
index 43b64d9309d0..6d332066202b 100644
@@ -1767,8 +1767,8 @@ static int fusb302_probe(struct i2c_client *client,
 	 */
 	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
 		chip->extcon = extcon_get_extcon_dev(name);
-		if (!chip->extcon)
-			return -EPROBE_DEFER;
+		if (IS_ERR(chip->extcon))
+			return PTR_ERR(chip->extcon);
 	}
 
 	chip->vbus = devm_regulator_get(chip->dev, "vbus");
maintainer
#5 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Hi Andy,

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

ENODEV is more correct error instead of EPROBE_DEFER.

Sorry. I'll withdraw my opinion related acked-by tag until we are clarifying it.

Quoted 52 lines · Chanwoo Choi

Hi Andy,

Quoted 9 lines · Andy Shevchenko

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Quoted 8 lines
---
 drivers/extcon/extcon-axp288.c        | 4 ++--
 drivers/extcon/extcon.c               | 2 +-
 drivers/power/supply/axp288_charger.c | 8 ++++----
 drivers/usb/phy/phy-omap-otg.c        | 6 +++---
 drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)

Best Regards,
Chanwoo Choi

Quoted 26 lines
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
 		if (name) {
 			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
 			dev_info(dev, "controlling USB role\n");
 		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
 		if (!strcmp(sd->name, extcon_name))
 			goto out;
 	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);

(snip)

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#6 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

Quoted 1 line

Sorry. I'll withdraw my opinion related acked-by tag until we are clarifying it.

I honestly don't know what to clarify here.

When we would have a real case we can change API correspondingly. For now, the score is 5:0 with use cases in practice.

Quoted 10 lines · Chanwoo Choi
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

Quoted 19 lines
Quoted 2 lines

Sorry. I'll withdraw my opinion related acked-by tag until we are clarifying it.

I honestly don't know what to clarify here.

When we would have a real case we can change API correspondingly. For now, the score is 5:0 with use cases in practice.

Quoted 10 lines · Chanwoo Choi
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#8 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 16 lines · Chanwoo Choi
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

Quoted 7 lines

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

I agree with this, but look at the current state of affairs. All users do the same. If we need to have another case we may consider this later.

API inside the kernel are not carved in the stone.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#9 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 21 lines · Andy Shevchenko
Quoted 20 lines · Chanwoo Choi
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

Quoted 6 lines
Quoted 3 lines

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

I agree with this, but look at the current state of affairs. All users do the same. If we need to have another case we may consider this later.

Because we know the potential wrong case of this change, I can't agree this change. If extcon_get_extcon_dev() returns ENODEV instead of EPROBE_DEFER,
it is clear and then there are no problem on both current and future.

Quoted 4 lines

API inside the kernel are not carved in the stone.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#10 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 27 lines · Chanwoo Choi
Quoted 25 lines · Andy Shevchenko
Quoted 23 lines · Chanwoo Choi
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

Quoted 6 lines
Quoted 2 lines

I agree with this, but look at the current state of affairs. All users do the same. If we need to have another case we may consider this later.

Because we know the potential wrong case of this change, I can't agree this change. If extcon_get_extcon_dev() returns ENODEV instead of EPROBE_DEFER,
it is clear and then there are no problem on both current and future.

Changing NULL to -ENODEV is a trading bad to worse. I would not go that way, so, it's your call.

Quoted 1 line
Quoted 1 line

API inside the kernel are not carved in the stone.

Only can repeat myself (see above). While I see *theoretical* rationale on your side, mine has *practical* proofs.
So, I'm giving up on this and will duplicate same what it's done in 4 current callers.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#11 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 31 lines · Andy Shevchenko
Quoted 30 lines · Chanwoo Choi
Quoted 27 lines · Andy Shevchenko
Quoted 16 lines · Chanwoo Choi
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

Quoted 7 lines

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

I agree with this, but look at the current state of affairs. All users do the same. If we need to have another case we may consider this later.

Quoted 6 lines
Quoted 3 lines

Because we know the potential wrong case of this change, I can't agree this change. If extcon_get_extcon_dev() returns ENODEV instead of EPROBE_DEFER,
it is clear and then there are no problem on both current and future.

Changing NULL to -ENODEV is a trading bad to worse. I would not go that way, so, it's your call.

If you think that this change is not necessary, just keep the current code without the modification. Please drop this patch on next version.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

API inside the kernel are not carved in the stone.

Only can repeat myself (see above). While I see *theoretical* rationale on your side, mine has *practical* proofs.
So, I'm giving up on this and will duplicate same what it's done in 4 current callers.

I think that it is more important for removing the potential wrong case instead of removing the duplicate code. The many device drivers already decided the proper error value by using the return value of function of kernel framework.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#12 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 35 lines · Chanwoo Choi
Quoted 34 lines · Andy Shevchenko
Quoted 32 lines · Chanwoo Choi
Quoted 21 lines · Andy Shevchenko
Quoted 20 lines · Chanwoo Choi
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Chanwoo Choi

I was thinking about again to change from NULL to EPROBE_DEFER.

extcon_get_extcon_dev() function was almost called in the probe function. But, this function might be called on other position instead of probe.

Quoted 7 lines

*Might be* sounds like a theoretical thing, care to share what is in you mind? Current users and more important the new coming one are *all* doing the same.

Quoted 1 line

ENODEV is more correct error instead of EPROBE_DEFER.

So, you are proposing to continue duplicating conversion from ENODEV to EPROBE_DEFER in *each* caller?

The extcon core don't know the caller situation is in either probe() or other position in the caller driver. The caller driver should decide the kind of error value by using the return value of extcon_get_extcon_dev().

Quoted 6 lines
Quoted 3 lines

extcon_get_extcon_dev() function cannot be modified for only one case. If some device driver call extcon_get_extcon_dev() out of probe() fuction, EPROBE_DEFER is not always correct.

I agree with this, but look at the current state of affairs. All users do the same. If we need to have another case we may consider this later.

Because we know the potential wrong case of this change, I can't agree this change. If extcon_get_extcon_dev() returns ENODEV instead of EPROBE_DEFER,
it is clear and then there are no problem on both current and future.

Quoted 5 lines
Quoted 2 lines

Changing NULL to -ENODEV is a trading bad to worse. I would not go that way, so, it's your call.

If you think that this change is not necessary, just keep the current code without the modification.

Not only this, the useless churn for no benefit to anyone, except some *theoretical* cases no one saw.

Quoted 1 line

Please drop this patch on next version.

I will.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

API inside the kernel are not carved in the stone.

Only can repeat myself (see above). While I see *theoretical* rationale on your side, mine has *practical* proofs.
So, I'm giving up on this and will duplicate same what it's done in 4 current callers.

Quoted 4 lines

I think that it is more important for removing the potential wrong case instead of removing the duplicate code. The many device drivers already decided the proper error value by using the return value of function of kernel framework.

The API has been introduced back in 2012.

commit 74c5d09bd562edc220d6e076b8f1e118819c178f

Author: Donggeun Kim <[email protected]>
Date:   Fri Apr 20 14:16:24 2012 +0900

So, you are insisting that 6.5 years of use in a way people are using it is wrong?

I don't know what might change your mind, but for me it's a clear win-win to switch to deferred probe error code based on the *practical* evidence.
But as I said, I gave up now.

P.S. I still disagree with your arguments in relation to de facto use of an API.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Chanwoo Choi
Quoted 1 line

Changing NULL to -ENODEV is a trading bad to worse.

P.S. I still disagree with your arguments in relation to de facto use of an API.

I spoke to colleagues of mine and they are agree that semantically -EPROBE_DEFER is a wrong error code from API that matches against some list.
On the other hand, they agree with me that changing NULL to -ENODEV is a trading bad to worse.

So, I withdraw mine complaints against API.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#14 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Chanwoo Choi
Quoted 1 line

Changing NULL to -ENODEV is a trading bad to worse.

P.S. I still disagree with your arguments in relation to de facto use of an API.

Quoted 8 lines

I spoke to colleagues of mine and they are agree that semantically -EPROBE_DEFER is a wrong error code from API that matches against some list.
On the other hand, they agree with me that changing NULL to -ENODEV is a trading bad to worse.

So, I withdraw mine complaints against API.

OK. Thanks.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
maintainer Reviewed-by on v1 2/5
#15 lore raw

Re: [PATCH v1 2/5] extcon: Return -EPROBE_DEFER when extcon device is not found

In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

All current users of extcon_get_extcon_dev() API considers an extcon device a mandatory to appear. Thus, they all convert NULL pointer to -EPROBE_DEFER error code.

There is one more caller anticipated with the same requirements.

To decrease a code duplication and a burden to the callers, return -EPROBE_DEFER directly from extcon_get_extcon_dev().

Quoted 99 lines
---
 drivers/extcon/extcon-axp288.c        | 4 ++--
 drivers/extcon/extcon.c               | 2 +-
 drivers/power/supply/axp288_charger.c | 8 ++++----
 drivers/usb/phy/phy-omap-otg.c        | 6 +++---
 drivers/usb/typec/tcpm/fusb302.c      | 4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/extcon/extcon-axp288.c +2 -2
index a983708b77a6..3472d3b756ed 100644
@@ -360,8 +360,8 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
 		if (name) {
 			info->id_extcon = extcon_get_extcon_dev(name);
-			if (!info->id_extcon)
-				return -EPROBE_DEFER;
+			if (IS_ERR(info->id_extcon))
+				return PTR_ERR(info->id_extcon);
 
 			dev_info(dev, "controlling USB role\n");
 		} else {
drivers/extcon/extcon.c +1 -1
index 5ab0498be652..2bd0f2f33f05 100644
@@ -884,7 +884,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
 		if (!strcmp(sd->name, extcon_name))
 			goto out;
 	}
-	sd = NULL;
+	sd = ERR_PTR(-EPROBE_DEFER);
 out:
 	mutex_unlock(&extcon_dev_list_lock);
 	return sd;
drivers/power/supply/axp288_charger.c +4 -4
index 735658ee1c60..8558577fccf5 100644
@@ -768,17 +768,17 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	info->regmap_irqc = axp20x->regmap_irqc;
 
 	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
-	if (info->cable.edev == NULL) {
+	if (IS_ERR(info->cable.edev)) {
 		dev_dbg(&pdev->dev, "%s is not ready, probe deferred\n",
 			AXP288_EXTCON_DEV_NAME);
-		return -EPROBE_DEFER;
+		return PTR_ERR(info->cable.edev);
 	}
 
 	if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) {
 		info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME);
-		if (info->otg.cable == NULL) {
+		if (IS_ERR(info->otg.cable)) {
 			dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n");
-			return -EPROBE_DEFER;
+			return PTR_ERR(info->otg.cable);
 		}
 		dev_info(&pdev->dev,
 			 "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n");
drivers/usb/phy/phy-omap-otg.c +3 -3
index ee0863c6553e..605314ddcd3d 100644
@@ -91,12 +91,12 @@ static int omap_otg_probe(struct platform_device *pdev)
 	int ret;
 	u32 rev;
 
-	if (!config || !config->extcon)
+	if (!config)
 		return -ENODEV;
 
 	extcon = extcon_get_extcon_dev(config->extcon);
-	if (!extcon)
-		return -EPROBE_DEFER;
+	if (IS_ERR(extcon))
+		return PTR_ERR(extcon);
 
 	otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
 	if (!otg_dev)
drivers/usb/typec/tcpm/fusb302.c +2 -2
index 43b64d9309d0..6d332066202b 100644
@@ -1767,8 +1767,8 @@ static int fusb302_probe(struct i2c_client *client,
 	 */
 	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
 		chip->extcon = extcon_get_extcon_dev(name);
-		if (!chip->extcon)
-			return -EPROBE_DEFER;
+		if (IS_ERR(chip->extcon))
+			return PTR_ERR(chip->extcon);
 	}
 
 	chip->vbus = devm_regulator_get(chip->dev, "vbus");
Signature · 1 line
2.19.1
Signature · 1 line
heikki
#16 lore raw

PATCH 3/5 staging: typec: fusb302: Rename fcs,extcon-name to linux,extcon-name

In reply to Andy Shevchenko

Since we are going to use the same in Designware USB 3 driver, rename the property to be consistent across the drivers.

No functional change intended.

Cc Hans de Goede <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 drivers/platform/x86/intel_cht_int33fe.c | 2 +-
 drivers/usb/typec/tcpm/fusb302.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_cht_int33fe.c +1 -1
index 464fe93657b5..87cbf18d0305 100644
@@ -79,7 +79,7 @@ static const struct property_entry max17047_props[] = {
 };
 
 static const struct property_entry fusb302_props[] = {
-	PROPERTY_ENTRY_STRING("fcs,extcon-name", "cht_wcove_pwrsrc"),
+	PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"),
 	PROPERTY_ENTRY_U32("fcs,max-sink-microvolt", 12000000),
 	PROPERTY_ENTRY_U32("fcs,max-sink-microamp",   3000000),
 	PROPERTY_ENTRY_U32("fcs,max-sink-microwatt", 36000000),
drivers/usb/typec/tcpm/fusb302.c +1 -1
index 6d332066202b..62816ac571a0 100644
@@ -1765,7 +1765,7 @@ static int fusb302_probe(struct i2c_client *client,
 	 * to be set by the platform code which also registers the i2c client
 	 * for the fusb302.
 	 */
-	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
+	if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
 		chip->extcon = extcon_get_extcon_dev(name);
 		if (IS_ERR(chip->extcon))
 			return PTR_ERR(chip->extcon);
Signature · 1 line
2.19.1
Acked-by on v1 3/5
#17 lore raw

Re: [PATCH v1 3/5] staging: typec: fusb302: Rename fcs,extcon-name to linux,extcon-name

Quoted 8 lines · Andy Shevchenko

Since we are going to use the same in Designware USB 3 driver, rename the property to be consistent across the drivers.

No functional change intended.

Cc Hans de Goede <[email protected]>
Cc Guenter Roeck <[email protected]>
Quoted 32 lines
---
  drivers/platform/x86/intel_cht_int33fe.c | 2 +-
  drivers/usb/typec/tcpm/fusb302.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_cht_int33fe.c +1 -1
index 464fe93657b5..87cbf18d0305 100644
@@ -79,7 +79,7 @@ static const struct property_entry max17047_props[] = {
  };
 
  static const struct property_entry fusb302_props[] = {
-	PROPERTY_ENTRY_STRING("fcs,extcon-name", "cht_wcove_pwrsrc"),
+	PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"),
  	PROPERTY_ENTRY_U32("fcs,max-sink-microvolt", 12000000),
  	PROPERTY_ENTRY_U32("fcs,max-sink-microamp",   3000000),
  	PROPERTY_ENTRY_U32("fcs,max-sink-microwatt", 36000000),
drivers/usb/typec/tcpm/fusb302.c +1 -1
index 6d332066202b..62816ac571a0 100644
@@ -1765,7 +1765,7 @@ static int fusb302_probe(struct i2c_client *client,
  	 * to be set by the platform code which also registers the i2c client
  	 * for the fusb302.
  	 */
-	if (device_property_read_string(dev, "fcs,extcon-name", &name) == 0) {
+	if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
  		chip->extcon = extcon_get_extcon_dev(name);
  		if (IS_ERR(chip->extcon))
  			return PTR_ERR(chip->extcon);
#18 lore raw

PATCH 4/5 usb: dwc3: drd: Switch to device property for 'extcon' handling

In reply to Andy Shevchenko

Switch to device property for 'extcon' handling.
No functional change intended.

---
 drivers/usb/dwc3/drd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/dwc3/drd.c +3 -2
index e7e421521a34..5dc4cddd5b68 100644
@@ -10,6 +10,7 @@
 #include <linux/extcon.h>
 #include <linux/of_graph.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 
 #include "debug.h"
 #include "core.h"
@@ -485,8 +486,8 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 	struct device_node *np_phy, *np_conn;
 	struct extcon_dev *edev;
 
-	if (of_property_read_bool(dev->of_node, "extcon"))
-		return extcon_get_edev_by_phandle(dwc->dev, 0);
+	if (device_property_read_bool(dev, "extcon"))
+		return extcon_get_edev_by_phandle(dev, 0);
 
 	np_phy = of_parse_phandle(dev->of_node, "phys", 0);
 	np_conn = of_graph_get_remote_node(np_phy, -1, -1);
Signature · 1 line
2.19.1
#19 lore raw

Re: [PATCH v1 4/5] usb: dwc3: drd: Switch to device property for 'extcon' handling

Hi,

Quoted 21 lines · Andy Shevchenko

Switch to device property for 'extcon' handling.
No functional change intended.

---
 drivers/usb/dwc3/drd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/dwc3/drd.c +1 -0
index e7e421521a34..5dc4cddd5b68 100644
@@ -10,6 +10,7 @@
 #include <linux/extcon.h>
 #include <linux/of_graph.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 
 #include "debug.h"
 #include "core.h"

drivers/usb/dwc3/drd.c static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) · line 490

Quoted 7 lines
drivers/usb/dwc3/drd.c +2 -2
@@ -485,8 +486,8 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 	struct device_node *np_phy, *np_conn;
 	struct extcon_dev *edev;
 
-	if (of_property_read_bool(dev->of_node, "extcon"))
-		return extcon_get_edev_by_phandle(dwc->dev, 0);
+	if (device_property_read_bool(dev, "extcon"))
+		return extcon_get_edev_by_phandle(dev, 0);

No reservations against any of the patches. What is the idea for getting these merged upstream? I don't mind taking 4-5 through my tree, but what are the other folks considering?

Signature · 1 line
balbi
#20 lore raw

PATCH 5/5 usb: dwc3: drd: Add support for DR detection through extcon

In reply to Andy Shevchenko

Allow extcon device, found by name, to provide DR status for USB. This is needed, for example, in case of Intel Merrifield platform, where the Intel Basin Cove PMIC provides an extcon device to communicate the detected role.

Note, that the "linux,extcon-name" property name is only for kernel internal use by X86/ACPI platform code and as such is not documented in the device tree bindings.

---
 drivers/usb/dwc3/drd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/usb/dwc3/drd.c +10 -0
index 5dc4cddd5b68..d6b47829fdca 100644
@@ -485,10 +485,20 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 	struct device *dev = dwc->dev;
 	struct device_node *np_phy, *np_conn;
 	struct extcon_dev *edev;
+	const char *name;
 
 	if (device_property_read_bool(dev, "extcon"))
 		return extcon_get_edev_by_phandle(dev, 0);
 
+	/*
+	 * Device tree platforms should get extcon via phandle.
+	 * On ACPI platforms, we get the name from a device property.
+	 * This device property is for kernel internal use only and
+	 * is expected to be set by the glue code.
+	 */
+	if (device_property_read_string(dev, "linux,extcon-name", &name) == 0)
+		return extcon_get_extcon_dev(name);
+
 	np_phy = of_parse_phandle(dev->of_node, "phys", 0);
 	np_conn = of_graph_get_remote_node(np_phy, -1, -1);
 
Signature · 1 line
2.19.1
#21 lore raw
In reply to Andy Shevchenko
Quoted 48 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
Quoted 3 lines
---
 drivers/base/dd.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)

Shouldn't there be a "Fixes:" line and cc: stable here?

thanks,

greg k-h

#22 lore raw
Quoted 53 lines · Greg Kroah-Hartman
Quoted 48 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
Quoted 3 lines
---
 drivers/base/dd.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
Quoted 1 line

Shouldn't there be a "Fixes:" line and cc: stable here?

I'm not sure (yet). I would like to hear from people first, especially from Grant (I spoke to him already for the matters at ELCE in Edinburg).

Perhaps, Hans can have a chance to test this and comment on.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#23 lore raw

Hi,

Quoted 54 lines · Andy Shevchenko
Quoted 53 lines · Greg Kroah-Hartman
Quoted 51 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
---
  drivers/base/dd.c | 27 ++-------------------------
  1 file changed, 2 insertions(+), 25 deletions(-)
Quoted 6 lines
Quoted 1 line

Shouldn't there be a "Fixes:" line and cc: stable here?

I'm not sure (yet). I would like to hear from people first, especially from Grant (I spoke to him already for the matters at ELCE in Edinburg).

Perhaps, Hans can have a chance to test this and comment on.

I'm currently hitting a regression in 4.20-rc1 which causes it to not boot on my Cherry Trail test devices (sdhci driver times out so it cannot find its root filesystem).

I'm currently debugging this (it looks like I need todo a full bisect to find the cause) once I've that working, if I hit something which look likes you've described I will give this patch a test. But currently I cannot reproduce the problem you describe.

As for patches 2-55, they look good to me:

Regards,

Hans

#24 lore raw
In reply to Andy Shevchenko

I seems Grant's mail delivery bounces messages. I delibirately reduced the Cc list for sake of ping Grant in case it would pass.

Quoted 132 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
---
 drivers/base/dd.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/base/dd.c +2 -26
index 169412ee4ae8..9a966e45fda5 100644
@@ -53,7 +53,6 @@
 static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
-static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
 static struct dentry *deferred_devices;
 static bool initcalls_done;
 
@@ -143,17 +142,6 @@ static bool driver_deferred_probe_enable = false;
  * This functions moves all devices from the pending list to the active
  * list and schedules the deferred probe workqueue to process them.  It
  * should be called anytime a driver is successfully bound to a device.
- *
- * Note, there is a race condition in multi-threaded probe. In the case where
- * more than one device is probing at the same time, it is possible for one
- * probe to complete successfully while another is about to defer. If the second
- * depends on the first, then it will get put on the pending list after the
- * trigger event has already occurred and will be stuck there.
- *
- * The atomic 'deferred_trigger_count' is used to determine if a successful
- * trigger has occurred in the midst of probing a driver. If the trigger count
- * changes in the midst of a probe, then deferred processing should be triggered
- * again.
  */
 static void driver_deferred_probe_trigger(void)
 {
@@ -166,7 +154,6 @@ static void driver_deferred_probe_trigger(void)
         * into the active list so they can be retried by the workqueue
         */
        mutex_lock(&deferred_probe_mutex);
-       atomic_inc(&deferred_trigger_count);
        list_splice_tail_init(&deferred_probe_pending_list,
                              &deferred_probe_active_list);
        mutex_unlock(&deferred_probe_mutex);
@@ -434,19 +421,9 @@ EXPORT_SYMBOL_GPL(device_bind_driver);
 static atomic_t probe_count = ATOMIC_INIT(0);
 static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
 
-static void driver_deferred_probe_add_trigger(struct device *dev,
-                                             int local_trigger_count)
-{
-       driver_deferred_probe_add(dev);
-       /* Did a trigger occur while probing? Need to re-trigger if yes */
-       if (local_trigger_count != atomic_read(&deferred_trigger_count))
-               driver_deferred_probe_trigger();
-}
-
 static int really_probe(struct device *dev, struct device_driver *drv)
 {
        int ret = -EPROBE_DEFER;
-       int local_trigger_count = atomic_read(&deferred_trigger_count);
        bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
                           !drv->suppress_bind_attrs;
 
@@ -463,7 +440,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 
        ret = device_links_check_suppliers(dev);
        if (ret == -EPROBE_DEFER)
-               driver_deferred_probe_add_trigger(dev, local_trigger_count);
+               driver_deferred_probe_add(dev);
        if (ret)
                return ret;
 
@@ -559,7 +536,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
        case -EPROBE_DEFER:
                /* Driver requested deferred probing */
                dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
-               driver_deferred_probe_add_trigger(dev, local_trigger_count);
+               driver_deferred_probe_add(dev);
                break;
        case -ENODEV:
        case -ENXIO:
--

2.19.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#25 lore raw
Quoted 3 lines · Andy Shevchenko

I seems Grant's mail delivery bounces messages. I delibirately reduced the Cc list for sake of ping Grant in case it would pass.

That would be because he is not at Linaro anymore. Added his ARM account.

Quoted 37 lines
Quoted 35 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Quoted 6 lines
Quoted 6 lines

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

How is behavior that's been there for 4.5 years a regression? Aren't we going to break Davinci that this commit was supposed to fix? What else could be relying on current behavior?

Rob

#26 lore raw
Quoted 7 lines · Rob Herring
Quoted 2 lines · Andy Shevchenko

I seems Grant's mail delivery bounces messages. I delibirately reduced the Cc list for sake of ping Grant in case it would pass.

That would be because he is not at Linaro anymore. Added his ARM account.

Thanks!

Quoted 41 lines
Quoted 41 lines
Quoted 39 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

How is behavior that's been there for 4.5 years a regression? Aren't we going to break Davinci that this commit was supposed to fix? What else could be relying on current behavior?

I guess we are purerly on a side of luck. I don't remember people build usb and extcon as modules
and using Buildroot, or anything that probes modules let's say,in "arbitrary" way.
(That is one of the reason why I didn't dare to put Fixes tag there). Nevertheless, I have actual issue. I'm all ears to know about another possibility
how to fix the issue on my side.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#27 lore raw
In reply to Rob Herring
Quoted 49 lines · Rob Herring
Quoted 3 lines · Andy Shevchenko

I seems Grant's mail delivery bounces messages. I delibirately reduced the Cc list for sake of ping Grant in case it would pass.

That would be because he is not at Linaro anymore. Added his ARM account.

Quoted 41 lines
Quoted 39 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

How is behavior that's been there for 4.5 years a regression? Aren't we going to break Davinci that this commit was supposed to fix? What else could be relying on current behavior?

It has been a long time since I looked at this code, but so this may be totally wrong. Something is causing driver_deferred_probe_trigger to get called. I suspect all of this is happening within the single probe event. This driver creates nested devices, which are bound to there own driver. If one of those child devices probes successfully, and then the parent probe fails with -EPROBE_DEFER, does it cause the whole structure to be torn down again? If so, then that's the cause. The successful probe will cause the probe loop.

You should investigate what driver probe/remove events happen in the failure case. That will tell you exactly what is happening.

g.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#28 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 32 lines · Andy Shevchenko

Consider the following scenario.

There are two independent devices coupled together by functional dependencies:
- USB OTG (dwc3-pci)
- extcon (tested with extcon-intel-mrfld, not yet in upstream)

Each of the driver services a corresponding device is built as a module. In the Buildroot environment the modules are probed by alphabetical ordering of their modaliases. The latter comes to the case when USB OTG driver will be probed first followed by extcon one.

So, if the platform anticipates extcon device to be appeared, in the above case we will get deferred probe of USB OTG, because of ordering.

Now, a cherry on top of the cake, the deferred probing list contains the only two modules, i.e. USB OTG and extcon. Due to above circumstances, values in the local_trigger_count and deferred_trigger_count are not the same, and thus provokes deferred probe triggering again and again.

...

[   20.678332] platform dwc3.0.auto: Retrying from deferred list
[   20.694743] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.701254] platform dwc3.0.auto: Added to deferred list
[   20.706620] platform dwc3.0.auto: driver_deferred_probe_add_trigger 1 2
[   20.713732] platform dwc3.0.auto: Retrying from deferred list
[   20.730035] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.736540] platform dwc3.0.auto: Added to deferred list
[   20.741889] platform dwc3.0.auto: driver_deferred_probe_add_trigger 3 4
[   20.748991] platform dwc3.0.auto: Retrying from deferred list
[   20.765416] platform dwc3.0.auto: Driver dwc3 requests probe deferral
[   20.771914] platform dwc3.0.auto: Added to deferred list
[   20.777279] platform dwc3.0.auto: driver_deferred_probe_add_trigger 5 6
Quoted 8 lines

...

Deeper investigation shows the culprit commit 58b116bce136 ("drivercore: deferral race condition fix") which was dedicated to fix some other issue while bringing a regression.

This reverts commit 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835 for good until we will have better solution.

if we revert the commit then the original issue will re-surfaces. afaik it was not only audio which hit the 'last driver to be probed from the deferred list would never probe, unless we provoke the kernel to load additional module, or remove/reload the module' issue.

Do I understand correctly that in your case you have two modules (dwc3-pci and extcon-intel-mrfld) in a deferred probe loop, iow both of the drivers returns -EPROBE_DEFER and they just spin?

If both is deferring, how this supposed to work?

If we revert 58b116bce13612e5aa6fcd49ecbd4cf8bb59e835, then you might be hitting the very same issue as described by the commit:
s/davinci_evm sound.3/dwc3-pci
s/davinci-mcasp 4803c000.mcasp/extcon-intel-mrfld

Am I missing something?

Quoted 81 lines
Cc Grant Likely <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Mark Brown <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andrzej Hajda <[email protected]>
---
 drivers/base/dd.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/base/dd.c +1 -24
index 169412ee4ae8..9a966e45fda5 100644
@@ -53,7 +53,6 @@
 static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
-static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
 static struct dentry *deferred_devices;
 static bool initcalls_done;
 
@@ -143,17 +142,6 @@ static bool driver_deferred_probe_enable = false;
  * This functions moves all devices from the pending list to the active
  * list and schedules the deferred probe workqueue to process them.  It
  * should be called anytime a driver is successfully bound to a device.
- *
- * Note, there is a race condition in multi-threaded probe. In the case where
- * more than one device is probing at the same time, it is possible for one
- * probe to complete successfully while another is about to defer. If the second
- * depends on the first, then it will get put on the pending list after the
- * trigger event has already occurred and will be stuck there.
- *
- * The atomic 'deferred_trigger_count' is used to determine if a successful
- * trigger has occurred in the midst of probing a driver. If the trigger count
- * changes in the midst of a probe, then deferred processing should be triggered
- * again.
  */
 static void driver_deferred_probe_trigger(void)
 {
@@ -166,7 +154,6 @@ static void driver_deferred_probe_trigger(void)
 	 * into the active list so they can be retried by the workqueue
 	 */
 	mutex_lock(&deferred_probe_mutex);
-	atomic_inc(&deferred_trigger_count);
 	list_splice_tail_init(&deferred_probe_pending_list,
 			      &deferred_probe_active_list);
 	mutex_unlock(&deferred_probe_mutex);
@@ -434,19 +421,9 @@ EXPORT_SYMBOL_GPL(device_bind_driver);
 static atomic_t probe_count = ATOMIC_INIT(0);
 static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
 
-static void driver_deferred_probe_add_trigger(struct device *dev,
-					      int local_trigger_count)
-{
-	driver_deferred_probe_add(dev);
-	/* Did a trigger occur while probing? Need to re-trigger if yes */
-	if (local_trigger_count != atomic_read(&deferred_trigger_count))
-		driver_deferred_probe_trigger();
-}
-
 static int really_probe(struct device *dev, struct device_driver *drv)
 {
 	int ret = -EPROBE_DEFER;
-	int local_trigger_count = atomic_read(&deferred_trigger_count);
 	bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
 			   !drv->suppress_bind_attrs;
 
@@ -463,7 +440,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 
 	ret = device_links_check_suppliers(dev);
 	if (ret == -EPROBE_DEFER)
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
+		driver_deferred_probe_add(dev);
 	if (ret)
 		return ret;
 

drivers/base/dd.c static int really_probe(struct device *dev, struct device_driver *drv) · line 542

Quoted 8 lines
drivers/base/dd.c +1 -1
@@ -559,7 +536,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	case -EPROBE_DEFER:
 		/* Driver requested deferred probing */
 		dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
+		driver_deferred_probe_add(dev);
 		break;
 	case -ENODEV:
 	case -ENXIO:

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

#29 lore raw
Quoted 4 lines · Peter Ujfalusi

if we revert the commit then the original issue will re-surfaces. afaik it was not only audio which hit the 'last driver to be probed from the deferred list would never probe, unless we provoke the kernel to load additional module, or remove/reload the module' issue.

Right, aren't we just going to be swapping one bug for another?

Quoted 5 lines

Do I understand correctly that in your case you have two modules (dwc3-pci and extcon-intel-mrfld) in a deferred probe loop, iow both of the drivers returns -EPROBE_DEFER and they just spin?

If both is deferring, how this supposed to work?

I'm struggling to follow the original explanation too :(

#30 lore raw
Quoted 9 lines · Mark Brown
Quoted 4 lines · Peter Ujfalusi

if we revert the commit then the original issue will re-surfaces. afaik it was not only audio which hit the 'last driver to be probed from the deferred list would never probe, unless we provoke the kernel to load additional module, or remove/reload the module' issue.

Right, aren't we just going to be swapping one bug for another?

Have anyone in possession of Davinchi tested most recent kernel with this revert?

Quoted 7 lines
Quoted 5 lines

Do I understand correctly that in your case you have two modules (dwc3-pci and extcon-intel-mrfld) in a deferred probe loop, iow both of the drivers returns -EPROBE_DEFER and they just spin?

If both is deferring, how this supposed to work?

I'm struggling to follow the original explanation too :(

Sorry, guys, I confused a nit myself. The bug is there, but exxplanation is not fully corrent, indeed. I'll come back with more details later.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#31 lore raw

Andy,

Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Mark Brown
Quoted 4 lines · Peter Ujfalusi

if we revert the commit then the original issue will re-surfaces. afaik it was not only audio which hit the 'last driver to be probed from the deferred list would never probe, unless we provoke the kernel to load additional module, or remove/reload the module' issue.

Quoted 4 lines
Quoted 1 line

Right, aren't we just going to be swapping one bug for another?

Have anyone in possession of Davinchi tested most recent kernel with this revert?

I don't think it is related to daVinci, in fact we have seen the very same issue with OMAP4.
Fwiw this was my initial patch
http://lkml.iu.edu/hypermail/linux/kernel/1404.0/01603.html
Grant based his change on this.

Note the part in the commit message:
"The issue has been observed on embedded systems with CONFIG_PREEMPT enabled, audio support built as modules and using nfsroot for root filesystem."

as I recall I was only able to reproduce the stall with nfsroot and buildroot fs. The timings were different compared to MMC rootfs.

Anyways the patch fixes a real race condition which is generic:
We have driverA and driverB as modules. driverB needs driverA to be registered to a framework (no direct, hard dependency).

1. driverA starts to probe
2. driverB starts to probe
3. driverB can not continue as driverA is not registered itself to the framework -> driverB will defer
4. driverA registers to the framework
5. driverA probes successfully
6. driver core will prepare the deferred probe list (note: driverB is still in it's probe, not in the deferred list)
7. driverB returns from it's probe with -EPROBE_DEFER

and here we are, driverB is alone in the deferred list and the list is not going to be tried as driverA and driverB were the last ones to probe.

So, driverB is in the deferred list and stays there until other driver probes successfully as the deferred driver list only tried when a driver loads successfully (to see if that satisfy any of the deferred driver).

We have evidence that this has happened, it is a generic issue given that now days we have more frameworks drivers are relying on.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Do I understand correctly that in your case you have two modules (dwc3-pci and extcon-intel-mrfld) in a deferred probe loop, iow both of the drivers returns -EPROBE_DEFER and they just spin?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

If both is deferring, how this supposed to work?

I'm struggling to follow the original explanation too :(

Sorry, guys, I confused a nit myself. The bug is there, but exxplanation is not fully corrent, indeed. I'll come back with more details later.

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki