linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Martin Kurbanov <mmkurbanov@sberdevices.ru>
Cc: Pavel Machek <pavel@ucw.cz>,
	Raphael Teysseyre <rteysseyre@gmail.com>,
	Baolin Wang <baolin.wang@linaro.org>,
	Linux LED Subsystem <linux-leds@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	kernel <kernel@sberdevices.ru>
Subject: Re: [PATCH v1] leds: trigger: pattern: notify userpace if pattern finished
Date: Wed, 24 Aug 2022 18:51:21 +0300	[thread overview]
Message-ID: <CAHp75VeQX_8niAu4uORW1YEfjxhLJFWsnm_JccECfAOAzAh32A@mail.gmail.com> (raw)
In-Reply-To: <20220824114927.79231-1-mmkurbanov@sberdevices.ru>

On Wed, Aug 24, 2022 at 3:06 PM Martin Kurbanov
<mmkurbanov@sberdevices.ru> wrote:
>
> In the current moment, userspace caller can schedule led pattern with

LED

> appropriate parameters, but it doesn't have ability to listen any events

listen to

> indicated pattern finished. This patch implements such an event using
> sysfs node and sysfs_notify_dirent() call.

Where is the ABI documentation for that?

Also, any example of user space code (GitHub repository / gist) how to
use the feature?

...

>         bool is_indefinite;
>         bool is_hw_pattern;
> +       bool running;

is_running ?

...

> +static ssize_t pattern_ended_show(struct device *dev,
> +                                 struct device_attribute *attr, char *buf)
> +{
> +       struct led_classdev *led_cdev = dev_get_drvdata(dev);
> +       struct pattern_trig_data *data = led_get_trigger_data(led_cdev);
> +
> +       return scnprintf(buf, PAGE_SIZE, "%d\n", !data->running);

sysfs_emit().

> +}

> +

No need for this blank line.

> +static DEVICE_ATTR_RO(pattern_ended);

WRT previous two comments, if the current code is stylic in the above
way, you can convert it first and then add this patch in a series.

...

> +static int pattern_trig_add_pattern_ended(struct led_classdev *led_cdev)
> +{
> +       struct pattern_trig_data *data = led_get_trigger_data(led_cdev);
> +       struct device *dev = led_cdev->dev;
> +       int ret;
> +
> +       ret = device_create_file(dev, &dev_attr_pattern_ended);
> +       if (ret) {
> +               dev_err(dev,
> +                       "Error creating pattern_ended (%pe)\n", ERR_PTR(ret));
> +               return ret;
> +       }
> +
> +       data->pattern_ended = sysfs_get_dirent(dev->kobj.sd, "pattern_ended");
> +       if (!data->pattern_ended) {
> +               dev_err(dev, "Error getting pattern_ended kernelfs\n");
> +               device_remove_file(dev, &dev_attr_pattern_ended);
> +               return -ENXIO;
> +       }
> +
> +       return 0;
> +}
> +
> +static void pattern_trig_remove_pattern_ended(struct led_classdev *led_cdev)
> +{
> +       struct pattern_trig_data *data = led_get_trigger_data(led_cdev);
> +
> +       sysfs_put(data->pattern_ended);
> +       device_remove_file(led_cdev->dev, &dev_attr_pattern_ended);
> +}

I'm wondering if you can always have a file and instead provide a
value there, so user space may use epoll() mechanism on that. It will
simplify your code here.

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2022-08-24 15:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24 11:49 [PATCH v1] leds: trigger: pattern: notify userpace if pattern finished Martin Kurbanov
2022-08-24 15:51 ` Andy Shevchenko [this message]
2022-08-25 21:16   ` Martin Kurbanov
2022-09-01 22:43   ` Dmitry Rokosov
2022-09-02  5:35     ` Andy Shevchenko

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=CAHp75VeQX_8niAu4uORW1YEfjxhLJFWsnm_JccECfAOAzAh32A@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=baolin.wang@linaro.org \
    --cc=kernel@sberdevices.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mmkurbanov@sberdevices.ru \
    --cc=pavel@ucw.cz \
    --cc=rteysseyre@gmail.com \
    /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).