Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Driver core: add generic "subsystem" link to all devices

Like the SUBSYTEM= key we find in the environment of the uevent, this
creates a generic "subsystem" link in sysfs for every device. Userspace
usually doesn't care at all if its a "class" or a "bus" device. This
provides an unified way to determine the subsytem of a device, regardless
of the way the driver core has created it.

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Kay Sievers and committed by
Greg Kroah-Hartman
b9d9c82b 23681e47

+17 -7
+2 -5
block/genhd.c
··· 17 17 #include <linux/buffer_head.h> 18 18 #include <linux/mutex.h> 19 19 20 - static struct subsystem block_subsys; 21 - 20 + struct subsystem block_subsys; 22 21 static DEFINE_MUTEX(block_subsys_lock); 23 22 24 23 /* ··· 510 511 .uevent = block_uevent, 511 512 }; 512 513 513 - /* declare block_subsys. */ 514 - static decl_subsys(block, &ktype_block, &block_uevent_ops); 515 - 514 + decl_subsys(block, &ktype_block, &block_uevent_ops); 516 515 517 516 /* 518 517 * aggregate disk stat collector. Uses the same stats that the sysfs
+2
drivers/base/bus.c
··· 374 374 error = device_add_attrs(bus, dev); 375 375 if (!error) { 376 376 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 377 + sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); 377 378 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); 378 379 } 379 380 } ··· 409 408 void bus_remove_device(struct device * dev) 410 409 { 411 410 if (dev->bus) { 411 + sysfs_remove_link(&dev->kobj, "subsystem"); 412 412 sysfs_remove_link(&dev->kobj, "bus"); 413 413 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); 414 414 device_remove_attrs(dev->bus, dev);
+2
drivers/base/class.c
··· 561 561 goto out2; 562 562 563 563 /* add the needed attributes to this device */ 564 + sysfs_create_link(&class_dev->kobj, &parent_class->subsys.kset.kobj, "subsystem"); 564 565 class_dev->uevent_attr.attr.name = "uevent"; 565 566 class_dev->uevent_attr.attr.mode = S_IWUSR; 566 567 class_dev->uevent_attr.attr.owner = parent_class->owner; ··· 738 737 sysfs_remove_link(&class_dev->kobj, "device"); 739 738 sysfs_remove_link(&class_dev->dev->kobj, class_name); 740 739 } 740 + sysfs_remove_link(&class_dev->kobj, "subsystem"); 741 741 class_device_remove_file(class_dev, &class_dev->uevent_attr); 742 742 if (class_dev->devt_attr) 743 743 class_device_remove_file(class_dev, class_dev->devt_attr);
+7 -2
drivers/base/core.c
··· 319 319 dev->devt_attr = attr; 320 320 } 321 321 322 - if (dev->class) 322 + if (dev->class) { 323 + sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj, 324 + "subsystem"); 323 325 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, 324 326 dev->bus_id); 327 + } 325 328 326 329 if ((error = device_pm_add(dev))) 327 330 goto PMError; ··· 425 422 klist_del(&dev->knode_parent); 426 423 if (dev->devt_attr) 427 424 device_remove_file(dev, dev->devt_attr); 428 - if (dev->class) 425 + if (dev->class) { 426 + sysfs_remove_link(&dev->kobj, "subsystem"); 429 427 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); 428 + } 430 429 device_remove_file(dev, &dev->uevent_attr); 431 430 432 431 /* Notify the platform of the removal, in case they
+4
fs/partitions/check.c
··· 329 329 p->ios[0] = p->ios[1] = 0; 330 330 p->sectors[0] = p->sectors[1] = 0; 331 331 devfs_remove("%s/part%d", disk->devfs_name, part); 332 + sysfs_remove_link(&p->kobj, "subsystem"); 332 333 if (p->holder_dir) 333 334 kobject_unregister(p->holder_dir); 334 335 kobject_uevent(&p->kobj, KOBJ_REMOVE); ··· 364 363 kobject_add(&p->kobj); 365 364 if (!disk->part_uevent_suppress) 366 365 kobject_uevent(&p->kobj, KOBJ_ADD); 366 + sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem"); 367 367 partition_sysfs_add_subdir(p); 368 368 disk->part[part-1] = p; 369 369 } ··· 400 398 kfree(disk_name); 401 399 } 402 400 } 401 + sysfs_create_link(&disk->kobj, &block_subsys.kset.kobj, "subsystem"); 403 402 } 404 403 405 404 /* Not exported, helper to add_disk(). */ ··· 551 548 put_device(disk->driverfs_dev); 552 549 disk->driverfs_dev = NULL; 553 550 } 551 + sysfs_remove_link(&disk->kobj, "subsystem"); 554 552 kobject_del(&disk->kobj); 555 553 }