2023-06-20 19:05:40

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH] oradax: make 'cl' a static const structure

From: Ivan Orlov <[email protected]>

Now that the driver core allows for struct class to be in read-only
memory, move the 'cl' structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Cc: "David S. Miller" <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Benjamin Tissoires <[email protected]>
Cc: "Mike Rapoport (IBM)" <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Ivan Orlov <[email protected]>
Cc: [email protected]
Suggested-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Ivan Orlov <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/sbus/char/oradax.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/sbus/char/oradax.c b/drivers/sbus/char/oradax.c
index aafce8d00000..a536dd6f4f7c 100644
--- a/drivers/sbus/char/oradax.c
+++ b/drivers/sbus/char/oradax.c
@@ -226,8 +226,10 @@ static int dax_ccb_info(u64 ca, struct ccb_info_result *info);
static int dax_ccb_kill(u64 ca, u16 *kill_res);

static struct cdev c_dev;
-static struct class *cl;
static dev_t first;
+static const struct class cl = {
+ .name = DAX_NAME,
+};

static int max_ccb_version;
static int dax_debug;
@@ -323,14 +325,11 @@ static int __init dax_attach(void)
goto done;
}

- cl = class_create(DAX_NAME);
- if (IS_ERR(cl)) {
- dax_err("class_create failed");
- ret = PTR_ERR(cl);
+ ret = class_register(&cl);
+ if (ret)
goto class_error;
- }

- if (device_create(cl, NULL, first, NULL, dax_name) == NULL) {
+ if (device_create(&cl, NULL, first, NULL, dax_name) == NULL) {
dax_err("device_create failed");
ret = -ENXIO;
goto device_error;
@@ -347,9 +346,9 @@ static int __init dax_attach(void)
goto done;

cdev_error:
- device_destroy(cl, first);
+ device_destroy(&cl, first);
device_error:
- class_destroy(cl);
+ class_unregister(&cl);
class_error:
unregister_chrdev_region(first, 1);
done:
@@ -362,8 +361,8 @@ static void __exit dax_detach(void)
{
pr_info("Cleaning up DAX module\n");
cdev_del(&c_dev);
- device_destroy(cl, first);
- class_destroy(cl);
+ device_destroy(&cl, first);
+ class_unregister(&cl);
unregister_chrdev_region(first, 1);
}
module_exit(dax_detach);
--
2.41.0



2023-06-20 19:16:44

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] oradax: make 'cl' a static const structure

On Tue, Jun 20, 2023 at 08:34:47PM +0200, Greg Kroah-Hartman wrote:
> From: Ivan Orlov <[email protected]>
>
> Now that the driver core allows for struct class to be in read-only
> memory, move the 'cl' structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at load time.
>
> Cc: "David S. Miller" <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Jonathan Corbet <[email protected]>
> Cc: Benjamin Tissoires <[email protected]>
> Cc: "Mike Rapoport (IBM)" <[email protected]>
> Cc: Suren Baghdasaryan <[email protected]>
> Cc: Ivan Orlov <[email protected]>
> Cc: [email protected]
> Suggested-by: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Ivan Orlov <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
Acked-by: Sam Ravnborg <[email protected]>