Re: [PATCH v1] leds: trigger: pattern: notify userpace if pattern finished

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 24, 2022 at 3:06 PM Martin Kurbanov
<mmkurbanov@xxxxxxxxxxxxxx> 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



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux