Commit cdb55bdb authored by Ivan Orlov's avatar Ivan Orlov Committed by Wolfram Sang

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: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent bcfaaa97
...@@ -636,7 +636,10 @@ static const struct file_operations i2cdev_fops = { ...@@ -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) static void i2cdev_dev_release(struct device *dev)
{ {
...@@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev) ...@@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev)
device_initialize(&i2c_dev->dev); device_initialize(&i2c_dev->dev);
i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr); 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.parent = &adap->dev;
i2c_dev->dev.release = i2cdev_dev_release; i2c_dev->dev.release = i2cdev_dev_release;
...@@ -751,12 +754,9 @@ static int __init i2c_dev_init(void) ...@@ -751,12 +754,9 @@ static int __init i2c_dev_init(void)
if (res) if (res)
goto out; goto out;
i2c_dev_class = class_create("i2c-dev"); res = class_register(&i2c_dev_class);
if (IS_ERR(i2c_dev_class)) { if (res)
res = PTR_ERR(i2c_dev_class);
goto out_unreg_chrdev; goto out_unreg_chrdev;
}
i2c_dev_class->dev_groups = i2c_groups;
/* Keep track of adapters which will be added or removed later */ /* Keep track of adapters which will be added or removed later */
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
...@@ -769,7 +769,7 @@ static int __init i2c_dev_init(void) ...@@ -769,7 +769,7 @@ static int __init i2c_dev_init(void)
return 0; return 0;
out_unreg_class: out_unreg_class:
class_destroy(i2c_dev_class); class_unregister(&i2c_dev_class);
out_unreg_chrdev: out_unreg_chrdev:
unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
out: out:
...@@ -781,7 +781,7 @@ static void __exit i2c_dev_exit(void) ...@@ -781,7 +781,7 @@ static void __exit i2c_dev_exit(void)
{ {
bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier); bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier);
i2c_for_each_dev(NULL, i2c_dev_detach_adapter); 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); unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment