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: <20200916231650.11484-8-marek.behun@nic.cz>
Date:   Thu, 17 Sep 2020 01:16:47 +0200
From:   Marek Behún <marek.behun@....cz>
To:     linux-leds@...r.kernel.org
Cc:     Pavel Machek <pavel@....cz>, Dan Murphy <dmurphy@...com>,
        Ondřej Jirman <megous@...ous.com>,
        linux-kernel@...r.kernel.org, Rob Herring <robh+dt@...nel.org>,
        devicetree@...r.kernel.org,
        Marek Behún <marek.behun@....cz>,
        "H . Nikolaus Schaller" <hns@...delico.com>,
        David Rivshin <drivshin@...worx.com>
Subject: [PATCH leds v1 07/10] leds: is31fl32xx: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property nor `linux,default-trigger` property.

This driver needed small refactoring for this to work nicely.

Signed-off-by: Marek Behún <marek.behun@....cz>
Cc: H. Nikolaus Schaller <hns@...delico.com>
Cc: David Rivshin <drivshin@...worx.com>
---
 drivers/leds/leds-is31fl32xx.c | 95 +++++++++++++---------------------
 1 file changed, 35 insertions(+), 60 deletions(-)

diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index cd768f991da10..769cce5fd2814 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -324,84 +324,63 @@ static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv)
 	return 0;
 }
 
-static int is31fl32xx_parse_child_dt(const struct device *dev,
-				     const struct device_node *child,
-				     struct is31fl32xx_led_data *led_data)
+static bool is31fl32xx_has_led(struct is31fl32xx_priv *priv, u8 channel)
 {
-	struct led_classdev *cdev = &led_data->cdev;
-	int ret = 0;
-	u32 reg;
+	int i;
 
-	if (of_property_read_string(child, "label", &cdev->name))
-		cdev->name = child->name;
+	for (i = 0; i < priv->num_leds; ++i)
+		if (priv->leds[i].channel == channel)
+			return true;
+
+	return false;
+}
+
+static int is31fl32xx_led_register(struct device *dev, struct device_node *np,
+				   struct is31fl32xx_led_data *led_data)
+{
+	struct led_init_data init_data = {};
+	u32 reg;
+	int ret;
 
-	ret = of_property_read_u32(child, "reg", &reg);
+	ret = of_property_read_u32(np, "reg", &reg);
 	if (ret || reg < 1 || reg > led_data->priv->cdef->channels) {
-		dev_err(dev,
-			"Child node %pOF does not have a valid reg property\n",
-			child);
+		dev_err(dev, "Node %pOF has no valid reg property\n", np);
 		return -EINVAL;
 	}
-	led_data->channel = reg;
-
-	of_property_read_string(child, "linux,default-trigger",
-				&cdev->default_trigger);
 
-	cdev->brightness_set_blocking = is31fl32xx_brightness_set;
-
-	return 0;
-}
+	if (is31fl32xx_has_led(led_data->priv, reg)) {
+		dev_err(dev, "Node %pOF reg property already used\n", np);
+		return -EEXIST;
+	}
 
-static struct is31fl32xx_led_data *is31fl32xx_find_led_data(
-					struct is31fl32xx_priv *priv,
-					u8 channel)
-{
-	size_t i;
+	led_data->channel = reg;
+	led_data->cdev.brightness_set_blocking = is31fl32xx_brightness_set;
+	init_data.fwnode = of_fwnode_handle(np);
 
-	for (i = 0; i < priv->num_leds; i++) {
-		if (priv->leds[i].channel == channel)
-			return &priv->leds[i];
-	}
+	ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
+	if (ret)
+		dev_err(dev, "Failed to register LED for %pOF: %d\n", np,
+			ret);
 
-	return NULL;
+	return ret;
 }
 
-static int is31fl32xx_parse_dt(struct device *dev,
-			       struct is31fl32xx_priv *priv)
+static int is31fl32xx_leds_register(struct device *dev,
+				    struct is31fl32xx_priv *priv)
 {
 	struct device_node *child;
-	int ret = 0;
+	int ret;
 
-	for_each_child_of_node(dev->of_node, child) {
+	for_each_child_of_node(dev_of_node(dev), child) {
 		struct is31fl32xx_led_data *led_data =
 			&priv->leds[priv->num_leds];
-		const struct is31fl32xx_led_data *other_led_data;
 
 		led_data->priv = priv;
 
-		ret = is31fl32xx_parse_child_dt(dev, child, led_data);
+		ret = is31fl32xx_led_register(dev, child, led_data);
 		if (ret)
 			goto err;
 
-		/* Detect if channel is already in use by another child */
-		other_led_data = is31fl32xx_find_led_data(priv,
-							  led_data->channel);
-		if (other_led_data) {
-			dev_err(dev,
-				"%s and %s both attempting to use channel %d\n",
-				led_data->cdev.name,
-				other_led_data->cdev.name,
-				led_data->channel);
-			goto err;
-		}
-
-		ret = devm_led_classdev_register(dev, &led_data->cdev);
-		if (ret) {
-			dev_err(dev, "failed to register PWM led for %s: %d\n",
-				led_data->cdev.name, ret);
-			goto err;
-		}
-
 		priv->num_leds++;
 	}
 
@@ -457,11 +436,7 @@ static int is31fl32xx_probe(struct i2c_client *client,
 	if (ret)
 		return ret;
 
-	ret = is31fl32xx_parse_dt(dev, priv);
-	if (ret)
-		return ret;
-
-	return 0;
+	return is31fl32xx_leds_register(dev, priv);
 }
 
 static int is31fl32xx_remove(struct i2c_client *client)
-- 
2.26.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ