mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
dca: make dca_class a static const structure
The driver core allows for struct class to be in read-only memory. Move the dca_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20240412151726.189030-1-ivan.orlov0322@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
bd7246a19e
commit
d7d3ae441e
@ -13,7 +13,9 @@
|
|||||||
#include <linux/gfp.h>
|
#include <linux/gfp.h>
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
|
|
||||||
static struct class *dca_class;
|
static const struct class dca_class = {
|
||||||
|
.name = "dca",
|
||||||
|
};
|
||||||
static struct idr dca_idr;
|
static struct idr dca_idr;
|
||||||
static spinlock_t dca_idr_lock;
|
static spinlock_t dca_idr_lock;
|
||||||
|
|
||||||
@ -22,14 +24,14 @@ int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
|
|||||||
struct device *cd;
|
struct device *cd;
|
||||||
static int req_count;
|
static int req_count;
|
||||||
|
|
||||||
cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1), NULL,
|
cd = device_create(&dca_class, dca->cd, MKDEV(0, slot + 1), NULL,
|
||||||
"requester%d", req_count++);
|
"requester%d", req_count++);
|
||||||
return PTR_ERR_OR_ZERO(cd);
|
return PTR_ERR_OR_ZERO(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dca_sysfs_remove_req(struct dca_provider *dca, int slot)
|
void dca_sysfs_remove_req(struct dca_provider *dca, int slot)
|
||||||
{
|
{
|
||||||
device_destroy(dca_class, MKDEV(0, slot + 1));
|
device_destroy(&dca_class, MKDEV(0, slot + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
|
int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
|
||||||
@ -49,7 +51,7 @@ int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
|
cd = device_create(&dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
|
||||||
if (IS_ERR(cd)) {
|
if (IS_ERR(cd)) {
|
||||||
spin_lock(&dca_idr_lock);
|
spin_lock(&dca_idr_lock);
|
||||||
idr_remove(&dca_idr, dca->id);
|
idr_remove(&dca_idr, dca->id);
|
||||||
@ -71,20 +73,22 @@ void dca_sysfs_remove_provider(struct dca_provider *dca)
|
|||||||
|
|
||||||
int __init dca_sysfs_init(void)
|
int __init dca_sysfs_init(void)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
idr_init(&dca_idr);
|
idr_init(&dca_idr);
|
||||||
spin_lock_init(&dca_idr_lock);
|
spin_lock_init(&dca_idr_lock);
|
||||||
|
|
||||||
dca_class = class_create("dca");
|
err = class_register(&dca_class);
|
||||||
if (IS_ERR(dca_class)) {
|
if (err) {
|
||||||
idr_destroy(&dca_idr);
|
idr_destroy(&dca_idr);
|
||||||
return PTR_ERR(dca_class);
|
return err;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __exit dca_sysfs_exit(void)
|
void __exit dca_sysfs_exit(void)
|
||||||
{
|
{
|
||||||
class_destroy(dca_class);
|
class_unregister(&dca_class);
|
||||||
idr_destroy(&dca_idr);
|
idr_destroy(&dca_idr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user