diff mbox series

[net-next,1/6] net: hns: make hnae_class constant

Message ID 20240302-class_cleanup-net-next-v1-1-8fa378595b93@marliere.net (mailing list archive)
State Accepted
Commit b6e3c115efb5bec0542508a9120b99960073870f
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: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: benjamin.tissoires@redhat.com
netdev/build_clang success Errors and warnings before: 956 this patch: 956
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: 956 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 41 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 hnae_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/ethernet/hisilicon/hns/hnae.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Simon Horman March 4, 2024, 5:52 p.m. UTC | #1
+ Benjamin Tissoires <benjamin.tissoires@redhat.com>

On Sat, Mar 02, 2024 at 02:05:57PM -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 hnae_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/ethernet/hisilicon/hns/hnae.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c b/drivers/net/ethernet/hisilicon/hns/hnae.c
> index 8a1027ad340d..d4293f76d69d 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hnae.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
> @@ -12,7 +12,9 @@
>  
>  #define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev)
>  
> -static struct class *hnae_class;
> +static const struct class hnae_class = {
> +	.name = "hnae",
> +};
>  
>  static void
>  hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head)
> @@ -111,7 +113,7 @@ static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
>  
>  	WARN_ON(!fwnode);
>  
> -	dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
> +	dev = class_find_device(&hnae_class, NULL, fwnode, __ae_match);
>  
>  	return dev ? cls_to_ae_dev(dev) : NULL;
>  }
> @@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
>  	hdev->owner = owner;
>  	hdev->id = (int)atomic_inc_return(&id);
>  	hdev->cls_dev.parent = hdev->dev;
> -	hdev->cls_dev.class = hnae_class;
> +	hdev->cls_dev.class = &hnae_class;
>  	hdev->cls_dev.release = hnae_release;
>  	(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
>  	ret = device_register(&hdev->cls_dev);
> @@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister);
>  
>  static int __init hnae_init(void)
>  {
> -	hnae_class = class_create("hnae");
> -	return PTR_ERR_OR_ZERO(hnae_class);
> +	return class_register(&hnae_class);
>  }
>  
>  static void __exit hnae_exit(void)
>  {
> -	class_destroy(hnae_class);
> +	class_unregister(&hnae_class);
>  }
>  
>  subsys_initcall(hnae_init);
> 
> -- 
> 2.43.0
> 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 8a1027ad340d..d4293f76d69d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -12,7 +12,9 @@ 
 
 #define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev)
 
-static struct class *hnae_class;
+static const struct class hnae_class = {
+	.name = "hnae",
+};
 
 static void
 hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head)
@@ -111,7 +113,7 @@  static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
 
 	WARN_ON(!fwnode);
 
-	dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
+	dev = class_find_device(&hnae_class, NULL, fwnode, __ae_match);
 
 	return dev ? cls_to_ae_dev(dev) : NULL;
 }
@@ -415,7 +417,7 @@  int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
 	hdev->owner = owner;
 	hdev->id = (int)atomic_inc_return(&id);
 	hdev->cls_dev.parent = hdev->dev;
-	hdev->cls_dev.class = hnae_class;
+	hdev->cls_dev.class = &hnae_class;
 	hdev->cls_dev.release = hnae_release;
 	(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
 	ret = device_register(&hdev->cls_dev);
@@ -448,13 +450,12 @@  EXPORT_SYMBOL(hnae_ae_unregister);
 
 static int __init hnae_init(void)
 {
-	hnae_class = class_create("hnae");
-	return PTR_ERR_OR_ZERO(hnae_class);
+	return class_register(&hnae_class);
 }
 
 static void __exit hnae_exit(void)
 {
-	class_destroy(hnae_class);
+	class_unregister(&hnae_class);
 }
 
 subsys_initcall(hnae_init);