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>] [day] [month] [year] [list]
Message-Id: <20240305-pps-v1-1-d1a1d9f66695@marliere.net>
Date: Tue, 05 Mar 2024 17:09:35 -0300
From: "Ricardo B. Marliere" <ricardo@...liere.net>
To: Rodolfo Giometti <giometti@...eenne.com>
Cc: linux-kernel@...r.kernel.org, 
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
 "Ricardo B. Marliere" <ricardo@...liere.net>
Subject: [PATCH] pps: make pps_class constant

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the pps_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.

Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@...liere.net>
---
 drivers/pps/pps.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 5d19baae6a38..b902f4c66c10 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -26,7 +26,10 @@
  */
 
 static dev_t pps_devt;
-static struct class *pps_class;
+static const struct class pps_class = {
+	.name = "pps",
+	.dev_groups = pps_groups,
+};
 
 static DEFINE_MUTEX(pps_idr_lock);
 static DEFINE_IDR(pps_idr);
@@ -377,7 +380,7 @@ int pps_register_cdev(struct pps_device *pps)
 				pps->info.name, MAJOR(pps_devt), pps->id);
 		goto free_idr;
 	}
-	pps->dev = device_create(pps_class, pps->info.dev, devt, pps,
+	pps->dev = device_create(&pps_class, pps->info.dev, devt, pps,
 							"pps%d", pps->id);
 	if (IS_ERR(pps->dev)) {
 		err = PTR_ERR(pps->dev);
@@ -407,7 +410,7 @@ void pps_unregister_cdev(struct pps_device *pps)
 {
 	pr_debug("unregistering pps%d\n", pps->id);
 	pps->lookup_cookie = NULL;
-	device_destroy(pps_class, pps->dev->devt);
+	device_destroy(&pps_class, pps->dev->devt);
 }
 
 /*
@@ -448,7 +451,7 @@ EXPORT_SYMBOL(pps_lookup_dev);
 
 static void __exit pps_exit(void)
 {
-	class_destroy(pps_class);
+	class_unregister(&pps_class);
 	unregister_chrdev_region(pps_devt, PPS_MAX_SOURCES);
 }
 
@@ -456,12 +459,11 @@ static int __init pps_init(void)
 {
 	int err;
 
-	pps_class = class_create("pps");
-	if (IS_ERR(pps_class)) {
-		pr_err("failed to allocate class\n");
-		return PTR_ERR(pps_class);
+	err = class_register(&pps_class);
+	if (err) {
+		pr_err("failed to register class\n");
+		return err;
 	}
-	pps_class->dev_groups = pps_groups;
 
 	err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps");
 	if (err < 0) {
@@ -476,7 +478,7 @@ static int __init pps_init(void)
 	return 0;
 
 remove_class:
-	class_destroy(pps_class);
+	class_unregister(&pps_class);
 
 	return err;
 }

---
base-commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72
change-id: 20240305-pps-f3e4dcb46a8e

Best regards,
-- 
Ricardo B. Marliere <ricardo@...liere.net>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ