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

x86/MSR: make msr_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the msr_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-5-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f4a5fbfa
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
#include <asm/msr.h> #include <asm/msr.h>
static struct class *msr_class;
static enum cpuhp_state cpuhp_msr_state; static enum cpuhp_state cpuhp_msr_state;
enum allow_write_msrs { enum allow_write_msrs {
...@@ -235,26 +234,31 @@ static const struct file_operations msr_fops = { ...@@ -235,26 +234,31 @@ static const struct file_operations msr_fops = {
.compat_ioctl = msr_ioctl, .compat_ioctl = msr_ioctl,
}; };
static char *msr_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
}
static const struct class msr_class = {
.name = "msr",
.devnode = msr_devnode,
};
static int msr_device_create(unsigned int cpu) static int msr_device_create(unsigned int cpu)
{ {
struct device *dev; struct device *dev;
dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL, dev = device_create(&msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL,
"msr%d", cpu); "msr%d", cpu);
return PTR_ERR_OR_ZERO(dev); return PTR_ERR_OR_ZERO(dev);
} }
static int msr_device_destroy(unsigned int cpu) static int msr_device_destroy(unsigned int cpu)
{ {
device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu)); device_destroy(&msr_class, MKDEV(MSR_MAJOR, cpu));
return 0; return 0;
} }
static char *msr_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
}
static int __init msr_init(void) static int __init msr_init(void)
{ {
int err; int err;
...@@ -263,12 +267,9 @@ static int __init msr_init(void) ...@@ -263,12 +267,9 @@ static int __init msr_init(void)
pr_err("unable to get major %d for msr\n", MSR_MAJOR); pr_err("unable to get major %d for msr\n", MSR_MAJOR);
return -EBUSY; return -EBUSY;
} }
msr_class = class_create("msr"); err = class_register(&msr_class);
if (IS_ERR(msr_class)) { if (err)
err = PTR_ERR(msr_class);
goto out_chrdev; goto out_chrdev;
}
msr_class->devnode = msr_devnode;
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online", err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online",
msr_device_create, msr_device_destroy); msr_device_create, msr_device_destroy);
...@@ -278,7 +279,7 @@ static int __init msr_init(void) ...@@ -278,7 +279,7 @@ static int __init msr_init(void)
return 0; return 0;
out_class: out_class:
class_destroy(msr_class); class_unregister(&msr_class);
out_chrdev: out_chrdev:
__unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
return err; return err;
...@@ -288,7 +289,7 @@ module_init(msr_init); ...@@ -288,7 +289,7 @@ module_init(msr_init);
static void __exit msr_exit(void) static void __exit msr_exit(void)
{ {
cpuhp_remove_state(cpuhp_msr_state); cpuhp_remove_state(cpuhp_msr_state);
class_destroy(msr_class); class_unregister(&msr_class);
__unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
} }
module_exit(msr_exit) module_exit(msr_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