Messages in this thread | | | Date | Fri, 11 Aug 2023 11:34:14 +0400 | Subject | Re: [PATCH v2 3/3] fpga: region: make fpga_region_class a static const structure | From | Ivan Orlov <> |
| |
On 8/11/23 11:30, Ivan Orlov wrote: > Now that the driver core allows for struct class to be in read-only > memory, move the fpga_region_class structure to be declared at build > time placing it into read-only memory, instead of having to be > dynamically allocated at boot time. > > Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> > --- > drivers/fpga/fpga-region.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c > index ccf6fdab1360..6abd8a154047 100644 > --- a/drivers/fpga/fpga-region.c > +++ b/drivers/fpga/fpga-region.c > @@ -16,7 +16,7 @@ > #include <linux/spinlock.h> > > static DEFINE_IDA(fpga_region_ida); > -static struct class *fpga_region_class; > +static const struct class fpga_region_class; > > struct fpga_region * > fpga_region_class_find(struct device *start, const void *data, > @@ -24,7 +24,7 @@ fpga_region_class_find(struct device *start, const void *data, > { > struct device *dev; > > - dev = class_find_device(fpga_region_class, start, data, match); > + dev = class_find_device(&fpga_region_class, start, data, match); > if (!dev) > return NULL; > > @@ -216,7 +216,7 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info * > mutex_init(®ion->mutex); > INIT_LIST_HEAD(®ion->bridge_list); > > - region->dev.class = fpga_region_class; > + region->dev.class = &fpga_region_class; > region->dev.parent = parent; > region->dev.of_node = parent->of_node; > region->dev.id = id; > @@ -287,25 +287,24 @@ static void fpga_region_dev_release(struct device *dev) > kfree(region); > } > > +static const struct class fpga_region_class = { > + .name = "fpga_region", > + .dev_groups = fpga_region_groups, > + .dev_release = fpga_region_dev_release, > +}; > + > /** > * fpga_region_init - init function for fpga_region class > * Creates the fpga_region class and registers a reconfig notifier. > */ > static int __init fpga_region_init(void) > { > - fpga_region_class = class_create("fpga_region"); > - if (IS_ERR(fpga_region_class)) > - return PTR_ERR(fpga_region_class); > - > - fpga_region_class->dev_groups = fpga_region_groups; > - fpga_region_class->dev_release = fpga_region_dev_release; > - > - return 0; > + return class_register(&fpga_region_class); > } > > static void __exit fpga_region_exit(void) > { > - class_destroy(fpga_region_class); > + class_unregister(&fpga_region_class); > ida_destroy(&fpga_region_ida); > } > And I forgot the changelog here.
V1 -> V2: - Add forward declaration of fpga_region_class - Move definition of fpga_region_class to more logical place
| |