lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 31 Aug 2013 11:32:58 -0700
From:	Guenter Roeck <linux@...ck-us.net>
To:	devel@...verdev.osuosl.org
Cc:	linux-kernel@...r.kernel.org,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Kees Cook <keescook@...omium.org>,
	Guenter Roeck <linux@...ck-us.net>
Subject: [PATCH] staging: android/timed_output: Create 'enable' attribute automatically

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@...ck-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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ