From: Lee Jones <lee@kernel.org>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Pavel Machek <pavel@ucw.cz>, linux-leds@vger.kernel.org
Subject: Re: [RFC 1/2] leds: trigger: input-events: Replace led_on with a flags field
Date: Thu, 13 Jun 2024 15:01:59 +0100 [thread overview]
Message-ID: <20240613140159.GD2561462@google.com> (raw)
In-Reply-To: <20240601195528.48308-2-hdegoede@redhat.com>
On Sat, 01 Jun 2024, Hans de Goede wrote:
> Replace the led_on boolean with a flags field, using bit 0 for FL_LED_ON,
> this is a preparation patch for adding further flags.
I'm generally okay with the principle.
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/leds/trigger/ledtrig-input-events.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/leds/trigger/ledtrig-input-events.c b/drivers/leds/trigger/ledtrig-input-events.c
> index 1de0176799f9..94d5580ea093 100644
> --- a/drivers/leds/trigger/ledtrig-input-events.c
> +++ b/drivers/leds/trigger/ledtrig-input-events.c
> @@ -17,14 +17,16 @@
>
> #define DEFAULT_LED_OFF_DELAY_MS 5000
>
> +/* To avoid repeatedly setting the brightness while there are events */
> +#define FL_LED_ON 0
FL is non-obvious.
FLAGS_LED_ON?
> +
> struct input_events_data {
> struct input_handler handler;
> struct delayed_work work;
> spinlock_t lock;
> struct led_classdev *led_cdev;
> int led_cdev_saved_flags;
> - /* To avoid repeatedly setting the brightness while there are events */
> - bool led_on;
> + unsigned long flags;
> unsigned long led_off_time;
> unsigned long led_off_delay;
> };
> @@ -42,7 +44,7 @@ static void led_input_events_work(struct work_struct *work)
> */
> if (time_after_eq(jiffies, data->led_off_time)) {
> led_set_brightness_nosleep(data->led_cdev, LED_OFF);
> - data->led_on = false;
> + clear_bit(FL_LED_ON, &data->flags);
> }
>
> spin_unlock_irq(&data->lock);
> @@ -95,10 +97,9 @@ static void input_events_event(struct input_handle *handle, unsigned int type,
>
> spin_lock_irqsave(&data->lock, flags);
>
> - if (!data->led_on) {
> + if (!test_and_set_bit(FL_LED_ON, &data->flags))
> led_set_brightness_nosleep(led_cdev, led_cdev->blink_brightness);
> - data->led_on = true;
> - }
> +
> data->led_off_time = jiffies + led_off_delay;
>
> spin_unlock_irqrestore(&data->lock, flags);
> --
> 2.45.1
>
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2024-06-13 14:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-01 19:55 [RFC 0/2] leds: trigger: input-events: Fix locking issues of input_lock vs led-trigger locks Hans de Goede
2024-06-01 19:55 ` [RFC 1/2] leds: trigger: input-events: Replace led_on with a flags field Hans de Goede
2024-06-13 14:01 ` Lee Jones [this message]
2024-06-01 19:55 ` [RFC 2/2] leds: trigger: input-events: Fix locking issues of input_lock vs led-trigger locks Hans de Goede
2024-06-02 2:30 ` Hillf Danton
2024-06-02 13:43 ` Hans de Goede
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=20240613140159.GD2561462@google.com \
--to=lee@kernel.org \
--cc=hdegoede@redhat.com \
--cc=linux-leds@vger.kernel.org \
--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).