Commit d6bdbbdf authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarRafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230331093318.82288-4-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2df418cf
...@@ -209,6 +209,16 @@ int devtmpfs_init(void); ...@@ -209,6 +209,16 @@ int devtmpfs_init(void);
static inline int devtmpfs_init(void) { return 0; } static inline int devtmpfs_init(void) { return 0; }
#endif #endif
#ifdef CONFIG_BLOCK
extern struct class block_class;
static inline bool is_blockdev(struct device *dev)
{
return dev->class == &block_class;
}
#else
static inline bool is_blockdev(struct device *dev) { return false; }
#endif
/* Device links support */ /* Device links support */
int device_links_read_lock(void); int device_links_read_lock(void);
void device_links_read_unlock(int idx); void device_links_read_unlock(int idx);
......
...@@ -3430,27 +3430,13 @@ int dev_set_name(struct device *dev, const char *fmt, ...) ...@@ -3430,27 +3430,13 @@ int dev_set_name(struct device *dev, const char *fmt, ...)
} }
EXPORT_SYMBOL_GPL(dev_set_name); EXPORT_SYMBOL_GPL(dev_set_name);
/** /* select a /sys/dev/ directory for the device */
* 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.
*/
static struct kobject *device_to_dev_kobj(struct device *dev) static struct kobject *device_to_dev_kobj(struct device *dev)
{ {
struct kobject *kobj; if (is_blockdev(dev))
return sysfs_dev_block_kobj;
if (dev->class)
kobj = dev->class->dev_kobj;
else else
kobj = sysfs_dev_char_kobj; return sysfs_dev_char_kobj;
return kobj;
} }
static int device_create_sys_dev_entry(struct device *dev) static int device_create_sys_dev_entry(struct device *dev)
......
...@@ -94,15 +94,6 @@ static struct file_system_type dev_fs_type = { ...@@ -94,15 +94,6 @@ static struct file_system_type dev_fs_type = {
.mount = public_dev_mount, .mount = public_dev_mount,
}; };
#ifdef CONFIG_BLOCK
static inline int is_blockdev(struct device *dev)
{
return dev->class == &block_class;
}
#else
static inline int is_blockdev(struct device *dev) { return 0; }
#endif
static int devtmpfs_submit_req(struct req *req, const char *tmp) static int devtmpfs_submit_req(struct req *req, const char *tmp)
{ {
init_completion(&req->done); init_completion(&req->done);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment