linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: David Lechner <david@lechnology.com>,
	Jacek Anaszewski <j.anaszewski@samsung.com>,
	Richard Purdie <rpurdie@rpsys.net>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] leds: uleds: make max_brightness configurable
Date: Sun, 13 Nov 2016 13:29:40 +0100	[thread overview]
Message-ID: <c7bcef39-7010-83ee-96ea-b3773b0aa5b8@gmail.com> (raw)
In-Reply-To: <1478885730-23190-1-git-send-email-david@lechnology.com>

Hi David,

Thanks for the patch. I fixed the original ones up.
Note that I changed also the macro name:

LEDS_MAX_NAME_SIZE ->  LED_MAX_NAME_SIZE

to match the macro prefixes from linux/leds.h

Best regards,
Jacek Anaszewski

On 11/11/2016 06:35 PM, David Lechner wrote:
> This adds support for configuring max_brightness when setting up a
> userspace LED device. It also requires changing the brightness value
> returned from a single byte to an integer. Since the uleds driver has
> not made it into the mainline kernel yet, this is not breaking userspace.
>
> Signed-off-by: David Lechner <david@lechnology.com>
> ---
>  drivers/leds/uleds.c       | 16 +++++++++++-----
>  include/uapi/linux/uleds.h |  1 +
>  tools/leds/uledmon.c       |  5 +++--
>  3 files changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/leds/uleds.c b/drivers/leds/uleds.c
> index 2bbc73a..5e9e8a1 100644
> --- a/drivers/leds/uleds.c
> +++ b/drivers/leds/uleds.c
> @@ -39,7 +39,7 @@ struct uleds_device {
>  	struct mutex		mutex;
>  	enum uleds_state	state;
>  	wait_queue_head_t	waitq;
> -	unsigned char		brightness;
> +	int			brightness;
>  	bool			new_data;
>  };
>
> @@ -67,7 +67,6 @@ static int uleds_open(struct inode *inode, struct file *file)
>  		return -ENOMEM;
>
>  	udev->led_cdev.name = udev->user_dev.name;
> -	udev->led_cdev.max_brightness = LED_FULL;
>  	udev->led_cdev.brightness_set = uleds_brightness_set;
>
>  	mutex_init(&udev->mutex);
> @@ -117,6 +116,12 @@ static ssize_t uleds_write(struct file *file, const char __user *buffer,
>  		goto out;
>  	}
>
> +	if (udev->user_dev.max_brightness <= 0) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +	udev->led_cdev.max_brightness = udev->user_dev.max_brightness;
> +
>  	ret = devm_led_classdev_register(uleds_misc.this_device,
>  					 &udev->led_cdev);
>  	if (ret < 0)
> @@ -138,7 +143,7 @@ static ssize_t uleds_read(struct file *file, char __user *buffer, size_t count,
>  	struct uleds_device *udev = file->private_data;
>  	ssize_t retval;
>
> -	if (count == 0)
> +	if (count < sizeof(udev->brightness))
>  		return 0;
>
>  	do {
> @@ -151,9 +156,10 @@ static ssize_t uleds_read(struct file *file, char __user *buffer, size_t count,
>  		} else if (!udev->new_data && (file->f_flags & O_NONBLOCK)) {
>  			retval = -EAGAIN;
>  		} else if (udev->new_data) {
> -			retval = copy_to_user(buffer, &udev->brightness, 1);
> +			retval = copy_to_user(buffer, &udev->brightness,
> +					      sizeof(udev->brightness));
>  			udev->new_data = false;
> -			retval = 1;
> +			retval = sizeof(udev->brightness);
>  		}
>
>  		mutex_unlock(&udev->mutex);
> diff --git a/include/uapi/linux/uleds.h b/include/uapi/linux/uleds.h
> index 2545b79..3788d5e 100644
> --- a/include/uapi/linux/uleds.h
> +++ b/include/uapi/linux/uleds.h
> @@ -18,6 +18,7 @@
>
>  struct uleds_user_dev {
>  	char name[LEDS_MAX_NAME_SIZE];
> +	int max_brightness;
>  };
>
>  #endif /* _UAPI__ULEDS_H_ */
> diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
> index 44d8634..163da85 100644
> --- a/tools/leds/uledmon.c
> +++ b/tools/leds/uledmon.c
> @@ -22,7 +22,7 @@ int main(int argc, char const *argv[])
>  {
>  	struct uleds_user_dev uleds_dev;
>  	int fd, ret;
> -	unsigned char brightness;
> +	int brightness;
>  	struct timespec ts;
>
>  	if (argc != 2) {
> @@ -31,6 +31,7 @@ int main(int argc, char const *argv[])
>  	}
>
>  	strncpy(uleds_dev.name, argv[1], LEDS_MAX_NAME_SIZE);
> +	uleds_dev.max_brightness = 100;
>
>  	fd = open("/dev/uleds", O_RDWR);
>  	if (fd == -1) {
> @@ -46,7 +47,7 @@ int main(int argc, char const *argv[])
>  	}
>
>  	while (1) {
> -		ret = read(fd, &brightness, 1);
> +		ret = read(fd, &brightness, sizeof(brightness));
>  		if (ret == -1) {
>  			perror("Failed to read from /dev/uleds");
>  			close(fd);
>

      reply	other threads:[~2016-11-13 12:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 17:35 [PATCH] leds: uleds: make max_brightness configurable David Lechner
2016-11-13 12:29 ` Jacek Anaszewski [this message]

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=c7bcef39-7010-83ee-96ea-b3773b0aa5b8@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=david@lechnology.com \
    --cc=j.anaszewski@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    /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).