lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220615154918.521687-3-jjhiblot@traphandler.com>
Date:   Wed, 15 Jun 2022 17:49:16 +0200
From:   Jean-Jacques Hiblot <jjhiblot@...phandler.com>
To:     <pavel@....cz>, <robh+dt@...nel.org>,
        <sven.schwermer@...ruptive-technologies.com>,
        <krzysztof.kozlowski+dt@...aro.org>
CC:     <johan+linaro@...nel.org>, <marijn.suijten@...ainline.org>,
        <bjorn.andersson@...aro.org>, <andy.shevchenko@...il.com>,
        <linux-leds@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>,
        Jean-Jacques Hiblot <jjhiblot@...phandler.com>
Subject: [PATCH 2/4] led: class: Add devm_fwnode_led_get() to get a LED from a firmware node

Same functionality as devm_of_led_get(), but it takes a firmware node
as a parameter.
This mimic devm_fwnode_pwm_get() found in the PWM core.

The ACPI implementation is missing and the function returns -EOPNOTSUPP
when the firmware node is actually an ACPI node.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@...phandler.com>
---
 drivers/leds/led-class.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/leds.h     |  4 ++++
 2 files changed, 38 insertions(+)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 72fd6ee7af88..7faa953a3870 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -297,6 +297,40 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_of_led_get);
 
+/**
+ * devm_fwnode_led_get() - request a resource managed LED from firmware node
+ * @dev: device for LED consumer
+ * @fwnode: firmware node to get the LED from
+ * @index:	index of the LED to obtain in the consumer
+ *
+ * Returns the LED device parsed from the firmware node. See of_led_get().
+ *
+ * Returns: A pointer to the requested LED device or an ERR_PTR()-encoded
+ * error code on failure.
+ */
+struct led_classdev *__must_check devm_fwnode_led_get(struct device *dev,
+				       struct fwnode_handle *fwnode,
+				       int index)
+{
+	struct led_classdev *led = ERR_PTR(-ENODEV);
+	int ret;
+
+	if (is_of_node(fwnode))
+		led = of_led_get(to_of_node(fwnode), index);
+	else if (is_acpi_node(fwnode))
+		/* ACPI support is not yet implemented */
+		led = ERR_PTR(-EOPNOTSUPP);
+	if (IS_ERR(led))
+		return led;
+
+	ret = devm_add_action_or_reset(dev, devm_led_release, led);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return led;
+}
+EXPORT_SYMBOL_GPL(devm_fwnode_led_get);
+
 static int led_classdev_next_name(const char *init_name, char *name,
 				  size_t len)
 {
diff --git a/include/linux/leds.h b/include/linux/leds.h
index ba4861ec73d3..ace0130bfcd2 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -216,6 +216,10 @@ extern void led_put(struct led_classdev *led_cdev);
 struct led_classdev *__must_check devm_of_led_get(struct device *dev,
 						  int index);
 
+struct led_classdev *__must_check devm_fwnode_led_get(struct device *dev,
+				       struct fwnode_handle *fwnode,
+				       int index);
+
 /**
  * led_blink_set - set blinking with software fallback
  * @led_cdev: the LED to start blinking
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ