linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>, Pavel Machek <pavel@ucw.cz>,
	Lee Jones <lee@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 05/11] leds: trigger: netdev: introduce validating requested mode
Date: Thu, 27 Apr 2023 02:15:35 +0200	[thread overview]
Message-ID: <20230427001541.18704-6-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com>

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@gmail.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


  parent reply	other threads:[~2023-04-27  0:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  0:15 [PATCH 00/11] leds: introduce new LED hw control APIs Christian Marangi
2023-04-27  0:15 ` [PATCH 01/11] leds: add binding for LEDs hw control Christian Marangi
2023-04-27  0:15 ` [PATCH 02/11] leds: add binding to check support for LED " Christian Marangi
2023-04-30 18:08   ` Andrew Lunn
2023-04-27  0:15 ` [PATCH 03/11] leds: add helper function to use trigger in hw blink mode Christian Marangi
2023-04-27  0:15 ` [PATCH 04/11] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Christian Marangi
2023-05-11  3:06   ` Bagas Sanjaya
2023-04-27  0:15 ` Christian Marangi [this message]
2023-04-30 22:42   ` [PATCH 05/11] leds: trigger: netdev: introduce validating requested mode Andrew Lunn
2023-04-27  0:15 ` [PATCH 06/11] leds: trigger: netdev: add knob to set hw control possible Christian Marangi
2023-04-27  0:15 ` [PATCH 07/11] leds: trigger: netdev: reject interval and device store for hw_control Christian Marangi
2023-05-08 11:31   ` Sascha Hauer
2023-04-27  0:15 ` [PATCH 08/11] leds: trigger: netdev: add support for LED hw control Christian Marangi
2023-04-30 17:55   ` Andrew Lunn
2023-05-02 16:00     ` Christian Marangi
2023-04-27  0:15 ` [PATCH 09/11] leds: trigger: netdev: init mode if hw control already active Christian Marangi
2023-04-27  0:15 ` [PATCH 10/11] leds: trigger: netdev: expose netdev trigger modes in linux include Christian Marangi
2023-04-27  0:15 ` [PATCH 11/11] net: dsa: qca8k: implement hw_control ops Christian Marangi
2023-05-08 12:25 ` [PATCH 00/11] leds: introduce new LED hw control APIs Sascha Hauer
2023-05-08 12:33   ` Christian Marangi
2023-05-08 12:52     ` Sascha Hauer
2023-05-08 13:11       ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427001541.18704-6-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).