bsr: make bsr_class a static const structure
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 2/9 dsp56k: make dsp56k_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the dsp56k_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
--- drivers/char/dsp56k.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/char/dsp56k.c +9 -9
@@ -101,7 +101,9 @@ static struct dsp56k_device {int tx_wsize, rx_wsize; } dsp56k; -static struct class *dsp56k_class; +static const struct class dsp56k_class = { + .name ="dsp56k" , +};static int dsp56k_reset (void ) {
@@ -493,7 +495,7 @@ static const char banner[] __initconst = KERN_INFO "DSP56k driver installed\n";static int __init dsp56k_init_driver (void ) { -int err =0 ; +int err;if (!MACH_IS_ATARI || !ATARIHW_PRESENT (DSP56K )) {printk ("DSP56k driver: Hardware not present\n" );
@@ -504,12 +506,10 @@ static int __init dsp56k_init_driver(void)printk ("DSP56k driver: Unable to register driver\n" );return -ENODEV ; } - dsp56k_class =class_create ("dsp56k" ); -if (IS_ERR (dsp56k_class)) { - err =PTR_ERR (dsp56k_class); + err =class_register (&dsp56k_class); +if (err) goto out_chrdev; - } -device_create (dsp56k_class,NULL ,MKDEV (DSP56K_MAJOR ,0 ),NULL , +device_create (&dsp56k_class,NULL ,MKDEV (DSP56K_MAJOR ,0 ),NULL ,"dsp56k" );printk (banner);
@@ -524,8 +524,8 @@ module_init(dsp56k_init_driver); static void __exit dsp56k_cleanup_driver(void) { -device_destroy (dsp56k_class,MKDEV (DSP56K_MAJOR ,0 )); -class_destroy (dsp56k_class); +device_destroy (&dsp56k_class,MKDEV (DSP56K_MAJOR ,0 )); +class_unregister (&dsp56k_class);unregister_chrdev (DSP56K_MAJOR ,"dsp56k" ); }module_exit (dsp56k_cleanup_driver);
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 1/9 bsr: make bsr_class a static const structure
From: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the bsr_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
--- drivers/char/bsr.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/char/bsr.c +10 -11
@@ -61,7 +61,6 @@ struct bsr_dev {static unsigned total_bsr_devs;static LIST_HEAD (bsr_devs); -static struct class *bsr_class;static int bsr_major;enum {
@@ -108,6 +107,11 @@ static struct attribute *bsr_dev_attrs[] = { };ATTRIBUTE_GROUPS (bsr_dev); +static const struct class bsr_class = { + .name ="bsr" , + .dev_groups = bsr_dev_groups, +}; +static int bsr_mmap (struct file *filp,struct vm_area_struct *vma) {unsigned long size = vma->vm_end - vma->vm_start;
@@ -244,7 +248,7 @@ static int bsr_add_node(struct device_node *bn) goto out_err; } - cur->bsr_device =device_create (bsr_class,NULL , cur->bsr_dev, + cur->bsr_device =device_create (&bsr_class,NULL , cur->bsr_dev, cur,"%s" , cur->bsr_name);if (IS_ERR (cur->bsr_device)) { printk(KERN_ERR "device_create failed for %s\n",
@@ -293,13 +297,9 @@ static int __init bsr_init(void)if (!np) goto out_err; - bsr_class =class_create ("bsr" ); -if (IS_ERR (bsr_class)) { -printk (KERN_ERR "class_create() failed for bsr_class\n" ); - ret =PTR_ERR (bsr_class); + ret =class_register (&bsr_class); +if (err) goto out_err_1; - } - bsr_class->dev_groups = bsr_dev_groups; ret =alloc_chrdev_region (&bsr_dev,0 ,BSR_MAX_DEVS ,"bsr" ); bsr_major =MAJOR (bsr_dev);
@@ -320,7 +320,7 @@ static int __init bsr_init(void)unregister_chrdev_region (bsr_dev,BSR_MAX_DEVS ); out_err_2: -class_destroy (bsr_class); +class_unregister (&bsr_class); out_err_1:of_node_put (np);
@@ -335,8 +335,7 @@ static void __exit bsr_exit(void)bsr_cleanup_devs (); -if (bsr_class) -class_destroy (bsr_class); +class_unregister (&bsr_class);if (bsr_major)unregister_chrdev_region (MKDEV (bsr_major,0 ),BSR_MAX_DEVS );
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 3/9 char: lp: make lp_class a static const structure
From: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the lp_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/lp.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/char/lp.c +9 -9
@@ -145,7 +145,9 @@ static struct lp_struct lp_table[LP_NO];static int port_num[LP_NO ];static unsigned int lp_count =0 ; -static struct class *lp_class; +static const struct class lp_class = { + .name ="printer" , +};#ifdef CONFIG_LP_CONSOLE static struct parport *console_registered;
@@ -932,7 +934,7 @@ static int lp_register(int nr, struct parport *port)if (reset)lp_reset (nr); -device_create (lp_class, port->dev,MKDEV (LP_MAJOR , nr),NULL , +device_create (&lp_class, port->dev,MKDEV (LP_MAJOR , nr),NULL ,"lp%d" , nr); printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
@@ -1004,7 +1006,7 @@ static void lp_detach(struct parport *port)if (port_num[n] == port->number) { port_num[n] =-1 ; lp_count--; -device_destroy (lp_class,MKDEV (LP_MAJOR , n)); +device_destroy (&lp_class,MKDEV (LP_MAJOR , n));parport_unregister_device (lp_table[n].dev); } }
@@ -1049,11 +1051,9 @@ static int __init lp_init(void)return -EIO ; } - lp_class =class_create ("printer" ); -if (IS_ERR (lp_class)) { - err =PTR_ERR (lp_class); + err =class_register (&lp_class); +if (err) goto out_reg; - }if (parport_register_driver (&lp_driver)) {printk (KERN_ERR "lp: unable to register with parport\n" );
@@ -1072,7 +1072,7 @@ static int __init lp_init(void)return 0 ; out_class: -class_destroy (lp_class); +class_unregister (&lp_class); out_reg:unregister_chrdev (LP_MAJOR ,"lp" );return err;
@@ -1115,7 +1115,7 @@ static void lp_cleanup_module(void)#endif unregister_chrdev (LP_MAJOR ,"lp" ); -class_destroy (lp_class); +class_unregister (&lp_class); }__setup ("lp=" , lp_setup);
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 4/9 /dev/mem: make mem_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the mem_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/mem.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/char/mem.c +9 -6
@@ -753,20 +753,23 @@ static char *mem_devnode(const struct device *dev, umode_t *mode)return NULL ; } -static struct class *mem_class; +static const struct class mem_class = { + .name ="mem" , + .devnode = mem_devnode, +};static int __init chr_dev_init (void ) { +int retval;int minor;if (register_chrdev (MEM_MAJOR ,"mem" , &memory_fops))printk ("unable to get major %d for memory devs\n" ,MEM_MAJOR ); - mem_class =class_create ("mem" ); -if (IS_ERR (mem_class)) -return PTR_ERR (mem_class); + retval =class_register (&mem_class); +if (retval) +return retval; - mem_class->devnode = mem_devnode;for (minor =1 ; minor <ARRAY_SIZE (devlist); minor++) {if (!devlist[minor].name)continue ;
@@ -777,7 +780,7 @@ static int __init chr_dev_init(void)if ((minor ==DEVPORT_MINOR ) && !arch_has_dev_port ())continue ; -device_create (mem_class,NULL ,MKDEV (MEM_MAJOR , minor), +device_create (&mem_class,NULL ,MKDEV (MEM_MAJOR , minor),NULL , devlist[minor].name); }
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 7/9 virtio_console: make port class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
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.
--- drivers/char/virtio_console.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/char/virtio_console.c +11 -13
@@ -40,9 +40,6 @@* across multiple devices and multiple ports per device. */ struct ports_driver_data { -/* Used for registering chardevs */ -struct class *class; -/* Used for exporting per-port information to debugfs */ struct dentry *debugfs_dir;
@@ -55,6 +52,10 @@ struct ports_driver_data {static struct ports_driver_data pdrvdata; +static const struct class port_class = { + .name ="virtio-ports" , +}; +static DEFINE_SPINLOCK (pdrvdata_lock);static DECLARE_COMPLETION (early_console_added);
@@ -1399,7 +1400,7 @@ static int add_port(struct ports_device *portdev, u32 id) "Error %d adding cdev for port %u\n", err, id); goto free_cdev; } - port->dev =device_create (pdrvdata.class, &port->portdev->vdev->dev, + port->dev =device_create (&port_class, &port->portdev->vdev->dev, devt, port,"vport%up%u" , port->portdev->vdev->index, id);if (IS_ERR (port->dev)) {
@@ -1465,7 +1466,7 @@ static int add_port(struct ports_device *portdev, u32 id) free_inbufs: free_device: -device_destroy (pdrvdata.class, port->dev->devt); +device_destroy (&port_class, port->dev->devt); free_cdev:cdev_del (port->cdev); free_port:
@@ -1540,7 +1541,7 @@ static void unplug_port(struct port *port) port->portdev =NULL ;sysfs_remove_group (&port->dev->kobj, &port_attribute_group); -device_destroy (pdrvdata.class, port->dev->devt); +device_destroy (&port_class, port->dev->devt);cdev_del (port->cdev);debugfs_remove (port->debugfs_file);
@@ -2244,12 +2245,9 @@ static int __init virtio_console_init(void) {int err; - pdrvdata.class =class_create ("virtio-ports" ); -if (IS_ERR (pdrvdata.class)) { - err =PTR_ERR (pdrvdata.class); -pr_err ("Error %d creating virtio-ports class\n" , err); + err =class_register (&port_class); +if (err)return err; - } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL );INIT_LIST_HEAD (&pdrvdata.consoles);
@@ -2271,7 +2269,7 @@ static int __init virtio_console_init(void)unregister_virtio_driver (&virtio_console); free:debugfs_remove_recursive (pdrvdata.debugfs_dir); -class_destroy (pdrvdata.class); +class_unregister (&port_class);return err; }
@@ -2282,7 +2280,7 @@ static void __exit virtio_console_fini(void)unregister_virtio_driver (&virtio_console);unregister_virtio_driver (&virtio_rproc_serial); -class_destroy (pdrvdata.class); +class_unregister (&port_class);debugfs_remove_recursive (pdrvdata.debugfs_dir); }module_init (virtio_console_init);
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Greg Kroah-Hartman
maintainerPATCH 5/9 char: misc: make misc_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the misc_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/misc.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/char/misc.c +20 -19
@@ -168,7 +168,21 @@ static int misc_open(struct inode *inode, struct file *file)return err; } -static struct class *misc_class; +static char *misc_devnode (const struct device *dev,umode_t *mode) +{ +const struct miscdevice *c =dev_get_drvdata (dev); + +if (mode && c->mode) + *mode = c->mode; +if (c->nodename) +return kstrdup (c->nodename,GFP_KERNEL ); +return NULL ; +} + +static const struct class misc_class = { + .name ="misc" , + .devnode = misc_devnode, +};static const struct file_operations misc_fops = { .owner =THIS_MODULE ,
@@ -226,7 +240,7 @@ int misc_register(struct miscdevice *misc) dev =MKDEV (MISC_MAJOR , misc->minor); misc->this_device = -device_create_with_groups (misc_class, misc->parent, dev, +device_create_with_groups (&misc_class, misc->parent, dev, misc, misc->groups,"%s" , misc->name);if (IS_ERR (misc->this_device)) {if (is_dynamic) {
@@ -263,43 +277,30 @@ void misc_deregister(struct miscdevice *misc)mutex_lock (&misc_mtx);list_del (&misc->list); -device_destroy (misc_class,MKDEV (MISC_MAJOR , misc->minor)); +device_destroy (&misc_class,MKDEV (MISC_MAJOR , misc->minor));misc_minor_free (misc->minor);mutex_unlock (&misc_mtx); }EXPORT_SYMBOL (misc_deregister); -static char *misc_devnode (const struct device *dev,umode_t *mode) -{ -const struct miscdevice *c =dev_get_drvdata (dev); - -if (mode && c->mode) - *mode = c->mode; -if (c->nodename) -return kstrdup (c->nodename,GFP_KERNEL ); -return NULL ; -} -static int __init misc_init (void ) {int err;struct proc_dir_entry *ret; ret =proc_create_seq ("misc" ,0 ,NULL , &misc_seq_ops); - misc_class =class_create ("misc" ); - err =PTR_ERR (misc_class); -if (IS_ERR (misc_class)) + err =class_register (&misc_class); +if (err) goto fail_remove; err = -EIO ;if (register_chrdev (MISC_MAJOR ,"misc" , &misc_fops)) goto fail_printk; - misc_class->devnode = misc_devnode;return 0 ; fail_printk:pr_err ("unable to get major %d for misc devices\n" ,MISC_MAJOR ); -class_destroy (misc_class); +class_unregister (&misc_class); fail_remove:if (ret)remove_proc_entry ("misc" ,NULL );
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 6/9 ppdev: make ppdev_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the ppdev_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/ppdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/char/ppdev.c +10 -9
@@ -773,7 +773,9 @@ static __poll_t pp_poll(struct file *file, poll_table *wait)return mask; } -static struct class *ppdev_class; +static const struct class ppdev_class = { + .name =CHRDEV , +};static const struct file_operations pp_fops = { .owner =THIS_MODULE ,
@@ -794,7 +796,7 @@ static void pp_attach(struct parport *port)if (devices[port->number])return ; - ret =device_create (ppdev_class, port->dev, + ret =device_create (&ppdev_class, port->dev,MKDEV (PP_MAJOR , port->number),NULL ,"parport%d" , port->number);if (IS_ERR (ret)) {
@@ -810,7 +812,7 @@ static void pp_detach(struct parport *port)if (!devices[port->number])return ; -device_destroy (ppdev_class,MKDEV (PP_MAJOR , port->number)); +device_destroy (&ppdev_class,MKDEV (PP_MAJOR , port->number)); devices[port->number] =NULL ; }
@@ -841,11 +843,10 @@ static int __init ppdev_init(void)pr_warn (CHRDEV ": unable to get major %d\n" ,PP_MAJOR );return -EIO ; } - ppdev_class =class_create (CHRDEV ); -if (IS_ERR (ppdev_class)) { - err =PTR_ERR (ppdev_class); + err =class_register (&ppdev_class); +if (err) goto out_chrdev; - } + err =parport_register_driver (&pp_driver);if (err <0 ) {pr_warn (CHRDEV ": unable to register with parport\n" );
@@ -856,7 +857,7 @@ static int __init ppdev_init(void) goto out; out_class: -class_destroy (ppdev_class); +class_unregister (&ppdev_class); out_chrdev:unregister_chrdev (PP_MAJOR ,CHRDEV ); out:
@@ -867,7 +868,7 @@ static void __exit ppdev_cleanup(void) {/* Clean up all parport stuff */ parport_unregister_driver (&pp_driver); -class_destroy (ppdev_class); +class_unregister (&ppdev_class);unregister_chrdev (PP_MAJOR ,CHRDEV ); }
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 8/9 xilinx_hwicap: make icap_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the icap_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/xilinx_hwicap/xilinx_hwicap.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/char/xilinx_hwicap/xilinx_hwicap.c +9 -5
@@ -113,7 +113,9 @@ static DEFINE_MUTEX(hwicap_mutex);static bool probed_devices[HWICAP_DEVICES ];static struct mutex icap_sem; -static struct class *icap_class; +static const struct class icap_class = { + .name ="xilinx_config" , +};#define UNIMPLEMENTED 0xFFFF
@@ -687,7 +689,7 @@ static int hwicap_setup(struct device *dev, int id, goto failed3; } -device_create (icap_class, dev, devt,NULL ,"%s%d" ,DRIVER_NAME , id); +device_create (&icap_class, dev, devt,NULL ,"%s%d" ,DRIVER_NAME , id);return 0 ;/* success */ failed3:
@@ -730,7 +732,7 @@ static int hwicap_remove(struct device *dev)if (!drvdata)return 0 ; -device_destroy (icap_class, drvdata->devt); +device_destroy (&icap_class, drvdata->devt);cdev_del (&drvdata->cdev);iounmap (drvdata->base_address);release_mem_region (drvdata->mem_start, drvdata->mem_size);
@@ -856,7 +858,9 @@ static int __init hwicap_module_init(void)dev_t devt;int retval; - icap_class =class_create ("xilinx_config" ); + retval =class_register (&icap_class); +if (retval) +return retval;mutex_init (&icap_sem); devt =MKDEV (XHWICAP_MAJOR ,XHWICAP_MINOR );
@@ -882,7 +886,7 @@ static void __exit hwicap_module_cleanup(void) {dev_t devt =MKDEV (XHWICAP_MAJOR ,XHWICAP_MINOR ); -class_destroy (icap_class); +class_unregister (&icap_class);platform_driver_unregister (&hwicap_platform_driver);
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerPATCH 9/9 char: xillybus: make xillybus_class a static const structure
In reply to Greg Kroah-HartmanFrom: Ivan Orlov <[email protected]>
Now that the driver core allows for struct class to be in read-only memory, move the xillybus_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time.
--- drivers/char/xillybus/xillybus_class.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/char/xillybus/xillybus_class.c +8 -13
@@ -23,7 +23,9 @@ MODULE_LICENSE("GPL v2");static DEFINE_MUTEX (unit_mutex);static LIST_HEAD (unit_list); -static struct class *xillybus_class; +static const struct class xillybus_class = { + .name ="xillybus" , +};#define UNITNAMELEN 16
@@ -121,7 +123,7 @@ int xillybus_init_chrdev(struct device *dev, len -= namelen +1 ; idt += namelen +1 ; - device = device_create(xillybus_class, + device = device_create(&xillybus_class, NULL, MKDEV(unit->major, i + unit->lowest_minor),
@@ -152,7 +154,7 @@ int xillybus_init_chrdev(struct device *dev, unroll_device_create:for (i--; i >=0 ; i--) -device_destroy (xillybus_class,MKDEV (unit->major, +device_destroy (&xillybus_class,MKDEV (unit->major, i + unit->lowest_minor));cdev_del (unit->cdev);
@@ -193,7 +195,7 @@ void xillybus_cleanup_chrdev(void *private_data,for (minor = unit->lowest_minor; minor < (unit->lowest_minor + unit->num_nodes); minor++) -device_destroy (xillybus_class,MKDEV (unit->major, minor)); +device_destroy (&xillybus_class,MKDEV (unit->major, minor));cdev_del (unit->cdev);
@@ -242,19 +244,12 @@ EXPORT_SYMBOL(xillybus_find_inode);static int __init xillybus_class_init (void ) { - xillybus_class =class_create ("xillybus" ); - -if (IS_ERR (xillybus_class)) { -pr_warn ("Failed to register xillybus class\n" ); - -return PTR_ERR (xillybus_class); - } -return 0 ; +return class_register (&xillybus_class); } static void __exit xillybus_class_exit(void) { -class_destroy (xillybus_class); +class_unregister (&xillybus_class); }module_init (xillybus_class_init);
Signature · 1 line
2.41.0
Re: [PATCH 9/9] char: xillybus: make xillybus_class a static const structure