Skip to content

Commit 11680fd

Browse files
ivanorlov2206gregkh
authored andcommitted
virtio_console: make port class a static const structure
Now that the driver core allows for struct class to be in read-only memory, remove the class field of the ports_driver_data structure and create the port_class static class structure declared at build time which places it into read-only memory, instead of having it to be dynamically allocated at load time. Cc: Amit Shah <amit@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: virtualization@lists.linux-foundation.org Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230620143751.578239-16-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 98ab58a commit 11680fd

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

drivers/char/virtio_console.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
* across multiple devices and multiple ports per device.
4141
*/
4242
struct ports_driver_data {
43-
/* Used for registering chardevs */
44-
struct class *class;
45-
4643
/* Used for exporting per-port information to debugfs */
4744
struct dentry *debugfs_dir;
4845

@@ -55,6 +52,10 @@ struct ports_driver_data {
5552

5653
static struct ports_driver_data pdrvdata;
5754

55+
static const struct class port_class = {
56+
.name = "virtio-ports",
57+
};
58+
5859
static DEFINE_SPINLOCK(pdrvdata_lock);
5960
static DECLARE_COMPLETION(early_console_added);
6061

@@ -1399,7 +1400,7 @@ static int add_port(struct ports_device *portdev, u32 id)
13991400
"Error %d adding cdev for port %u\n", err, id);
14001401
goto free_cdev;
14011402
}
1402-
port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
1403+
port->dev = device_create(&port_class, &port->portdev->vdev->dev,
14031404
devt, port, "vport%up%u",
14041405
port->portdev->vdev->index, id);
14051406
if (IS_ERR(port->dev)) {
@@ -1465,7 +1466,7 @@ static int add_port(struct ports_device *portdev, u32 id)
14651466

14661467
free_inbufs:
14671468
free_device:
1468-
device_destroy(pdrvdata.class, port->dev->devt);
1469+
device_destroy(&port_class, port->dev->devt);
14691470
free_cdev:
14701471
cdev_del(port->cdev);
14711472
free_port:
@@ -1540,7 +1541,7 @@ static void unplug_port(struct port *port)
15401541
port->portdev = NULL;
15411542

15421543
sysfs_remove_group(&port->dev->kobj, &port_attribute_group);
1543-
device_destroy(pdrvdata.class, port->dev->devt);
1544+
device_destroy(&port_class, port->dev->devt);
15441545
cdev_del(port->cdev);
15451546

15461547
debugfs_remove(port->debugfs_file);
@@ -2244,12 +2245,9 @@ static int __init virtio_console_init(void)
22442245
{
22452246
int err;
22462247

2247-
pdrvdata.class = class_create("virtio-ports");
2248-
if (IS_ERR(pdrvdata.class)) {
2249-
err = PTR_ERR(pdrvdata.class);
2250-
pr_err("Error %d creating virtio-ports class\n", err);
2248+
err = class_register(&port_class);
2249+
if (err)
22512250
return err;
2252-
}
22532251

22542252
pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL);
22552253
INIT_LIST_HEAD(&pdrvdata.consoles);
@@ -2271,7 +2269,7 @@ static int __init virtio_console_init(void)
22712269
unregister_virtio_driver(&virtio_console);
22722270
free:
22732271
debugfs_remove_recursive(pdrvdata.debugfs_dir);
2274-
class_destroy(pdrvdata.class);
2272+
class_unregister(&port_class);
22752273
return err;
22762274
}
22772275

@@ -2282,7 +2280,7 @@ static void __exit virtio_console_fini(void)
22822280
unregister_virtio_driver(&virtio_console);
22832281
unregister_virtio_driver(&virtio_rproc_serial);
22842282

2285-
class_destroy(pdrvdata.class);
2283+
class_unregister(&port_class);
22862284
debugfs_remove_recursive(pdrvdata.debugfs_dir);
22872285
}
22882286
module_init(virtio_console_init);

0 commit comments

Comments
 (0)