From d6bdbbdfb0d45a92407b90209e377bf8c0ed49e9 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 31 Mar 2023 11:33:15 +0200 Subject: driver core: clean up the logic to determine which /sys/dev/ directory to use When a dev_t is set in a struct device, an symlink in /sys/dev/ is created for it either under /sys/dev/block/ or /sys/dev/char/ depending on the device type. The logic to determine this would trigger off of the class of the object, and the kobj_type set in that location. But it turns out that this deep nesting isn't needed at all, as it's either a choice of block or "everything else" which is a char device. So make the logic a lot more simple and obvious, and remove the incorrect comments in the code that tried to document something that was not happening at all (it is impossible to set class->dev_kobj to NULL as the class core prevented that from happening. This removes the only place that class->dev_kobj was being used, so after this, it can be removed entirely. Acked-by: Rafael J. Wysocki Link: https://lore.kernel.org/r/20230331093318.82288-4-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'drivers/base/core.c') diff --git a/drivers/base/core.c b/drivers/base/core.c index e3bc34fcf779..dbc2ba6dfffc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3430,27 +3430,13 @@ int dev_set_name(struct device *dev, const char *fmt, ...) } EXPORT_SYMBOL_GPL(dev_set_name); -/** - * device_to_dev_kobj - select a /sys/dev/ directory for the device - * @dev: device - * - * By default we select char/ for new entries. Setting class->dev_obj - * to NULL prevents an entry from being created. class->dev_kobj must - * be set (or cleared) before any devices are registered to the class - * otherwise device_create_sys_dev_entry() and - * device_remove_sys_dev_entry() will disagree about the presence of - * the link. - */ +/* select a /sys/dev/ directory for the device */ static struct kobject *device_to_dev_kobj(struct device *dev) { - struct kobject *kobj; - - if (dev->class) - kobj = dev->class->dev_kobj; + if (is_blockdev(dev)) + return sysfs_dev_block_kobj; else - kobj = sysfs_dev_char_kobj; - - return kobj; + return sysfs_dev_char_kobj; } static int device_create_sys_dev_entry(struct device *dev) -- cgit