Commit f4a5fbfa authored by Ivan Orlov's avatar Ivan Orlov Committed by Greg Kroah-Hartman

x86/cpuid: make cpuid_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the cpuid_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: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230620144431.583290-4-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 32944855
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/msr.h> #include <asm/msr.h>
static struct class *cpuid_class;
static enum cpuhp_state cpuhp_cpuid_state; static enum cpuhp_state cpuhp_cpuid_state;
struct cpuid_regs_done { struct cpuid_regs_done {
...@@ -124,26 +123,31 @@ static const struct file_operations cpuid_fops = { ...@@ -124,26 +123,31 @@ static const struct file_operations cpuid_fops = {
.open = cpuid_open, .open = cpuid_open,
}; };
static char *cpuid_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
}
static const struct class cpuid_class = {
.name = "cpuid",
.devnode = cpuid_devnode,
};
static int cpuid_device_create(unsigned int cpu) static int cpuid_device_create(unsigned int cpu)
{ {
struct device *dev; struct device *dev;
dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL, dev = device_create(&cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
"cpu%d", cpu); "cpu%d", cpu);
return PTR_ERR_OR_ZERO(dev); return PTR_ERR_OR_ZERO(dev);
} }
static int cpuid_device_destroy(unsigned int cpu) static int cpuid_device_destroy(unsigned int cpu)
{ {
device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu)); device_destroy(&cpuid_class, MKDEV(CPUID_MAJOR, cpu));
return 0; return 0;
} }
static char *cpuid_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
}
static int __init cpuid_init(void) static int __init cpuid_init(void)
{ {
int err; int err;
...@@ -154,12 +158,9 @@ static int __init cpuid_init(void) ...@@ -154,12 +158,9 @@ static int __init cpuid_init(void)
CPUID_MAJOR); CPUID_MAJOR);
return -EBUSY; return -EBUSY;
} }
cpuid_class = class_create("cpuid"); err = class_register(&cpuid_class);
if (IS_ERR(cpuid_class)) { if (err)
err = PTR_ERR(cpuid_class);
goto out_chrdev; goto out_chrdev;
}
cpuid_class->devnode = cpuid_devnode;
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/cpuid:online", err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/cpuid:online",
cpuid_device_create, cpuid_device_destroy); cpuid_device_create, cpuid_device_destroy);
...@@ -170,7 +171,7 @@ static int __init cpuid_init(void) ...@@ -170,7 +171,7 @@ static int __init cpuid_init(void)
return 0; return 0;
out_class: out_class:
class_destroy(cpuid_class); class_unregister(&cpuid_class);
out_chrdev: out_chrdev:
__unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
return err; return err;
...@@ -180,7 +181,7 @@ module_init(cpuid_init); ...@@ -180,7 +181,7 @@ module_init(cpuid_init);
static void __exit cpuid_exit(void) static void __exit cpuid_exit(void)
{ {
cpuhp_remove_state(cpuhp_cpuid_state); cpuhp_remove_state(cpuhp_cpuid_state);
class_destroy(cpuid_class); class_unregister(&cpuid_class);
__unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
} }
module_exit(cpuid_exit); module_exit(cpuid_exit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment