[PATCH RESEND drm-misc 4/4] dma-buf: heaps: make dma_heap_class constant

T.J. Mercier tjmercier at google.com
Tue Mar 5 17:07:17 UTC 2024


On Tue, Mar 5, 2024 at 3:34 AM Ricardo B. Marliere <ricardo at marliere.net> wrote:
>
> Since commit 43a7206b0963 ("driver core: class: make class_register() take
> a const *"), the driver core allows for struct class to be in read-only
> memory, so move the dma_heap_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.
>
> Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> Suggested-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> Signed-off-by: Ricardo B. Marliere <ricardo at marliere.net>
> ---
>  drivers/dma-buf/dma-heap.c | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
> index 84ae708fafe7..bcca6a2bbce8 100644
> --- a/drivers/dma-buf/dma-heap.c
> +++ b/drivers/dma-buf/dma-heap.c
> @@ -43,10 +43,18 @@ struct dma_heap {
>         struct cdev heap_cdev;
>  };
>
> +static char *dma_heap_devnode(const struct device *dev, umode_t *mode)
> +{
> +       return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev));
> +}
> +
>  static LIST_HEAD(heap_list);
>  static DEFINE_MUTEX(heap_list_lock);
>  static dev_t dma_heap_devt;
> -static struct class *dma_heap_class;
> +static struct class dma_heap_class = {
> +       .name = DEVNAME,
> +       .devnode = dma_heap_devnode,
> +};
>  static DEFINE_XARRAY_ALLOC(dma_heap_minors);
>
>  static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
> @@ -261,7 +269,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
>                 goto err1;
>         }
>
> -       dev_ret = device_create(dma_heap_class,
> +       dev_ret = device_create(&dma_heap_class,
>                                 NULL,
>                                 heap->heap_devt,
>                                 NULL,
> @@ -291,7 +299,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
>         return heap;
>
>  err3:
> -       device_destroy(dma_heap_class, heap->heap_devt);
> +       device_destroy(&dma_heap_class, heap->heap_devt);
>  err2:
>         cdev_del(&heap->heap_cdev);
>  err1:
> @@ -301,11 +309,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
>         return err_ret;
>  }
>
> -static char *dma_heap_devnode(const struct device *dev, umode_t *mode)
> -{
> -       return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev));
> -}
> -
>  static int dma_heap_init(void)
>  {
>         int ret;
> @@ -314,12 +317,11 @@ static int dma_heap_init(void)
>         if (ret)
>                 return ret;
>
> -       dma_heap_class = class_create(DEVNAME);
> -       if (IS_ERR(dma_heap_class)) {
> +       ret = class_register(&dma_heap_class);
> +       if (ret) {
>                 unregister_chrdev_region(dma_heap_devt, NUM_HEAP_MINORS);
> -               return PTR_ERR(dma_heap_class);
> +               return ret;
>         }
> -       dma_heap_class->devnode = dma_heap_devnode;
>
>         return 0;
>  }
>
> --
> 2.43.0

Reviewed-by: T.J. Mercier <tjmercier at google.com>

Is this really a resend? I don't see anything on lore and I can't
recall seeing this patch in my inbox before.


More information about the dri-devel mailing list