Re: [PATCH v5 3/3] leds: trigger: implement a tty trigger

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

 



Hi!

> +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
> @@ -0,0 +1,6 @@
> +What:		/sys/class/leds/<led>/dev
> +Date:		Dec 2019
> +KernelVersion:	5.6
> +Contact:	linux-leds@xxxxxxxxxxxxxxx
> +Description:
> +		Specifies $major:$minor of the triggering tty

Ok, sounds reasonable.

> +static ssize_t dev_store(struct device *dev,
> +			 struct device_attribute *attr, const char *buf,
> +			 size_t size)
> +{
> +	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
> +	struct tty_struct *tty;
> +	unsigned major, minor;
> +	int ret;
> +
> +	if (size == 0 || (size == 1 && buf[0] == '\n')) {
> +		tty = NULL;
> +	} else {
> +		ret = sscanf(buf, "%u:%u", &major, &minor);
> +		if (ret < 2)
> +			return -EINVAL;

If user writes 1:2:badparsingofdata into the file, it will pass, right?

> +		tty = tty_kopen_shared(MKDEV(major, minor));
> +		if (IS_ERR(tty))
> +			return PTR_ERR(tty);
> +	}

Do you need to do some kind of tty_kclose()? What happens if the
device disappears, for example because the USB modem is unplugged?

> +static void ledtrig_tty_work(struct work_struct *work)
> +{
> +	struct ledtrig_tty_data *trigger_data =
> +		container_of(work, struct ledtrig_tty_data, dwork.work);
> +	struct serial_icounter_struct icount;
> +	int ret;
> +
> +	if (!trigger_data->tty) {
> +		led_set_brightness(trigger_data->led_cdev, LED_OFF);
> +		return;
> +	}
> +
> +	ret = tty_get_icount(trigger_data->tty, &icount);
> +	if (ret)
> +		return;
> +
> +	if (icount.rx != trigger_data->rx ||
> +	    icount.tx != trigger_data->tx) {
> +		unsigned long delay_on = 100, delay_off = 100;
> +
> +		led_blink_set_oneshot(trigger_data->led_cdev,
> +				      &delay_on, &delay_off, 0);
> +
> +		trigger_data->rx = icount.rx;
> +		trigger_data->tx = icount.tx;
> +	}

Since you are polling this, anyway, can you just manipulate brightness
directly instead of using _oneshot()? _oneshot() will likely invoke
another set of workqueues.

LED triggers were meant to operate directly from the events, not based
on statistics like this.

Best regards,

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux