Skip to content

Commit cdb55bd

Browse files
ivanorlov2206wsakernel
authored andcommitted
i2c: dev: make i2c_dev_class a static const structure
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> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent bcfaaa9 commit cdb55bd

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

drivers/i2c/i2c-dev.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,10 @@ static const struct file_operations i2cdev_fops = {
636636

637637
/* ------------------------------------------------------------------------- */
638638

639-
static struct class *i2c_dev_class;
639+
static const struct class i2c_dev_class = {
640+
.name = "i2c-dev",
641+
.dev_groups = i2c_groups,
642+
};
640643

641644
static void i2cdev_dev_release(struct device *dev)
642645
{
@@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev)
665668

666669
device_initialize(&i2c_dev->dev);
667670
i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr);
668-
i2c_dev->dev.class = i2c_dev_class;
671+
i2c_dev->dev.class = &i2c_dev_class;
669672
i2c_dev->dev.parent = &adap->dev;
670673
i2c_dev->dev.release = i2cdev_dev_release;
671674

@@ -751,12 +754,9 @@ static int __init i2c_dev_init(void)
751754
if (res)
752755
goto out;
753756

754-
i2c_dev_class = class_create("i2c-dev");
755-
if (IS_ERR(i2c_dev_class)) {
756-
res = PTR_ERR(i2c_dev_class);
757+
res = class_register(&i2c_dev_class);
758+
if (res)
757759
goto out_unreg_chrdev;
758-
}
759-
i2c_dev_class->dev_groups = i2c_groups;
760760

761761
/* Keep track of adapters which will be added or removed later */
762762
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
@@ -769,7 +769,7 @@ static int __init i2c_dev_init(void)
769769
return 0;
770770

771771
out_unreg_class:
772-
class_destroy(i2c_dev_class);
772+
class_unregister(&i2c_dev_class);
773773
out_unreg_chrdev:
774774
unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
775775
out:
@@ -781,7 +781,7 @@ static void __exit i2c_dev_exit(void)
781781
{
782782
bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier);
783783
i2c_for_each_dev(NULL, i2c_dev_detach_adapter);
784-
class_destroy(i2c_dev_class);
784+
class_unregister(&i2c_dev_class);
785785
unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
786786
}
787787

0 commit comments

Comments
 (0)