Skip to content

Commit

Permalink
driver core: force NOIO allocations during unplug
Browse files Browse the repository at this point in the history
There is one overlooked situation under which a driver must not do IO to
allocate memory. You cannot do that while disconnecting a device. A
device being disconnected is no longer functional in most cases, yet IO
may fail only when the handler runs.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Link: https://lore.kernel.org/r/20200916191544.5104-1-oneukum@suse.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
oneukum authored and gregkh committed Sep 17, 2020
1 parent 9ef8638 commit b853001
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/pm_runtime.h>
#include <linux/netdevice.h>
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
#include <linux/sysfs.h>

#include "base.h"
Expand Down Expand Up @@ -3062,6 +3063,7 @@ void device_del(struct device *dev)
struct device *parent = dev->parent;
struct kobject *glue_dir = NULL;
struct class_interface *class_intf;
unsigned int noio_flag;

device_lock(dev);
kill_device(dev);
Expand All @@ -3073,6 +3075,7 @@ void device_del(struct device *dev)
/* Notify clients of device removal. This call must come
* before dpm_sysfs_remove().
*/
noio_flag = memalloc_noio_save();
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
Expand Down Expand Up @@ -3114,6 +3117,7 @@ void device_del(struct device *dev)
glue_dir = get_glue_dir(dev);
kobject_del(&dev->kobj);
cleanup_glue_dir(dev, glue_dir);
memalloc_noio_restore(noio_flag);
put_device(parent);
}
EXPORT_SYMBOL_GPL(device_del);
Expand Down

0 comments on commit b853001

Please sign in to comment.