2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-25 21:54:06 +08:00

mtip32xx: simplify sysfs setup

Pass the driver specific attributes directly to device_add_disk instead
of manually creating them after the disk registration.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210614060343.3965416-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2021-06-14 08:03:42 +02:00 committed by Jens Axboe
parent 440462198d
commit d2efa81dd8

View File

@ -2160,6 +2160,20 @@ static ssize_t mtip_hw_show_status(struct device *dev,
static DEVICE_ATTR(status, 0444, mtip_hw_show_status, NULL);
static struct attribute *mtip_disk_attrs[] = {
&dev_attr_status.attr,
NULL,
};
static const struct attribute_group mtip_disk_attr_group = {
.attrs = mtip_disk_attrs,
};
static const struct attribute_group *mtip_disk_attr_groups[] = {
&mtip_disk_attr_group,
NULL,
};
/* debugsfs entries */
static ssize_t show_device_status(struct device_driver *drv, char *buf)
@ -2374,47 +2388,6 @@ static const struct file_operations mtip_flags_fops = {
.llseek = no_llseek,
};
/*
* Create the sysfs related attributes.
*
* @dd Pointer to the driver data structure.
* @kobj Pointer to the kobj for the block device.
*
* return value
* 0 Operation completed successfully.
* -EINVAL Invalid parameter.
*/
static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
{
if (!kobj || !dd)
return -EINVAL;
if (sysfs_create_file(kobj, &dev_attr_status.attr))
dev_warn(&dd->pdev->dev,
"Error creating 'status' sysfs entry\n");
return 0;
}
/*
* Remove the sysfs related attributes.
*
* @dd Pointer to the driver data structure.
* @kobj Pointer to the kobj for the block device.
*
* return value
* 0 Operation completed successfully.
* -EINVAL Invalid parameter.
*/
static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj)
{
if (!kobj || !dd)
return -EINVAL;
sysfs_remove_file(kobj, &dev_attr_status.attr);
return 0;
}
static int mtip_hw_debugfs_init(struct driver_data *dd)
{
if (!dfs_parent)
@ -3566,7 +3539,6 @@ static int mtip_block_initialize(struct driver_data *dd)
int rv = 0, wait_for_rebuild = 0;
sector_t capacity;
unsigned int index = 0;
struct kobject *kobj;
if (dd->disk)
goto skip_create_disk; /* hw init done, before rebuild */
@ -3672,17 +3644,7 @@ skip_create_disk:
set_capacity(dd->disk, capacity);
/* Enable the block device and add it to /dev */
device_add_disk(&dd->pdev->dev, dd->disk, NULL);
/*
* Now that the disk is active, initialize any sysfs attributes
* managed by the protocol layer.
*/
kobj = kobject_get(&disk_to_dev(dd->disk)->kobj);
if (kobj) {
mtip_hw_sysfs_init(dd, kobj);
kobject_put(kobj);
}
device_add_disk(&dd->pdev->dev, dd->disk, mtip_disk_attr_groups);
if (dd->mtip_svc_handler) {
set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
@ -3751,8 +3713,6 @@ static bool mtip_no_dev_cleanup(struct request *rq, void *data, bool reserv)
*/
static int mtip_block_remove(struct driver_data *dd)
{
struct kobject *kobj;
mtip_hw_debugfs_exit(dd);
if (dd->mtip_svc_handler) {
@ -3761,15 +3721,6 @@ static int mtip_block_remove(struct driver_data *dd)
kthread_stop(dd->mtip_svc_handler);
}
/* Clean up the sysfs attributes, if created */
if (test_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag)) {
kobj = kobject_get(&disk_to_dev(dd->disk)->kobj);
if (kobj) {
mtip_hw_sysfs_exit(dd, kobj);
kobject_put(kobj);
}
}
if (!dd->sr) {
/*
* Explicitly wait here for IOs to quiesce,