[PATCH 1/2] leds: core: add struct device_node pointer to the struct led_classdev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Rafał Miłecki <rafal@xxxxxxxxxx>

This allows every led_classdev_register user to set of_node before
calling that function. Thanks to this LEDs core code may access DT node
during LED registration (e.g. to read extra info).

A small disadvantage of this imlementation is keeping of_node pointer in
two places: struct led_classdev and struct device.
Another solutions were:
1) Passing pointer with a led_classdev_register call
   This would require changing & complicating the API.
2) Moving allocation part of led_classdev_register to separated function
   This would make registering LED even more complicated.

Having duplicated pointer semms like a reasonable trade-off.

Signed-off-by: Rafał Miłecki <rafal@xxxxxxxxxx>
---
 drivers/leds/led-class.c | 1 +
 include/linux/leds.h     | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 326ee6e925a2..9db9d05e4832 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -199,6 +199,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 				led_cdev, led_cdev->groups, "%s", name);
 	if (IS_ERR(led_cdev->dev))
 		return PTR_ERR(led_cdev->dev);
+	led_cdev->dev->of_node = led_cdev->of_node;
 
 	if (ret)
 		dev_warn(parent, "Led %s renamed to %s due to name collision",
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 569cb531094c..7dc4a679f376 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -85,6 +85,7 @@ struct led_classdev {
 				     unsigned long *delay_off);
 
 	struct device		*dev;
+	struct device_node	*of_node;
 	const struct attribute_group	**groups;
 
 	struct list_head	 node;			/* LED Device list */
-- 
2.11.0




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux