diff mbox series

[net-next,2/6] net: wan: framer: make framer_class constant

Message ID 20240302-class_cleanup-net-next-v1-2-8fa378595b93@marliere.net (mailing list archive)
State Accepted
Commit 63767a76318c4e2b8321b9eed728ba18020aaccf
Delegated to: Netdev Maintainers
Headers show
Series net: constify struct class usage | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: herve.codina@bootlin.com
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 958 this patch: 958
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 44 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-05--06-00 (tests: 891)

Commit Message

Ricardo B. Marliere March 2, 2024, 5:05 p.m. UTC
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 framer_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/net/wan/framer/framer-core.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Comments

Simon Horman March 4, 2024, 5:52 p.m. UTC | #1
+ Herve Codina <herve.codina@bootlin.com>

On Sat, Mar 02, 2024 at 02:05:58PM -0300, Ricardo B. Marliere 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 framer_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>

Reviewed-by: Simon Horman <horms@kernel.org>

> ---
>  drivers/net/wan/framer/framer-core.c | 21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/wan/framer/framer-core.c b/drivers/net/wan/framer/framer-core.c
> index 33b358b99f70..f547c22e26ac 100644
> --- a/drivers/net/wan/framer/framer-core.c
> +++ b/drivers/net/wan/framer/framer-core.c
> @@ -18,7 +18,12 @@
>  #include <linux/regulator/consumer.h>
>  #include <linux/slab.h>
>  
> -static struct class *framer_class;
> +static void framer_release(struct device *dev);
> +static const struct class framer_class = {
> +	.name = "framer",
> +	.dev_release = framer_release,
> +};
> +
>  static DEFINE_MUTEX(framer_provider_mutex);
>  static LIST_HEAD(framer_provider_list);
>  static DEFINE_IDA(framer_ida);
> @@ -627,7 +632,7 @@ struct framer *framer_create(struct device *dev, struct device_node *node,
>  	INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work);
>  	BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list);
>  
> -	framer->dev.class = framer_class;
> +	framer->dev.class = &framer_class;
>  	framer->dev.parent = dev;
>  	framer->dev.of_node = node ? node : dev->of_node;
>  	framer->id = id;
> @@ -741,7 +746,7 @@ struct framer *framer_provider_simple_of_xlate(struct device *dev,
>  	struct class_dev_iter iter;
>  	struct framer *framer;
>  
> -	class_dev_iter_init(&iter, framer_class, NULL, NULL);
> +	class_dev_iter_init(&iter, &framer_class, NULL, NULL);
>  	while ((dev = class_dev_iter_next(&iter))) {
>  		framer = dev_to_framer(dev);
>  		if (args->np != framer->dev.of_node)
> @@ -870,14 +875,6 @@ static void framer_release(struct device *dev)
>  
>  static int __init framer_core_init(void)
>  {
> -	framer_class = class_create("framer");
> -	if (IS_ERR(framer_class)) {
> -		pr_err("failed to create framer class (%pe)\n", framer_class);
> -		return PTR_ERR(framer_class);
> -	}
> -
> -	framer_class->dev_release = framer_release;
> -
> -	return 0;
> +	return class_register(&framer_class);
>  }
>  device_initcall(framer_core_init);
> 
> -- 
> 2.43.0
> 
>
Herve Codina March 5, 2024, 7:17 a.m. UTC | #2
Hi,

On Mon, 4 Mar 2024 17:52:46 +0000
Simon Horman <horms@kernel.org> wrote:

> + Herve Codina <herve.codina@bootlin.com>
> 
> On Sat, Mar 02, 2024 at 02:05:58PM -0300, Ricardo B. Marliere 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 framer_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>
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 

Thanks for the patch.

Acked-by: Herve Codina <herve.codina@bootlin.com>

Best regards,
Hervé
diff mbox series

Patch

diff --git a/drivers/net/wan/framer/framer-core.c b/drivers/net/wan/framer/framer-core.c
index 33b358b99f70..f547c22e26ac 100644
--- a/drivers/net/wan/framer/framer-core.c
+++ b/drivers/net/wan/framer/framer-core.c
@@ -18,7 +18,12 @@ 
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 
-static struct class *framer_class;
+static void framer_release(struct device *dev);
+static const struct class framer_class = {
+	.name = "framer",
+	.dev_release = framer_release,
+};
+
 static DEFINE_MUTEX(framer_provider_mutex);
 static LIST_HEAD(framer_provider_list);
 static DEFINE_IDA(framer_ida);
@@ -627,7 +632,7 @@  struct framer *framer_create(struct device *dev, struct device_node *node,
 	INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work);
 	BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list);
 
-	framer->dev.class = framer_class;
+	framer->dev.class = &framer_class;
 	framer->dev.parent = dev;
 	framer->dev.of_node = node ? node : dev->of_node;
 	framer->id = id;
@@ -741,7 +746,7 @@  struct framer *framer_provider_simple_of_xlate(struct device *dev,
 	struct class_dev_iter iter;
 	struct framer *framer;
 
-	class_dev_iter_init(&iter, framer_class, NULL, NULL);
+	class_dev_iter_init(&iter, &framer_class, NULL, NULL);
 	while ((dev = class_dev_iter_next(&iter))) {
 		framer = dev_to_framer(dev);
 		if (args->np != framer->dev.of_node)
@@ -870,14 +875,6 @@  static void framer_release(struct device *dev)
 
 static int __init framer_core_init(void)
 {
-	framer_class = class_create("framer");
-	if (IS_ERR(framer_class)) {
-		pr_err("failed to create framer class (%pe)\n", framer_class);
-		return PTR_ERR(framer_class);
-	}
-
-	framer_class->dev_release = framer_release;
-
-	return 0;
+	return class_register(&framer_class);
 }
 device_initcall(framer_core_init);