public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: android/timed_output: Create 'enable' attribute automatically
@ 2013-08-31 18:32 Guenter Roeck
  2013-08-31 20:55 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2013-08-31 18:32 UTC (permalink / raw)
  To: devel; +Cc: linux-kernel, Greg Kroah-Hartman, Kees Cook, Guenter Roeck

The 'enable' attribute is needed for all timed_output_class devices.
It can thus be created automatically when creating the timed_output device.
This simplifies the code and ensures that the attribute exists when the
udev event announcing device registration is generated.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Compile tested only.

 drivers/staging/android/timed_output.c |   54 +++++++++-----------------------
 1 file changed, 15 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
index ee3a57f..99cdb8f 100644
--- a/drivers/staging/android/timed_output.c
+++ b/drivers/staging/android/timed_output.c
@@ -24,7 +24,6 @@
 
 #include "timed_output.h"
 
-static struct class *timed_output_class;
 static atomic_t device_count;
 
 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
@@ -51,71 +50,48 @@ static ssize_t enable_store(
 	return size;
 }
 
-static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
+static struct device_attribute timed_output_attrs[] = {
+	__ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store),
+	{ }
+};
 
-static int create_timed_output_class(void)
-{
-	if (!timed_output_class) {
-		timed_output_class = class_create(THIS_MODULE, "timed_output");
-		if (IS_ERR(timed_output_class))
-			return PTR_ERR(timed_output_class);
-		atomic_set(&device_count, 0);
-	}
-
-	return 0;
-}
+static struct class timed_output_class = {
+	.owner = THIS_MODULE,
+	.name = "timed_output",
+	.dev_attrs = timed_output_attrs,
+};
 
 int timed_output_dev_register(struct timed_output_dev *tdev)
 {
-	int ret;
-
 	if (!tdev || !tdev->name || !tdev->enable || !tdev->get_time)
 		return -EINVAL;
 
-	ret = create_timed_output_class();
-	if (ret < 0)
-		return ret;
-
+	tdev->state = 0;
 	tdev->index = atomic_inc_return(&device_count);
-	tdev->dev = device_create(timed_output_class, NULL,
-		MKDEV(0, tdev->index), NULL, "%s", tdev->name);
+	tdev->dev = device_create(&timed_output_class, NULL,
+		MKDEV(0, tdev->index), tdev, "%s", tdev->name);
 	if (IS_ERR(tdev->dev))
 		return PTR_ERR(tdev->dev);
 
-	ret = device_create_file(tdev->dev, &dev_attr_enable);
-	if (ret < 0)
-		goto err_create_file;
-
-	dev_set_drvdata(tdev->dev, tdev);
-	tdev->state = 0;
 	return 0;
-
-err_create_file:
-	device_destroy(timed_output_class, MKDEV(0, tdev->index));
-	pr_err("failed to register driver %s\n",
-			tdev->name);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(timed_output_dev_register);
 
 void timed_output_dev_unregister(struct timed_output_dev *tdev)
 {
 	tdev->enable(tdev, 0);
-	device_remove_file(tdev->dev, &dev_attr_enable);
-	device_destroy(timed_output_class, MKDEV(0, tdev->index));
-	dev_set_drvdata(tdev->dev, NULL);
+	device_destroy(&timed_output_class, MKDEV(0, tdev->index));
 }
 EXPORT_SYMBOL_GPL(timed_output_dev_unregister);
 
 static int __init timed_output_init(void)
 {
-	return create_timed_output_class();
+	return class_register(&timed_output_class);
 }
 
 static void __exit timed_output_exit(void)
 {
-	class_destroy(timed_output_class);
+	class_unregister(&timed_output_class);
 }
 
 module_init(timed_output_init);
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: android/timed_output: Create 'enable' attribute automatically
  2013-08-31 18:32 [PATCH] staging: android/timed_output: Create 'enable' attribute automatically Guenter Roeck
@ 2013-08-31 20:55 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2013-08-31 20:55 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: devel, Greg Kroah-Hartman, linux-kernel, Kees Cook

On Sat, Aug 31, 2013 at 11:32:58AM -0700, Guenter Roeck wrote:
> The 'enable' attribute is needed for all timed_output_class devices.
> It can thus be created automatically when creating the timed_output device.
> This simplifies the code and ensures that the attribute exists when the
> udev event announcing device registration is generated.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

This patch has a bug so it was replaced by a v2 patch in a later thread.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-31 20:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-31 18:32 [PATCH] staging: android/timed_output: Create 'enable' attribute automatically Guenter Roeck
2013-08-31 20:55 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox