linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@denx.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Dan Murphy <dmurphy@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v5 3/3] leds: trigger: implement a tty trigger
Date: Sat, 21 Dec 2019 19:40:47 +0100	[thread overview]
Message-ID: <20191221184047.GC32732@amd> (raw)
In-Reply-To: <20191219093947.15502-4-u.kleine-koenig@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 2295 bytes --]

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@vger.kernel.org
> +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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2019-12-21 18:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  9:39 [PATCH v5 0/3] tty/leds: implement a trigger for ttys Uwe Kleine-König
2019-12-19  9:39 ` [PATCH v5 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared() Uwe Kleine-König
2019-12-19  9:39 ` [PATCH v5 2/3] tty: new helper function tty_get_icount() Uwe Kleine-König
2019-12-19  9:39 ` [PATCH v5 3/3] leds: trigger: implement a tty trigger Uwe Kleine-König
2019-12-21 18:40   ` Pavel Machek [this message]
2019-12-23 10:08     ` Uwe Kleine-König
2020-01-06 18:59       ` Greg Kroah-Hartman
2020-01-07  7:29         ` Uwe Kleine-König
2020-01-07  7:44           ` Greg Kroah-Hartman
2020-01-07  9:34         ` Pavel Machek

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=20191221184047.GC32732@amd \
    --to=pavel@denx.de \
    --cc=dmurphy@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=jslaby@suse.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).