Re: [PATCH -next 1/2] leds: add /sys/devices/virtual/led-trigger/

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

 



On Thu, Oct 03, 2019 at 12:13:00AM +0900, Akinobu Mita wrote:
> Reading /sys/class/leds/<led>/trigger returns all available LED triggers.
> However, this violates the "one value per file" rule of sysfs.
> 
> This makes led_triggers "real" devices and provides an
> /sys/devices/virtual/led-trigger/ directory that contains a sub-directoriy
> for each LED trigger device. The name of the sub-directory matches the LED
> trigger name.
> 
> We can find all available LED triggers by listing this directory contents.
> 
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
> Cc: Jacek Anaszewski <jacek.anaszewski@xxxxxxxxx>
> Cc: Pavel Machek <pavel@xxxxxx>
> Cc: Dan Murphy <dmurphy@xxxxxx>
> Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
> ---
>  .../ABI/testing/sysfs-devices-virtual-led-trigger  |  8 +++
>  drivers/leds/led-triggers.c                        | 57 ++++++++++++++++++++++
>  include/linux/leds.h                               |  3 ++
>  3 files changed, 68 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-devices-virtual-led-trigger
> 
> diff --git a/Documentation/ABI/testing/sysfs-devices-virtual-led-trigger b/Documentation/ABI/testing/sysfs-devices-virtual-led-trigger
> new file mode 100644
> index 0000000..b8eb8f3
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-devices-virtual-led-trigger
> @@ -0,0 +1,8 @@
> +What:		/sys/devices/virtual/leds-trigger/
> +Date:		September 2019
> +KernelVersion:	5.5
> +Contact:	linux-leds@xxxxxxxxxxxxxxx
> +Description:
> +		This directory contains a sub-directoriy for each LED trigger
> +		device. The name of the sub-directory matches the LED trigger
> +		name.
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index 79e30d2..0b810cf 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -267,21 +267,76 @@ void led_trigger_rename_static(const char *name, struct led_trigger *trig)
>  }
>  EXPORT_SYMBOL_GPL(led_trigger_rename_static);
>  
> +struct ledtrig_device {
> +	struct device dev;
> +};
> +
> +static void ledtrig_device_release(struct device *dev)
> +{
> +	struct ledtrig_device *trig_dev =
> +		container_of(dev, struct ledtrig_device, dev);
> +
> +	kfree(trig_dev);
> +}
> +
> +static struct bus_type led_trigger_subsys = {
> +	.name = "led-trigger",
> +};
> +
> +static int led_trigger_subsys_init(void)
> +{
> +	static DEFINE_MUTEX(init_mutex);
> +	static bool init_done;
> +	int ret = 0;
> +
> +	mutex_lock(&init_mutex);
> +	if (!init_done) {

a test and set of an atomic would solve the issue of having both a mutex
and a boolean, right?

thanks,

greg k-h



[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