vduse: make vduse_class constant

Message ID 2023100643-tricolor-citizen-6c2d@gregkh
State New
Headers
Series vduse: make vduse_class constant |

Commit Message

Greg KH Oct. 6, 2023, 2:30 p.m. UTC
  Now that the driver core allows for struct class to be in read-only
memory, we should make all 'class' structures declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at runtime.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++--------------
 1 file changed, 21 insertions(+), 19 deletions(-)
  

Comments

Yongji Xie Oct. 7, 2023, 8:21 a.m. UTC | #1
On Fri, Oct 6, 2023 at 10:31 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> Now that the driver core allows for struct class to be in read-only
> memory, we should make all 'class' structures declared at build time
> placing them into read-only memory, instead of having to be dynamically
> allocated at runtime.
>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Cc: Xie Yongji <xieyongji@bytedance.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---

Reviewed-by: Xie Yongji <xieyongji@bytedance.com>

Thanks,
Yongji

>  drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index df7869537ef1..0ddd4b8abecb 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock);
>  static DEFINE_IDR(vduse_idr);
>
>  static dev_t vduse_major;
> -static struct class *vduse_class;
>  static struct cdev vduse_ctrl_cdev;
>  static struct cdev vduse_cdev;
>  static struct workqueue_struct *vduse_irq_wq;
> @@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type = {
>         .default_groups = vq_groups,
>  };
>
> +static char *vduse_devnode(const struct device *dev, umode_t *mode)
> +{
> +       return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> +}
> +
> +static const struct class vduse_class = {
> +       .name = "vduse",
> +       .devnode = vduse_devnode,
> +};
> +
>  static void vduse_dev_deinit_vqs(struct vduse_dev *dev)
>  {
>         int i;
> @@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name)
>         mutex_unlock(&dev->lock);
>
>         vduse_dev_reset(dev);
> -       device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +       device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>         idr_remove(&vduse_idr, dev->minor);
>         kvfree(dev->config);
>         vduse_dev_deinit_vqs(dev);
> @@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>
>         dev->minor = ret;
>         dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
> -       dev->dev = device_create_with_groups(vduse_class, NULL,
> +       dev->dev = device_create_with_groups(&vduse_class, NULL,
>                                 MKDEV(MAJOR(vduse_major), dev->minor),
>                                 dev, vduse_dev_groups, "%s", config->name);
>         if (IS_ERR(dev->dev)) {
> @@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>
>         return 0;
>  err_vqs:
> -       device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +       device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>  err_dev:
>         idr_remove(&vduse_idr, dev->minor);
>  err_idr:
> @@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fops = {
>         .llseek         = noop_llseek,
>  };
>
> -static char *vduse_devnode(const struct device *dev, umode_t *mode)
> -{
> -       return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> -}
> -
>  struct vduse_mgmt_dev {
>         struct vdpa_mgmt_dev mgmt_dev;
>         struct device dev;
> @@ -2082,11 +2086,9 @@ static int vduse_init(void)
>         int ret;
>         struct device *dev;
>
> -       vduse_class = class_create("vduse");
> -       if (IS_ERR(vduse_class))
> -               return PTR_ERR(vduse_class);
> -
> -       vduse_class->devnode = vduse_devnode;
> +       ret = class_register(&vduse_class);
> +       if (ret)
> +               return ret;
>
>         ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
>         if (ret)
> @@ -2099,7 +2101,7 @@ static int vduse_init(void)
>         if (ret)
>                 goto err_ctrl_cdev;
>
> -       dev = device_create(vduse_class, NULL, vduse_major, NULL, "control");
> +       dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control");
>         if (IS_ERR(dev)) {
>                 ret = PTR_ERR(dev);
>                 goto err_device;
> @@ -2141,13 +2143,13 @@ static int vduse_init(void)
>  err_wq:
>         cdev_del(&vduse_cdev);
>  err_cdev:
> -       device_destroy(vduse_class, vduse_major);
> +       device_destroy(&vduse_class, vduse_major);
>  err_device:
>         cdev_del(&vduse_ctrl_cdev);
>  err_ctrl_cdev:
>         unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
>  err_chardev_region:
> -       class_destroy(vduse_class);
> +       class_unregister(&vduse_class);
>         return ret;
>  }
>  module_init(vduse_init);
> @@ -2159,10 +2161,10 @@ static void vduse_exit(void)
>         destroy_workqueue(vduse_irq_bound_wq);
>         destroy_workqueue(vduse_irq_wq);
>         cdev_del(&vduse_cdev);
> -       device_destroy(vduse_class, vduse_major);
> +       device_destroy(&vduse_class, vduse_major);
>         cdev_del(&vduse_ctrl_cdev);
>         unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
> -       class_destroy(vduse_class);
> +       class_unregister(&vduse_class);
>  }
>  module_exit(vduse_exit);
>
> --
> 2.42.0
>
  
Jason Wang Oct. 8, 2023, 5:28 a.m. UTC | #2
On Fri, Oct 6, 2023 at 10:31 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> Now that the driver core allows for struct class to be in read-only
> memory, we should make all 'class' structures declared at build time
> placing them into read-only memory, instead of having to be dynamically
> allocated at runtime.
>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Cc: Xie Yongji <xieyongji@bytedance.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index df7869537ef1..0ddd4b8abecb 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock);
>  static DEFINE_IDR(vduse_idr);
>
>  static dev_t vduse_major;
> -static struct class *vduse_class;
>  static struct cdev vduse_ctrl_cdev;
>  static struct cdev vduse_cdev;
>  static struct workqueue_struct *vduse_irq_wq;
> @@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type = {
>         .default_groups = vq_groups,
>  };
>
> +static char *vduse_devnode(const struct device *dev, umode_t *mode)
> +{
> +       return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> +}
> +
> +static const struct class vduse_class = {
> +       .name = "vduse",
> +       .devnode = vduse_devnode,
> +};
> +
>  static void vduse_dev_deinit_vqs(struct vduse_dev *dev)
>  {
>         int i;
> @@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name)
>         mutex_unlock(&dev->lock);
>
>         vduse_dev_reset(dev);
> -       device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +       device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>         idr_remove(&vduse_idr, dev->minor);
>         kvfree(dev->config);
>         vduse_dev_deinit_vqs(dev);
> @@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>
>         dev->minor = ret;
>         dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
> -       dev->dev = device_create_with_groups(vduse_class, NULL,
> +       dev->dev = device_create_with_groups(&vduse_class, NULL,
>                                 MKDEV(MAJOR(vduse_major), dev->minor),
>                                 dev, vduse_dev_groups, "%s", config->name);
>         if (IS_ERR(dev->dev)) {
> @@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>
>         return 0;
>  err_vqs:
> -       device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +       device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>  err_dev:
>         idr_remove(&vduse_idr, dev->minor);
>  err_idr:
> @@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fops = {
>         .llseek         = noop_llseek,
>  };
>
> -static char *vduse_devnode(const struct device *dev, umode_t *mode)
> -{
> -       return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> -}
> -
>  struct vduse_mgmt_dev {
>         struct vdpa_mgmt_dev mgmt_dev;
>         struct device dev;
> @@ -2082,11 +2086,9 @@ static int vduse_init(void)
>         int ret;
>         struct device *dev;
>
> -       vduse_class = class_create("vduse");
> -       if (IS_ERR(vduse_class))
> -               return PTR_ERR(vduse_class);
> -
> -       vduse_class->devnode = vduse_devnode;
> +       ret = class_register(&vduse_class);
> +       if (ret)
> +               return ret;
>
>         ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
>         if (ret)
> @@ -2099,7 +2101,7 @@ static int vduse_init(void)
>         if (ret)
>                 goto err_ctrl_cdev;
>
> -       dev = device_create(vduse_class, NULL, vduse_major, NULL, "control");
> +       dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control");
>         if (IS_ERR(dev)) {
>                 ret = PTR_ERR(dev);
>                 goto err_device;
> @@ -2141,13 +2143,13 @@ static int vduse_init(void)
>  err_wq:
>         cdev_del(&vduse_cdev);
>  err_cdev:
> -       device_destroy(vduse_class, vduse_major);
> +       device_destroy(&vduse_class, vduse_major);
>  err_device:
>         cdev_del(&vduse_ctrl_cdev);
>  err_ctrl_cdev:
>         unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
>  err_chardev_region:
> -       class_destroy(vduse_class);
> +       class_unregister(&vduse_class);
>         return ret;
>  }
>  module_init(vduse_init);
> @@ -2159,10 +2161,10 @@ static void vduse_exit(void)
>         destroy_workqueue(vduse_irq_bound_wq);
>         destroy_workqueue(vduse_irq_wq);
>         cdev_del(&vduse_cdev);
> -       device_destroy(vduse_class, vduse_major);
> +       device_destroy(&vduse_class, vduse_major);
>         cdev_del(&vduse_ctrl_cdev);
>         unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
> -       class_destroy(vduse_class);
> +       class_unregister(&vduse_class);
>  }
>  module_exit(vduse_exit);
>
> --
> 2.42.0
>
  
Michael S. Tsirkin Oct. 8, 2023, 6:20 a.m. UTC | #3
On Fri, Oct 06, 2023 at 04:30:44PM +0200, Greg Kroah-Hartman wrote:
> Now that the driver core allows for struct class to be in read-only
> memory, we should make all 'class' structures declared at build time
> placing them into read-only memory, instead of having to be dynamically
> allocated at runtime.
> 
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Cc: Xie Yongji <xieyongji@bytedance.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

Greg should I merge it or do you intend to merge all these patches?

> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index df7869537ef1..0ddd4b8abecb 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock);
>  static DEFINE_IDR(vduse_idr);
>  
>  static dev_t vduse_major;
> -static struct class *vduse_class;
>  static struct cdev vduse_ctrl_cdev;
>  static struct cdev vduse_cdev;
>  static struct workqueue_struct *vduse_irq_wq;
> @@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type = {
>  	.default_groups	= vq_groups,
>  };
>  
> +static char *vduse_devnode(const struct device *dev, umode_t *mode)
> +{
> +	return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> +}
> +
> +static const struct class vduse_class = {
> +	.name = "vduse",
> +	.devnode = vduse_devnode,
> +};
> +
>  static void vduse_dev_deinit_vqs(struct vduse_dev *dev)
>  {
>  	int i;
> @@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name)
>  	mutex_unlock(&dev->lock);
>  
>  	vduse_dev_reset(dev);
> -	device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +	device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>  	idr_remove(&vduse_idr, dev->minor);
>  	kvfree(dev->config);
>  	vduse_dev_deinit_vqs(dev);
> @@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>  
>  	dev->minor = ret;
>  	dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
> -	dev->dev = device_create_with_groups(vduse_class, NULL,
> +	dev->dev = device_create_with_groups(&vduse_class, NULL,
>  				MKDEV(MAJOR(vduse_major), dev->minor),
>  				dev, vduse_dev_groups, "%s", config->name);
>  	if (IS_ERR(dev->dev)) {
> @@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>  
>  	return 0;
>  err_vqs:
> -	device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
> +	device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
>  err_dev:
>  	idr_remove(&vduse_idr, dev->minor);
>  err_idr:
> @@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fops = {
>  	.llseek		= noop_llseek,
>  };
>  
> -static char *vduse_devnode(const struct device *dev, umode_t *mode)
> -{
> -	return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
> -}
> -
>  struct vduse_mgmt_dev {
>  	struct vdpa_mgmt_dev mgmt_dev;
>  	struct device dev;
> @@ -2082,11 +2086,9 @@ static int vduse_init(void)
>  	int ret;
>  	struct device *dev;
>  
> -	vduse_class = class_create("vduse");
> -	if (IS_ERR(vduse_class))
> -		return PTR_ERR(vduse_class);
> -
> -	vduse_class->devnode = vduse_devnode;
> +	ret = class_register(&vduse_class);
> +	if (ret)
> +		return ret;
>  
>  	ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
>  	if (ret)
> @@ -2099,7 +2101,7 @@ static int vduse_init(void)
>  	if (ret)
>  		goto err_ctrl_cdev;
>  
> -	dev = device_create(vduse_class, NULL, vduse_major, NULL, "control");
> +	dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control");
>  	if (IS_ERR(dev)) {
>  		ret = PTR_ERR(dev);
>  		goto err_device;
> @@ -2141,13 +2143,13 @@ static int vduse_init(void)
>  err_wq:
>  	cdev_del(&vduse_cdev);
>  err_cdev:
> -	device_destroy(vduse_class, vduse_major);
> +	device_destroy(&vduse_class, vduse_major);
>  err_device:
>  	cdev_del(&vduse_ctrl_cdev);
>  err_ctrl_cdev:
>  	unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
>  err_chardev_region:
> -	class_destroy(vduse_class);
> +	class_unregister(&vduse_class);
>  	return ret;
>  }
>  module_init(vduse_init);
> @@ -2159,10 +2161,10 @@ static void vduse_exit(void)
>  	destroy_workqueue(vduse_irq_bound_wq);
>  	destroy_workqueue(vduse_irq_wq);
>  	cdev_del(&vduse_cdev);
> -	device_destroy(vduse_class, vduse_major);
> +	device_destroy(&vduse_class, vduse_major);
>  	cdev_del(&vduse_ctrl_cdev);
>  	unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
> -	class_destroy(vduse_class);
> +	class_unregister(&vduse_class);
>  }
>  module_exit(vduse_exit);
>  
> -- 
> 2.42.0
  
Greg KH Oct. 8, 2023, 6:40 a.m. UTC | #4
On Sun, Oct 08, 2023 at 02:20:52AM -0400, Michael S. Tsirkin wrote:
> On Fri, Oct 06, 2023 at 04:30:44PM +0200, Greg Kroah-Hartman wrote:
> > Now that the driver core allows for struct class to be in read-only
> > memory, we should make all 'class' structures declared at build time
> > placing them into read-only memory, instead of having to be dynamically
> > allocated at runtime.
> > 
> > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > Cc: Jason Wang <jasowang@redhat.com>
> > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > Cc: Xie Yongji <xieyongji@bytedance.com>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> 
> Greg should I merge it or do you intend to merge all these patches?

"all"?  There's loads of them for all sorts of subsystems, so feel free
to take it through your subsystem tree if you want.  I usually scoop up
the ones that no one picks after a release and take them through my
tree, to pick up the stragglers.

So it's your call, whatever is easier for you is fine for me.

thanks,

greg k-h
  
Michael S. Tsirkin Oct. 8, 2023, 6:41 a.m. UTC | #5
On Sun, Oct 08, 2023 at 08:40:05AM +0200, Greg Kroah-Hartman wrote:
> On Sun, Oct 08, 2023 at 02:20:52AM -0400, Michael S. Tsirkin wrote:
> > On Fri, Oct 06, 2023 at 04:30:44PM +0200, Greg Kroah-Hartman wrote:
> > > Now that the driver core allows for struct class to be in read-only
> > > memory, we should make all 'class' structures declared at build time
> > > placing them into read-only memory, instead of having to be dynamically
> > > allocated at runtime.
> > > 
> > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > Cc: Jason Wang <jasowang@redhat.com>
> > > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > Cc: Xie Yongji <xieyongji@bytedance.com>
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > 
> > Acked-by: Michael S. Tsirkin <mst@redhat.com>
> > 
> > Greg should I merge it or do you intend to merge all these patches?
> 
> "all"?  There's loads of them for all sorts of subsystems, so feel free
> to take it through your subsystem tree if you want.  I usually scoop up
> the ones that no one picks after a release and take them through my
> tree, to pick up the stragglers.
> 
> So it's your call, whatever is easier for you is fine for me.
> 
> thanks,
> 
> greg k-h

To clarify which commit does this depend on?
  
Greg KH Oct. 8, 2023, 6:46 a.m. UTC | #6
On Sun, Oct 08, 2023 at 02:41:22AM -0400, Michael S. Tsirkin wrote:
> On Sun, Oct 08, 2023 at 08:40:05AM +0200, Greg Kroah-Hartman wrote:
> > On Sun, Oct 08, 2023 at 02:20:52AM -0400, Michael S. Tsirkin wrote:
> > > On Fri, Oct 06, 2023 at 04:30:44PM +0200, Greg Kroah-Hartman wrote:
> > > > Now that the driver core allows for struct class to be in read-only
> > > > memory, we should make all 'class' structures declared at build time
> > > > placing them into read-only memory, instead of having to be dynamically
> > > > allocated at runtime.
> > > > 
> > > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > > Cc: Jason Wang <jasowang@redhat.com>
> > > > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > Cc: Xie Yongji <xieyongji@bytedance.com>
> > > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > 
> > > Acked-by: Michael S. Tsirkin <mst@redhat.com>
> > > 
> > > Greg should I merge it or do you intend to merge all these patches?
> > 
> > "all"?  There's loads of them for all sorts of subsystems, so feel free
> > to take it through your subsystem tree if you want.  I usually scoop up
> > the ones that no one picks after a release and take them through my
> > tree, to pick up the stragglers.
> > 
> > So it's your call, whatever is easier for you is fine for me.
> > 
> > thanks,
> > 
> > greg k-h
> 
> To clarify which commit does this depend on?

The 6.4 kernel release :)
  
Michael S. Tsirkin Oct. 8, 2023, 7:07 a.m. UTC | #7
On Sun, Oct 08, 2023 at 08:46:45AM +0200, Greg Kroah-Hartman wrote:
> On Sun, Oct 08, 2023 at 02:41:22AM -0400, Michael S. Tsirkin wrote:
> > On Sun, Oct 08, 2023 at 08:40:05AM +0200, Greg Kroah-Hartman wrote:
> > > On Sun, Oct 08, 2023 at 02:20:52AM -0400, Michael S. Tsirkin wrote:
> > > > On Fri, Oct 06, 2023 at 04:30:44PM +0200, Greg Kroah-Hartman wrote:
> > > > > Now that the driver core allows for struct class to be in read-only
> > > > > memory, we should make all 'class' structures declared at build time
> > > > > placing them into read-only memory, instead of having to be dynamically
> > > > > allocated at runtime.
> > > > > 
> > > > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > > > Cc: Jason Wang <jasowang@redhat.com>
> > > > > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > > Cc: Xie Yongji <xieyongji@bytedance.com>
> > > > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > > 
> > > > Acked-by: Michael S. Tsirkin <mst@redhat.com>
> > > > 
> > > > Greg should I merge it or do you intend to merge all these patches?
> > > 
> > > "all"?  There's loads of them for all sorts of subsystems, so feel free
> > > to take it through your subsystem tree if you want.  I usually scoop up
> > > the ones that no one picks after a release and take them through my
> > > tree, to pick up the stragglers.
> > > 
> > > So it's your call, whatever is easier for you is fine for me.
> > > 
> > > thanks,
> > > 
> > > greg k-h
> > 
> > To clarify which commit does this depend on?
> 
> The 6.4 kernel release :)

I'll pick this up then. Thanks!
  

Patch

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index df7869537ef1..0ddd4b8abecb 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -134,7 +134,6 @@  static DEFINE_MUTEX(vduse_lock);
 static DEFINE_IDR(vduse_idr);
 
 static dev_t vduse_major;
-static struct class *vduse_class;
 static struct cdev vduse_ctrl_cdev;
 static struct cdev vduse_cdev;
 static struct workqueue_struct *vduse_irq_wq;
@@ -1528,6 +1527,16 @@  static const struct kobj_type vq_type = {
 	.default_groups	= vq_groups,
 };
 
+static char *vduse_devnode(const struct device *dev, umode_t *mode)
+{
+	return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
+}
+
+static const struct class vduse_class = {
+	.name = "vduse",
+	.devnode = vduse_devnode,
+};
+
 static void vduse_dev_deinit_vqs(struct vduse_dev *dev)
 {
 	int i;
@@ -1638,7 +1647,7 @@  static int vduse_destroy_dev(char *name)
 	mutex_unlock(&dev->lock);
 
 	vduse_dev_reset(dev);
-	device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
+	device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
 	idr_remove(&vduse_idr, dev->minor);
 	kvfree(dev->config);
 	vduse_dev_deinit_vqs(dev);
@@ -1805,7 +1814,7 @@  static int vduse_create_dev(struct vduse_dev_config *config,
 
 	dev->minor = ret;
 	dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
-	dev->dev = device_create_with_groups(vduse_class, NULL,
+	dev->dev = device_create_with_groups(&vduse_class, NULL,
 				MKDEV(MAJOR(vduse_major), dev->minor),
 				dev, vduse_dev_groups, "%s", config->name);
 	if (IS_ERR(dev->dev)) {
@@ -1821,7 +1830,7 @@  static int vduse_create_dev(struct vduse_dev_config *config,
 
 	return 0;
 err_vqs:
-	device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
+	device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
 err_dev:
 	idr_remove(&vduse_idr, dev->minor);
 err_idr:
@@ -1934,11 +1943,6 @@  static const struct file_operations vduse_ctrl_fops = {
 	.llseek		= noop_llseek,
 };
 
-static char *vduse_devnode(const struct device *dev, umode_t *mode)
-{
-	return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
-}
-
 struct vduse_mgmt_dev {
 	struct vdpa_mgmt_dev mgmt_dev;
 	struct device dev;
@@ -2082,11 +2086,9 @@  static int vduse_init(void)
 	int ret;
 	struct device *dev;
 
-	vduse_class = class_create("vduse");
-	if (IS_ERR(vduse_class))
-		return PTR_ERR(vduse_class);
-
-	vduse_class->devnode = vduse_devnode;
+	ret = class_register(&vduse_class);
+	if (ret)
+		return ret;
 
 	ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
 	if (ret)
@@ -2099,7 +2101,7 @@  static int vduse_init(void)
 	if (ret)
 		goto err_ctrl_cdev;
 
-	dev = device_create(vduse_class, NULL, vduse_major, NULL, "control");
+	dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control");
 	if (IS_ERR(dev)) {
 		ret = PTR_ERR(dev);
 		goto err_device;
@@ -2141,13 +2143,13 @@  static int vduse_init(void)
 err_wq:
 	cdev_del(&vduse_cdev);
 err_cdev:
-	device_destroy(vduse_class, vduse_major);
+	device_destroy(&vduse_class, vduse_major);
 err_device:
 	cdev_del(&vduse_ctrl_cdev);
 err_ctrl_cdev:
 	unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
 err_chardev_region:
-	class_destroy(vduse_class);
+	class_unregister(&vduse_class);
 	return ret;
 }
 module_init(vduse_init);
@@ -2159,10 +2161,10 @@  static void vduse_exit(void)
 	destroy_workqueue(vduse_irq_bound_wq);
 	destroy_workqueue(vduse_irq_wq);
 	cdev_del(&vduse_cdev);
-	device_destroy(vduse_class, vduse_major);
+	device_destroy(&vduse_class, vduse_major);
 	cdev_del(&vduse_ctrl_cdev);
 	unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
-	class_destroy(vduse_class);
+	class_unregister(&vduse_class);
 }
 module_exit(vduse_exit);