public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <shuahkhan@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: shuahkhan@gmail.com, neilb@suse.de,
	LKML <linux-kernel@vger.kernel.org>,
	Jonas Bonn <jonas@southpole.se>,
	Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: Re: [PATCH ] leds: add new transient trigger for one shot timer support
Date: Fri, 20 Apr 2012 16:48:38 -0600	[thread overview]
Message-ID: <1334962118.3255.40.camel@lorien2> (raw)
In-Reply-To: <20120420141914.a3235c61.akpm@linux-foundation.org>


> 
> Are there no comments from anyone on this?
Thanks for the comments.
> 
> >
> > ...
> >
> > config LEDS_TRIGGER_TRANSIENT
> > +	tristate "LED Transient Trigger"
> > +	depends on LEDS_TRIGGERS
> > +	help
> > +	  This allows one time enable of a transient state on GPIO/PWM based
> > +	  hadrware.
> 
> Make it "This allows one time enabling of a transient state on GPIO/PWM
> based hardware."
Will do.
> 
> > +	  If unsure, say Y.
> > +
> >
> > ...
> >
> > +static void transient_timer_function(unsigned long data)
> > +{
> > +	struct led_classdev *led_cdev = (struct led_classdev *) data;
> > +	struct transient_trig_data *transient_data = led_cdev->trigger_data;
> > +
> > +	if (transient_data->transient_enabled) {
> > +		transient_data->transient_enabled = 0;
> > +		led_cdev->brightness_set(led_cdev, LED_OFF);
> > +		del_timer(&transient_data->timer);
> 
> Deleting the timer from within its handler is ...  odd.  Also it is a
> bit racy against a concurrent add_timer() on a different CPU.
Good point. Will fix.
> 
> > +	}
> > +}
> > +
> >
> > ...
> >
> > +static ssize_t led_transient_enabled_store(struct device *dev,
> > +		struct device_attribute *attr, const char *buf, size_t size)
> > +{
> > +	struct led_classdev *led_cdev = dev_get_drvdata(dev);
> > +	struct transient_trig_data *transient_data = led_cdev->trigger_data;
> > +	unsigned long state;
> > +	ssize_t ret = -EINVAL;
> > +
> > +	ret = kstrtoul(buf, 10, &state);
> > +	if (ret)
> > +		return ret;
> > +
> > +	if (state != 1 && state != 0)
> > +		return ret;
> 
> Bug - we'll return 0 here.  Use "return -EINVAL" and remove the above
> initialisation of `ret'.

Good point. Will fix.
> 
> 
> > +	/* cancel the running timer */
> > +	if (state == 0) {
> > +		transient_timer_function((unsigned long) led_cdev);
> 
> And this is perhaps why transient_timer_function() does del_timer().
> 
> I suggest it would be cleaner and simpler to do
> 
> 	transient_data->transient_enabled = 0;
> 	del_timer(...);
> 
> right here.

Will fix it.
> 
> This is all rather racy in its handling of ->transient_enabled (at
> least), but afacit the races are harmless.

I am a bit concerned about it as well. Does adding a mutex to
trigger_data a good way to go to protect transient_enabled? I will give
that a try.

> The typecast is unneeded.
ok
> 
> > +	/* start timer with transient_time value */
> > +	if (state == 1 && transient_data->transient_time != 0) {
> > +		led_cdev->brightness_set(led_cdev, LED_FULL);
> > +		mod_timer(&transient_data->timer,
> > +			  jiffies + transient_data->transient_time);
> > +	}
> > +
> > +	return size;
> > +}
> > +
> >
> > ...
> >
> > +static ssize_t led_transient_time_store(struct device *dev,
> > +		struct device_attribute *attr, const char *buf, size_t size)
> > +{
> > +	struct led_classdev *led_cdev = dev_get_drvdata(dev);
> > +	struct transient_trig_data *transient_data = led_cdev->trigger_data;
> > +	unsigned long state;
> > +	ssize_t ret = -EINVAL;
> 
> Unneeded initialisation.
Yup
> 
> > +	ret = kstrtoul(buf, 10, &state);
> > +	if (ret)
> > +		return ret;
> > +
> > +	transient_data->transient_time = state;
> > +
> > +	return size;
> > +}
> > +
> >
> > ...
> >
> > +static void transient_trig_deactivate(struct led_classdev *led_cdev)
> > +{
> > +	struct transient_trig_data *transient_data = led_cdev->trigger_data;
> > +
> > +	if (led_cdev->activated) {
> > +		device_remove_file(led_cdev->dev, &dev_attr_transient_enabled);
> > +		device_remove_file(led_cdev->dev, &dev_attr_transient_time);
> > +		del_timer_sync(&transient_data->timer);
> > +		led_cdev->trigger_data = NULL;
> > +		led_cdev->activated = false;
> > +		kfree(transient_data);
> 
> OK.  But it might be nicer to kill off the timer before doing anything else.
Yes that is correct - will fix it.
> 
> > +	}
> > +	printk(KERN_DEBUG "Deativated led transient trigger %s\n",
> > +		led_cdev->name);
> > +}
> > +
> >
> > ...
> >
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



  reply	other threads:[~2012-04-20 22:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-01 19:53 [PATCH RESEND] LEDS-One-Shot-Timer-Trigger-implementation Shuah Khan
2012-04-03 15:06 ` Shuah Khan
2012-04-06 23:53 ` Andrew Morton
2012-04-07 14:13   ` Shuah Khan
2012-04-07 21:56     ` Dmitry Torokhov
2012-04-08 23:42       ` NeilBrown
2012-04-09  0:06         ` Dmitry Torokhov
2012-04-09 22:25           ` NeilBrown
2012-04-10  8:21             ` Dmitry Torokhov
2012-04-09 16:55       ` Shuah Khan
2012-04-09 17:37         ` Dmitry Torokhov
2012-04-09 18:16           ` Shuah Khan
2012-04-09 18:45             ` Dmitry Torokhov
2012-04-09 20:20               ` Shuah Khan
2012-04-09 20:42                 ` Dmitry Torokhov
2012-04-09 22:40                   ` Shuah Khan
2012-04-10  7:17                     ` Dmitry Torokhov
2012-04-10 18:34                       ` Shuah Khan
2012-04-08 23:58   ` NeilBrown
2012-04-10 13:24 ` Richard Purdie
2012-04-10 15:31   ` Shuah Khan
2012-04-11 10:05     ` Richard Purdie
2012-04-11 15:33       ` Shuah Khan
2012-04-15 16:35   ` Shuah Khan
2012-04-15 22:34     ` [PATCH 1/1] leds: add "kickable" LED trigger Jonas Bonn
2012-04-15 22:37       ` Jonas Bonn
2012-04-16 15:28         ` Shuah Khan
2012-04-16 22:33           ` Jonas Bonn
2012-04-16 23:05             ` Shuah Khan
2012-04-20  4:04     ` [PATCH ] leds: add new transient trigger for one shot timer support Shuah Khan
2012-04-20 21:19       ` Andrew Morton
2012-04-20 22:48         ` Shuah Khan [this message]
2012-04-21  4:41       ` Jonas Bonn
2012-04-22 23:51         ` Shuah Khan
2012-04-23  1:56           ` NeilBrown
2012-04-23  5:29             ` Jonas Bonn
2012-04-23  5:45               ` NeilBrown
2012-04-23 22:22                 ` Shuah Khan
2012-04-25 17:42                   ` [PATCH v2] leds: add new transient trigger for one shot timer activation Shuah Khan
2012-04-26  6:02                     ` NeilBrown
2012-04-26 14:48                       ` Shuah Khan
2012-04-26 23:00                     ` Andrew Morton
2012-04-30 20:33                       ` [PATCH v3] " Shuah Khan
2012-04-23  5:07           ` [PATCH ] leds: add new transient trigger for one shot timer support Jonas Bonn

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=1334962118.3255.40.camel@lorien2 \
    --to=shuahkhan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jonas@southpole.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=richard.purdie@linuxfoundation.org \
    /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