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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240305-class_cleanup-media-v1-1-53e1538973cd@marliere.net>
Date: Tue, 05 Mar 2024 10:26:25 -0300
From: "Ricardo B. Marliere" <ricardo@...liere.net>
To: Mauro Carvalho Chehab <mchehab@...nel.org>, Sean Young <sean@...s.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
 linux-media@...r.kernel.org, linux-kernel@...r.kernel.org, 
 "Ricardo B. Marliere" <ricardo@...liere.net>
Subject: [PATCH 1/2] media: dvbdev: make dvb_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 dvb_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/media/dvb-core/dvbdev.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 733d0bc4b4cc..dcbf68b00240 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -78,7 +78,13 @@ static const u8 minor_type[] = {
 #define MAX_DVB_MINORS		(DVB_MAX_ADAPTERS * 64)
 #endif
 
-static struct class *dvb_class;
+static int dvb_uevent(const struct device *dev, struct kobj_uevent_env *env);
+static char *dvb_devnode(const struct device *dev, umode_t *mode);
+static const struct class dvb_class = {
+	.name = "dvb",
+	.dev_uevent = dvb_uevent,
+	.devnode = dvb_devnode,
+};
 
 static struct dvb_device *dvb_minors[MAX_DVB_MINORS];
 static DECLARE_RWSEM(minor_rwsem);
@@ -561,7 +567,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 		return ret;
 	}
 
-	clsdev = device_create(dvb_class, adap->device,
+	clsdev = device_create(&dvb_class, adap->device,
 			       MKDEV(DVB_MAJOR, minor),
 			       dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id);
 	if (IS_ERR(clsdev)) {
@@ -600,7 +606,7 @@ void dvb_remove_device(struct dvb_device *dvbdev)
 
 	dvb_media_device_free(dvbdev);
 
-	device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
+	device_destroy(&dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
 
 	list_del(&dvbdev->list_head);
 }
@@ -1096,13 +1102,10 @@ static int __init init_dvbdev(void)
 		goto error;
 	}
 
-	dvb_class = class_create("dvb");
-	if (IS_ERR(dvb_class)) {
-		retval = PTR_ERR(dvb_class);
+	retval = class_register(&dvb_class);
+	if (retval != 0)
 		goto error;
-	}
-	dvb_class->dev_uevent = dvb_uevent;
-	dvb_class->devnode = dvb_devnode;
+
 	return 0;
 
 error:
@@ -1115,7 +1118,7 @@ static void __exit exit_dvbdev(void)
 {
 	struct dvbdevfops_node *node, *next;
 
-	class_destroy(dvb_class);
+	class_unregister(&dvb_class);
 	cdev_del(&dvb_device_cdev);
 	unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
 

-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ