diff --git a/block/partitions/core.c b/block/partitions/core.c index 347c56a51d87..3fc0364c1c35 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -291,7 +291,11 @@ static void delete_partition(struct block_device *part) __invalidate_device(part, true); xa_erase(&part->bd_disk->part_tbl, part->bd_partno); - kobject_put(part->bd_holder_dir); + + if (!part->bd_holder_dir) { + kobject_put(part->bd_holder_dir); + } + device_del(&part->bd_device); /* diff --git a/drivers/base/core.c b/drivers/base/core.c index 2a61003ea2c1..d4f43fd0d0ae 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3486,16 +3486,20 @@ void device_del(struct device *dev) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); - dpm_sysfs_remove(dev); - if (parent) + if (dev->kobj.sd) + dpm_sysfs_remove(dev); + if (parent && klist_node_attached(&dev->p->knode_parent)) klist_del(&dev->p->knode_parent); if (MAJOR(dev->devt)) { devtmpfs_delete_node(dev); device_remove_sys_dev_entry(dev); - device_remove_file(dev, &dev_attr_dev); + + if (dev->kobj.sd) + device_remove_file(dev, &dev_attr_dev); } if (dev->class) { - device_remove_class_symlinks(dev); + if (dev->kobj.sd) + device_remove_class_symlinks(dev); mutex_lock(&dev->class->p->mutex); /* notify any interfaces that the device is now gone */ @@ -3504,11 +3508,14 @@ void device_del(struct device *dev) if (class_intf->remove_dev) class_intf->remove_dev(dev, class_intf); /* remove the device from the class list */ - klist_del(&dev->p->knode_class); + if (klist_node_attached(&dev->p->knode_class)) + klist_del(&dev->p->knode_class); mutex_unlock(&dev->class->p->mutex); } - device_remove_file(dev, &dev_attr_uevent); - device_remove_attrs(dev); + if (dev->kobj.sd) { + device_remove_file(dev, &dev_attr_uevent); + device_remove_attrs(dev); + } bus_remove_device(dev); device_pm_remove(dev); driver_deferred_probe_del(dev);