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

Merge tag 'driver-core-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
"Here's the "big" driver core update for 4.7-rc1.

Mostly just debugfs changes, the long-known and messy races with
removing debugfs files should be fixed thanks to the great work of
Nicolai Stange. We also have some isa updates in here (the x86
maintainers told me to take it through this tree), a new warning when
we run out of dynamic char major numbers, and a few other assorted
changes, details in the shortlog.

All have been in linux-next for some time with no reported issues"

* tag 'driver-core-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (32 commits)
Revert "base: dd: don't remove driver_data in -EPROBE_DEFER case"
gpio: ws16c48: Utilize the ISA bus driver
gpio: 104-idio-16: Utilize the ISA bus driver
gpio: 104-idi-48: Utilize the ISA bus driver
gpio: 104-dio-48e: Utilize the ISA bus driver
watchdog: ebc-c384_wdt: Utilize the ISA bus driver
iio: stx104: Utilize the module_isa_driver and max_num_isa_dev macros
iio: stx104: Add X86 dependency to STX104 Kconfig option
Documentation: Add ISA bus driver documentation
isa: Implement the max_num_isa_dev macro
isa: Implement the module_isa_driver macro
pnp: pnpbios: Add explicit X86_32 dependency to PNPBIOS
isa: Decouple X86_32 dependency from the ISA Kconfig option
driver-core: use 'dev' argument in dev_dbg_ratelimited stub
base: dd: don't remove driver_data in -EPROBE_DEFER case
kernfs: Move faulting copy_user operations outside of the mutex
devcoredump: add scatterlist support
debugfs: unproxify files created through debugfs_create_u32_array()
debugfs: unproxify files created through debugfs_create_blob()
debugfs: unproxify files created through debugfs_create_bool()
...

+1160 -519
+1
CREDITS
··· 768 768 D: Former security contact point (please use vendor-sec@lst.de) 769 769 D: ex 2.2 maintainer 770 770 D: 2.1.x modular sound 771 + D: Assigned major/minor numbers maintainer at lanana.org 771 772 S: c/o Red Hat UK Ltd 772 773 S: Alexandra House 773 774 S: Alexandra Terrace
+27 -57
Documentation/devices.txt
··· 1 1 2 - LINUX ALLOCATED DEVICES (2.6+ version) 3 - 4 - Maintained by Alan Cox <device@lanana.org> 5 - 6 - Last revised: 6th April 2009 2 + LINUX ALLOCATED DEVICES (4.x+ version) 7 3 8 4 This list is the Linux Device List, the official registry of allocated 9 5 device numbers and /dev directory nodes for the Linux operating 10 6 system. 11 7 12 - The latest version of this list is available from 13 - http://www.lanana.org/docs/device-list/ or 14 - ftp://ftp.kernel.org/pub/linux/docs/device-list/. This version may be 15 - newer than the one distributed with the Linux kernel. 16 - 17 - The LaTeX version of this document is no longer maintained. 8 + The LaTeX version of this document is no longer maintained, nor is 9 + the document that used to reside at lanana.org. This version in the 10 + mainline Linux kernel is the master document. Updates shall be sent 11 + as patches to the kernel maintainers (see the SubmittingPatches document). 12 + Specifically explore the sections titled "CHAR and MISC DRIVERS", and 13 + "BLOCK LAYER" in the MAINTAINERS file to find the right maintainers 14 + to involve for character and block devices. 18 15 19 16 This document is included by reference into the Filesystem Hierarchy 20 17 Standard (FHS). The FHS is available from http://www.pathname.com/fhs/. ··· 20 23 platform only. Allocations marked (68k/Atari) apply to Linux/68k on 21 24 the Atari platform only. 22 25 23 - The symbol {2.6} means the allocation is obsolete and scheduled for 24 - removal once kernel version 2.6 (or equivalent) is released. Some of these 25 - allocations have already been removed. 26 - 27 - This document is in the public domain. The author requests, however, 26 + This document is in the public domain. The authors requests, however, 28 27 that semantically altered versions are not distributed without 29 - permission of the author, assuming the author can be contacted without 28 + permission of the authors, assuming the authors can be contacted without 30 29 an unreasonable effort. 31 - 32 - In particular, please don't sent patches for this list to Linus, at 33 - least not without contacting me first. 34 - 35 - I do not have any information about these devices beyond what appears 36 - on this list. Any such information requests will be deleted without 37 - reply. 38 30 39 31 40 32 **** DEVICE DRIVERS AUTHORS PLEASE READ THIS **** 41 33 34 + Linux now has extensive support for dynamic allocation of device numbering 35 + and can use sysfs and udev (systemd) to handle the naming needs. There are 36 + still some exceptions in the serial and boot device area. Before asking 37 + for a device number make sure you actually need one. 38 + 42 39 To have a major number allocated, or a minor number in situations 43 - where that applies (e.g. busmice), please contact me with the 44 - appropriate device information. Also, if you have additional 45 - information regarding any of the devices listed below, or if I have 46 - made a mistake, I would greatly appreciate a note. 40 + where that applies (e.g. busmice), please submit a patch and send to 41 + the authors as indicated above. 47 42 48 - I do, however, make a few requests about the nature of your report. 49 - This is necessary for me to be able to keep this list up to date and 50 - correct in a timely manner. First of all, *please* send it to the 51 - correct address... <device@lanana.org>. I receive hundreds of email 52 - messages a day, so mail sent to other addresses may very well get lost 53 - in the avalanche. Please put in a descriptive subject, so I can find 54 - your mail again should I need to. Too many people send me email 55 - saying just "device number request" in the subject. 56 - 57 - Second, please include a description of the device *in the same format 58 - as this list*. The reason for this is that it is the only way I have 59 - found to ensure I have all the requisite information to publish your 43 + Keep the description of the device *in the same format 44 + as this list*. The reason for this is that it is the only way we have 45 + found to ensure we have all the requisite information to publish your 60 46 device and avoid conflicts. 61 47 62 - Third, please don't assume that the distributed version of the list is 63 - up to date. Due to the number of registrations I have to maintain it 64 - in "batch mode", so there is likely additional registrations that 65 - haven't been listed yet. 66 - 67 - Fourth, remember that Linux now has extensive support for dynamic allocation 68 - of device numbering and can use sysfs and udev to handle the naming needs. 69 - There are still some exceptions in the serial and boot device area. Before 70 - asking for a device number make sure you actually need one. 71 - 72 - Finally, sometimes I have to play "namespace police." Please don't be 73 - offended. I often get submissions for /dev names that would be bound 74 - to cause conflicts down the road. I am trying to avoid getting in a 48 + Finally, sometimes we have to play "namespace police." Please don't be 49 + offended. We often get submissions for /dev names that would be bound 50 + to cause conflicts down the road. We are trying to avoid getting in a 75 51 situation where we would have to suffer an incompatible forward 76 - change. Therefore, please consult with me *before* you make your 52 + change. Therefore, please consult with us *before* you make your 77 53 device names and numbers in any way public, at least to the point 78 54 where it would be at all difficult to get them changed. 79 55 ··· 3069 3099 129 = /dev/ipath_sma Device used by Subnet Management Agent 3070 3100 130 = /dev/ipath_diag Device used by diagnostics programs 3071 3101 3072 - 234-239 UNASSIGNED 3073 - 3074 - 240-254 char LOCAL/EXPERIMENTAL USE 3102 + 234-254 char RESERVED FOR DYNAMIC ASSIGNMENT 3103 + Character devices that request a dynamic allocation of major number will 3104 + take numbers starting from 254 and downward. 3075 3105 3076 3106 240-254 block LOCAL/EXPERIMENTAL USE 3077 3107 Allocated for local/experimental use. For devices not
+121
Documentation/isa.txt
··· 1 + ISA Drivers 2 + ----------- 3 + 4 + The following text is adapted from the commit message of the initial 5 + commit of the ISA bus driver authored by Rene Herman. 6 + 7 + During the recent "isa drivers using platform devices" discussion it was 8 + pointed out that (ALSA) ISA drivers ran into the problem of not having 9 + the option to fail driver load (device registration rather) upon not 10 + finding their hardware due to a probe() error not being passed up 11 + through the driver model. In the course of that, I suggested a separate 12 + ISA bus might be best; Russell King agreed and suggested this bus could 13 + use the .match() method for the actual device discovery. 14 + 15 + The attached does this. For this old non (generically) discoverable ISA 16 + hardware only the driver itself can do discovery so as a difference with 17 + the platform_bus, this isa_bus also distributes match() up to the 18 + driver. 19 + 20 + As another difference: these devices only exist in the driver model due 21 + to the driver creating them because it might want to drive them, meaning 22 + that all device creation has been made internal as well. 23 + 24 + The usage model this provides is nice, and has been acked from the ALSA 25 + side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's 26 + now (for oldisa-only drivers) become: 27 + 28 + static int __init alsa_card_foo_init(void) 29 + { 30 + return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS); 31 + } 32 + 33 + static void __exit alsa_card_foo_exit(void) 34 + { 35 + isa_unregister_driver(&snd_foo_isa_driver); 36 + } 37 + 38 + Quite like the other bus models therefore. This removes a lot of 39 + duplicated init code from the ALSA ISA drivers. 40 + 41 + The passed in isa_driver struct is the regular driver struct embedding a 42 + struct device_driver, the normal probe/remove/shutdown/suspend/resume 43 + callbacks, and as indicated that .match callback. 44 + 45 + The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev" 46 + parameter, indicating how many devices to create and call our methods 47 + with. 48 + 49 + The platform_driver callbacks are called with a platform_device param; 50 + the isa_driver callbacks are being called with a "struct device *dev, 51 + unsigned int id" pair directly -- with the device creation completely 52 + internal to the bus it's much cleaner to not leak isa_dev's by passing 53 + them in at all. The id is the only thing we ever want other then the 54 + struct device * anyways, and it makes for nicer code in the callbacks as 55 + well. 56 + 57 + With this additional .match() callback ISA drivers have all options. If 58 + ALSA would want to keep the old non-load behaviour, it could stick all 59 + of the old .probe in .match, which would only keep them registered after 60 + everything was found to be present and accounted for. If it wanted the 61 + behaviour of always loading as it inadvertently did for a bit after the 62 + changeover to platform devices, it could just not provide a .match() and 63 + do everything in .probe() as before. 64 + 65 + If it, as Takashi Iwai already suggested earlier as a way of following 66 + the model from saner buses more closely, wants to load when a later bind 67 + could conceivably succeed, it could use .match() for the prerequisites 68 + (such as checking the user wants the card enabled and that port/irq/dma 69 + values have been passed in) and .probe() for everything else. This is 70 + the nicest model. 71 + 72 + To the code... 73 + 74 + This exports only two functions; isa_{,un}register_driver(). 75 + 76 + isa_register_driver() register's the struct device_driver, and then 77 + loops over the passed in ndev creating devices and registering them. 78 + This causes the bus match method to be called for them, which is: 79 + 80 + int isa_bus_match(struct device *dev, struct device_driver *driver) 81 + { 82 + struct isa_driver *isa_driver = to_isa_driver(driver); 83 + 84 + if (dev->platform_data == isa_driver) { 85 + if (!isa_driver->match || 86 + isa_driver->match(dev, to_isa_dev(dev)->id)) 87 + return 1; 88 + dev->platform_data = NULL; 89 + } 90 + return 0; 91 + } 92 + 93 + The first thing this does is check if this device is in fact one of this 94 + driver's devices by seeing if the device's platform_data pointer is set 95 + to this driver. Platform devices compare strings, but we don't need to 96 + do that with everything being internal, so isa_register_driver() abuses 97 + dev->platform_data as a isa_driver pointer which we can then check here. 98 + I believe platform_data is available for this, but if rather not, moving 99 + the isa_driver pointer to the private struct isa_dev is ofcourse fine as 100 + well. 101 + 102 + Then, if the the driver did not provide a .match, it matches. If it did, 103 + the driver match() method is called to determine a match. 104 + 105 + If it did _not_ match, dev->platform_data is reset to indicate this to 106 + isa_register_driver which can then unregister the device again. 107 + 108 + If during all this, there's any error, or no devices matched at all 109 + everything is backed out again and the error, or -ENODEV, is returned. 110 + 111 + isa_unregister_driver() just unregisters the matched devices and the 112 + driver itself. 113 + 114 + module_isa_driver is a helper macro for ISA drivers which do not do 115 + anything special in module init/exit. This eliminates a lot of 116 + boilerplate code. Each module may only use this macro once, and calling 117 + it replaces module_init and module_exit. 118 + 119 + max_num_isa_dev is a macro to determine the maximum possible number of 120 + ISA devices which may be registered in the I/O port address space given 121 + the address extent of the ISA devices.
+7
MAINTAINERS
··· 6067 6067 F: kernel/irq/irqdomain.c 6068 6068 F: kernel/irq/msi.c 6069 6069 6070 + ISA 6071 + M: William Breathitt Gray <vilhelm.gray@gmail.com> 6072 + S: Maintained 6073 + F: Documentation/isa.txt 6074 + F: drivers/base/isa.c 6075 + F: include/linux/isa.h 6076 + 6070 6077 ISAPNP 6071 6078 M: Jaroslav Kysela <perex@perex.cz> 6072 6079 S: Maintained
+2 -2
arch/x86/Kconfig
··· 2445 2445 Enables ISA-style DMA support for devices requiring such controllers. 2446 2446 If unsure, say Y. 2447 2447 2448 - if X86_32 2449 - 2450 2448 config ISA 2451 2449 bool "ISA support" 2452 2450 ---help--- ··· 2453 2455 inside your box. Other bus systems are PCI, EISA, MicroChannel 2454 2456 (MCA) or VESA. ISA is an older system, now being displaced by PCI; 2455 2457 newer boards don't support it. If you have ISA, say Y, otherwise N. 2458 + 2459 + if X86_32 2456 2460 2457 2461 config EISA 2458 2462 bool "EISA support"
+74 -9
drivers/base/devcoredump.c
··· 4 4 * GPL LICENSE SUMMARY 5 5 * 6 6 * Copyright(c) 2014 Intel Mobile Communications GmbH 7 + * Copyright(c) 2015 Intel Deutschland GmbH 7 8 * 8 9 * This program is free software; you can redistribute it and/or modify 9 10 * it under the terms of version 2 of the GNU General Public License as ··· 42 41 43 42 struct devcd_entry { 44 43 struct device devcd_dev; 45 - const void *data; 44 + void *data; 46 45 size_t datalen; 47 46 struct module *owner; 48 47 ssize_t (*read)(char *buffer, loff_t offset, size_t count, 49 - const void *data, size_t datalen); 50 - void (*free)(const void *data); 48 + void *data, size_t datalen); 49 + void (*free)(void *data); 51 50 struct delayed_work del_wk; 52 51 struct device *failing_dev; 53 52 }; ··· 175 174 }; 176 175 177 176 static ssize_t devcd_readv(char *buffer, loff_t offset, size_t count, 178 - const void *data, size_t datalen) 177 + void *data, size_t datalen) 179 178 { 180 179 if (offset > datalen) 181 180 return -EINVAL; ··· 189 188 return count; 190 189 } 191 190 191 + static void devcd_freev(void *data) 192 + { 193 + vfree(data); 194 + } 195 + 192 196 /** 193 197 * dev_coredumpv - create device coredump with vmalloc data 194 198 * @dev: the struct device for the crashed device ··· 204 198 * This function takes ownership of the vmalloc'ed data and will free 205 199 * it when it is no longer used. See dev_coredumpm() for more information. 206 200 */ 207 - void dev_coredumpv(struct device *dev, const void *data, size_t datalen, 201 + void dev_coredumpv(struct device *dev, void *data, size_t datalen, 208 202 gfp_t gfp) 209 203 { 210 - dev_coredumpm(dev, NULL, data, datalen, gfp, devcd_readv, vfree); 204 + dev_coredumpm(dev, NULL, data, datalen, gfp, devcd_readv, devcd_freev); 211 205 } 212 206 EXPORT_SYMBOL_GPL(dev_coredumpv); 213 207 ··· 216 210 struct devcd_entry *devcd = dev_to_devcd(dev); 217 211 218 212 return devcd->failing_dev == failing; 213 + } 214 + 215 + /** 216 + * devcd_free_sgtable - free all the memory of the given scatterlist table 217 + * (i.e. both pages and scatterlist instances) 218 + * NOTE: if two tables allocated with devcd_alloc_sgtable and then chained 219 + * using the sg_chain function then that function should be called only once 220 + * on the chained table 221 + * @table: pointer to sg_table to free 222 + */ 223 + static void devcd_free_sgtable(void *data) 224 + { 225 + _devcd_free_sgtable(data); 226 + } 227 + 228 + /** 229 + * devcd_read_from_table - copy data from sg_table to a given buffer 230 + * and return the number of bytes read 231 + * @buffer: the buffer to copy the data to it 232 + * @buf_len: the length of the buffer 233 + * @data: the scatterlist table to copy from 234 + * @offset: start copy from @offset@ bytes from the head of the data 235 + * in the given scatterlist 236 + * @data_len: the length of the data in the sg_table 237 + */ 238 + static ssize_t devcd_read_from_sgtable(char *buffer, loff_t offset, 239 + size_t buf_len, void *data, 240 + size_t data_len) 241 + { 242 + struct scatterlist *table = data; 243 + 244 + if (offset > data_len) 245 + return -EINVAL; 246 + 247 + if (offset + buf_len > data_len) 248 + buf_len = data_len - offset; 249 + return sg_pcopy_to_buffer(table, sg_nents(table), buffer, buf_len, 250 + offset); 219 251 } 220 252 221 253 /** ··· 272 228 * function will be called to free the data. 273 229 */ 274 230 void dev_coredumpm(struct device *dev, struct module *owner, 275 - const void *data, size_t datalen, gfp_t gfp, 231 + void *data, size_t datalen, gfp_t gfp, 276 232 ssize_t (*read)(char *buffer, loff_t offset, size_t count, 277 - const void *data, size_t datalen), 278 - void (*free)(const void *data)) 233 + void *data, size_t datalen), 234 + void (*free)(void *data)) 279 235 { 280 236 static atomic_t devcd_count = ATOMIC_INIT(0); 281 237 struct devcd_entry *devcd; ··· 334 290 free(data); 335 291 } 336 292 EXPORT_SYMBOL_GPL(dev_coredumpm); 293 + 294 + /** 295 + * dev_coredumpmsg - create device coredump that uses scatterlist as data 296 + * parameter 297 + * @dev: the struct device for the crashed device 298 + * @table: the dump data 299 + * @datalen: length of the data 300 + * @gfp: allocation flags 301 + * 302 + * Creates a new device coredump for the given device. If a previous one hasn't 303 + * been read yet, the new coredump is discarded. The data lifetime is determined 304 + * by the device coredump framework and when it is no longer needed 305 + * it will free the data. 306 + */ 307 + void dev_coredumpsg(struct device *dev, struct scatterlist *table, 308 + size_t datalen, gfp_t gfp) 309 + { 310 + dev_coredumpm(dev, NULL, table, datalen, gfp, devcd_read_from_sgtable, 311 + devcd_free_sgtable); 312 + } 313 + EXPORT_SYMBOL_GPL(dev_coredumpsg); 337 314 338 315 static int __init devcoredump_init(void) 339 316 {
+1 -3
drivers/firmware/qemu_fw_cfg.c
··· 125 125 # define FW_CFG_CTRL_OFF 0x00 126 126 # define FW_CFG_DATA_OFF 0x01 127 127 # else 128 - # warning "QEMU FW_CFG may not be available on this architecture!" 129 - # define FW_CFG_CTRL_OFF 0x00 130 - # define FW_CFG_DATA_OFF 0x01 128 + # error "QEMU FW_CFG not available on this architecture!" 131 129 # endif 132 130 #endif 133 131
+22 -16
drivers/gpio/Kconfig
··· 530 530 531 531 config GPIO_104_DIO_48E 532 532 tristate "ACCES 104-DIO-48E GPIO support" 533 + depends on ISA 533 534 select GPIOLIB_IRQCHIP 534 535 help 535 - Enables GPIO support for the ACCES 104-DIO-48E family. The base port 536 - address for the device may be configured via the dio_48e_base module 537 - parameter. The interrupt line number for the device may be configured 538 - via the dio_48e_irq module parameter. 536 + Enables GPIO support for the ACCES 104-DIO-48E series (104-DIO-48E, 537 + 104-DIO-24E). The base port addresses for the devices may be 538 + configured via the base module parameter. The interrupt line numbers 539 + for the devices may be configured via the irq module parameter. 539 540 540 541 config GPIO_104_IDIO_16 541 542 tristate "ACCES 104-IDIO-16 GPIO support" 543 + depends on ISA 542 544 select GPIOLIB_IRQCHIP 543 545 help 544 - Enables GPIO support for the ACCES 104-IDIO-16 family. The base port 545 - address for the device may be set via the idio_16_base module 546 - parameter. The interrupt line number for the device may be set via the 547 - idio_16_irq module parameter. 546 + Enables GPIO support for the ACCES 104-IDIO-16 family (104-IDIO-16, 547 + 104-IDIO-16E, 104-IDO-16, 104-IDIO-8, 104-IDIO-8E, 104-IDO-8). The 548 + base port addresses for the devices may be configured via the base 549 + module parameter. The interrupt line numbers for the devices may be 550 + configured via the irq module parameter. 548 551 549 552 config GPIO_104_IDI_48 550 553 tristate "ACCES 104-IDI-48 GPIO support" 554 + depends on ISA 551 555 select GPIOLIB_IRQCHIP 552 556 help 553 - Enables GPIO support for the ACCES 104-IDI-48 family. The base port 554 - address for the device may be configured via the idi_48_base module 555 - parameter. The interrupt line number for the device may be configured 556 - via the idi_48_irq module parameter. 557 + Enables GPIO support for the ACCES 104-IDI-48 family (104-IDI-48A, 558 + 104-IDI-48AC, 104-IDI-48B, 104-IDI-48BC). The base port addresses for 559 + the devices may be configured via the base module parameter. The 560 + interrupt line numbers for the devices may be configured via the irq 561 + module parameter. 557 562 558 563 config GPIO_F7188X 559 564 tristate "F71869, F71869A, F71882FG, F71889F and F81866 GPIO support" ··· 627 622 628 623 config GPIO_WS16C48 629 624 tristate "WinSystems WS16C48 GPIO support" 625 + depends on ISA 630 626 select GPIOLIB_IRQCHIP 631 627 help 632 - Enables GPIO support for the WinSystems WS16C48. The base port address 633 - for the device may be configured via the ws16c48_base module 634 - parameter. The interrupt line number for the device may be configured 635 - via the ws16c48_irq module parameter. 628 + Enables GPIO support for the WinSystems WS16C48. The base port 629 + addresses for the devices may be configured via the base module 630 + parameter. The interrupt line numbers for the devices may be 631 + configured via the irq module parameter. 636 632 637 633 endmenu 638 634
+38 -68
drivers/gpio/gpio-104-dio-48e.c
··· 1 1 /* 2 - * GPIO driver for the ACCES 104-DIO-48E 2 + * GPIO driver for the ACCES 104-DIO-48E series 3 3 * Copyright (C) 2016 William Breathitt Gray 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify ··· 10 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 12 * General Public License for more details. 13 + * 14 + * This driver supports the following ACCES devices: 104-DIO-48E and 15 + * 104-DIO-24E. 13 16 */ 14 17 #include <linux/bitops.h> 15 18 #include <linux/device.h> ··· 22 19 #include <linux/ioport.h> 23 20 #include <linux/interrupt.h> 24 21 #include <linux/irqdesc.h> 22 + #include <linux/isa.h> 25 23 #include <linux/kernel.h> 26 24 #include <linux/module.h> 27 25 #include <linux/moduleparam.h> 28 - #include <linux/platform_device.h> 29 26 #include <linux/spinlock.h> 30 27 31 - static unsigned dio_48e_base; 32 - module_param(dio_48e_base, uint, 0); 33 - MODULE_PARM_DESC(dio_48e_base, "ACCES 104-DIO-48E base address"); 34 - static unsigned dio_48e_irq; 35 - module_param(dio_48e_irq, uint, 0); 36 - MODULE_PARM_DESC(dio_48e_irq, "ACCES 104-DIO-48E interrupt line number"); 28 + #define DIO48E_EXTENT 16 29 + #define MAX_NUM_DIO48E max_num_isa_dev(DIO48E_EXTENT) 30 + 31 + static unsigned int base[MAX_NUM_DIO48E]; 32 + static unsigned int num_dio48e; 33 + module_param_array(base, uint, &num_dio48e, 0); 34 + MODULE_PARM_DESC(base, "ACCES 104-DIO-48E base addresses"); 35 + 36 + static unsigned int irq[MAX_NUM_DIO48E]; 37 + module_param_array(irq, uint, NULL, 0); 38 + MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers"); 37 39 38 40 /** 39 41 * struct dio48e_gpio - GPIO device private data structure ··· 302 294 return IRQ_HANDLED; 303 295 } 304 296 305 - static int __init dio48e_probe(struct platform_device *pdev) 297 + static int dio48e_probe(struct device *dev, unsigned int id) 306 298 { 307 - struct device *dev = &pdev->dev; 308 299 struct dio48e_gpio *dio48egpio; 309 - const unsigned base = dio_48e_base; 310 - const unsigned extent = 16; 311 300 const char *const name = dev_name(dev); 312 301 int err; 313 - const unsigned irq = dio_48e_irq; 314 302 315 303 dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL); 316 304 if (!dio48egpio) 317 305 return -ENOMEM; 318 306 319 - if (!devm_request_region(dev, base, extent, name)) { 307 + if (!devm_request_region(dev, base[id], DIO48E_EXTENT, name)) { 320 308 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 321 - base, base + extent); 309 + base[id], base[id] + DIO48E_EXTENT); 322 310 return -EBUSY; 323 311 } 324 312 ··· 328 324 dio48egpio->chip.direction_output = dio48e_gpio_direction_output; 329 325 dio48egpio->chip.get = dio48e_gpio_get; 330 326 dio48egpio->chip.set = dio48e_gpio_set; 331 - dio48egpio->base = base; 332 - dio48egpio->irq = irq; 327 + dio48egpio->base = base[id]; 328 + dio48egpio->irq = irq[id]; 333 329 334 330 spin_lock_init(&dio48egpio->lock); 335 331 ··· 342 338 } 343 339 344 340 /* initialize all GPIO as output */ 345 - outb(0x80, base + 3); 346 - outb(0x00, base); 347 - outb(0x00, base + 1); 348 - outb(0x00, base + 2); 349 - outb(0x00, base + 3); 350 - outb(0x80, base + 7); 351 - outb(0x00, base + 4); 352 - outb(0x00, base + 5); 353 - outb(0x00, base + 6); 354 - outb(0x00, base + 7); 341 + outb(0x80, base[id] + 3); 342 + outb(0x00, base[id]); 343 + outb(0x00, base[id] + 1); 344 + outb(0x00, base[id] + 2); 345 + outb(0x00, base[id] + 3); 346 + outb(0x80, base[id] + 7); 347 + outb(0x00, base[id] + 4); 348 + outb(0x00, base[id] + 5); 349 + outb(0x00, base[id] + 6); 350 + outb(0x00, base[id] + 7); 355 351 356 352 /* disable IRQ by default */ 357 - inb(base + 0xB); 353 + inb(base[id] + 0xB); 358 354 359 355 err = gpiochip_irqchip_add(&dio48egpio->chip, &dio48e_irqchip, 0, 360 356 handle_edge_irq, IRQ_TYPE_NONE); ··· 363 359 goto err_gpiochip_remove; 364 360 } 365 361 366 - err = request_irq(irq, dio48e_irq_handler, 0, name, dio48egpio); 362 + err = request_irq(irq[id], dio48e_irq_handler, 0, name, dio48egpio); 367 363 if (err) { 368 364 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 369 365 goto err_gpiochip_remove; ··· 376 372 return err; 377 373 } 378 374 379 - static int dio48e_remove(struct platform_device *pdev) 375 + static int dio48e_remove(struct device *dev, unsigned int id) 380 376 { 381 - struct dio48e_gpio *const dio48egpio = platform_get_drvdata(pdev); 377 + struct dio48e_gpio *const dio48egpio = dev_get_drvdata(dev); 382 378 383 379 free_irq(dio48egpio->irq, dio48egpio); 384 380 gpiochip_remove(&dio48egpio->chip); ··· 386 382 return 0; 387 383 } 388 384 389 - static struct platform_device *dio48e_device; 390 - 391 - static struct platform_driver dio48e_driver = { 385 + static struct isa_driver dio48e_driver = { 386 + .probe = dio48e_probe, 392 387 .driver = { 393 388 .name = "104-dio-48e" 394 389 }, 395 390 .remove = dio48e_remove 396 391 }; 397 - 398 - static void __exit dio48e_exit(void) 399 - { 400 - platform_device_unregister(dio48e_device); 401 - platform_driver_unregister(&dio48e_driver); 402 - } 403 - 404 - static int __init dio48e_init(void) 405 - { 406 - int err; 407 - 408 - dio48e_device = platform_device_alloc(dio48e_driver.driver.name, -1); 409 - if (!dio48e_device) 410 - return -ENOMEM; 411 - 412 - err = platform_device_add(dio48e_device); 413 - if (err) 414 - goto err_platform_device; 415 - 416 - err = platform_driver_probe(&dio48e_driver, dio48e_probe); 417 - if (err) 418 - goto err_platform_driver; 419 - 420 - return 0; 421 - 422 - err_platform_driver: 423 - platform_device_del(dio48e_device); 424 - err_platform_device: 425 - platform_device_put(dio48e_device); 426 - return err; 427 - } 428 - 429 - module_init(dio48e_init); 430 - module_exit(dio48e_exit); 392 + module_isa_driver(dio48e_driver, num_dio48e); 431 393 432 394 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 433 395 MODULE_DESCRIPTION("ACCES 104-DIO-48E GPIO driver");
+28 -58
drivers/gpio/gpio-104-idi-48.c
··· 10 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 12 * General Public License for more details. 13 + * 14 + * This driver supports the following ACCES devices: 104-IDI-48A, 15 + * 104-IDI-48AC, 104-IDI-48B, and 104-IDI-48BC. 13 16 */ 14 17 #include <linux/bitops.h> 15 18 #include <linux/device.h> ··· 22 19 #include <linux/ioport.h> 23 20 #include <linux/interrupt.h> 24 21 #include <linux/irqdesc.h> 22 + #include <linux/isa.h> 25 23 #include <linux/kernel.h> 26 24 #include <linux/module.h> 27 25 #include <linux/moduleparam.h> 28 - #include <linux/platform_device.h> 29 26 #include <linux/spinlock.h> 30 27 31 - static unsigned idi_48_base; 32 - module_param(idi_48_base, uint, 0); 33 - MODULE_PARM_DESC(idi_48_base, "ACCES 104-IDI-48 base address"); 34 - static unsigned idi_48_irq; 35 - module_param(idi_48_irq, uint, 0); 36 - MODULE_PARM_DESC(idi_48_irq, "ACCES 104-IDI-48 interrupt line number"); 28 + #define IDI_48_EXTENT 8 29 + #define MAX_NUM_IDI_48 max_num_isa_dev(IDI_48_EXTENT) 30 + 31 + static unsigned int base[MAX_NUM_IDI_48]; 32 + static unsigned int num_idi_48; 33 + module_param_array(base, uint, &num_idi_48, 0); 34 + MODULE_PARM_DESC(base, "ACCES 104-IDI-48 base addresses"); 35 + 36 + static unsigned int irq[MAX_NUM_IDI_48]; 37 + module_param_array(irq, uint, NULL, 0); 38 + MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers"); 37 39 38 40 /** 39 41 * struct idi_48_gpio - GPIO device private data structure ··· 219 211 return IRQ_HANDLED; 220 212 } 221 213 222 - static int __init idi_48_probe(struct platform_device *pdev) 214 + static int idi_48_probe(struct device *dev, unsigned int id) 223 215 { 224 - struct device *dev = &pdev->dev; 225 216 struct idi_48_gpio *idi48gpio; 226 - const unsigned base = idi_48_base; 227 - const unsigned extent = 8; 228 217 const char *const name = dev_name(dev); 229 218 int err; 230 - const unsigned irq = idi_48_irq; 231 219 232 220 idi48gpio = devm_kzalloc(dev, sizeof(*idi48gpio), GFP_KERNEL); 233 221 if (!idi48gpio) 234 222 return -ENOMEM; 235 223 236 - if (!devm_request_region(dev, base, extent, name)) { 224 + if (!devm_request_region(dev, base[id], IDI_48_EXTENT, name)) { 237 225 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 238 - base, base + extent); 226 + base[id], base[id] + IDI_48_EXTENT); 239 227 return -EBUSY; 240 228 } 241 229 ··· 243 239 idi48gpio->chip.get_direction = idi_48_gpio_get_direction; 244 240 idi48gpio->chip.direction_input = idi_48_gpio_direction_input; 245 241 idi48gpio->chip.get = idi_48_gpio_get; 246 - idi48gpio->base = base; 247 - idi48gpio->irq = irq; 242 + idi48gpio->base = base[id]; 243 + idi48gpio->irq = irq[id]; 248 244 249 245 spin_lock_init(&idi48gpio->lock); 250 246 ··· 257 253 } 258 254 259 255 /* Disable IRQ by default */ 260 - outb(0, base + 7); 261 - inb(base + 7); 256 + outb(0, base[id] + 7); 257 + inb(base[id] + 7); 262 258 263 259 err = gpiochip_irqchip_add(&idi48gpio->chip, &idi_48_irqchip, 0, 264 260 handle_edge_irq, IRQ_TYPE_NONE); ··· 267 263 goto err_gpiochip_remove; 268 264 } 269 265 270 - err = request_irq(irq, idi_48_irq_handler, IRQF_SHARED, name, 266 + err = request_irq(irq[id], idi_48_irq_handler, IRQF_SHARED, name, 271 267 idi48gpio); 272 268 if (err) { 273 269 dev_err(dev, "IRQ handler registering failed (%d)\n", err); ··· 281 277 return err; 282 278 } 283 279 284 - static int idi_48_remove(struct platform_device *pdev) 280 + static int idi_48_remove(struct device *dev, unsigned int id) 285 281 { 286 - struct idi_48_gpio *const idi48gpio = platform_get_drvdata(pdev); 282 + struct idi_48_gpio *const idi48gpio = dev_get_drvdata(dev); 287 283 288 284 free_irq(idi48gpio->irq, idi48gpio); 289 285 gpiochip_remove(&idi48gpio->chip); ··· 291 287 return 0; 292 288 } 293 289 294 - static struct platform_device *idi_48_device; 295 - 296 - static struct platform_driver idi_48_driver = { 290 + static struct isa_driver idi_48_driver = { 291 + .probe = idi_48_probe, 297 292 .driver = { 298 293 .name = "104-idi-48" 299 294 }, 300 295 .remove = idi_48_remove 301 296 }; 302 - 303 - static void __exit idi_48_exit(void) 304 - { 305 - platform_device_unregister(idi_48_device); 306 - platform_driver_unregister(&idi_48_driver); 307 - } 308 - 309 - static int __init idi_48_init(void) 310 - { 311 - int err; 312 - 313 - idi_48_device = platform_device_alloc(idi_48_driver.driver.name, -1); 314 - if (!idi_48_device) 315 - return -ENOMEM; 316 - 317 - err = platform_device_add(idi_48_device); 318 - if (err) 319 - goto err_platform_device; 320 - 321 - err = platform_driver_probe(&idi_48_driver, idi_48_probe); 322 - if (err) 323 - goto err_platform_driver; 324 - 325 - return 0; 326 - 327 - err_platform_driver: 328 - platform_device_del(idi_48_device); 329 - err_platform_device: 330 - platform_device_put(idi_48_device); 331 - return err; 332 - } 333 - 334 - module_init(idi_48_init); 335 - module_exit(idi_48_exit); 297 + module_isa_driver(idi_48_driver, num_idi_48); 336 298 337 299 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 338 300 MODULE_DESCRIPTION("ACCES 104-IDI-48 GPIO driver");
+28 -57
drivers/gpio/gpio-104-idio-16.c
··· 10 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 12 * General Public License for more details. 13 + * 14 + * This driver supports the following ACCES devices: 104-IDIO-16, 15 + * 104-IDIO-16E, 104-IDO-16, 104-IDIO-8, 104-IDIO-8E, and 104-IDO-8. 13 16 */ 14 17 #include <linux/bitops.h> 15 18 #include <linux/device.h> ··· 22 19 #include <linux/ioport.h> 23 20 #include <linux/interrupt.h> 24 21 #include <linux/irqdesc.h> 22 + #include <linux/isa.h> 25 23 #include <linux/kernel.h> 26 24 #include <linux/module.h> 27 25 #include <linux/moduleparam.h> 28 - #include <linux/platform_device.h> 29 26 #include <linux/spinlock.h> 30 27 31 - static unsigned idio_16_base; 32 - module_param(idio_16_base, uint, 0); 33 - MODULE_PARM_DESC(idio_16_base, "ACCES 104-IDIO-16 base address"); 34 - static unsigned idio_16_irq; 35 - module_param(idio_16_irq, uint, 0); 36 - MODULE_PARM_DESC(idio_16_irq, "ACCES 104-IDIO-16 interrupt line number"); 28 + #define IDIO_16_EXTENT 8 29 + #define MAX_NUM_IDIO_16 max_num_isa_dev(IDIO_16_EXTENT) 30 + 31 + static unsigned int base[MAX_NUM_IDIO_16]; 32 + static unsigned int num_idio_16; 33 + module_param_array(base, uint, &num_idio_16, 0); 34 + MODULE_PARM_DESC(base, "ACCES 104-IDIO-16 base addresses"); 35 + 36 + static unsigned int irq[MAX_NUM_IDIO_16]; 37 + module_param_array(irq, uint, NULL, 0); 38 + MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers"); 37 39 38 40 /** 39 41 * struct idio_16_gpio - GPIO device private data structure ··· 193 185 return IRQ_HANDLED; 194 186 } 195 187 196 - static int __init idio_16_probe(struct platform_device *pdev) 188 + static int idio_16_probe(struct device *dev, unsigned int id) 197 189 { 198 - struct device *dev = &pdev->dev; 199 190 struct idio_16_gpio *idio16gpio; 200 - const unsigned base = idio_16_base; 201 - const unsigned extent = 8; 202 191 const char *const name = dev_name(dev); 203 192 int err; 204 - const unsigned irq = idio_16_irq; 205 193 206 194 idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL); 207 195 if (!idio16gpio) 208 196 return -ENOMEM; 209 197 210 - if (!devm_request_region(dev, base, extent, name)) { 198 + if (!devm_request_region(dev, base[id], IDIO_16_EXTENT, name)) { 211 199 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 212 - base, base + extent); 200 + base[id], base[id] + IDIO_16_EXTENT); 213 201 return -EBUSY; 214 202 } 215 203 ··· 219 215 idio16gpio->chip.direction_output = idio_16_gpio_direction_output; 220 216 idio16gpio->chip.get = idio_16_gpio_get; 221 217 idio16gpio->chip.set = idio_16_gpio_set; 222 - idio16gpio->base = base; 223 - idio16gpio->irq = irq; 218 + idio16gpio->base = base[id]; 219 + idio16gpio->irq = irq[id]; 224 220 idio16gpio->out_state = 0xFFFF; 225 221 226 222 spin_lock_init(&idio16gpio->lock); ··· 234 230 } 235 231 236 232 /* Disable IRQ by default */ 237 - outb(0, base + 2); 238 - outb(0, base + 1); 233 + outb(0, base[id] + 2); 234 + outb(0, base[id] + 1); 239 235 240 236 err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0, 241 237 handle_edge_irq, IRQ_TYPE_NONE); ··· 244 240 goto err_gpiochip_remove; 245 241 } 246 242 247 - err = request_irq(irq, idio_16_irq_handler, 0, name, idio16gpio); 243 + err = request_irq(irq[id], idio_16_irq_handler, 0, name, idio16gpio); 248 244 if (err) { 249 245 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 250 246 goto err_gpiochip_remove; ··· 257 253 return err; 258 254 } 259 255 260 - static int idio_16_remove(struct platform_device *pdev) 256 + static int idio_16_remove(struct device *dev, unsigned int id) 261 257 { 262 - struct idio_16_gpio *const idio16gpio = platform_get_drvdata(pdev); 258 + struct idio_16_gpio *const idio16gpio = dev_get_drvdata(dev); 263 259 264 260 free_irq(idio16gpio->irq, idio16gpio); 265 261 gpiochip_remove(&idio16gpio->chip); ··· 267 263 return 0; 268 264 } 269 265 270 - static struct platform_device *idio_16_device; 271 - 272 - static struct platform_driver idio_16_driver = { 266 + static struct isa_driver idio_16_driver = { 267 + .probe = idio_16_probe, 273 268 .driver = { 274 269 .name = "104-idio-16" 275 270 }, 276 271 .remove = idio_16_remove 277 272 }; 278 273 279 - static void __exit idio_16_exit(void) 280 - { 281 - platform_device_unregister(idio_16_device); 282 - platform_driver_unregister(&idio_16_driver); 283 - } 284 - 285 - static int __init idio_16_init(void) 286 - { 287 - int err; 288 - 289 - idio_16_device = platform_device_alloc(idio_16_driver.driver.name, -1); 290 - if (!idio_16_device) 291 - return -ENOMEM; 292 - 293 - err = platform_device_add(idio_16_device); 294 - if (err) 295 - goto err_platform_device; 296 - 297 - err = platform_driver_probe(&idio_16_driver, idio_16_probe); 298 - if (err) 299 - goto err_platform_driver; 300 - 301 - return 0; 302 - 303 - err_platform_driver: 304 - platform_device_del(idio_16_device); 305 - err_platform_device: 306 - platform_device_put(idio_16_device); 307 - return err; 308 - } 309 - 310 - module_init(idio_16_init); 311 - module_exit(idio_16_exit); 274 + module_isa_driver(idio_16_driver, num_idio_16); 312 275 313 276 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 314 277 MODULE_DESCRIPTION("ACCES 104-IDIO-16 GPIO driver");
+28 -60
drivers/gpio/gpio-ws16c48.c
··· 19 19 #include <linux/ioport.h> 20 20 #include <linux/interrupt.h> 21 21 #include <linux/irqdesc.h> 22 + #include <linux/isa.h> 22 23 #include <linux/kernel.h> 23 24 #include <linux/module.h> 24 25 #include <linux/moduleparam.h> 25 - #include <linux/platform_device.h> 26 26 #include <linux/spinlock.h> 27 27 28 - static unsigned ws16c48_base; 29 - module_param(ws16c48_base, uint, 0); 30 - MODULE_PARM_DESC(ws16c48_base, "WinSystems WS16C48 base address"); 31 - static unsigned ws16c48_irq; 32 - module_param(ws16c48_irq, uint, 0); 33 - MODULE_PARM_DESC(ws16c48_irq, "WinSystems WS16C48 interrupt line number"); 28 + #define WS16C48_EXTENT 16 29 + #define MAX_NUM_WS16C48 max_num_isa_dev(WS16C48_EXTENT) 30 + 31 + static unsigned int base[MAX_NUM_WS16C48]; 32 + static unsigned int num_ws16c48; 33 + module_param_array(base, uint, &num_ws16c48, 0); 34 + MODULE_PARM_DESC(base, "WinSystems WS16C48 base addresses"); 35 + 36 + static unsigned int irq[MAX_NUM_WS16C48]; 37 + module_param_array(irq, uint, NULL, 0); 38 + MODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers"); 34 39 35 40 /** 36 41 * struct ws16c48_gpio - GPIO device private data structure ··· 303 298 return IRQ_HANDLED; 304 299 } 305 300 306 - static int __init ws16c48_probe(struct platform_device *pdev) 301 + static int ws16c48_probe(struct device *dev, unsigned int id) 307 302 { 308 - struct device *dev = &pdev->dev; 309 303 struct ws16c48_gpio *ws16c48gpio; 310 - const unsigned base = ws16c48_base; 311 - const unsigned extent = 16; 312 304 const char *const name = dev_name(dev); 313 305 int err; 314 - const unsigned irq = ws16c48_irq; 315 306 316 307 ws16c48gpio = devm_kzalloc(dev, sizeof(*ws16c48gpio), GFP_KERNEL); 317 308 if (!ws16c48gpio) 318 309 return -ENOMEM; 319 310 320 - if (!devm_request_region(dev, base, extent, name)) { 311 + if (!devm_request_region(dev, base[id], WS16C48_EXTENT, name)) { 321 312 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 322 - base, base + extent); 313 + base[id], base[id] + WS16C48_EXTENT); 323 314 return -EBUSY; 324 315 } 325 316 ··· 329 328 ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; 330 329 ws16c48gpio->chip.get = ws16c48_gpio_get; 331 330 ws16c48gpio->chip.set = ws16c48_gpio_set; 332 - ws16c48gpio->base = base; 333 - ws16c48gpio->irq = irq; 331 + ws16c48gpio->base = base[id]; 332 + ws16c48gpio->irq = irq[id]; 334 333 335 334 spin_lock_init(&ws16c48gpio->lock); 336 335 ··· 343 342 } 344 343 345 344 /* Disable IRQ by default */ 346 - outb(0x80, base + 7); 347 - outb(0, base + 8); 348 - outb(0, base + 9); 349 - outb(0, base + 10); 350 - outb(0xC0, base + 7); 345 + outb(0x80, base[id] + 7); 346 + outb(0, base[id] + 8); 347 + outb(0, base[id] + 9); 348 + outb(0, base[id] + 10); 349 + outb(0xC0, base[id] + 7); 351 350 352 351 err = gpiochip_irqchip_add(&ws16c48gpio->chip, &ws16c48_irqchip, 0, 353 352 handle_edge_irq, IRQ_TYPE_NONE); ··· 356 355 goto err_gpiochip_remove; 357 356 } 358 357 359 - err = request_irq(irq, ws16c48_irq_handler, IRQF_SHARED, name, 358 + err = request_irq(irq[id], ws16c48_irq_handler, IRQF_SHARED, name, 360 359 ws16c48gpio); 361 360 if (err) { 362 361 dev_err(dev, "IRQ handler registering failed (%d)\n", err); ··· 370 369 return err; 371 370 } 372 371 373 - static int ws16c48_remove(struct platform_device *pdev) 372 + static int ws16c48_remove(struct device *dev, unsigned int id) 374 373 { 375 - struct ws16c48_gpio *const ws16c48gpio = platform_get_drvdata(pdev); 374 + struct ws16c48_gpio *const ws16c48gpio = dev_get_drvdata(dev); 376 375 377 376 free_irq(ws16c48gpio->irq, ws16c48gpio); 378 377 gpiochip_remove(&ws16c48gpio->chip); ··· 380 379 return 0; 381 380 } 382 381 383 - static struct platform_device *ws16c48_device; 384 - 385 - static struct platform_driver ws16c48_driver = { 382 + static struct isa_driver ws16c48_driver = { 383 + .probe = ws16c48_probe, 386 384 .driver = { 387 385 .name = "ws16c48" 388 386 }, 389 387 .remove = ws16c48_remove 390 388 }; 391 389 392 - static void __exit ws16c48_exit(void) 393 - { 394 - platform_device_unregister(ws16c48_device); 395 - platform_driver_unregister(&ws16c48_driver); 396 - } 397 - 398 - static int __init ws16c48_init(void) 399 - { 400 - int err; 401 - 402 - ws16c48_device = platform_device_alloc(ws16c48_driver.driver.name, -1); 403 - if (!ws16c48_device) 404 - return -ENOMEM; 405 - 406 - err = platform_device_add(ws16c48_device); 407 - if (err) 408 - goto err_platform_device; 409 - 410 - err = platform_driver_probe(&ws16c48_driver, ws16c48_probe); 411 - if (err) 412 - goto err_platform_driver; 413 - 414 - return 0; 415 - 416 - err_platform_driver: 417 - platform_device_del(ws16c48_device); 418 - err_platform_device: 419 - platform_device_put(ws16c48_device); 420 - return err; 421 - } 422 - 423 - module_init(ws16c48_init); 424 - module_exit(ws16c48_exit); 390 + module_isa_driver(ws16c48_driver, num_ws16c48); 425 391 426 392 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 427 393 MODULE_DESCRIPTION("WinSystems WS16C48 GPIO driver");
+1 -1
drivers/iio/dac/Kconfig
··· 210 210 211 211 config STX104 212 212 tristate "Apex Embedded Systems STX104 DAC driver" 213 - depends on ISA 213 + depends on X86 && ISA 214 214 help 215 215 Say yes here to build support for the 2-channel DAC on the Apex 216 216 Embedded Systems STX104 integrated analog PC/104 card. The base port
+3 -21
drivers/iio/dac/stx104.c
··· 33 33 } 34 34 35 35 #define STX104_EXTENT 16 36 - /** 37 - * The highest base address possible for an ISA device is 0x3FF; this results in 38 - * 1024 possible base addresses. Dividing the number of possible base addresses 39 - * by the address extent taken by each device results in the maximum number of 40 - * devices on a system. 41 - */ 42 - #define MAX_NUM_STX104 (1024 / STX104_EXTENT) 43 36 44 - static unsigned base[MAX_NUM_STX104]; 45 - static unsigned num_stx104; 37 + static unsigned int base[max_num_isa_dev(STX104_EXTENT)]; 38 + static unsigned int num_stx104; 46 39 module_param_array(base, uint, &num_stx104, 0); 47 40 MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses"); 48 41 ··· 127 134 } 128 135 }; 129 136 130 - static void __exit stx104_exit(void) 131 - { 132 - isa_unregister_driver(&stx104_driver); 133 - } 134 - 135 - static int __init stx104_init(void) 136 - { 137 - return isa_register_driver(&stx104_driver, num_stx104); 138 - } 139 - 140 - module_init(stx104_init); 141 - module_exit(stx104_exit); 137 + module_isa_driver(stx104_driver, num_stx104); 142 138 143 139 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 144 140 MODULE_DESCRIPTION("Apex Embedded Systems STX104 DAC driver");
+2 -2
drivers/net/wireless/intel/iwlwifi/mvm/fw-dbg.c
··· 71 71 #include "iwl-csr.h" 72 72 73 73 static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count, 74 - const void *data, size_t datalen) 74 + void *data, size_t datalen) 75 75 { 76 76 const struct iwl_mvm_dump_ptrs *dump_ptrs = data; 77 77 ssize_t bytes_read; ··· 104 104 return bytes_read + bytes_read_trans; 105 105 } 106 106 107 - static void iwl_mvm_free_coredump(const void *data) 107 + static void iwl_mvm_free_coredump(void *data) 108 108 { 109 109 const struct iwl_mvm_dump_ptrs *fw_error_dump = data; 110 110
+1 -1
drivers/pnp/pnpbios/Kconfig
··· 3 3 # 4 4 config PNPBIOS 5 5 bool "Plug and Play BIOS support" 6 - depends on ISA && X86 6 + depends on ISA && X86_32 7 7 default n 8 8 ---help--- 9 9 Linux uses the PNPBIOS as defined in "Plug and Play BIOS
+1 -1
drivers/watchdog/Kconfig
··· 738 738 739 739 config EBC_C384_WDT 740 740 tristate "WinSystems EBC-C384 Watchdog Timer" 741 - depends on X86 741 + depends on X86 && ISA 742 742 select WATCHDOG_CORE 743 743 help 744 744 Enables watchdog timer support for the watchdog timer on the
+10 -33
drivers/watchdog/ebc-c384_wdt.c
··· 16 16 #include <linux/errno.h> 17 17 #include <linux/io.h> 18 18 #include <linux/ioport.h> 19 + #include <linux/isa.h> 19 20 #include <linux/kernel.h> 20 21 #include <linux/module.h> 21 22 #include <linux/moduleparam.h> 22 - #include <linux/platform_device.h> 23 23 #include <linux/types.h> 24 24 #include <linux/watchdog.h> 25 25 ··· 95 95 .identity = MODULE_NAME 96 96 }; 97 97 98 - static int __init ebc_c384_wdt_probe(struct platform_device *pdev) 98 + static int ebc_c384_wdt_probe(struct device *dev, unsigned int id) 99 99 { 100 - struct device *dev = &pdev->dev; 101 100 struct watchdog_device *wdd; 102 101 103 102 if (!devm_request_region(dev, BASE_ADDR, ADDR_EXTENT, dev_name(dev))) { ··· 121 122 dev_warn(dev, "Invalid timeout (%u seconds), using default (%u seconds)\n", 122 123 timeout, WATCHDOG_TIMEOUT); 123 124 124 - platform_set_drvdata(pdev, wdd); 125 + dev_set_drvdata(dev, wdd); 125 126 126 127 return watchdog_register_device(wdd); 127 128 } 128 129 129 - static int ebc_c384_wdt_remove(struct platform_device *pdev) 130 + static int ebc_c384_wdt_remove(struct device *dev, unsigned int id) 130 131 { 131 - struct watchdog_device *wdd = platform_get_drvdata(pdev); 132 + struct watchdog_device *wdd = dev_get_drvdata(dev); 132 133 133 134 watchdog_unregister_device(wdd); 134 135 135 136 return 0; 136 137 } 137 138 138 - static struct platform_driver ebc_c384_wdt_driver = { 139 + static struct isa_driver ebc_c384_wdt_driver = { 140 + .probe = ebc_c384_wdt_probe, 139 141 .driver = { 140 142 .name = MODULE_NAME 141 143 }, 142 144 .remove = ebc_c384_wdt_remove 143 145 }; 144 146 145 - static struct platform_device *ebc_c384_wdt_device; 146 - 147 147 static int __init ebc_c384_wdt_init(void) 148 148 { 149 - int err; 150 - 151 149 if (!dmi_match(DMI_BOARD_NAME, "EBC-C384 SBC")) 152 150 return -ENODEV; 153 151 154 - ebc_c384_wdt_device = platform_device_alloc(MODULE_NAME, -1); 155 - if (!ebc_c384_wdt_device) 156 - return -ENOMEM; 157 - 158 - err = platform_device_add(ebc_c384_wdt_device); 159 - if (err) 160 - goto err_platform_device; 161 - 162 - err = platform_driver_probe(&ebc_c384_wdt_driver, ebc_c384_wdt_probe); 163 - if (err) 164 - goto err_platform_driver; 165 - 166 - return 0; 167 - 168 - err_platform_driver: 169 - platform_device_del(ebc_c384_wdt_device); 170 - err_platform_device: 171 - platform_device_put(ebc_c384_wdt_device); 172 - return err; 152 + return isa_register_driver(&ebc_c384_wdt_driver, 1); 173 153 } 174 154 175 155 static void __exit ebc_c384_wdt_exit(void) 176 156 { 177 - platform_device_unregister(ebc_c384_wdt_device); 178 - platform_driver_unregister(&ebc_c384_wdt_driver); 157 + isa_unregister_driver(&ebc_c384_wdt_driver); 179 158 } 180 159 181 160 module_init(ebc_c384_wdt_init); ··· 162 185 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 163 186 MODULE_DESCRIPTION("WinSystems EBC-C384 watchdog timer driver"); 164 187 MODULE_LICENSE("GPL v2"); 165 - MODULE_ALIAS("platform:" MODULE_NAME); 188 + MODULE_ALIAS("isa:" MODULE_NAME);
+4
fs/char_dev.c
··· 91 91 break; 92 92 } 93 93 94 + if (i < CHRDEV_MAJOR_DYN_END) 95 + pr_warn("CHRDEV \"%s\" major number %d goes below the dynamic allocation range", 96 + name, i); 97 + 94 98 if (i == 0) { 95 99 ret = -EBUSY; 96 100 goto out;
+370 -66
fs/debugfs/file.c
··· 22 22 #include <linux/slab.h> 23 23 #include <linux/atomic.h> 24 24 #include <linux/device.h> 25 + #include <linux/srcu.h> 26 + #include <asm/poll.h> 27 + 28 + #include "internal.h" 29 + 30 + struct poll_table_struct; 25 31 26 32 static ssize_t default_read_file(struct file *file, char __user *buf, 27 33 size_t count, loff_t *ppos) ··· 41 35 return count; 42 36 } 43 37 44 - const struct file_operations debugfs_file_operations = { 38 + const struct file_operations debugfs_noop_file_operations = { 45 39 .read = default_read_file, 46 40 .write = default_write_file, 47 41 .open = simple_open, 48 42 .llseek = noop_llseek, 49 43 }; 50 44 51 - static struct dentry *debugfs_create_mode(const char *name, umode_t mode, 52 - struct dentry *parent, void *value, 53 - const struct file_operations *fops, 54 - const struct file_operations *fops_ro, 55 - const struct file_operations *fops_wo) 45 + /** 46 + * debugfs_use_file_start - mark the beginning of file data access 47 + * @dentry: the dentry object whose data is being accessed. 48 + * @srcu_idx: a pointer to some memory to store a SRCU index in. 49 + * 50 + * Up to a matching call to debugfs_use_file_finish(), any 51 + * successive call into the file removing functions debugfs_remove() 52 + * and debugfs_remove_recursive() will block. Since associated private 53 + * file data may only get freed after a successful return of any of 54 + * the removal functions, you may safely access it after a successful 55 + * call to debugfs_use_file_start() without worrying about 56 + * lifetime issues. 57 + * 58 + * If -%EIO is returned, the file has already been removed and thus, 59 + * it is not safe to access any of its data. If, on the other hand, 60 + * it is allowed to access the file data, zero is returned. 61 + * 62 + * Regardless of the return code, any call to 63 + * debugfs_use_file_start() must be followed by a matching call 64 + * to debugfs_use_file_finish(). 65 + */ 66 + int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx) 67 + __acquires(&debugfs_srcu) 68 + { 69 + *srcu_idx = srcu_read_lock(&debugfs_srcu); 70 + barrier(); 71 + if (d_unlinked(dentry)) 72 + return -EIO; 73 + return 0; 74 + } 75 + EXPORT_SYMBOL_GPL(debugfs_use_file_start); 76 + 77 + /** 78 + * debugfs_use_file_finish - mark the end of file data access 79 + * @srcu_idx: the SRCU index "created" by a former call to 80 + * debugfs_use_file_start(). 81 + * 82 + * Allow any ongoing concurrent call into debugfs_remove() or 83 + * debugfs_remove_recursive() blocked by a former call to 84 + * debugfs_use_file_start() to proceed and return to its caller. 85 + */ 86 + void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu) 87 + { 88 + srcu_read_unlock(&debugfs_srcu, srcu_idx); 89 + } 90 + EXPORT_SYMBOL_GPL(debugfs_use_file_finish); 91 + 92 + #define F_DENTRY(filp) ((filp)->f_path.dentry) 93 + 94 + #define REAL_FOPS_DEREF(dentry) \ 95 + ((const struct file_operations *)(dentry)->d_fsdata) 96 + 97 + static int open_proxy_open(struct inode *inode, struct file *filp) 98 + { 99 + const struct dentry *dentry = F_DENTRY(filp); 100 + const struct file_operations *real_fops = NULL; 101 + int srcu_idx, r; 102 + 103 + r = debugfs_use_file_start(dentry, &srcu_idx); 104 + if (r) { 105 + r = -ENOENT; 106 + goto out; 107 + } 108 + 109 + real_fops = REAL_FOPS_DEREF(dentry); 110 + real_fops = fops_get(real_fops); 111 + if (!real_fops) { 112 + /* Huh? Module did not clean up after itself at exit? */ 113 + WARN(1, "debugfs file owner did not clean up at exit: %pd", 114 + dentry); 115 + r = -ENXIO; 116 + goto out; 117 + } 118 + replace_fops(filp, real_fops); 119 + 120 + if (real_fops->open) 121 + r = real_fops->open(inode, filp); 122 + 123 + out: 124 + fops_put(real_fops); 125 + debugfs_use_file_finish(srcu_idx); 126 + return r; 127 + } 128 + 129 + const struct file_operations debugfs_open_proxy_file_operations = { 130 + .open = open_proxy_open, 131 + }; 132 + 133 + #define PROTO(args...) args 134 + #define ARGS(args...) args 135 + 136 + #define FULL_PROXY_FUNC(name, ret_type, filp, proto, args) \ 137 + static ret_type full_proxy_ ## name(proto) \ 138 + { \ 139 + const struct dentry *dentry = F_DENTRY(filp); \ 140 + const struct file_operations *real_fops = \ 141 + REAL_FOPS_DEREF(dentry); \ 142 + int srcu_idx; \ 143 + ret_type r; \ 144 + \ 145 + r = debugfs_use_file_start(dentry, &srcu_idx); \ 146 + if (likely(!r)) \ 147 + r = real_fops->name(args); \ 148 + debugfs_use_file_finish(srcu_idx); \ 149 + return r; \ 150 + } 151 + 152 + FULL_PROXY_FUNC(llseek, loff_t, filp, 153 + PROTO(struct file *filp, loff_t offset, int whence), 154 + ARGS(filp, offset, whence)); 155 + 156 + FULL_PROXY_FUNC(read, ssize_t, filp, 157 + PROTO(struct file *filp, char __user *buf, size_t size, 158 + loff_t *ppos), 159 + ARGS(filp, buf, size, ppos)); 160 + 161 + FULL_PROXY_FUNC(write, ssize_t, filp, 162 + PROTO(struct file *filp, const char __user *buf, size_t size, 163 + loff_t *ppos), 164 + ARGS(filp, buf, size, ppos)); 165 + 166 + FULL_PROXY_FUNC(unlocked_ioctl, long, filp, 167 + PROTO(struct file *filp, unsigned int cmd, unsigned long arg), 168 + ARGS(filp, cmd, arg)); 169 + 170 + static unsigned int full_proxy_poll(struct file *filp, 171 + struct poll_table_struct *wait) 172 + { 173 + const struct dentry *dentry = F_DENTRY(filp); 174 + const struct file_operations *real_fops = REAL_FOPS_DEREF(dentry); 175 + int srcu_idx; 176 + unsigned int r = 0; 177 + 178 + if (debugfs_use_file_start(dentry, &srcu_idx)) { 179 + debugfs_use_file_finish(srcu_idx); 180 + return POLLHUP; 181 + } 182 + 183 + r = real_fops->poll(filp, wait); 184 + debugfs_use_file_finish(srcu_idx); 185 + return r; 186 + } 187 + 188 + static int full_proxy_release(struct inode *inode, struct file *filp) 189 + { 190 + const struct dentry *dentry = F_DENTRY(filp); 191 + const struct file_operations *real_fops = REAL_FOPS_DEREF(dentry); 192 + const struct file_operations *proxy_fops = filp->f_op; 193 + int r = 0; 194 + 195 + /* 196 + * We must not protect this against removal races here: the 197 + * original releaser should be called unconditionally in order 198 + * not to leak any resources. Releasers must not assume that 199 + * ->i_private is still being meaningful here. 200 + */ 201 + if (real_fops->release) 202 + r = real_fops->release(inode, filp); 203 + 204 + replace_fops(filp, d_inode(dentry)->i_fop); 205 + kfree((void *)proxy_fops); 206 + fops_put(real_fops); 207 + return 0; 208 + } 209 + 210 + static void __full_proxy_fops_init(struct file_operations *proxy_fops, 211 + const struct file_operations *real_fops) 212 + { 213 + proxy_fops->release = full_proxy_release; 214 + if (real_fops->llseek) 215 + proxy_fops->llseek = full_proxy_llseek; 216 + if (real_fops->read) 217 + proxy_fops->read = full_proxy_read; 218 + if (real_fops->write) 219 + proxy_fops->write = full_proxy_write; 220 + if (real_fops->poll) 221 + proxy_fops->poll = full_proxy_poll; 222 + if (real_fops->unlocked_ioctl) 223 + proxy_fops->unlocked_ioctl = full_proxy_unlocked_ioctl; 224 + } 225 + 226 + static int full_proxy_open(struct inode *inode, struct file *filp) 227 + { 228 + const struct dentry *dentry = F_DENTRY(filp); 229 + const struct file_operations *real_fops = NULL; 230 + struct file_operations *proxy_fops = NULL; 231 + int srcu_idx, r; 232 + 233 + r = debugfs_use_file_start(dentry, &srcu_idx); 234 + if (r) { 235 + r = -ENOENT; 236 + goto out; 237 + } 238 + 239 + real_fops = REAL_FOPS_DEREF(dentry); 240 + real_fops = fops_get(real_fops); 241 + if (!real_fops) { 242 + /* Huh? Module did not cleanup after itself at exit? */ 243 + WARN(1, "debugfs file owner did not clean up at exit: %pd", 244 + dentry); 245 + r = -ENXIO; 246 + goto out; 247 + } 248 + 249 + proxy_fops = kzalloc(sizeof(*proxy_fops), GFP_KERNEL); 250 + if (!proxy_fops) { 251 + r = -ENOMEM; 252 + goto free_proxy; 253 + } 254 + __full_proxy_fops_init(proxy_fops, real_fops); 255 + replace_fops(filp, proxy_fops); 256 + 257 + if (real_fops->open) { 258 + r = real_fops->open(inode, filp); 259 + 260 + if (filp->f_op != proxy_fops) { 261 + /* No protection against file removal anymore. */ 262 + WARN(1, "debugfs file owner replaced proxy fops: %pd", 263 + dentry); 264 + goto free_proxy; 265 + } 266 + } 267 + 268 + goto out; 269 + free_proxy: 270 + kfree(proxy_fops); 271 + fops_put(real_fops); 272 + out: 273 + debugfs_use_file_finish(srcu_idx); 274 + return r; 275 + } 276 + 277 + const struct file_operations debugfs_full_proxy_file_operations = { 278 + .open = full_proxy_open, 279 + }; 280 + 281 + ssize_t debugfs_attr_read(struct file *file, char __user *buf, 282 + size_t len, loff_t *ppos) 283 + { 284 + ssize_t ret; 285 + int srcu_idx; 286 + 287 + ret = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 288 + if (likely(!ret)) 289 + ret = simple_attr_read(file, buf, len, ppos); 290 + debugfs_use_file_finish(srcu_idx); 291 + return ret; 292 + } 293 + EXPORT_SYMBOL_GPL(debugfs_attr_read); 294 + 295 + ssize_t debugfs_attr_write(struct file *file, const char __user *buf, 296 + size_t len, loff_t *ppos) 297 + { 298 + ssize_t ret; 299 + int srcu_idx; 300 + 301 + ret = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 302 + if (likely(!ret)) 303 + ret = simple_attr_write(file, buf, len, ppos); 304 + debugfs_use_file_finish(srcu_idx); 305 + return ret; 306 + } 307 + EXPORT_SYMBOL_GPL(debugfs_attr_write); 308 + 309 + static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode, 310 + struct dentry *parent, void *value, 311 + const struct file_operations *fops, 312 + const struct file_operations *fops_ro, 313 + const struct file_operations *fops_wo) 56 314 { 57 315 /* if there are no write bits set, make read only */ 58 316 if (!(mode & S_IWUGO)) 59 - return debugfs_create_file(name, mode, parent, value, fops_ro); 317 + return debugfs_create_file_unsafe(name, mode, parent, value, 318 + fops_ro); 60 319 /* if there are no read bits set, make write only */ 61 320 if (!(mode & S_IRUGO)) 62 - return debugfs_create_file(name, mode, parent, value, fops_wo); 321 + return debugfs_create_file_unsafe(name, mode, parent, value, 322 + fops_wo); 63 323 64 - return debugfs_create_file(name, mode, parent, value, fops); 324 + return debugfs_create_file_unsafe(name, mode, parent, value, fops); 65 325 } 66 326 67 327 static int debugfs_u8_set(void *data, u64 val) ··· 340 68 *val = *(u8 *)data; 341 69 return 0; 342 70 } 343 - DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n"); 344 - DEFINE_SIMPLE_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%llu\n"); 345 - DEFINE_SIMPLE_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n"); 71 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n"); 72 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%llu\n"); 73 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n"); 346 74 347 75 /** 348 76 * debugfs_create_u8 - create a debugfs file that is used to read and write an unsigned 8-bit value ··· 371 99 struct dentry *debugfs_create_u8(const char *name, umode_t mode, 372 100 struct dentry *parent, u8 *value) 373 101 { 374 - return debugfs_create_mode(name, mode, parent, value, &fops_u8, 102 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u8, 375 103 &fops_u8_ro, &fops_u8_wo); 376 104 } 377 105 EXPORT_SYMBOL_GPL(debugfs_create_u8); ··· 386 114 *val = *(u16 *)data; 387 115 return 0; 388 116 } 389 - DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n"); 390 - DEFINE_SIMPLE_ATTRIBUTE(fops_u16_ro, debugfs_u16_get, NULL, "%llu\n"); 391 - DEFINE_SIMPLE_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n"); 117 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n"); 118 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_ro, debugfs_u16_get, NULL, "%llu\n"); 119 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n"); 392 120 393 121 /** 394 122 * debugfs_create_u16 - create a debugfs file that is used to read and write an unsigned 16-bit value ··· 417 145 struct dentry *debugfs_create_u16(const char *name, umode_t mode, 418 146 struct dentry *parent, u16 *value) 419 147 { 420 - return debugfs_create_mode(name, mode, parent, value, &fops_u16, 148 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u16, 421 149 &fops_u16_ro, &fops_u16_wo); 422 150 } 423 151 EXPORT_SYMBOL_GPL(debugfs_create_u16); ··· 432 160 *val = *(u32 *)data; 433 161 return 0; 434 162 } 435 - DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n"); 436 - DEFINE_SIMPLE_ATTRIBUTE(fops_u32_ro, debugfs_u32_get, NULL, "%llu\n"); 437 - DEFINE_SIMPLE_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n"); 163 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n"); 164 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_ro, debugfs_u32_get, NULL, "%llu\n"); 165 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n"); 438 166 439 167 /** 440 168 * debugfs_create_u32 - create a debugfs file that is used to read and write an unsigned 32-bit value ··· 463 191 struct dentry *debugfs_create_u32(const char *name, umode_t mode, 464 192 struct dentry *parent, u32 *value) 465 193 { 466 - return debugfs_create_mode(name, mode, parent, value, &fops_u32, 194 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u32, 467 195 &fops_u32_ro, &fops_u32_wo); 468 196 } 469 197 EXPORT_SYMBOL_GPL(debugfs_create_u32); ··· 479 207 *val = *(u64 *)data; 480 208 return 0; 481 209 } 482 - DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n"); 483 - DEFINE_SIMPLE_ATTRIBUTE(fops_u64_ro, debugfs_u64_get, NULL, "%llu\n"); 484 - DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n"); 210 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n"); 211 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_ro, debugfs_u64_get, NULL, "%llu\n"); 212 + DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n"); 485 213 486 214 /** 487 215 * debugfs_create_u64 - create a debugfs file that is used to read and write an unsigned 64-bit value ··· 510 238 struct dentry *debugfs_create_u64(const char *name, umode_t mode, 511 239 struct dentry *parent, u64 *value) 512 240 { 513 - return debugfs_create_mode(name, mode, parent, value, &fops_u64, 241 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u64, 514 242 &fops_u64_ro, &fops_u64_wo); 515 243 } 516 244 EXPORT_SYMBOL_GPL(debugfs_create_u64); ··· 526 254 *val = *(unsigned long *)data; 527 255 return 0; 528 256 } 529 - DEFINE_SIMPLE_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, "%llu\n"); 530 - DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n"); 531 - DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n"); 257 + DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, 258 + "%llu\n"); 259 + DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n"); 260 + DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n"); 532 261 533 262 /** 534 263 * debugfs_create_ulong - create a debugfs file that is used to read and write ··· 559 286 struct dentry *debugfs_create_ulong(const char *name, umode_t mode, 560 287 struct dentry *parent, unsigned long *value) 561 288 { 562 - return debugfs_create_mode(name, mode, parent, value, &fops_ulong, 563 - &fops_ulong_ro, &fops_ulong_wo); 289 + return debugfs_create_mode_unsafe(name, mode, parent, value, 290 + &fops_ulong, &fops_ulong_ro, 291 + &fops_ulong_wo); 564 292 } 565 293 EXPORT_SYMBOL_GPL(debugfs_create_ulong); 566 294 567 - DEFINE_SIMPLE_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n"); 568 - DEFINE_SIMPLE_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n"); 569 - DEFINE_SIMPLE_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n"); 295 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n"); 296 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n"); 297 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n"); 570 298 571 - DEFINE_SIMPLE_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set, "0x%04llx\n"); 572 - DEFINE_SIMPLE_ATTRIBUTE(fops_x16_ro, debugfs_u16_get, NULL, "0x%04llx\n"); 573 - DEFINE_SIMPLE_ATTRIBUTE(fops_x16_wo, NULL, debugfs_u16_set, "0x%04llx\n"); 299 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set, 300 + "0x%04llx\n"); 301 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_ro, debugfs_u16_get, NULL, "0x%04llx\n"); 302 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_wo, NULL, debugfs_u16_set, "0x%04llx\n"); 574 303 575 - DEFINE_SIMPLE_ATTRIBUTE(fops_x32, debugfs_u32_get, debugfs_u32_set, "0x%08llx\n"); 576 - DEFINE_SIMPLE_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n"); 577 - DEFINE_SIMPLE_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n"); 304 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x32, debugfs_u32_get, debugfs_u32_set, 305 + "0x%08llx\n"); 306 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n"); 307 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n"); 578 308 579 - DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n"); 580 - DEFINE_SIMPLE_ATTRIBUTE(fops_x64_ro, debugfs_u64_get, NULL, "0x%016llx\n"); 581 - DEFINE_SIMPLE_ATTRIBUTE(fops_x64_wo, NULL, debugfs_u64_set, "0x%016llx\n"); 309 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, 310 + "0x%016llx\n"); 311 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_ro, debugfs_u64_get, NULL, "0x%016llx\n"); 312 + DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_wo, NULL, debugfs_u64_set, "0x%016llx\n"); 582 313 583 314 /* 584 315 * debugfs_create_x{8,16,32,64} - create a debugfs file that is used to read and write an unsigned {8,16,32,64}-bit value ··· 605 328 struct dentry *debugfs_create_x8(const char *name, umode_t mode, 606 329 struct dentry *parent, u8 *value) 607 330 { 608 - return debugfs_create_mode(name, mode, parent, value, &fops_x8, 331 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x8, 609 332 &fops_x8_ro, &fops_x8_wo); 610 333 } 611 334 EXPORT_SYMBOL_GPL(debugfs_create_x8); ··· 623 346 struct dentry *debugfs_create_x16(const char *name, umode_t mode, 624 347 struct dentry *parent, u16 *value) 625 348 { 626 - return debugfs_create_mode(name, mode, parent, value, &fops_x16, 349 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x16, 627 350 &fops_x16_ro, &fops_x16_wo); 628 351 } 629 352 EXPORT_SYMBOL_GPL(debugfs_create_x16); ··· 641 364 struct dentry *debugfs_create_x32(const char *name, umode_t mode, 642 365 struct dentry *parent, u32 *value) 643 366 { 644 - return debugfs_create_mode(name, mode, parent, value, &fops_x32, 367 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x32, 645 368 &fops_x32_ro, &fops_x32_wo); 646 369 } 647 370 EXPORT_SYMBOL_GPL(debugfs_create_x32); ··· 659 382 struct dentry *debugfs_create_x64(const char *name, umode_t mode, 660 383 struct dentry *parent, u64 *value) 661 384 { 662 - return debugfs_create_mode(name, mode, parent, value, &fops_x64, 385 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x64, 663 386 &fops_x64_ro, &fops_x64_wo); 664 387 } 665 388 EXPORT_SYMBOL_GPL(debugfs_create_x64); ··· 675 398 *val = *(size_t *)data; 676 399 return 0; 677 400 } 678 - DEFINE_SIMPLE_ATTRIBUTE(fops_size_t, debugfs_size_t_get, debugfs_size_t_set, 679 - "%llu\n"); /* %llu and %zu are more or less the same */ 680 - DEFINE_SIMPLE_ATTRIBUTE(fops_size_t_ro, debugfs_size_t_get, NULL, "%llu\n"); 681 - DEFINE_SIMPLE_ATTRIBUTE(fops_size_t_wo, NULL, debugfs_size_t_set, "%llu\n"); 401 + DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t, debugfs_size_t_get, debugfs_size_t_set, 402 + "%llu\n"); /* %llu and %zu are more or less the same */ 403 + DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_ro, debugfs_size_t_get, NULL, "%llu\n"); 404 + DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_wo, NULL, debugfs_size_t_set, "%llu\n"); 682 405 683 406 /** 684 407 * debugfs_create_size_t - create a debugfs file that is used to read and write an size_t value ··· 693 416 struct dentry *debugfs_create_size_t(const char *name, umode_t mode, 694 417 struct dentry *parent, size_t *value) 695 418 { 696 - return debugfs_create_mode(name, mode, parent, value, &fops_size_t, 697 - &fops_size_t_ro, &fops_size_t_wo); 419 + return debugfs_create_mode_unsafe(name, mode, parent, value, 420 + &fops_size_t, &fops_size_t_ro, 421 + &fops_size_t_wo); 698 422 } 699 423 EXPORT_SYMBOL_GPL(debugfs_create_size_t); 700 424 ··· 709 431 *val = atomic_read((atomic_t *)data); 710 432 return 0; 711 433 } 712 - DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, 434 + DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, 713 435 debugfs_atomic_t_set, "%lld\n"); 714 - DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, "%lld\n"); 715 - DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%lld\n"); 436 + DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, 437 + "%lld\n"); 438 + DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, 439 + "%lld\n"); 716 440 717 441 /** 718 442 * debugfs_create_atomic_t - create a debugfs file that is used to read and ··· 730 450 struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, 731 451 struct dentry *parent, atomic_t *value) 732 452 { 733 - return debugfs_create_mode(name, mode, parent, value, &fops_atomic_t, 734 - &fops_atomic_t_ro, &fops_atomic_t_wo); 453 + return debugfs_create_mode_unsafe(name, mode, parent, value, 454 + &fops_atomic_t, &fops_atomic_t_ro, 455 + &fops_atomic_t_wo); 735 456 } 736 457 EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); 737 458 ··· 740 459 size_t count, loff_t *ppos) 741 460 { 742 461 char buf[3]; 743 - bool *val = file->private_data; 462 + bool val; 463 + int r, srcu_idx; 744 464 745 - if (*val) 465 + r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 466 + if (likely(!r)) 467 + val = *(bool *)file->private_data; 468 + debugfs_use_file_finish(srcu_idx); 469 + if (r) 470 + return r; 471 + 472 + if (val) 746 473 buf[0] = 'Y'; 747 474 else 748 475 buf[0] = 'N'; ··· 766 477 char buf[32]; 767 478 size_t buf_size; 768 479 bool bv; 480 + int r, srcu_idx; 769 481 bool *val = file->private_data; 770 482 771 483 buf_size = min(count, (sizeof(buf)-1)); ··· 774 484 return -EFAULT; 775 485 776 486 buf[buf_size] = '\0'; 777 - if (strtobool(buf, &bv) == 0) 778 - *val = bv; 487 + if (strtobool(buf, &bv) == 0) { 488 + r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 489 + if (likely(!r)) 490 + *val = bv; 491 + debugfs_use_file_finish(srcu_idx); 492 + if (r) 493 + return r; 494 + } 779 495 780 496 return count; 781 497 } ··· 833 537 struct dentry *debugfs_create_bool(const char *name, umode_t mode, 834 538 struct dentry *parent, bool *value) 835 539 { 836 - return debugfs_create_mode(name, mode, parent, value, &fops_bool, 540 + return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_bool, 837 541 &fops_bool_ro, &fops_bool_wo); 838 542 } 839 543 EXPORT_SYMBOL_GPL(debugfs_create_bool); ··· 842 546 size_t count, loff_t *ppos) 843 547 { 844 548 struct debugfs_blob_wrapper *blob = file->private_data; 845 - return simple_read_from_buffer(user_buf, count, ppos, blob->data, 846 - blob->size); 549 + ssize_t r; 550 + int srcu_idx; 551 + 552 + r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 553 + if (likely(!r)) 554 + r = simple_read_from_buffer(user_buf, count, ppos, blob->data, 555 + blob->size); 556 + debugfs_use_file_finish(srcu_idx); 557 + return r; 847 558 } 848 559 849 560 static const struct file_operations fops_blob = { ··· 887 584 struct dentry *parent, 888 585 struct debugfs_blob_wrapper *blob) 889 586 { 890 - return debugfs_create_file(name, mode, parent, blob, &fops_blob); 587 + return debugfs_create_file_unsafe(name, mode, parent, blob, &fops_blob); 891 588 } 892 589 EXPORT_SYMBOL_GPL(debugfs_create_blob); 893 590 ··· 992 689 data->array = array; 993 690 data->elements = elements; 994 691 995 - return debugfs_create_file(name, mode, parent, data, &u32_array_fops); 692 + return debugfs_create_file_unsafe(name, mode, parent, data, 693 + &u32_array_fops); 996 694 } 997 695 EXPORT_SYMBOL_GPL(debugfs_create_u32_array); 998 696
+89 -21
fs/debugfs/inode.c
··· 27 27 #include <linux/parser.h> 28 28 #include <linux/magic.h> 29 29 #include <linux/slab.h> 30 + #include <linux/srcu.h> 31 + 32 + #include "internal.h" 30 33 31 34 #define DEBUGFS_DEFAULT_MODE 0700 35 + 36 + DEFINE_SRCU(debugfs_srcu); 32 37 33 38 static struct vfsmount *debugfs_mount; 34 39 static int debugfs_mount_count; ··· 44 39 struct inode *inode = new_inode(sb); 45 40 if (inode) { 46 41 inode->i_ino = get_next_ino(); 47 - inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 42 + inode->i_atime = inode->i_mtime = 43 + inode->i_ctime = current_fs_time(sb); 48 44 } 49 45 return inode; 50 46 } ··· 300 294 return dentry; 301 295 } 302 296 297 + static struct dentry *__debugfs_create_file(const char *name, umode_t mode, 298 + struct dentry *parent, void *data, 299 + const struct file_operations *proxy_fops, 300 + const struct file_operations *real_fops) 301 + { 302 + struct dentry *dentry; 303 + struct inode *inode; 304 + 305 + if (!(mode & S_IFMT)) 306 + mode |= S_IFREG; 307 + BUG_ON(!S_ISREG(mode)); 308 + dentry = start_creating(name, parent); 309 + 310 + if (IS_ERR(dentry)) 311 + return NULL; 312 + 313 + inode = debugfs_get_inode(dentry->d_sb); 314 + if (unlikely(!inode)) 315 + return failed_creating(dentry); 316 + 317 + inode->i_mode = mode; 318 + inode->i_private = data; 319 + 320 + inode->i_fop = proxy_fops; 321 + dentry->d_fsdata = (void *)real_fops; 322 + 323 + d_instantiate(dentry, inode); 324 + fsnotify_create(d_inode(dentry->d_parent), dentry); 325 + return end_creating(dentry); 326 + } 327 + 303 328 /** 304 329 * debugfs_create_file - create a file in the debugfs filesystem 305 330 * @name: a pointer to a string containing the name of the file to create. ··· 361 324 struct dentry *parent, void *data, 362 325 const struct file_operations *fops) 363 326 { 364 - struct dentry *dentry; 365 - struct inode *inode; 366 327 367 - if (!(mode & S_IFMT)) 368 - mode |= S_IFREG; 369 - BUG_ON(!S_ISREG(mode)); 370 - dentry = start_creating(name, parent); 371 - 372 - if (IS_ERR(dentry)) 373 - return NULL; 374 - 375 - inode = debugfs_get_inode(dentry->d_sb); 376 - if (unlikely(!inode)) 377 - return failed_creating(dentry); 378 - 379 - inode->i_mode = mode; 380 - inode->i_fop = fops ? fops : &debugfs_file_operations; 381 - inode->i_private = data; 382 - d_instantiate(dentry, inode); 383 - fsnotify_create(d_inode(dentry->d_parent), dentry); 384 - return end_creating(dentry); 328 + return __debugfs_create_file(name, mode, parent, data, 329 + fops ? &debugfs_full_proxy_file_operations : 330 + &debugfs_noop_file_operations, 331 + fops); 385 332 } 386 333 EXPORT_SYMBOL_GPL(debugfs_create_file); 334 + 335 + /** 336 + * debugfs_create_file_unsafe - create a file in the debugfs filesystem 337 + * @name: a pointer to a string containing the name of the file to create. 338 + * @mode: the permission that the file should have. 339 + * @parent: a pointer to the parent dentry for this file. This should be a 340 + * directory dentry if set. If this parameter is NULL, then the 341 + * file will be created in the root of the debugfs filesystem. 342 + * @data: a pointer to something that the caller will want to get to later 343 + * on. The inode.i_private pointer will point to this value on 344 + * the open() call. 345 + * @fops: a pointer to a struct file_operations that should be used for 346 + * this file. 347 + * 348 + * debugfs_create_file_unsafe() is completely analogous to 349 + * debugfs_create_file(), the only difference being that the fops 350 + * handed it will not get protected against file removals by the 351 + * debugfs core. 352 + * 353 + * It is your responsibility to protect your struct file_operation 354 + * methods against file removals by means of debugfs_use_file_start() 355 + * and debugfs_use_file_finish(). ->open() is still protected by 356 + * debugfs though. 357 + * 358 + * Any struct file_operations defined by means of 359 + * DEFINE_DEBUGFS_ATTRIBUTE() is protected against file removals and 360 + * thus, may be used here. 361 + */ 362 + struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode, 363 + struct dentry *parent, void *data, 364 + const struct file_operations *fops) 365 + { 366 + 367 + return __debugfs_create_file(name, mode, parent, data, 368 + fops ? &debugfs_open_proxy_file_operations : 369 + &debugfs_noop_file_operations, 370 + fops); 371 + } 372 + EXPORT_SYMBOL_GPL(debugfs_create_file_unsafe); 387 373 388 374 /** 389 375 * debugfs_create_file_size - create a file in the debugfs filesystem ··· 521 461 inode->i_flags |= S_AUTOMOUNT; 522 462 inode->i_private = data; 523 463 dentry->d_fsdata = (void *)f; 464 + /* directory inodes start off with i_nlink == 2 (for "." entry) */ 465 + inc_nlink(inode); 524 466 d_instantiate(dentry, inode); 467 + inc_nlink(d_inode(dentry->d_parent)); 468 + fsnotify_mkdir(d_inode(dentry->d_parent), dentry); 525 469 return end_creating(dentry); 526 470 } 527 471 EXPORT_SYMBOL(debugfs_create_automount); ··· 629 565 inode_unlock(d_inode(parent)); 630 566 if (!ret) 631 567 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 568 + 569 + synchronize_srcu(&debugfs_srcu); 632 570 } 633 571 EXPORT_SYMBOL_GPL(debugfs_remove); 634 572 ··· 708 642 if (!__debugfs_remove(child, parent)) 709 643 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 710 644 inode_unlock(d_inode(parent)); 645 + 646 + synchronize_srcu(&debugfs_srcu); 711 647 } 712 648 EXPORT_SYMBOL_GPL(debugfs_remove_recursive); 713 649
+26
fs/debugfs/internal.h
··· 1 + /* 2 + * internal.h - declarations internal to debugfs 3 + * 4 + * Copyright (C) 2016 Nicolai Stange <nicstange@gmail.com> 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License version 8 + * 2 as published by the Free Software Foundation. 9 + * 10 + */ 11 + 12 + #ifndef _DEBUGFS_INTERNAL_H_ 13 + #define _DEBUGFS_INTERNAL_H_ 14 + 15 + struct file_operations; 16 + 17 + /* declared over in file.c */ 18 + extern const struct file_operations debugfs_noop_file_operations; 19 + extern const struct file_operations debugfs_open_proxy_file_operations; 20 + extern const struct file_operations debugfs_full_proxy_file_operations; 21 + 22 + struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode, 23 + struct dentry *parent, void *data, 24 + const struct file_operations *fops); 25 + 26 + #endif /* _DEBUGFS_INTERNAL_H_ */
+5 -3
fs/kernfs/dir.c
··· 753 753 ps_iattr = parent->iattr; 754 754 if (ps_iattr) { 755 755 struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 756 - ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 756 + ktime_get_real_ts(&ps_iattrs->ia_ctime); 757 + ps_iattrs->ia_mtime = ps_iattrs->ia_ctime; 757 758 } 758 759 759 760 mutex_unlock(&kernfs_mutex); ··· 1280 1279 1281 1280 /* update timestamps on the parent */ 1282 1281 if (ps_iattr) { 1283 - ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 1284 - ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 1282 + ktime_get_real_ts(&ps_iattr->ia_iattr.ia_ctime); 1283 + ps_iattr->ia_iattr.ia_mtime = 1284 + ps_iattr->ia_iattr.ia_ctime; 1285 1285 } 1286 1286 1287 1287 kernfs_put(pos);
+29 -22
fs/kernfs/file.c
··· 190 190 char *buf; 191 191 192 192 buf = of->prealloc_buf; 193 - if (!buf) 193 + if (buf) 194 + mutex_lock(&of->prealloc_mutex); 195 + else 194 196 buf = kmalloc(len, GFP_KERNEL); 195 197 if (!buf) 196 198 return -ENOMEM; 197 199 198 200 /* 199 201 * @of->mutex nests outside active ref and is used both to ensure that 200 - * the ops aren't called concurrently for the same open file, and 201 - * to provide exclusive access to ->prealloc_buf (when that exists). 202 + * the ops aren't called concurrently for the same open file. 202 203 */ 203 204 mutex_lock(&of->mutex); 204 205 if (!kernfs_get_active(of->kn)) { ··· 215 214 else 216 215 len = -EINVAL; 217 216 217 + kernfs_put_active(of->kn); 218 + mutex_unlock(&of->mutex); 219 + 218 220 if (len < 0) 219 - goto out_unlock; 221 + goto out_free; 220 222 221 223 if (copy_to_user(user_buf, buf, len)) { 222 224 len = -EFAULT; 223 - goto out_unlock; 225 + goto out_free; 224 226 } 225 227 226 228 *ppos += len; 227 229 228 - out_unlock: 229 - kernfs_put_active(of->kn); 230 - mutex_unlock(&of->mutex); 231 230 out_free: 232 - if (buf != of->prealloc_buf) 231 + if (buf == of->prealloc_buf) 232 + mutex_unlock(&of->prealloc_mutex); 233 + else 233 234 kfree(buf); 234 235 return len; 235 236 } ··· 287 284 } 288 285 289 286 buf = of->prealloc_buf; 290 - if (!buf) 287 + if (buf) 288 + mutex_lock(&of->prealloc_mutex); 289 + else 291 290 buf = kmalloc(len + 1, GFP_KERNEL); 292 291 if (!buf) 293 292 return -ENOMEM; 294 293 294 + if (copy_from_user(buf, user_buf, len)) { 295 + len = -EFAULT; 296 + goto out_free; 297 + } 298 + buf[len] = '\0'; /* guarantee string termination */ 299 + 295 300 /* 296 301 * @of->mutex nests outside active ref and is used both to ensure that 297 - * the ops aren't called concurrently for the same open file, and 298 - * to provide exclusive access to ->prealloc_buf (when that exists). 302 + * the ops aren't called concurrently for the same open file. 299 303 */ 300 304 mutex_lock(&of->mutex); 301 305 if (!kernfs_get_active(of->kn)) { ··· 311 301 goto out_free; 312 302 } 313 303 314 - if (copy_from_user(buf, user_buf, len)) { 315 - len = -EFAULT; 316 - goto out_unlock; 317 - } 318 - buf[len] = '\0'; /* guarantee string termination */ 319 - 320 304 ops = kernfs_ops(of->kn); 321 305 if (ops->write) 322 306 len = ops->write(of, buf, len, *ppos); 323 307 else 324 308 len = -EINVAL; 325 309 310 + kernfs_put_active(of->kn); 311 + mutex_unlock(&of->mutex); 312 + 326 313 if (len > 0) 327 314 *ppos += len; 328 315 329 - out_unlock: 330 - kernfs_put_active(of->kn); 331 - mutex_unlock(&of->mutex); 332 316 out_free: 333 - if (buf != of->prealloc_buf) 317 + if (buf == of->prealloc_buf) 318 + mutex_unlock(&of->prealloc_mutex); 319 + else 334 320 kfree(buf); 335 321 return len; 336 322 } ··· 693 687 error = -ENOMEM; 694 688 if (!of->prealloc_buf) 695 689 goto err_free; 690 + mutex_init(&of->prealloc_mutex); 696 691 } 697 692 698 693 /*
+10 -5
fs/kernfs/inode.c
··· 54 54 iattrs->ia_mode = kn->mode; 55 55 iattrs->ia_uid = GLOBAL_ROOT_UID; 56 56 iattrs->ia_gid = GLOBAL_ROOT_GID; 57 - iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME; 57 + 58 + ktime_get_real_ts(&iattrs->ia_atime); 59 + iattrs->ia_mtime = iattrs->ia_atime; 60 + iattrs->ia_ctime = iattrs->ia_atime; 58 61 59 62 simple_xattrs_init(&kn->iattr->xattrs); 60 63 out_unlock: ··· 239 236 static inline void set_default_inode_attr(struct inode *inode, umode_t mode) 240 237 { 241 238 inode->i_mode = mode; 242 - inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 239 + inode->i_atime = inode->i_mtime = 240 + inode->i_ctime = current_fs_time(inode->i_sb); 243 241 } 244 242 245 243 static inline void set_inode_attr(struct inode *inode, struct iattr *iattr) 246 244 { 245 + struct super_block *sb = inode->i_sb; 247 246 inode->i_uid = iattr->ia_uid; 248 247 inode->i_gid = iattr->ia_gid; 249 - inode->i_atime = iattr->ia_atime; 250 - inode->i_mtime = iattr->ia_mtime; 251 - inode->i_ctime = iattr->ia_ctime; 248 + inode->i_atime = timespec_trunc(iattr->ia_atime, sb->s_time_gran); 249 + inode->i_mtime = timespec_trunc(iattr->ia_mtime, sb->s_time_gran); 250 + inode->i_ctime = timespec_trunc(iattr->ia_ctime, sb->s_time_gran); 252 251 } 253 252 254 253 static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
+46 -3
include/linux/debugfs.h
··· 19 19 #include <linux/seq_file.h> 20 20 21 21 #include <linux/types.h> 22 + #include <linux/compiler.h> 22 23 23 24 struct device; 24 25 struct file_operations; 26 + struct srcu_struct; 25 27 26 28 struct debugfs_blob_wrapper { 27 29 void *data; ··· 43 41 44 42 extern struct dentry *arch_debugfs_dir; 45 43 44 + extern struct srcu_struct debugfs_srcu; 45 + 46 46 #if defined(CONFIG_DEBUG_FS) 47 47 48 - /* declared over in file.c */ 49 - extern const struct file_operations debugfs_file_operations; 50 - 51 48 struct dentry *debugfs_create_file(const char *name, umode_t mode, 49 + struct dentry *parent, void *data, 50 + const struct file_operations *fops); 51 + struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode, 52 52 struct dentry *parent, void *data, 53 53 const struct file_operations *fops); 54 54 ··· 71 67 72 68 void debugfs_remove(struct dentry *dentry); 73 69 void debugfs_remove_recursive(struct dentry *dentry); 70 + 71 + int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx) 72 + __acquires(&debugfs_srcu); 73 + 74 + void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu); 75 + 76 + ssize_t debugfs_attr_read(struct file *file, char __user *buf, 77 + size_t len, loff_t *ppos); 78 + ssize_t debugfs_attr_write(struct file *file, const char __user *buf, 79 + size_t len, loff_t *ppos); 80 + 81 + #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 82 + static int __fops ## _open(struct inode *inode, struct file *file) \ 83 + { \ 84 + __simple_attr_check_format(__fmt, 0ull); \ 85 + return simple_attr_open(inode, file, __get, __set, __fmt); \ 86 + } \ 87 + static const struct file_operations __fops = { \ 88 + .owner = THIS_MODULE, \ 89 + .open = __fops ## _open, \ 90 + .release = simple_attr_release, \ 91 + .read = debugfs_attr_read, \ 92 + .write = debugfs_attr_write, \ 93 + .llseek = generic_file_llseek, \ 94 + } 74 95 75 96 struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 76 97 struct dentry *new_dir, const char *new_name); ··· 204 175 205 176 static inline void debugfs_remove_recursive(struct dentry *dentry) 206 177 { } 178 + 179 + static inline int debugfs_use_file_start(const struct dentry *dentry, 180 + int *srcu_idx) 181 + __acquires(&debugfs_srcu) 182 + { 183 + return 0; 184 + } 185 + 186 + static inline void debugfs_use_file_finish(int srcu_idx) 187 + __releases(&debugfs_srcu) 188 + { } 189 + 190 + #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 191 + static const struct file_operations __fops = { 0 } 207 192 208 193 static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 209 194 struct dentry *new_dir, char *new_name)
+78 -8
include/linux/devcoredump.h
··· 1 + /* 2 + * This file is provided under the GPLv2 license. 3 + * 4 + * GPL LICENSE SUMMARY 5 + * 6 + * Copyright(c) 2015 Intel Deutschland GmbH 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of version 2 of the GNU General Public License as 10 + * published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, but 13 + * WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + * 17 + * The full GNU General Public License is included in this distribution 18 + * in the file called COPYING. 19 + */ 1 20 #ifndef __DEVCOREDUMP_H 2 21 #define __DEVCOREDUMP_H 3 22 ··· 24 5 #include <linux/module.h> 25 6 #include <linux/vmalloc.h> 26 7 8 + #include <linux/scatterlist.h> 9 + #include <linux/slab.h> 10 + 11 + /* 12 + * _devcd_free_sgtable - free all the memory of the given scatterlist table 13 + * (i.e. both pages and scatterlist instances) 14 + * NOTE: if two tables allocated and chained using the sg_chain function then 15 + * this function should be called only once on the first table 16 + * @table: pointer to sg_table to free 17 + */ 18 + static inline void _devcd_free_sgtable(struct scatterlist *table) 19 + { 20 + int i; 21 + struct page *page; 22 + struct scatterlist *iter; 23 + struct scatterlist *delete_iter; 24 + 25 + /* free pages */ 26 + iter = table; 27 + for_each_sg(table, iter, sg_nents(table), i) { 28 + page = sg_page(iter); 29 + if (page) 30 + __free_page(page); 31 + } 32 + 33 + /* then free all chained tables */ 34 + iter = table; 35 + delete_iter = table; /* always points on a head of a table */ 36 + while (!sg_is_last(iter)) { 37 + iter++; 38 + if (sg_is_chain(iter)) { 39 + iter = sg_chain_ptr(iter); 40 + kfree(delete_iter); 41 + delete_iter = iter; 42 + } 43 + } 44 + 45 + /* free the last table */ 46 + kfree(delete_iter); 47 + } 48 + 49 + 27 50 #ifdef CONFIG_DEV_COREDUMP 28 - void dev_coredumpv(struct device *dev, const void *data, size_t datalen, 51 + void dev_coredumpv(struct device *dev, void *data, size_t datalen, 29 52 gfp_t gfp); 30 53 31 54 void dev_coredumpm(struct device *dev, struct module *owner, 32 - const void *data, size_t datalen, gfp_t gfp, 55 + void *data, size_t datalen, gfp_t gfp, 33 56 ssize_t (*read)(char *buffer, loff_t offset, size_t count, 34 - const void *data, size_t datalen), 35 - void (*free)(const void *data)); 57 + void *data, size_t datalen), 58 + void (*free)(void *data)); 59 + 60 + void dev_coredumpsg(struct device *dev, struct scatterlist *table, 61 + size_t datalen, gfp_t gfp); 36 62 #else 37 - static inline void dev_coredumpv(struct device *dev, const void *data, 63 + static inline void dev_coredumpv(struct device *dev, void *data, 38 64 size_t datalen, gfp_t gfp) 39 65 { 40 66 vfree(data); ··· 87 23 88 24 static inline void 89 25 dev_coredumpm(struct device *dev, struct module *owner, 90 - const void *data, size_t datalen, gfp_t gfp, 26 + void *data, size_t datalen, gfp_t gfp, 91 27 ssize_t (*read)(char *buffer, loff_t offset, size_t count, 92 - const void *data, size_t datalen), 93 - void (*free)(const void *data)) 28 + void *data, size_t datalen), 29 + void (*free)(void *data)) 94 30 { 95 31 free(data); 32 + } 33 + 34 + static inline void dev_coredumpsg(struct device *dev, struct scatterlist *table, 35 + size_t datalen, gfp_t gfp) 36 + { 37 + _devcd_free_sgtable(table); 96 38 } 97 39 #endif /* CONFIG_DEV_COREDUMP */ 98 40
+5 -2
include/linux/device.h
··· 1288 1288 dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \ 1289 1289 } while (0) 1290 1290 #else 1291 - #define dev_dbg_ratelimited(dev, fmt, ...) \ 1292 - no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 1291 + #define dev_dbg_ratelimited(dev, fmt, ...) \ 1292 + do { \ 1293 + if (0) \ 1294 + dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \ 1295 + } while (0) 1293 1296 #endif 1294 1297 1295 1298 #ifdef VERBOSE_DEBUG
+2
include/linux/fs.h
··· 2427 2427 2428 2428 /* fs/char_dev.c */ 2429 2429 #define CHRDEV_MAJOR_HASH_SIZE 255 2430 + /* Marks the bottom of the first segment of free char majors */ 2431 + #define CHRDEV_MAJOR_DYN_END 234 2430 2432 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); 2431 2433 extern int register_chrdev_region(dev_t, unsigned, const char *); 2432 2434 extern int __register_chrdev(unsigned int major, unsigned int baseminor,
+32
include/linux/isa.h
··· 36 36 } 37 37 #endif 38 38 39 + /** 40 + * module_isa_driver() - Helper macro for registering a ISA driver 41 + * @__isa_driver: isa_driver struct 42 + * @__num_isa_dev: number of devices to register 43 + * 44 + * Helper macro for ISA drivers which do not do anything special in module 45 + * init/exit. This eliminates a lot of boilerplate code. Each module may only 46 + * use this macro once, and calling it replaces module_init and module_exit. 47 + */ 48 + #define module_isa_driver(__isa_driver, __num_isa_dev) \ 49 + static int __init __isa_driver##_init(void) \ 50 + { \ 51 + return isa_register_driver(&(__isa_driver), __num_isa_dev); \ 52 + } \ 53 + module_init(__isa_driver##_init); \ 54 + static void __exit __isa_driver##_exit(void) \ 55 + { \ 56 + isa_unregister_driver(&(__isa_driver)); \ 57 + } \ 58 + module_exit(__isa_driver##_exit); 59 + 60 + /** 61 + * max_num_isa_dev() - Maximum possible number registered of an ISA device 62 + * @__ida_dev_ext: ISA device address extent 63 + * 64 + * The highest base address possible for an ISA device is 0x3FF; this results in 65 + * 1024 possible base addresses. Dividing the number of possible base addresses 66 + * by the address extent taken by each device results in the maximum number of 67 + * devices on a system. 68 + */ 69 + #define max_num_isa_dev(__isa_dev_ext) (1024 / __isa_dev_ext) 70 + 39 71 #endif /* __LINUX_ISA_H */
+1
include/linux/kernfs.h
··· 179 179 180 180 /* private fields, do not use outside kernfs proper */ 181 181 struct mutex mutex; 182 + struct mutex prealloc_mutex; 182 183 int event; 183 184 struct list_head list; 184 185 char *prealloc_buf;
+1
lib/Kconfig.debug
··· 257 257 258 258 config DEBUG_FS 259 259 bool "Debug Filesystem" 260 + select SRCU 260 261 help 261 262 debugfs is a virtual file system that kernel developers use to put 262 263 debugging files into. Enable this option to be able to read and
+67
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci
··· 1 + /// Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE 2 + /// for debugfs files. 3 + /// 4 + //# Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file() 5 + //# imposes some significant overhead as compared to 6 + //# DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe(). 7 + // 8 + // Copyright (C): 2016 Nicolai Stange 9 + // Options: --no-includes 10 + // 11 + 12 + virtual context 13 + virtual patch 14 + virtual org 15 + virtual report 16 + 17 + @dsa@ 18 + declarer name DEFINE_SIMPLE_ATTRIBUTE; 19 + identifier dsa_fops; 20 + expression dsa_get, dsa_set, dsa_fmt; 21 + position p; 22 + @@ 23 + DEFINE_SIMPLE_ATTRIBUTE@p(dsa_fops, dsa_get, dsa_set, dsa_fmt); 24 + 25 + @dcf@ 26 + expression name, mode, parent, data; 27 + identifier dsa.dsa_fops; 28 + @@ 29 + debugfs_create_file(name, mode, parent, data, &dsa_fops) 30 + 31 + 32 + @context_dsa depends on context && dcf@ 33 + declarer name DEFINE_DEBUGFS_ATTRIBUTE; 34 + identifier dsa.dsa_fops; 35 + expression dsa.dsa_get, dsa.dsa_set, dsa.dsa_fmt; 36 + @@ 37 + * DEFINE_SIMPLE_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt); 38 + 39 + 40 + @patch_dcf depends on patch expression@ 41 + expression name, mode, parent, data; 42 + identifier dsa.dsa_fops; 43 + @@ 44 + - debugfs_create_file(name, mode, parent, data, &dsa_fops) 45 + + debugfs_create_file_unsafe(name, mode, parent, data, &dsa_fops) 46 + 47 + @patch_dsa depends on patch_dcf && patch@ 48 + identifier dsa.dsa_fops; 49 + expression dsa.dsa_get, dsa.dsa_set, dsa.dsa_fmt; 50 + @@ 51 + - DEFINE_SIMPLE_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt); 52 + + DEFINE_DEBUGFS_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt); 53 + 54 + 55 + @script:python depends on org && dcf@ 56 + fops << dsa.dsa_fops; 57 + p << dsa.p; 58 + @@ 59 + msg="%s should be defined with DEFINE_DEBUGFS_ATTRIBUTE" % (fops) 60 + coccilib.org.print_todo(p[0], msg) 61 + 62 + @script:python depends on report && dcf@ 63 + fops << dsa.dsa_fops; 64 + p << dsa.p; 65 + @@ 66 + msg="WARNING: %s should be defined with DEFINE_DEBUGFS_ATTRIBUTE" % (fops) 67 + coccilib.report.print_report(p[0], msg)