Message ID | 20240305-class_cleanup-drm-v1-4-94f82740525a@marliere.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm: constify struct class usage | expand |
On Tue, Mar 5, 2024 at 3:34 AM Ricardo B. Marliere <ricardo@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@linuxfoundation.org> > Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Signed-off-by: Ricardo B. Marliere <ricardo@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@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.
On 5 Mar 09:07, T.J. Mercier wrote: > > Reviewed-by: T.J. Mercier <tjmercier@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. Hi T.J. thanks for reviewing! I'm sorry about that, I sent the series only to Greg before but I thought it had Cc'ed the lists as well. Then I realized it was sent publicly only once. Double mistake :( Best regards, - Ricardo.
On Tue, Mar 5, 2024 at 10:02 AM Ricardo B. Marliere <ricardo@marliere.net> wrote: > > On 5 Mar 09:07, T.J. Mercier wrote: > > > > Reviewed-by: T.J. Mercier <tjmercier@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. > > Hi T.J. thanks for reviewing! > > I'm sorry about that, I sent the series only to Greg before but I > thought it had Cc'ed the lists as well. Then I realized it was sent > publicly only once. Double mistake :( > > Best regards, > - Ricardo. Cheers, glad I don't have to try to rework my email filters. :)
Hello Ricardo, On Tue, 5 Mar 2024 at 22:37, T.J. Mercier <tjmercier@google.com> wrote: > > On Tue, Mar 5, 2024 at 3:34 AM Ricardo B. Marliere <ricardo@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@linuxfoundation.org> > > Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > Signed-off-by: Ricardo B. Marliere <ricardo@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@google.com> FWIW, please free to add my Acked-by: Sumit Semwal <sumit.semwal@linaro.org> > > > Is this really a resend? I don't see anything on lore and I can't > recall seeing this patch in my inbox before. Best, Sumit.
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; }
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@linuxfoundation.org> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net> --- drivers/dma-buf/dma-heap.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)