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

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

 



Hi!

> > > > +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?
> > 
> > Yes, and it will have the same effect as writing 1:2. I wonder if this
> > is bad.

It is.

> > > > +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.
> > 
> > I copied that from the netdev trigger. I failed to find a suitable
> > helper function, did I miss that or does it need creating?

You don't need helper function. You are periodically checking the
statistics, anyway, so use it to turn the LED on/off directly, without
oneshot helper, which uses another workqueue internally.

> > > LED triggers were meant to operate directly from the events, not based
> > > on statistics like this.
> > 
> > Ditto; just copied from the netdev trigger. I tried to find a suitable
> > place to add a trigger in the core, but this is hard without having to
> > modify all drivers; additionally this is in thier hot path. So I
> > considered using statistics a good idea. Greg also liked it and someone
> > before us for the network trigger, too ...
> 
> This still looks ok to me, any objections to me merging it in my tty
> tree?

Yes.

I guess using statistics is kind-off acceptable, but the stuff I quote
above is not.

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Attachment: signature.asc
Description: Digital signature


[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