Skip to contentSkip to conversation

leds: leds-mc13783: use unified device property API

PATCH Superseded Alexander Kurz 2 participants 4 messages Nov 21 LED

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 leds: leds-mc13783: use unified device property API

As preparation for a fix regarding deferred probing, replace OF-specific API calls with the unified device property variants.

---
 drivers/leds/leds-mc13783.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/leds/leds-mc13783.c +10 -10
index 19c1b51475db..c3bbbc8ef946 100644
@@ -16,8 +16,8 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/leds.h>
-#include <linux/of.h>
 #include <linux/mfd/mc13xxx.h>
 
 struct mc13xxx_led_devtype {
@@ -114,7 +114,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
 {
 	struct mc13xxx_leds *leds = platform_get_drvdata(pdev);
 	struct mc13xxx_leds_platform_data *pdata;
-	struct device_node *child;
+	struct fwnode_handle *child;
 	struct device *dev = &pdev->dev;
 	int i = 0, ret = -ENODATA;
 
@@ -122,34 +122,34 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
 	if (!pdata)
 		return ERR_PTR(-ENOMEM);
 
-	struct device_node *parent __free(device_node) =
-		of_get_child_by_name(dev_of_node(dev->parent), "leds");
+	struct fwnode_handle *parent __free(fwnode_handle) =
+		device_get_named_child_node(dev->parent, "leds");
 	if (!parent)
 		return ERR_PTR(-ENODATA);
 
-	ret = of_property_read_u32_array(parent, "led-control",
+	ret = fwnode_property_read_u32_array(parent, "fsl,led-control",
 					 pdata->led_control,
 					 leds->devtype->num_regs);
 	if (ret)
 		return ERR_PTR(ret);
 
-	pdata->num_leds = of_get_available_child_count(parent);
+	pdata->num_leds = fwnode_get_child_node_count(parent);
 
 	pdata->led = devm_kzalloc_objs(dev, *pdata->led, pdata->num_leds);
 	if (!pdata->led)
 		return ERR_PTR(-ENOMEM);
 
-	for_each_available_child_of_node(parent, child) {
+	fwnode_for_each_child_node(parent, child) {
 		const char *str;
 		u32 tmp;
 
-		if (of_property_read_u32(child, "reg", &tmp))
+		if (fwnode_property_read_u32(child, "reg", &tmp))
 			continue;
 		pdata->led[i].id = leds->devtype->led_min + tmp;
 
-		if (!of_property_read_string(child, "label", &str))
+		if (!fwnode_property_read_string(child, "label", &str))
 			pdata->led[i].name = str;
-		if (!of_property_read_string(child, "linux,default-trigger",
+		if (!fwnode_property_read_string(child, "linux,default-trigger",
 					     &str))
 			pdata->led[i].default_trigger = str;
 
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 leds: leds-mc13783: enable driver for deferred probe

The probe order between mfd and leds has been changed with commit 78efa53e715e ("leds: Init leds class earlier") so that mc13xxx-led driver was not registered any more due to the missing mfd instance. Use module_platform_driver() to replace module_platform_driver_probe(). The former utilizes platform_driver_register(), which allows the driver to defer probing when it doesn't acquire the necessary resources from the mfd device due to probe order.

Fixes 78efa53e715e ("leds: Init leds class earlier")
---
 drivers/leds/leds-mc13783.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/leds/leds-mc13783.c +5 -4
index c3bbbc8ef946..042cefde7853 100644
@@ -109,7 +109,7 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
 }
 
 #ifdef CONFIG_OF
-static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
+static struct mc13xxx_leds_platform_data *mc13xxx_led_probe_dt(
 	struct platform_device *pdev)
 {
 	struct mc13xxx_leds *leds = platform_get_drvdata(pdev);
@@ -163,14 +163,14 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
 	return pdata;
 }
 #else
-static inline struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
+static inline struct mc13xxx_leds_platform_data *mc13xxx_led_probe_dt(
 	struct platform_device *pdev)
 {
 	return ERR_PTR(-ENOSYS);
 }
 #endif
 
-static int __init mc13xxx_led_probe(struct platform_device *pdev)
+static int mc13xxx_led_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct mc13xxx_leds_platform_data *pdata = dev_get_platdata(dev);
@@ -296,13 +296,14 @@ static const struct platform_device_id mc13xxx_led_id_table[] = {
 MODULE_DEVICE_TABLE(platform, mc13xxx_led_id_table);
 
 static struct platform_driver mc13xxx_led_driver = {
+	.probe = mc13xxx_led_probe,
 	.driver	= {
 		.name	= "mc13xxx-led",
 	},
 	.remove		= mc13xxx_led_remove,
 	.id_table	= mc13xxx_led_id_table,
 };
-module_platform_driver_probe(mc13xxx_led_driver, mc13xxx_led_probe);
+module_platform_driver(mc13xxx_led_driver);
 
 MODULE_DESCRIPTION("LEDs driver for Freescale MC13XXX PMIC");
 MODULE_AUTHOR("Philippe Retornaz <[email protected]>");
Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH 2/2] leds: leds-mc13783: enable driver for deferred probe

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] leds: leds-mc13783: wrong DT property fsl,led-control breaks probe --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] leds: leds-mc13783: wrong DT property fsl,led-control breaks probe
--

commit 192aa62c8f136ce683903471ddceeeabc5b01f1f
Author: Alexander Kurz <[email protected]>

leds: leds-mc13783: enable driver for deferred probe

This commit replaces module_platform_driver_probe() with module_platform_driver() and drops __init from the probe functions so that mc13xxx-led can probe after the parent MFD device is registered.

drivers/leds/leds-mc13783.c static int mc13xxx_led_set(struct led_classdev *led_cdev, · line 115

Quoted 13 lines
drivers/leds/leds-mc13783.c +1 -1
index c3bbbc8ef946b..042cefde7853c 100644
@@ -109,7 +109,7 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
 }
 
 #ifdef CONFIG_OF
-static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
+static struct mc13xxx_leds_platform_data *mc13xxx_led_probe_dt(
 	struct platform_device *pdev)
 {
 	struct mc13xxx_leds *leds = platform_get_drvdata(pdev);

[Severity: High]
Does mc13xxx_led_probe_dt() fail with -EINVAL on all Device Tree boards now that mc13xxx_led_probe() can run?

The preceding commit "leds: leds-mc13783: use unified device property API" changed the property lookup in mc13xxx_led_probe_dt() from "led-control" to "fsl,led-control":

drivers/leds/leds-mc13783.c:mc13xxx_led_probe_dt() {
    ...
	ret = fwnode_property_read_u32_array(parent, "fsl,led-control",
					 pdata->led_control,
					 leds->devtype->num_regs);
	if (ret)
		return ERR_PTR(ret);
    ...
}

However, the binding in Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml (which sets
additionalProperties: false on the leds node) and all in-tree DTS files use "led-control" without a vendor prefix, so fwnode_property_read_u32_array() fails and aborts probe.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw
In reply to Alexander Kurz
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] leds: mc13783: wrong fsl,led-control property name in mc13xxx_led_probe_dt() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] leds: mc13783: wrong fsl,led-control property name in mc13xxx_led_probe_dt()
--

commit 68fd5224b7b684d27cc41e7ff6cfe1fa69173623
Author: Alexander Kurz <[email protected]>

leds: leds-mc13783: use unified device property API

This commit replaces OF-specific API calls in mc13xxx_led_probe_dt() with the unified fwnode device property API.

Quoted 4 lines
drivers/leds/leds-mc13783.c +0 -0
index 19c1b51475db6..c3bbbc8ef946b 100644

[ ... ]

Quoted 7 lines
drivers/leds/leds-mc13783.c +1 -2
@@ -122,34 +122,34 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
 	if (!pdata)
 		return ERR_PTR(-ENOMEM);
 
-	struct device_node *parent __free(device_node) =
-		of_get_child_by_name(dev_of_node(dev->parent), "leds");
+	struct fwnode_handle *parent __free(fwnode_handle) =

drivers/leds/leds-mc13783.c static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( · line 134

Quoted 10 lines
drivers/leds/leds-mc13783.c +2 -1
+		device_get_named_child_node(dev->parent, "leds");
 	if (!parent)
 		return ERR_PTR(-ENODATA);
 
-	ret = of_property_read_u32_array(parent, "led-control",
+	ret = fwnode_property_read_u32_array(parent, "fsl,led-control",
 					 pdata->led_control,
 					 leds->devtype->num_regs);
 	if (ret)
 		return ERR_PTR(ret);

[Severity: High]
Does changing the property name from "led-control" to "fsl,led-control" break Device Tree probing? The binding in Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml and all in-tree Device Trees define this property as "led-control", so fwnode_property_read_u32_array() will return -EINVAL and abort mc13xxx_led_probe_dt().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1