[PATCH] Driver Core: remove driver model detach_state

The driver model has a "detach_state" mechanism that:

- Has never been used by any in-kernel drive;
- Is superfluous, since driver remove() methods can do the same thing;
- Became buggy when the suspend() parameter changed semantics and type;
- Could self-deadlock when called from certain suspend contexts;
- Is effectively wasted documentation, object code, and headspace.

This removes that "detach_state" mechanism; net code shrink, as well
as a per-device saving in the driver model and sysfs.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg KH
0b405a0f 82428b62

+4 -112
+1 -3
Documentation/filesystems/sysfs-pci.txt
··· 7 7 |-- 0000:17:00.0 8 8 | |-- class 9 9 | |-- config 10 - | |-- detach_state 11 10 | |-- device 12 11 | |-- irq 13 12 | |-- local_cpus ··· 18 19 | |-- subsystem_device 19 20 | |-- subsystem_vendor 20 21 | `-- vendor 21 - `-- detach_state 22 + `-- ... 22 23 23 24 The topmost element describes the PCI domain and bus number. In this case, 24 25 the domain number is 0000 and the bus number is 17 (both values are in hex). ··· 30 31 ---- -------- 31 32 class PCI class (ascii, ro) 32 33 config PCI config space (binary, rw) 33 - detach_state connection status (bool, rw) 34 34 device PCI device (ascii, ro) 35 35 irq IRQ number (ascii, ro) 36 36 local_cpus nearby CPU mask (cpumask, ro)
-21
Documentation/power/devices.txt
··· 207 207 #READY_AFTER_RESUME 208 208 # 209 209 210 - Driver Detach Power Management 211 - 212 - The kernel now supports the ability to place a device in a low-power 213 - state when it is detached from its driver, which happens when its 214 - module is removed. 215 - 216 - Each device contains a 'detach_state' file in its sysfs directory 217 - which can be used to control this state. Reading from this file 218 - displays what the current detach state is set to. This is 0 (On) by 219 - default. A user may write a positive integer value to this file in the 220 - range of 1-4 inclusive. 221 - 222 - A value of 1-3 will indicate the device should be placed in that 223 - low-power state, which will cause ->suspend() to be called for that 224 - device. A value of 4 indicates that the device should be shutdown, so 225 - ->shutdown() will be called for that device. 226 - 227 - The driver is responsible for reinitializing the device when the 228 - module is re-inserted during it's ->probe() (or equivalent) method. 229 - The driver core will not call any extra functions when binding the 230 - device to the driver. 231 210 232 211 pm_message_t meaning 233 212
+2 -2
Documentation/powerpc/hvcs.txt
··· 347 347 looks like the following: 348 348 349 349 Pow5:/sys/bus/vio/drivers/hvcs/30000004 # ls 350 - . current_vty devspec name partner_vtys 351 - .. detach_state index partner_clcs vterm_state 350 + . current_vty devspec name partner_vtys 351 + .. index partner_clcs vterm_state 352 352 353 353 Each entry is provided, by default with a "name" attribute. Reading the 354 354 "name" attribute will reveal the device type as shown in the following
+1 -1
drivers/base/Makefile
··· 1 1 # Makefile for the Linux device tree 2 2 3 - obj-y := core.o sys.o interface.o bus.o \ 3 + obj-y := core.o sys.o bus.o \ 4 4 driver.o class.o class_simple.o platform.o \ 5 5 cpu.o firmware.o init.o map.o dmapool.o \ 6 6 attribute_container.o transport_class.o
-1
drivers/base/bus.c
··· 390 390 sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); 391 391 sysfs_remove_link(&dev->kobj, "driver"); 392 392 list_del_init(&dev->driver_list); 393 - device_detach_shutdown(dev); 394 393 if (drv->remove) 395 394 drv->remove(dev); 396 395 dev->driver = NULL;
-3
drivers/base/core.c
··· 31 31 #define to_dev(obj) container_of(obj, struct device, kobj) 32 32 #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) 33 33 34 - extern struct attribute * dev_default_attrs[]; 35 - 36 34 static ssize_t 37 35 dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 38 36 { ··· 87 89 static struct kobj_type ktype_device = { 88 90 .release = device_release, 89 91 .sysfs_ops = &dev_sysfs_ops, 90 - .default_attrs = dev_default_attrs, 91 92 }; 92 93 93 94
-51
drivers/base/interface.c
··· 1 - /* 2 - * drivers/base/interface.c - common driverfs interface that's exported to 3 - * the world for all devices. 4 - * 5 - * Copyright (c) 2002-3 Patrick Mochel 6 - * Copyright (c) 2002-3 Open Source Development Labs 7 - * 8 - * This file is released under the GPLv2 9 - * 10 - */ 11 - 12 - #include <linux/device.h> 13 - #include <linux/err.h> 14 - #include <linux/stat.h> 15 - #include <linux/string.h> 16 - 17 - /** 18 - * detach_state - control the default power state for the device. 19 - * 20 - * This is the state the device enters when it's driver module is 21 - * unloaded. The value is an unsigned integer, in the range of 0-4. 22 - * '0' indicates 'On', so no action will be taken when the driver is 23 - * unloaded. This is the default behavior. 24 - * '4' indicates 'Off', meaning the driver core will call the driver's 25 - * shutdown method to quiesce the device. 26 - * 1-3 indicate a low-power state for the device to enter via the 27 - * driver's suspend method. 28 - */ 29 - 30 - static ssize_t detach_show(struct device * dev, char * buf) 31 - { 32 - return sprintf(buf, "%u\n", dev->detach_state); 33 - } 34 - 35 - static ssize_t detach_store(struct device * dev, const char * buf, size_t n) 36 - { 37 - u32 state; 38 - state = simple_strtoul(buf, NULL, 10); 39 - if (state > 4) 40 - return -EINVAL; 41 - dev->detach_state = state; 42 - return n; 43 - } 44 - 45 - static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store); 46 - 47 - 48 - struct attribute * dev_default_attrs[] = { 49 - &dev_attr_detach_state.attr, 50 - NULL, 51 - };
-11
drivers/base/power/power.h
··· 1 - 2 - 3 - enum { 4 - DEVICE_PM_ON, 5 - DEVICE_PM1, 6 - DEVICE_PM2, 7 - DEVICE_PM3, 8 - DEVICE_PM_OFF, 9 - }; 10 - 11 1 /* 12 2 * shutdown.c 13 3 */ 14 4 15 - extern int device_detach_shutdown(struct device *); 16 5 extern void device_shutdown(void); 17 6 18 7
-16
drivers/base/power/shutdown.c
··· 19 19 extern struct subsystem devices_subsys; 20 20 21 21 22 - int device_detach_shutdown(struct device * dev) 23 - { 24 - if (!dev->detach_state) 25 - return 0; 26 - 27 - if (dev->detach_state == DEVICE_PM_OFF) { 28 - if (dev->driver && dev->driver->shutdown) { 29 - dev_dbg(dev, "shutdown\n"); 30 - dev->driver->shutdown(dev); 31 - } 32 - return 0; 33 - } 34 - return dpm_runtime_suspend(dev, dev->detach_state); 35 - } 36 - 37 - 38 22 /** 39 23 * We handle system devices differently - we suspend and shut them 40 24 * down last and resume them first. That way, we don't do anything stupid like
-3
include/linux/device.h
··· 273 273 BIOS data relevant to device) */ 274 274 struct dev_pm_info power; 275 275 276 - u32 detach_state; /* State to enter when device is 277 - detached from its driver. */ 278 - 279 276 u64 *dma_mask; /* dma mask (if dma'able device) */ 280 277 u64 coherent_dma_mask;/* Like dma_mask, but for 281 278 alloc_coherent mappings as