public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Richard Purdie <rpurdie@rpsys.net>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Russell King <rmk@arm.linux.org.uk>, John Lenz <lenz@cs.wisc.edu>,
	Pavel Machek <pavel@suse.cz>
Subject: Re: [RFC PATCH 1/8] LED: Add LED Class
Date: Tue, 6 Dec 2005 13:20:18 -0800	[thread overview]
Message-ID: <20051206212018.GB5937@kroah.com> (raw)
In-Reply-To: <1133788166.8101.125.camel@localhost.localdomain>

On Mon, Dec 05, 2005 at 01:09:26PM +0000, Richard Purdie wrote:
> +static void leds_class_release(struct class_device *dev)
> +{
> +	kfree(dev);
> +}
> +
> +static struct class leds_class = {
> +	.name		= "leds",
> +	.release	= leds_class_release,
> +};

Instead of this, just use class_create().  Then you don't need to
specify a release function at all.

> +/**
> + * leds_device_register - register a new object of led_device class.
> + * @dev: The device to register.
> + * @led_dev: the led_device structure for this device.
> + */
> +int leds_device_register(struct device *dev, struct led_device *led_dev)
> +{
> +	int rc;
> +
> +	led_dev->class_dev = kzalloc (sizeof (struct class_device), GFP_KERNEL);
> +	if (unlikely (!led_dev->class_dev))
> +		return -ENOMEM;
> +
> +	rwlock_init(&led_dev->lock);
> +
> +	led_dev->class_dev->class = &leds_class;
> +	led_dev->class_dev->dev = dev;
> +	led_dev->class_dev->class_data = led_dev;
> +
> +	/* assign this led its name */
> +	strncpy(led_dev->class_dev->class_id, led_dev->name, sizeof(led_dev->class_dev->class_id));
> +
> +	rc = class_device_register (led_dev->class_dev);

Use class_device_create() instead, it's simpler, and will work better
than creating your own class device in the future.

> +	if (unlikely (rc)) {
> +		kfree (led_dev->class_dev);
> +		return rc;
> +	}
> +
> +	/* register the attributes */
> +	class_device_create_file(led_dev->class_dev, &class_device_attr_brightness);
> +
> +	/* add to the list of leds */
> +	write_lock(&leds_list_lock);
> +	list_add_tail(&led_dev->node, &leds_list);
> +	write_unlock(&leds_list_lock);
> +
> +	printk(KERN_INFO "Registered led device: %s\n", led_dev->class_dev->class_id);
> +
> +	return 0;
> +}
> +
> +/**
> + * leds_device_unregister - unregisters a object of led_properties class.
> + * @led_dev: the led device to unreigister
> + *
> + * Unregisters a previously registered via leds_device_register object.
> + */
> +void leds_device_unregister(struct led_device *led_dev)
> +{
> +	class_device_remove_file (led_dev->class_dev, &class_device_attr_brightness);
> +
> +	class_device_unregister(led_dev->class_dev);
> +
> +	write_lock(&leds_list_lock);
> +	list_del(&led_dev->node);
> +	write_unlock(&leds_list_lock);
> +}
> +
> +EXPORT_SYMBOL(leds_device_suspend);
> +EXPORT_SYMBOL(leds_device_resume);
> +EXPORT_SYMBOL(leds_device_register);
> +EXPORT_SYMBOL(leds_device_unregister);

EXPORT_SYMBOL_GPL() perhaps?


> +
> +static int __init leds_init(void)
> +{
> +	return class_register(&leds_class);
> +}
> +
> +static void __exit leds_exit(void)
> +{
> +	class_unregister(&leds_class);

class_destroy() instead, if you use class_create().

Other than these minor things, looks good to me.

thanks,

greg k-h

      parent reply	other threads:[~2005-12-06 21:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-05 13:09 [RFC PATCH 1/8] LED: Add LED Class Richard Purdie
2005-12-05 14:59 ` David Vrabel
2005-12-05 15:38   ` Richard Purdie
2005-12-05 17:02   ` Pavel Machek
2005-12-06 21:20 ` Greg KH [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=20051206212018.GB5937@kroah.com \
    --to=greg@kroah.com \
    --cc=lenz@cs.wisc.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    --cc=rmk@arm.linux.org.uk \
    --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