[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230427001541.18704-6-ansuelsmth@gmail.com>
Date: Thu, 27 Apr 2023 02:15:35 +0200
From: Christian Marangi <ansuelsmth@...il.com>
To: Jonathan Corbet <corbet@....net>, Pavel Machek <pavel@....cz>,
Lee Jones <lee@...nel.org>, Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Christian Marangi <ansuelsmth@...il.com>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-leds@...r.kernel.org, netdev@...r.kernel.org
Subject: [PATCH 05/11] leds: trigger: netdev: introduce validating requested mode
Introduce function to validate the requested mode in preparation for
hw control support. Currently everything is handled in software so
every mode is validated and accepted.
Requested mode are always validated before making any change, to follow
this rework the attr_store function to set the mode to a temp variable
and then apply the new mode only if accepted and validated.
Signed-off-by: Christian Marangi <ansuelsmth@...il.com>
---
drivers/leds/trigger/ledtrig-netdev.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 115f2bae9eee..81e0b0083f2f 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -91,6 +91,12 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
}
}
+static int validate_requested_mode(struct led_netdev_data *trigger_data,
+ unsigned long mode)
+{
+ return 0;
+}
+
static ssize_t device_name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -168,7 +174,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
size_t size, enum led_trigger_netdev_modes attr)
{
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
- unsigned long state;
+ unsigned long state, new_mode = trigger_data->mode;
int ret;
int bit;
@@ -186,12 +192,18 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
return -EINVAL;
}
- cancel_delayed_work_sync(&trigger_data->work);
-
if (state)
- set_bit(bit, &trigger_data->mode);
+ set_bit(bit, &new_mode);
else
- clear_bit(bit, &trigger_data->mode);
+ clear_bit(bit, &new_mode);
+
+ ret = validate_requested_mode(trigger_data, new_mode);
+ if (ret)
+ return ret;
+
+ cancel_delayed_work_sync(&trigger_data->work);
+
+ trigger_data->mode = new_mode;
set_baseline_state(trigger_data);
--
2.39.2
Powered by blists - more mailing lists