diff mbox series

nvdimm: make nd_class constant

Message ID 2024061041-grandkid-coherence-19b0@gregkh (mailing list archive)
State Accepted
Commit 477e36546e6fa79282427d5b82a9a9a67504de1a
Headers show
Series nvdimm: make nd_class constant | expand

Commit Message

Greg Kroah-Hartman June 10, 2024, 8:19 a.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: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: nvdimm@lists.linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/nvdimm/bus.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Dan Williams June 10, 2024, 5:44 p.m. UTC | #1
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.

Change looks good to me,

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

...changelog grammar tripped me up though, how about:

"Now that the driver core allows for struct class to be in read-only
memory, it is possible to make all 'class' structures be declared at
build time. Move the class to a 'static const' declaration and register
it rather than dynamically create it."
Greg Kroah-Hartman June 12, 2024, 10 a.m. UTC | #2
On Mon, Jun 10, 2024 at 10:44:42AM -0700, Dan Williams wrote:
> 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.
> 
> Change looks good to me,
> 
> Reviewed-by: Dan Williams <dan.j.williams@intel.com>
> 
> ...changelog grammar tripped me up though, how about:
> 
> "Now that the driver core allows for struct class to be in read-only
> memory, it is possible to make all 'class' structures be declared at
> build time. Move the class to a 'static const' declaration and register
> it rather than dynamically create it."

That works too, want me to resubmit with this, or can I update it when I
commit it to my tree?

thanks,

greg "the changelog is the hardest part" k-h
Dan Williams June 12, 2024, 3:29 p.m. UTC | #3
Greg Kroah-Hartman wrote:
> On Mon, Jun 10, 2024 at 10:44:42AM -0700, Dan Williams wrote:
> > 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.
> > 
> > Change looks good to me,
> > 
> > Reviewed-by: Dan Williams <dan.j.williams@intel.com>
> > 
> > ...changelog grammar tripped me up though, how about:
> > 
> > "Now that the driver core allows for struct class to be in read-only
> > memory, it is possible to make all 'class' structures be declared at
> > build time. Move the class to a 'static const' declaration and register
> > it rather than dynamically create it."
> 
> That works too, want me to resubmit with this, or can I update it when I
> commit it to my tree?

Take it through your tree sounds good to me.

> thanks,
> 
> greg "the changelog is the hardest part" k-h

lol!

dan "can't code, but can proofread" williams
Ira Weiny June 12, 2024, 9:18 p.m. UTC | #4
Greg Kroah-Hartman wrote:
> On Mon, Jun 10, 2024 at 10:44:42AM -0700, Dan Williams wrote:
> > 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.
> > 
> > Change looks good to me,
> > 
> > Reviewed-by: Dan Williams <dan.j.williams@intel.com>
> > 
> > ...changelog grammar tripped me up though, how about:
> > 
> > "Now that the driver core allows for struct class to be in read-only
> > memory, it is possible to make all 'class' structures be declared at
> > build time. Move the class to a 'static const' declaration and register
> > it rather than dynamically create it."
> 
> That works too, want me to resubmit with this, or can I update it when I
> commit it to my tree?

In that case.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> 
> thanks,
> 
> greg "the changelog is the hardest part" k-h
diff mbox series

Patch

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 508aed017ddc..101c425f3e8b 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -25,9 +25,12 @@ 
 
 int nvdimm_major;
 static int nvdimm_bus_major;
-static struct class *nd_class;
 static DEFINE_IDA(nd_ida);
 
+static const struct class nd_class = {
+	.name = "nd",
+};
+
 static int to_nd_device_type(const struct device *dev)
 {
 	if (is_nvdimm(dev))
@@ -742,7 +745,7 @@  int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus)
 	device_initialize(dev);
 	lockdep_set_class(&dev->mutex, &nvdimm_ndctl_key);
 	device_set_pm_not_required(dev);
-	dev->class = nd_class;
+	dev->class = &nd_class;
 	dev->parent = &nvdimm_bus->dev;
 	dev->devt = devt;
 	dev->release = ndctl_release;
@@ -765,7 +768,7 @@  int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus)
 
 void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus)
 {
-	device_destroy(nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id));
+	device_destroy(&nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id));
 }
 
 static const struct nd_cmd_desc __nd_cmd_dimm_descs[] = {
@@ -1320,11 +1323,9 @@  int __init nvdimm_bus_init(void)
 		goto err_dimm_chrdev;
 	nvdimm_major = rc;
 
-	nd_class = class_create("nd");
-	if (IS_ERR(nd_class)) {
-		rc = PTR_ERR(nd_class);
+	rc = class_register(&nd_class);
+	if (rc)
 		goto err_class;
-	}
 
 	rc = driver_register(&nd_bus_driver.drv);
 	if (rc)
@@ -1333,7 +1334,7 @@  int __init nvdimm_bus_init(void)
 	return 0;
 
  err_nd_bus:
-	class_destroy(nd_class);
+	class_unregister(&nd_class);
  err_class:
 	unregister_chrdev(nvdimm_major, "dimmctl");
  err_dimm_chrdev:
@@ -1347,7 +1348,7 @@  int __init nvdimm_bus_init(void)
 void nvdimm_bus_exit(void)
 {
 	driver_unregister(&nd_bus_driver.drv);
-	class_destroy(nd_class);
+	class_unregister(&nd_class);
 	unregister_chrdev(nvdimm_bus_major, "ndctl");
 	unregister_chrdev(nvdimm_major, "dimmctl");
 	bus_unregister(&nvdimm_bus_type);