* [PATCH] i2c: dev: make i2c_dev_class a static const structure
@ 2023-08-10 17:46 Ivan Orlov
2023-09-19 20:10 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Ivan Orlov @ 2023-08-10 17:46 UTC (permalink / raw)
To: wsa; +Cc: Ivan Orlov, linux-i2c, linux-kernel, gregkh
Now that the driver core allows for struct class to be in read-only
memory, move the i2c_dev_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
drivers/i2c/i2c-dev.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index a01b59e3599b..a91201509bc1 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -636,7 +636,10 @@ static const struct file_operations i2cdev_fops = {
/* ------------------------------------------------------------------------- */
-static struct class *i2c_dev_class;
+static const struct class i2c_dev_class = {
+ .name = "i2c-dev",
+ .dev_groups = i2c_groups,
+};
static void i2cdev_dev_release(struct device *dev)
{
@@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev)
device_initialize(&i2c_dev->dev);
i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr);
- i2c_dev->dev.class = i2c_dev_class;
+ i2c_dev->dev.class = &i2c_dev_class;
i2c_dev->dev.parent = &adap->dev;
i2c_dev->dev.release = i2cdev_dev_release;
@@ -751,12 +754,9 @@ static int __init i2c_dev_init(void)
if (res)
goto out;
- i2c_dev_class = class_create("i2c-dev");
- if (IS_ERR(i2c_dev_class)) {
- res = PTR_ERR(i2c_dev_class);
+ res = class_register(&i2c_dev_class);
+ if (res)
goto out_unreg_chrdev;
- }
- i2c_dev_class->dev_groups = i2c_groups;
/* Keep track of adapters which will be added or removed later */
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
@@ -769,7 +769,7 @@ static int __init i2c_dev_init(void)
return 0;
out_unreg_class:
- class_destroy(i2c_dev_class);
+ class_unregister(&i2c_dev_class);
out_unreg_chrdev:
unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
out:
@@ -781,7 +781,7 @@ static void __exit i2c_dev_exit(void)
{
bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier);
i2c_for_each_dev(NULL, i2c_dev_detach_adapter);
- class_destroy(i2c_dev_class);
+ class_unregister(&i2c_dev_class);
unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: dev: make i2c_dev_class a static const structure
2023-08-10 17:46 [PATCH] i2c: dev: make i2c_dev_class a static const structure Ivan Orlov
@ 2023-09-19 20:10 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2023-09-19 20:10 UTC (permalink / raw)
To: Ivan Orlov; +Cc: linux-i2c, linux-kernel, gregkh
[-- Attachment #1: Type: text/plain, Size: 464 bytes --]
On Thu, Aug 10, 2023 at 09:46:18PM +0400, Ivan Orlov wrote:
> Now that the driver core allows for struct class to be in read-only
> memory, move the i2c_dev_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.
>
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-19 20:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 17:46 [PATCH] i2c: dev: make i2c_dev_class a static const structure Ivan Orlov
2023-09-19 20:10 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).