mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
bsg: make bsg_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the bsg_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: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jens Axboe <axboe@kernel.dk> Cc: linux-scsi@vger.kernel.org Cc: linux-block@vger.kernel.org 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> Link: https://lore.kernel.org/r/20230620180129.645646-8-gregkh@linuxfoundation.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
18
block/bsg.c
18
block/bsg.c
@@ -39,7 +39,7 @@ static inline struct bsg_device *to_bsg_device(struct inode *inode)
|
|||||||
#define BSG_MAX_DEVS 32768
|
#define BSG_MAX_DEVS 32768
|
||||||
|
|
||||||
static DEFINE_IDA(bsg_minor_ida);
|
static DEFINE_IDA(bsg_minor_ida);
|
||||||
static struct class *bsg_class;
|
static const struct class bsg_class;
|
||||||
static int bsg_major;
|
static int bsg_major;
|
||||||
|
|
||||||
static unsigned int bsg_timeout(struct bsg_device *bd, struct sg_io_v4 *hdr)
|
static unsigned int bsg_timeout(struct bsg_device *bd, struct sg_io_v4 *hdr)
|
||||||
@@ -208,7 +208,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
|
|||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
bd->device.devt = MKDEV(bsg_major, ret);
|
bd->device.devt = MKDEV(bsg_major, ret);
|
||||||
bd->device.class = bsg_class;
|
bd->device.class = &bsg_class;
|
||||||
bd->device.parent = parent;
|
bd->device.parent = parent;
|
||||||
bd->device.release = bsg_device_release;
|
bd->device.release = bsg_device_release;
|
||||||
dev_set_name(&bd->device, "%s", name);
|
dev_set_name(&bd->device, "%s", name);
|
||||||
@@ -242,15 +242,19 @@ static char *bsg_devnode(const struct device *dev, umode_t *mode)
|
|||||||
return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
|
return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct class bsg_class = {
|
||||||
|
.name = "bsg",
|
||||||
|
.devnode = bsg_devnode,
|
||||||
|
};
|
||||||
|
|
||||||
static int __init bsg_init(void)
|
static int __init bsg_init(void)
|
||||||
{
|
{
|
||||||
dev_t devid;
|
dev_t devid;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bsg_class = class_create("bsg");
|
ret = class_register(&bsg_class);
|
||||||
if (IS_ERR(bsg_class))
|
if (ret)
|
||||||
return PTR_ERR(bsg_class);
|
return ret;
|
||||||
bsg_class->devnode = bsg_devnode;
|
|
||||||
|
|
||||||
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
|
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -262,7 +266,7 @@ static int __init bsg_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
destroy_bsg_class:
|
destroy_bsg_class:
|
||||||
class_destroy(bsg_class);
|
class_unregister(&bsg_class);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user