[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VeQX_8niAu4uORW1YEfjxhLJFWsnm_JccECfAOAzAh32A@mail.gmail.com>
Date: Wed, 24 Aug 2022 18:51:21 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Martin Kurbanov <mmkurbanov@...rdevices.ru>
Cc: Pavel Machek <pavel@....cz>,
Raphael Teysseyre <rteysseyre@...il.com>,
Baolin Wang <baolin.wang@...aro.org>,
Linux LED Subsystem <linux-leds@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
kernel <kernel@...rdevices.ru>
Subject: Re: [PATCH v1] leds: trigger: pattern: notify userpace if pattern finished
On Wed, Aug 24, 2022 at 3:06 PM Martin Kurbanov
<mmkurbanov@...rdevices.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
Powered by blists - more mailing lists