[RFC 02/12] Drivers: hv: vmbus: Fix error path that deletes non-existent sysfs group

mhkelley58
2024-06-04T05:10:39Z

If vmbus_device_create() returns an error to vmbus_add_channel_work(),
the cleanup path calls free_channel(), which in turn calls
vmbus_remove_channel_attr_group(). But the channel attr group hasn't
been created yet, causing sysfs_remove_group() to generate multiple
WARNs about non-existent entries.

Fix the WARNs by adding a flag to struct vmbus_channel to indicate
whether the sysfs group for the channel has been created. Use the
flag to determine if the sysfs group should be removed.

Signed-off-by: Michael Kelley <mhklinux@outlook.com>
---
drivers/hv/vmbus_drv.c | 5 ++++-
include/linux/hyperv.h | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 12a707ab73f8..291a8358370b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1842,6 +1842,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
dev_err(device, "Unable to set up channel sysfs files\n");
return ret;
}
+ channel->channel_attr_set = true;

kobject_uevent(kobj, KOBJ_ADD);

@@ -1853,7 +1854,9 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
*/
void vmbus_remove_channel_attr_group(struct vmbus_channel *channel)
{
- sysfs_remove_group(&channel->kobj, &vmbus_chan_group);
+ if (channel->channel_attr_set)
+ sysfs_remove_group(&channel->kobj, &vmbus_chan_group);
+ channel->channel_attr_set = false;
}

/*
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 5e39baa7f6cb..d52c916cc492 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -980,6 +980,7 @@ struct vmbus_channel {
* For sysfs per-channel properties.
*/
struct kobject kobj;
+ bool channel_attr_set;

/*
* For performance critical channels (storage, networking
--
2.25.1