linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipmi: make ipmi_class a static const structure
@ 2023-06-20 14:37 Greg Kroah-Hartman
  2023-06-20 15:06 ` Corey Minyard
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20 14:37 UTC (permalink / raw)
  To: minyard; +Cc: linux-kernel, Ivan Orlov, openipmi-developer, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the ipmi_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: Corey Minyard <minyard@acm.org>
Cc: openipmi-developer@lists.sourceforge.net
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/char/ipmi/ipmi_devintf.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 73e5a9e28f85..332082e02ea5 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -807,7 +807,9 @@ struct ipmi_reg_list {
 static LIST_HEAD(reg_list);
 static DEFINE_MUTEX(reg_list_mutex);
 
-static struct class *ipmi_class;
+static const struct class ipmi_class = {
+	.name = "ipmi",
+};
 
 static void ipmi_new_smi(int if_num, struct device *device)
 {
@@ -822,7 +824,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
 	entry->dev = dev;
 
 	mutex_lock(&reg_list_mutex);
-	device_create(ipmi_class, device, dev, NULL, "ipmi%d", if_num);
+	device_create(&ipmi_class, device, dev, NULL, "ipmi%d", if_num);
 	list_add(&entry->link, &reg_list);
 	mutex_unlock(&reg_list_mutex);
 }
@@ -840,7 +842,7 @@ static void ipmi_smi_gone(int if_num)
 			break;
 		}
 	}
-	device_destroy(ipmi_class, dev);
+	device_destroy(&ipmi_class, dev);
 	mutex_unlock(&reg_list_mutex);
 }
 
@@ -860,15 +862,13 @@ static int __init init_ipmi_devintf(void)
 
 	pr_info("ipmi device interface\n");
 
-	ipmi_class = class_create("ipmi");
-	if (IS_ERR(ipmi_class)) {
-		pr_err("ipmi: can't register device class\n");
-		return PTR_ERR(ipmi_class);
-	}
+	rv = class_register(&ipmi_class);
+	if (rv)
+		return rv;
 
 	rv = register_chrdev(ipmi_major, DEVICE_NAME, &ipmi_fops);
 	if (rv < 0) {
-		class_destroy(ipmi_class);
+		class_unregister(&ipmi_class);
 		pr_err("ipmi: can't get major %d\n", ipmi_major);
 		return rv;
 	}
@@ -880,7 +880,7 @@ static int __init init_ipmi_devintf(void)
 	rv = ipmi_smi_watcher_register(&smi_watcher);
 	if (rv) {
 		unregister_chrdev(ipmi_major, DEVICE_NAME);
-		class_destroy(ipmi_class);
+		class_unregister(&ipmi_class);
 		pr_warn("ipmi: can't register smi watcher\n");
 		return rv;
 	}
@@ -895,11 +895,11 @@ static void __exit cleanup_ipmi(void)
 	mutex_lock(&reg_list_mutex);
 	list_for_each_entry_safe(entry, entry2, &reg_list, link) {
 		list_del(&entry->link);
-		device_destroy(ipmi_class, entry->dev);
+		device_destroy(&ipmi_class, entry->dev);
 		kfree(entry);
 	}
 	mutex_unlock(&reg_list_mutex);
-	class_destroy(ipmi_class);
+	class_unregister(&ipmi_class);
 	ipmi_smi_watcher_unregister(&smi_watcher);
 	unregister_chrdev(ipmi_major, DEVICE_NAME);
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ipmi: make ipmi_class a static const structure
  2023-06-20 14:37 [PATCH] ipmi: make ipmi_class a static const structure Greg Kroah-Hartman
@ 2023-06-20 15:06 ` Corey Minyard
  0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2023-06-20 15:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Ivan Orlov, openipmi-developer

On Tue, Jun 20, 2023 at 04:37:02PM +0200, Greg Kroah-Hartman wrote:
> From: Ivan Orlov <ivan.orlov0322@gmail.com>
> 
> Now that the driver core allows for struct class to be in read-only
> memory, move the ipmi_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.

This is in my next tree and seems to work fine.  Thanks.

-corey

> 
> Cc: Corey Minyard <minyard@acm.org>
> Cc: openipmi-developer@lists.sourceforge.net
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/char/ipmi/ipmi_devintf.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
> index 73e5a9e28f85..332082e02ea5 100644
> --- a/drivers/char/ipmi/ipmi_devintf.c
> +++ b/drivers/char/ipmi/ipmi_devintf.c
> @@ -807,7 +807,9 @@ struct ipmi_reg_list {
>  static LIST_HEAD(reg_list);
>  static DEFINE_MUTEX(reg_list_mutex);
>  
> -static struct class *ipmi_class;
> +static const struct class ipmi_class = {
> +	.name = "ipmi",
> +};
>  
>  static void ipmi_new_smi(int if_num, struct device *device)
>  {
> @@ -822,7 +824,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
>  	entry->dev = dev;
>  
>  	mutex_lock(&reg_list_mutex);
> -	device_create(ipmi_class, device, dev, NULL, "ipmi%d", if_num);
> +	device_create(&ipmi_class, device, dev, NULL, "ipmi%d", if_num);
>  	list_add(&entry->link, &reg_list);
>  	mutex_unlock(&reg_list_mutex);
>  }
> @@ -840,7 +842,7 @@ static void ipmi_smi_gone(int if_num)
>  			break;
>  		}
>  	}
> -	device_destroy(ipmi_class, dev);
> +	device_destroy(&ipmi_class, dev);
>  	mutex_unlock(&reg_list_mutex);
>  }
>  
> @@ -860,15 +862,13 @@ static int __init init_ipmi_devintf(void)
>  
>  	pr_info("ipmi device interface\n");
>  
> -	ipmi_class = class_create("ipmi");
> -	if (IS_ERR(ipmi_class)) {
> -		pr_err("ipmi: can't register device class\n");
> -		return PTR_ERR(ipmi_class);
> -	}
> +	rv = class_register(&ipmi_class);
> +	if (rv)
> +		return rv;
>  
>  	rv = register_chrdev(ipmi_major, DEVICE_NAME, &ipmi_fops);
>  	if (rv < 0) {
> -		class_destroy(ipmi_class);
> +		class_unregister(&ipmi_class);
>  		pr_err("ipmi: can't get major %d\n", ipmi_major);
>  		return rv;
>  	}
> @@ -880,7 +880,7 @@ static int __init init_ipmi_devintf(void)
>  	rv = ipmi_smi_watcher_register(&smi_watcher);
>  	if (rv) {
>  		unregister_chrdev(ipmi_major, DEVICE_NAME);
> -		class_destroy(ipmi_class);
> +		class_unregister(&ipmi_class);
>  		pr_warn("ipmi: can't register smi watcher\n");
>  		return rv;
>  	}
> @@ -895,11 +895,11 @@ static void __exit cleanup_ipmi(void)
>  	mutex_lock(&reg_list_mutex);
>  	list_for_each_entry_safe(entry, entry2, &reg_list, link) {
>  		list_del(&entry->link);
> -		device_destroy(ipmi_class, entry->dev);
> +		device_destroy(&ipmi_class, entry->dev);
>  		kfree(entry);
>  	}
>  	mutex_unlock(&reg_list_mutex);
> -	class_destroy(ipmi_class);
> +	class_unregister(&ipmi_class);
>  	ipmi_smi_watcher_unregister(&smi_watcher);
>  	unregister_chrdev(ipmi_major, DEVICE_NAME);
>  }
> -- 
> 2.41.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-20 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-20 14:37 [PATCH] ipmi: make ipmi_class a static const structure Greg Kroah-Hartman
2023-06-20 15:06 ` Corey Minyard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).