aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/arm/OMAP/DSS7
-rw-r--r--Documentation/cgroups/blkio-controller.txt27
-rw-r--r--Documentation/feature-removal-schedule.txt10
-rw-r--r--MAINTAINERS5
-rw-r--r--Makefile2
-rw-r--r--arch/arm/Kconfig32
-rw-r--r--arch/arm/mach-omap1/devices.c5
-rw-r--r--arch/arm/mach-omap1/include/mach/camera.h2
-rw-r--r--arch/arm/mach-omap2/board-devkit8000.c3
-rw-r--r--arch/arm/mach-s3c64xx/Kconfig2
-rw-r--r--arch/arm/mach-shmobile/board-ap4evb.c6
-rw-r--r--arch/arm/mach-shmobile/intc-sh7372.c2
-rw-r--r--arch/arm/plat-omap/dma.c2
-rw-r--r--arch/x86/pci/acpi.c103
-rw-r--r--block/blk-cgroup.c4
-rw-r--r--block/blk-core.c10
-rw-r--r--block/cfq-iosched.c56
-rw-r--r--block/ioctl.c5
-rw-r--r--drivers/block/drbd/drbd_int.h2
-rw-r--r--drivers/block/drbd/drbd_main.c7
-rw-r--r--drivers/block/drbd/drbd_nl.c103
-rw-r--r--drivers/block/pktcdvd.c22
-rw-r--r--drivers/char/i8k.c8
-rw-r--r--drivers/char/raw.c14
-rw-r--r--drivers/hwmon/amc6821.c2
-rw-r--r--drivers/hwmon/lm93.c4
-rw-r--r--drivers/hwmon/lm95241.c19
-rw-r--r--drivers/hwmon/max6650.c2
-rw-r--r--drivers/hwmon/w83795.c207
-rw-r--r--drivers/i2c/i2c-core.c12
-rw-r--r--drivers/i2c/i2c-mux.c1
-rw-r--r--drivers/md/dm-table.c20
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/md/md.c16
-rw-r--r--drivers/media/common/saa7146_i2c.c1
-rw-r--r--drivers/media/video/imx074.c2
-rw-r--r--drivers/media/video/ir-kbd-i2c.c1
-rw-r--r--drivers/media/video/ov6650.c2
-rw-r--r--drivers/misc/apds9802als.c1
-rw-r--r--drivers/mtd/devices/block2mtd.c10
-rw-r--r--drivers/pci/bus.c70
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c6
-rw-r--r--drivers/pci/pci-sysfs.c23
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--drivers/pci/pci.h7
-rw-r--r--drivers/pci/proc.c2
-rw-r--r--drivers/rtc/rtc-sh.c4
-rw-r--r--drivers/s390/block/dasd_genhd.c2
-rw-r--r--drivers/sh/clk/core.c4
-rw-r--r--drivers/sh/intc/virq.c2
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c4
-rw-r--r--drivers/usb/gadget/storage_common.c7
-rw-r--r--drivers/video/omap2/vram.c17
-rw-r--r--drivers/video/riva/rivafb-i2c.c1
-rw-r--r--drivers/video/sh_mobile_hdmi.c5
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c21
-rw-r--r--drivers/video/sis/sis_main.c8
-rw-r--r--fs/block_dev.c708
-rw-r--r--fs/btrfs/volumes.c28
-rw-r--r--fs/btrfs/volumes.h2
-rw-r--r--fs/ext3/super.c12
-rw-r--r--fs/ext4/super.c12
-rw-r--r--fs/gfs2/export.c46
-rw-r--r--fs/gfs2/glock.c21
-rw-r--r--fs/gfs2/inode.c152
-rw-r--r--fs/gfs2/inode.h4
-rw-r--r--fs/gfs2/ops_fstype.c8
-rw-r--r--fs/gfs2/rgrp.c91
-rw-r--r--fs/jfs/jfs_logmgr.c17
-rw-r--r--fs/logfs/dev_bdev.c7
-rw-r--r--fs/nilfs2/super.c8
-rw-r--r--fs/ocfs2/cluster/heartbeat.c2
-rw-r--r--fs/ocfs2/ocfs2.h6
-rw-r--r--fs/partitions/check.c11
-rw-r--r--fs/reiserfs/journal.c21
-rw-r--r--fs/super.c19
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c5
-rw-r--r--include/linux/fs.h25
-rw-r--r--include/linux/fsl-diu-fb.h1
-rw-r--r--include/linux/i2c-id.h22
-rw-r--r--include/linux/i2c.h2
-rw-r--r--include/linux/kernel.h245
-rw-r--r--include/linux/printk.h248
-rw-r--r--include/linux/security.h9
-rw-r--r--include/linux/sh_intc.h2
-rw-r--r--include/trace/events/block.h6
-rw-r--r--kernel/power/swap.c5
-rw-r--r--kernel/printk.c15
-rw-r--r--kernel/trace/blktrace.c12
-rw-r--r--mm/slub.c3
-rw-r--r--mm/swapfile.c7
-rw-r--r--security/capability.c5
-rw-r--r--security/commoncap.c21
-rw-r--r--security/security.c4
-rw-r--r--security/selinux/hooks.c6
-rw-r--r--security/smack/smack_lsm.c8
96 files changed, 1311 insertions, 1453 deletions
diff --git a/Documentation/arm/OMAP/DSS b/Documentation/arm/OMAP/DSS
index 0af0e9eed5d6..888ae7b83ae4 100644
--- a/Documentation/arm/OMAP/DSS
+++ b/Documentation/arm/OMAP/DSS
@@ -255,9 +255,10 @@ framebuffer parameters.
255Kernel boot arguments 255Kernel boot arguments
256--------------------- 256---------------------
257 257
258vram=<size> 258vram=<size>[,<physaddr>]
259 - Amount of total VRAM to preallocate. For example, "10M". omapfb 259 - Amount of total VRAM to preallocate and optionally a physical start
260 allocates memory for framebuffers from VRAM. 260 memory address. For example, "10M". omapfb allocates memory for
261 framebuffers from VRAM.
261 262
262omapfb.mode=<display>:<mode>[,...] 263omapfb.mode=<display>:<mode>[,...]
263 - Default video mode for specified displays. For example, 264 - Default video mode for specified displays. For example,
diff --git a/Documentation/cgroups/blkio-controller.txt b/Documentation/cgroups/blkio-controller.txt
index d6da611f8f63..4ed7b5ceeed2 100644
--- a/Documentation/cgroups/blkio-controller.txt
+++ b/Documentation/cgroups/blkio-controller.txt
@@ -89,6 +89,33 @@ Throttling/Upper Limit policy
89 89
90 Limits for writes can be put using blkio.write_bps_device file. 90 Limits for writes can be put using blkio.write_bps_device file.
91 91
92Hierarchical Cgroups
93====================
94- Currently none of the IO control policy supports hierarhical groups. But
95 cgroup interface does allow creation of hierarhical cgroups and internally
96 IO policies treat them as flat hierarchy.
97
98 So this patch will allow creation of cgroup hierarhcy but at the backend
99 everything will be treated as flat. So if somebody created a hierarchy like
100 as follows.
101
102 root
103 / \
104 test1 test2
105 |
106 test3
107
108 CFQ and throttling will practically treat all groups at same level.
109
110 pivot
111 / | \ \
112 root test1 test2 test3
113
114 Down the line we can implement hierarchical accounting/control support
115 and also introduce a new cgroup file "use_hierarchy" which will control
116 whether cgroup hierarchy is viewed as flat or hierarchical by the policy..
117 This is how memory controller also has implemented the things.
118
92Various user visible config options 119Various user visible config options
93=================================== 120===================================
94CONFIG_BLK_CGROUP 121CONFIG_BLK_CGROUP
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index d8f36f984faa..6c2f55e05f13 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -554,3 +554,13 @@ Why: This is a legacy interface which have been replaced by a more
554Who: NeilBrown <neilb@suse.de> 554Who: NeilBrown <neilb@suse.de>
555 555
556---------------------------- 556----------------------------
557
558What: i2c_adapter.id
559When: June 2011
560Why: This field is deprecated. I2C device drivers shouldn't change their
561 behavior based on the underlying I2C adapter. Instead, the I2C
562 adapter driver should instantiate the I2C devices and provide the
563 needed platform-specific information.
564Who: Jean Delvare <khali@linux-fr.org>
565
566----------------------------
diff --git a/MAINTAINERS b/MAINTAINERS
index 88b74a75d932..8e6548dbd5db 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -945,7 +945,7 @@ M: Magnus Damm <magnus.damm@gmail.com>
945L: linux-sh@vger.kernel.org 945L: linux-sh@vger.kernel.org
946W: http://oss.renesas.com 946W: http://oss.renesas.com
947Q: http://patchwork.kernel.org/project/linux-sh/list/ 947Q: http://patchwork.kernel.org/project/linux-sh/list/
948T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/genesis-2.6.git 948T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git rmobile-latest
949S: Supported 949S: Supported
950F: arch/arm/mach-shmobile/ 950F: arch/arm/mach-shmobile/
951F: drivers/sh/ 951F: drivers/sh/
@@ -2435,6 +2435,7 @@ F: drivers/net/wan/sdla.c
2435FRAMEBUFFER LAYER 2435FRAMEBUFFER LAYER
2436L: linux-fbdev@vger.kernel.org 2436L: linux-fbdev@vger.kernel.org
2437W: http://linux-fbdev.sourceforge.net/ 2437W: http://linux-fbdev.sourceforge.net/
2438T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/fbdev-2.6.git
2438S: Orphan 2439S: Orphan
2439F: Documentation/fb/ 2440F: Documentation/fb/
2440F: drivers/video/fb* 2441F: drivers/video/fb*
@@ -5705,7 +5706,7 @@ M: Paul Mundt <lethal@linux-sh.org>
5705L: linux-sh@vger.kernel.org 5706L: linux-sh@vger.kernel.org
5706W: http://www.linux-sh.org 5707W: http://www.linux-sh.org
5707Q: http://patchwork.kernel.org/project/linux-sh/list/ 5708Q: http://patchwork.kernel.org/project/linux-sh/list/
5708T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git 5709T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git sh-latest
5709S: Supported 5710S: Supported
5710F: Documentation/sh/ 5711F: Documentation/sh/
5711F: arch/sh/ 5712F: arch/sh/
diff --git a/Makefile b/Makefile
index 6619720f50dd..ab5359db3d17 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 37 3SUBLEVEL = 37
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc2
5NAME = Flesh-Eating Bats with Fangs 5NAME = Flesh-Eating Bats with Fangs
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 8ae3d48d504c..db524e75c4a2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -646,7 +646,7 @@ config ARCH_S3C2410
646 select ARCH_HAS_CPUFREQ 646 select ARCH_HAS_CPUFREQ
647 select HAVE_CLK 647 select HAVE_CLK
648 select ARCH_USES_GETTIMEOFFSET 648 select ARCH_USES_GETTIMEOFFSET
649 select HAVE_S3C2410_I2C 649 select HAVE_S3C2410_I2C if I2C
650 help 650 help
651 Samsung S3C2410X CPU based systems, such as the Simtec Electronics 651 Samsung S3C2410X CPU based systems, such as the Simtec Electronics
652 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or 652 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
@@ -676,8 +676,8 @@ config ARCH_S3C64XX
676 select S3C_DEV_NAND 676 select S3C_DEV_NAND
677 select USB_ARCH_HAS_OHCI 677 select USB_ARCH_HAS_OHCI
678 select SAMSUNG_GPIOLIB_4BIT 678 select SAMSUNG_GPIOLIB_4BIT
679 select HAVE_S3C2410_I2C 679 select HAVE_S3C2410_I2C if I2C
680 select HAVE_S3C2410_WATCHDOG 680 select HAVE_S3C2410_WATCHDOG if WATCHDOG
681 help 681 help
682 Samsung S3C64XX series based systems 682 Samsung S3C64XX series based systems
683 683
@@ -686,10 +686,10 @@ config ARCH_S5P64X0
686 select CPU_V6 686 select CPU_V6
687 select GENERIC_GPIO 687 select GENERIC_GPIO
688 select HAVE_CLK 688 select HAVE_CLK
689 select HAVE_S3C2410_WATCHDOG 689 select HAVE_S3C2410_WATCHDOG if WATCHDOG
690 select ARCH_USES_GETTIMEOFFSET 690 select ARCH_USES_GETTIMEOFFSET
691 select HAVE_S3C2410_I2C 691 select HAVE_S3C2410_I2C if I2C
692 select HAVE_S3C_RTC 692 select HAVE_S3C_RTC if RTC_CLASS
693 help 693 help
694 Samsung S5P64X0 CPU based systems, such as the Samsung SMDK6440, 694 Samsung S5P64X0 CPU based systems, such as the Samsung SMDK6440,
695 SMDK6450. 695 SMDK6450.
@@ -700,7 +700,7 @@ config ARCH_S5P6442
700 select GENERIC_GPIO 700 select GENERIC_GPIO
701 select HAVE_CLK 701 select HAVE_CLK
702 select ARCH_USES_GETTIMEOFFSET 702 select ARCH_USES_GETTIMEOFFSET
703 select HAVE_S3C2410_WATCHDOG 703 select HAVE_S3C2410_WATCHDOG if WATCHDOG
704 help 704 help
705 Samsung S5P6442 CPU based systems 705 Samsung S5P6442 CPU based systems
706 706
@@ -711,9 +711,9 @@ config ARCH_S5PC100
711 select CPU_V7 711 select CPU_V7
712 select ARM_L1_CACHE_SHIFT_6 712 select ARM_L1_CACHE_SHIFT_6
713 select ARCH_USES_GETTIMEOFFSET 713 select ARCH_USES_GETTIMEOFFSET
714 select HAVE_S3C2410_I2C 714 select HAVE_S3C2410_I2C if I2C
715 select HAVE_S3C_RTC 715 select HAVE_S3C_RTC if RTC_CLASS
716 select HAVE_S3C2410_WATCHDOG 716 select HAVE_S3C2410_WATCHDOG if WATCHDOG
717 help 717 help
718 Samsung S5PC100 series based systems 718 Samsung S5PC100 series based systems
719 719
@@ -726,9 +726,9 @@ config ARCH_S5PV210
726 select ARM_L1_CACHE_SHIFT_6 726 select ARM_L1_CACHE_SHIFT_6
727 select ARCH_HAS_CPUFREQ 727 select ARCH_HAS_CPUFREQ
728 select ARCH_USES_GETTIMEOFFSET 728 select ARCH_USES_GETTIMEOFFSET
729 select HAVE_S3C2410_I2C 729 select HAVE_S3C2410_I2C if I2C
730 select HAVE_S3C_RTC 730 select HAVE_S3C_RTC if RTC_CLASS
731 select HAVE_S3C2410_WATCHDOG 731 select HAVE_S3C2410_WATCHDOG if WATCHDOG
732 help 732 help
733 Samsung S5PV210/S5PC110 series based systems 733 Samsung S5PV210/S5PC110 series based systems
734 734
@@ -739,9 +739,9 @@ config ARCH_S5PV310
739 select GENERIC_GPIO 739 select GENERIC_GPIO
740 select HAVE_CLK 740 select HAVE_CLK
741 select GENERIC_CLOCKEVENTS 741 select GENERIC_CLOCKEVENTS
742 select HAVE_S3C_RTC 742 select HAVE_S3C_RTC if RTC_CLASS
743 select HAVE_S3C2410_I2C 743 select HAVE_S3C2410_I2C if I2C
744 select HAVE_S3C2410_WATCHDOG 744 select HAVE_S3C2410_WATCHDOG if WATCHDOG
745 help 745 help
746 Samsung S5PV310 series based systems 746 Samsung S5PV310 series based systems
747 747
diff --git a/arch/arm/mach-omap1/devices.c b/arch/arm/mach-omap1/devices.c
index ea0d80a89da7..e7f9ee63dce5 100644
--- a/arch/arm/mach-omap1/devices.c
+++ b/arch/arm/mach-omap1/devices.c
@@ -321,10 +321,9 @@ static struct platform_device omap_wdt_device = {
321static int __init omap_init_wdt(void) 321static int __init omap_init_wdt(void)
322{ 322{
323 if (!cpu_is_omap16xx()) 323 if (!cpu_is_omap16xx())
324 return; 324 return -ENODEV;
325 325
326 platform_device_register(&omap_wdt_device); 326 return platform_device_register(&omap_wdt_device);
327 return 0;
328} 327}
329subsys_initcall(omap_init_wdt); 328subsys_initcall(omap_init_wdt);
330#endif 329#endif
diff --git a/arch/arm/mach-omap1/include/mach/camera.h b/arch/arm/mach-omap1/include/mach/camera.h
index fd54b452eb22..847d00f0bb0a 100644
--- a/arch/arm/mach-omap1/include/mach/camera.h
+++ b/arch/arm/mach-omap1/include/mach/camera.h
@@ -1,6 +1,8 @@
1#ifndef __ASM_ARCH_CAMERA_H_ 1#ifndef __ASM_ARCH_CAMERA_H_
2#define __ASM_ARCH_CAMERA_H_ 2#define __ASM_ARCH_CAMERA_H_
3 3
4#include <media/omap1_camera.h>
5
4void omap1_camera_init(void *); 6void omap1_camera_init(void *);
5 7
6static inline void omap1_set_camera_info(struct omap1_cam_platform_data *info) 8static inline void omap1_set_camera_info(struct omap1_cam_platform_data *info)
diff --git a/arch/arm/mach-omap2/board-devkit8000.c b/arch/arm/mach-omap2/board-devkit8000.c
index 067f4379c87f..53ac762518bd 100644
--- a/arch/arm/mach-omap2/board-devkit8000.c
+++ b/arch/arm/mach-omap2/board-devkit8000.c
@@ -242,9 +242,6 @@ static int devkit8000_twl_gpio_setup(struct device *dev,
242 mmc[0].gpio_cd = gpio + 0; 242 mmc[0].gpio_cd = gpio + 0;
243 omap2_hsmmc_init(mmc); 243 omap2_hsmmc_init(mmc);
244 244
245 /* link regulators to MMC adapters */
246 devkit8000_vmmc1_supply.dev = mmc[0].dev;
247
248 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */ 245 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
249 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1; 246 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
250 247
diff --git a/arch/arm/mach-s3c64xx/Kconfig b/arch/arm/mach-s3c64xx/Kconfig
index 1ca7bdc6485c..579d2f0f4dd0 100644
--- a/arch/arm/mach-s3c64xx/Kconfig
+++ b/arch/arm/mach-s3c64xx/Kconfig
@@ -143,7 +143,7 @@ config MACH_SMDK6410
143 select S3C_DEV_USB_HSOTG 143 select S3C_DEV_USB_HSOTG
144 select S3C_DEV_WDT 144 select S3C_DEV_WDT
145 select SAMSUNG_DEV_KEYPAD 145 select SAMSUNG_DEV_KEYPAD
146 select HAVE_S3C2410_WATCHDOG 146 select HAVE_S3C2410_WATCHDOG if WATCHDOG
147 select S3C64XX_SETUP_SDHCI 147 select S3C64XX_SETUP_SDHCI
148 select S3C64XX_SETUP_I2C1 148 select S3C64XX_SETUP_I2C1
149 select S3C64XX_SETUP_IDE 149 select S3C64XX_SETUP_IDE
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index 32d9e2816e56..d3260542b943 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -163,11 +163,13 @@ static struct mtd_partition nor_flash_partitions[] = {
163 .name = "loader", 163 .name = "loader",
164 .offset = 0x00000000, 164 .offset = 0x00000000,
165 .size = 512 * 1024, 165 .size = 512 * 1024,
166 .mask_flags = MTD_WRITEABLE,
166 }, 167 },
167 { 168 {
168 .name = "bootenv", 169 .name = "bootenv",
169 .offset = MTDPART_OFS_APPEND, 170 .offset = MTDPART_OFS_APPEND,
170 .size = 512 * 1024, 171 .size = 512 * 1024,
172 .mask_flags = MTD_WRITEABLE,
171 }, 173 },
172 { 174 {
173 .name = "kernel_ro", 175 .name = "kernel_ro",
@@ -581,6 +583,10 @@ static int fsi_set_rate(int is_porta, int rate)
581 return -EINVAL; 583 return -EINVAL;
582 584
583 switch (rate) { 585 switch (rate) {
586 case 44100:
587 clk_set_rate(fsib_clk, clk_round_rate(fsib_clk, 11283000));
588 ret = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
589 break;
584 case 48000: 590 case 48000:
585 clk_set_rate(fsib_clk, clk_round_rate(fsib_clk, 85428000)); 591 clk_set_rate(fsib_clk, clk_round_rate(fsib_clk, 85428000));
586 clk_set_rate(fdiv_clk, clk_round_rate(fdiv_clk, 12204000)); 592 clk_set_rate(fdiv_clk, clk_round_rate(fdiv_clk, 12204000));
diff --git a/arch/arm/mach-shmobile/intc-sh7372.c b/arch/arm/mach-shmobile/intc-sh7372.c
index 4cd3cae38e72..30b2f400666a 100644
--- a/arch/arm/mach-shmobile/intc-sh7372.c
+++ b/arch/arm/mach-shmobile/intc-sh7372.c
@@ -98,7 +98,7 @@ static struct intc_vect intca_vectors[] __initdata = {
98 INTC_VECT(IRQ14A, 0x03c0), INTC_VECT(IRQ15A, 0x03e0), 98 INTC_VECT(IRQ14A, 0x03c0), INTC_VECT(IRQ15A, 0x03e0),
99 INTC_VECT(IRQ16A, 0x3200), INTC_VECT(IRQ17A, 0x3220), 99 INTC_VECT(IRQ16A, 0x3200), INTC_VECT(IRQ17A, 0x3220),
100 INTC_VECT(IRQ18A, 0x3240), INTC_VECT(IRQ19A, 0x3260), 100 INTC_VECT(IRQ18A, 0x3240), INTC_VECT(IRQ19A, 0x3260),
101 INTC_VECT(IRQ20A, 0x3280), INTC_VECT(IRQ31A, 0x32a0), 101 INTC_VECT(IRQ20A, 0x3280), INTC_VECT(IRQ21A, 0x32a0),
102 INTC_VECT(IRQ22A, 0x32c0), INTC_VECT(IRQ23A, 0x32e0), 102 INTC_VECT(IRQ22A, 0x32c0), INTC_VECT(IRQ23A, 0x32e0),
103 INTC_VECT(IRQ24A, 0x3300), INTC_VECT(IRQ25A, 0x3320), 103 INTC_VECT(IRQ24A, 0x3300), INTC_VECT(IRQ25A, 0x3320),
104 INTC_VECT(IRQ26A, 0x3340), INTC_VECT(IRQ27A, 0x3360), 104 INTC_VECT(IRQ26A, 0x3340), INTC_VECT(IRQ27A, 0x3360),
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index f5c5b8da9a87..2c2826571d45 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -1983,6 +1983,8 @@ static int omap2_dma_handle_ch(int ch)
1983 1983
1984 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch)); 1984 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
1985 dma_write(1 << ch, IRQSTATUS_L0); 1985 dma_write(1 << ch, IRQSTATUS_L0);
1986 /* read back the register to flush the write */
1987 dma_read(IRQSTATUS_L0);
1986 1988
1987 /* If the ch is not chained then chain_id will be -1 */ 1989 /* If the ch is not chained then chain_id will be -1 */
1988 if (dma_chan[ch].chain_id != -1) { 1990 if (dma_chan[ch].chain_id != -1) {
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 15466c096ba5..0972315c3860 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -138,7 +138,6 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
138 struct acpi_resource_address64 addr; 138 struct acpi_resource_address64 addr;
139 acpi_status status; 139 acpi_status status;
140 unsigned long flags; 140 unsigned long flags;
141 struct resource *root, *conflict;
142 u64 start, end; 141 u64 start, end;
143 142
144 status = resource_to_addr(acpi_res, &addr); 143 status = resource_to_addr(acpi_res, &addr);
@@ -146,12 +145,10 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
146 return AE_OK; 145 return AE_OK;
147 146
148 if (addr.resource_type == ACPI_MEMORY_RANGE) { 147 if (addr.resource_type == ACPI_MEMORY_RANGE) {
149 root = &iomem_resource;
150 flags = IORESOURCE_MEM; 148 flags = IORESOURCE_MEM;
151 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) 149 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
152 flags |= IORESOURCE_PREFETCH; 150 flags |= IORESOURCE_PREFETCH;
153 } else if (addr.resource_type == ACPI_IO_RANGE) { 151 } else if (addr.resource_type == ACPI_IO_RANGE) {
154 root = &ioport_resource;
155 flags = IORESOURCE_IO; 152 flags = IORESOURCE_IO;
156 } else 153 } else
157 return AE_OK; 154 return AE_OK;
@@ -172,25 +169,90 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
172 return AE_OK; 169 return AE_OK;
173 } 170 }
174 171
175 conflict = insert_resource_conflict(root, res); 172 info->res_num++;
176 if (conflict) { 173 if (addr.translation_offset)
177 dev_err(&info->bridge->dev, 174 dev_info(&info->bridge->dev, "host bridge window %pR "
178 "address space collision: host bridge window %pR " 175 "(PCI address [%#llx-%#llx])\n",
179 "conflicts with %s %pR\n", 176 res, res->start - addr.translation_offset,
180 res, conflict->name, conflict); 177 res->end - addr.translation_offset);
181 } else { 178 else
182 pci_bus_add_resource(info->bus, res, 0); 179 dev_info(&info->bridge->dev, "host bridge window %pR\n", res);
183 info->res_num++; 180
184 if (addr.translation_offset) 181 return AE_OK;
185 dev_info(&info->bridge->dev, "host bridge window %pR " 182}
186 "(PCI address [%#llx-%#llx])\n", 183
187 res, res->start - addr.translation_offset, 184static bool resource_contains(struct resource *res, resource_size_t point)
188 res->end - addr.translation_offset); 185{
186 if (res->start <= point && point <= res->end)
187 return true;
188 return false;
189}
190
191static void coalesce_windows(struct pci_root_info *info, int type)
192{
193 int i, j;
194 struct resource *res1, *res2;
195
196 for (i = 0; i < info->res_num; i++) {
197 res1 = &info->res[i];
198 if (!(res1->flags & type))
199 continue;
200
201 for (j = i + 1; j < info->res_num; j++) {
202 res2 = &info->res[j];
203 if (!(res2->flags & type))
204 continue;
205
206 /*
207 * I don't like throwing away windows because then
208 * our resources no longer match the ACPI _CRS, but
209 * the kernel resource tree doesn't allow overlaps.
210 */
211 if (resource_contains(res1, res2->start) ||
212 resource_contains(res1, res2->end) ||
213 resource_contains(res2, res1->start) ||
214 resource_contains(res2, res1->end)) {
215 res1->start = min(res1->start, res2->start);
216 res1->end = max(res1->end, res2->end);
217 dev_info(&info->bridge->dev,
218 "host bridge window expanded to %pR; %pR ignored\n",
219 res1, res2);
220 res2->flags = 0;
221 }
222 }
223 }
224}
225
226static void add_resources(struct pci_root_info *info)
227{
228 int i;
229 struct resource *res, *root, *conflict;
230
231 if (!pci_use_crs)
232 return;
233
234 coalesce_windows(info, IORESOURCE_MEM);
235 coalesce_windows(info, IORESOURCE_IO);
236
237 for (i = 0; i < info->res_num; i++) {
238 res = &info->res[i];
239
240 if (res->flags & IORESOURCE_MEM)
241 root = &iomem_resource;
242 else if (res->flags & IORESOURCE_IO)
243 root = &ioport_resource;
189 else 244 else
190 dev_info(&info->bridge->dev, 245 continue;
191 "host bridge window %pR\n", res); 246
247 conflict = insert_resource_conflict(root, res);
248 if (conflict)
249 dev_err(&info->bridge->dev,
250 "address space collision: host bridge window %pR "
251 "conflicts with %s %pR\n",
252 res, conflict->name, conflict);
253 else
254 pci_bus_add_resource(info->bus, res, 0);
192 } 255 }
193 return AE_OK;
194} 256}
195 257
196static void 258static void
@@ -224,6 +286,7 @@ get_current_resources(struct acpi_device *device, int busnum,
224 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, 286 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
225 &info); 287 &info);
226 288
289 add_resources(&info);
227 return; 290 return;
228 291
229name_alloc_fail: 292name_alloc_fail:
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index b1febd0f6d2a..455768a3eb9e 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1452,10 +1452,6 @@ blkiocg_create(struct cgroup_subsys *subsys, struct cgroup *cgroup)
1452 goto done; 1452 goto done;
1453 } 1453 }
1454 1454
1455 /* Currently we do not support hierarchy deeper than two level (0,1) */
1456 if (parent != cgroup->top_cgroup)
1457 return ERR_PTR(-EPERM);
1458
1459 blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL); 1455 blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
1460 if (!blkcg) 1456 if (!blkcg)
1461 return ERR_PTR(-ENOMEM); 1457 return ERR_PTR(-ENOMEM);
diff --git a/block/blk-core.c b/block/blk-core.c
index 4ce953f1b390..151070541e21 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -33,7 +33,7 @@
33 33
34#include "blk.h" 34#include "blk.h"
35 35
36EXPORT_TRACEPOINT_SYMBOL_GPL(block_remap); 36EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
37EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap); 37EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
38EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete); 38EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
39 39
@@ -1329,9 +1329,9 @@ static inline void blk_partition_remap(struct bio *bio)
1329 bio->bi_sector += p->start_sect; 1329 bio->bi_sector += p->start_sect;
1330 bio->bi_bdev = bdev->bd_contains; 1330 bio->bi_bdev = bdev->bd_contains;
1331 1331
1332 trace_block_remap(bdev_get_queue(bio->bi_bdev), bio, 1332 trace_block_bio_remap(bdev_get_queue(bio->bi_bdev), bio,
1333 bdev->bd_dev, 1333 bdev->bd_dev,
1334 bio->bi_sector - p->start_sect); 1334 bio->bi_sector - p->start_sect);
1335 } 1335 }
1336} 1336}
1337 1337
@@ -1500,7 +1500,7 @@ static inline void __generic_make_request(struct bio *bio)
1500 goto end_io; 1500 goto end_io;
1501 1501
1502 if (old_sector != -1) 1502 if (old_sector != -1)
1503 trace_block_remap(q, bio, old_dev, old_sector); 1503 trace_block_bio_remap(q, bio, old_dev, old_sector);
1504 1504
1505 old_sector = bio->bi_sector; 1505 old_sector = bio->bi_sector;
1506 old_dev = bio->bi_bdev->bd_dev; 1506 old_dev = bio->bi_bdev->bd_dev;
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 4cd59b0d7c15..9b186fd6bf47 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -87,7 +87,6 @@ struct cfq_rb_root {
87 unsigned count; 87 unsigned count;
88 unsigned total_weight; 88 unsigned total_weight;
89 u64 min_vdisktime; 89 u64 min_vdisktime;
90 struct rb_node *active;
91}; 90};
92#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, .left = NULL, \ 91#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, .left = NULL, \
93 .count = 0, .min_vdisktime = 0, } 92 .count = 0, .min_vdisktime = 0, }
@@ -180,7 +179,6 @@ struct cfq_group {
180 /* group service_tree key */ 179 /* group service_tree key */
181 u64 vdisktime; 180 u64 vdisktime;
182 unsigned int weight; 181 unsigned int weight;
183 bool on_st;
184 182
185 /* number of cfqq currently on this group */ 183 /* number of cfqq currently on this group */
186 int nr_cfqq; 184 int nr_cfqq;
@@ -563,11 +561,6 @@ static void update_min_vdisktime(struct cfq_rb_root *st)
563 u64 vdisktime = st->min_vdisktime; 561 u64 vdisktime = st->min_vdisktime;
564 struct cfq_group *cfqg; 562 struct cfq_group *cfqg;
565 563
566 if (st->active) {
567 cfqg = rb_entry_cfqg(st->active);
568 vdisktime = cfqg->vdisktime;
569 }
570
571 if (st->left) { 564 if (st->left) {
572 cfqg = rb_entry_cfqg(st->left); 565 cfqg = rb_entry_cfqg(st->left);
573 vdisktime = min_vdisktime(vdisktime, cfqg->vdisktime); 566 vdisktime = min_vdisktime(vdisktime, cfqg->vdisktime);
@@ -646,11 +639,11 @@ cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
646static inline bool cfq_slice_used(struct cfq_queue *cfqq) 639static inline bool cfq_slice_used(struct cfq_queue *cfqq)
647{ 640{
648 if (cfq_cfqq_slice_new(cfqq)) 641 if (cfq_cfqq_slice_new(cfqq))
649 return 0; 642 return false;
650 if (time_before(jiffies, cfqq->slice_end)) 643 if (time_before(jiffies, cfqq->slice_end))
651 return 0; 644 return false;
652 645
653 return 1; 646 return true;
654} 647}
655 648
656/* 649/*
@@ -869,7 +862,7 @@ cfq_group_service_tree_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
869 struct rb_node *n; 862 struct rb_node *n;
870 863
871 cfqg->nr_cfqq++; 864 cfqg->nr_cfqq++;
872 if (cfqg->on_st) 865 if (!RB_EMPTY_NODE(&cfqg->rb_node))
873 return; 866 return;
874 867
875 /* 868 /*
@@ -885,7 +878,6 @@ cfq_group_service_tree_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
885 cfqg->vdisktime = st->min_vdisktime; 878 cfqg->vdisktime = st->min_vdisktime;
886 879
887 __cfq_group_service_tree_add(st, cfqg); 880 __cfq_group_service_tree_add(st, cfqg);
888 cfqg->on_st = true;
889 st->total_weight += cfqg->weight; 881 st->total_weight += cfqg->weight;
890} 882}
891 883
@@ -894,9 +886,6 @@ cfq_group_service_tree_del(struct cfq_data *cfqd, struct cfq_group *cfqg)
894{ 886{
895 struct cfq_rb_root *st = &cfqd->grp_service_tree; 887 struct cfq_rb_root *st = &cfqd->grp_service_tree;
896 888
897 if (st->active == &cfqg->rb_node)
898 st->active = NULL;
899
900 BUG_ON(cfqg->nr_cfqq < 1); 889 BUG_ON(cfqg->nr_cfqq < 1);
901 cfqg->nr_cfqq--; 890 cfqg->nr_cfqq--;
902 891
@@ -905,7 +894,6 @@ cfq_group_service_tree_del(struct cfq_data *cfqd, struct cfq_group *cfqg)
905 return; 894 return;
906 895
907 cfq_log_cfqg(cfqd, cfqg, "del_from_rr group"); 896 cfq_log_cfqg(cfqd, cfqg, "del_from_rr group");
908 cfqg->on_st = false;
909 st->total_weight -= cfqg->weight; 897 st->total_weight -= cfqg->weight;
910 if (!RB_EMPTY_NODE(&cfqg->rb_node)) 898 if (!RB_EMPTY_NODE(&cfqg->rb_node))
911 cfq_rb_erase(&cfqg->rb_node, st); 899 cfq_rb_erase(&cfqg->rb_node, st);
@@ -1095,7 +1083,7 @@ static void cfq_put_cfqg(struct cfq_group *cfqg)
1095 if (!atomic_dec_and_test(&cfqg->ref)) 1083 if (!atomic_dec_and_test(&cfqg->ref))
1096 return; 1084 return;
1097 for_each_cfqg_st(cfqg, i, j, st) 1085 for_each_cfqg_st(cfqg, i, j, st)
1098 BUG_ON(!RB_EMPTY_ROOT(&st->rb) || st->active != NULL); 1086 BUG_ON(!RB_EMPTY_ROOT(&st->rb));
1099 kfree(cfqg); 1087 kfree(cfqg);
1100} 1088}
1101 1089
@@ -1687,9 +1675,6 @@ __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1687 if (cfqq == cfqd->active_queue) 1675 if (cfqq == cfqd->active_queue)
1688 cfqd->active_queue = NULL; 1676 cfqd->active_queue = NULL;
1689 1677
1690 if (&cfqq->cfqg->rb_node == cfqd->grp_service_tree.active)
1691 cfqd->grp_service_tree.active = NULL;
1692
1693 if (cfqd->active_cic) { 1678 if (cfqd->active_cic) {
1694 put_io_context(cfqd->active_cic->ioc); 1679 put_io_context(cfqd->active_cic->ioc);
1695 cfqd->active_cic = NULL; 1680 cfqd->active_cic = NULL;
@@ -1901,10 +1886,10 @@ static bool cfq_should_idle(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1901 * in their service tree. 1886 * in their service tree.
1902 */ 1887 */
1903 if (service_tree->count == 1 && cfq_cfqq_sync(cfqq)) 1888 if (service_tree->count == 1 && cfq_cfqq_sync(cfqq))
1904 return 1; 1889 return true;
1905 cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d", 1890 cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d",
1906 service_tree->count); 1891 service_tree->count);
1907 return 0; 1892 return false;
1908} 1893}
1909 1894
1910static void cfq_arm_slice_timer(struct cfq_data *cfqd) 1895static void cfq_arm_slice_timer(struct cfq_data *cfqd)
@@ -2116,6 +2101,7 @@ static void choose_service_tree(struct cfq_data *cfqd, struct cfq_group *cfqg)
2116 unsigned count; 2101 unsigned count;
2117 struct cfq_rb_root *st; 2102 struct cfq_rb_root *st;
2118 unsigned group_slice; 2103 unsigned group_slice;
2104 enum wl_prio_t original_prio = cfqd->serving_prio;
2119 2105
2120 if (!cfqg) { 2106 if (!cfqg) {
2121 cfqd->serving_prio = IDLE_WORKLOAD; 2107 cfqd->serving_prio = IDLE_WORKLOAD;
@@ -2134,6 +2120,9 @@ static void choose_service_tree(struct cfq_data *cfqd, struct cfq_group *cfqg)
2134 return; 2120 return;
2135 } 2121 }
2136 2122
2123 if (original_prio != cfqd->serving_prio)
2124 goto new_workload;
2125
2137 /* 2126 /*
2138 * For RT and BE, we have to choose also the type 2127 * For RT and BE, we have to choose also the type
2139 * (SYNC, SYNC_NOIDLE, ASYNC), and to compute a workload 2128 * (SYNC, SYNC_NOIDLE, ASYNC), and to compute a workload
@@ -2148,6 +2137,7 @@ static void choose_service_tree(struct cfq_data *cfqd, struct cfq_group *cfqg)
2148 if (count && !time_after(jiffies, cfqd->workload_expires)) 2137 if (count && !time_after(jiffies, cfqd->workload_expires))
2149 return; 2138 return;
2150 2139
2140new_workload:
2151 /* otherwise select new workload type */ 2141 /* otherwise select new workload type */
2152 cfqd->serving_type = 2142 cfqd->serving_type =
2153 cfq_choose_wl(cfqd, cfqg, cfqd->serving_prio); 2143 cfq_choose_wl(cfqd, cfqg, cfqd->serving_prio);
@@ -2199,7 +2189,6 @@ static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd)
2199 if (RB_EMPTY_ROOT(&st->rb)) 2189 if (RB_EMPTY_ROOT(&st->rb))
2200 return NULL; 2190 return NULL;
2201 cfqg = cfq_rb_first_group(st); 2191 cfqg = cfq_rb_first_group(st);
2202 st->active = &cfqg->rb_node;
2203 update_min_vdisktime(st); 2192 update_min_vdisktime(st);
2204 return cfqg; 2193 return cfqg;
2205} 2194}
@@ -2293,6 +2282,17 @@ static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
2293 goto keep_queue; 2282 goto keep_queue;
2294 } 2283 }
2295 2284
2285 /*
2286 * This is a deep seek queue, but the device is much faster than
2287 * the queue can deliver, don't idle
2288 **/
2289 if (CFQQ_SEEKY(cfqq) && cfq_cfqq_idle_window(cfqq) &&
2290 (cfq_cfqq_slice_new(cfqq) ||
2291 (cfqq->slice_end - jiffies > jiffies - cfqq->slice_start))) {
2292 cfq_clear_cfqq_deep(cfqq);
2293 cfq_clear_cfqq_idle_window(cfqq);
2294 }
2295
2296 if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) { 2296 if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
2297 cfqq = NULL; 2297 cfqq = NULL;
2298 goto keep_queue; 2298 goto keep_queue;
@@ -2367,12 +2367,12 @@ static inline bool cfq_slice_used_soon(struct cfq_data *cfqd,
2367{ 2367{
2368 /* the queue hasn't finished any request, can't estimate */ 2368 /* the queue hasn't finished any request, can't estimate */
2369 if (cfq_cfqq_slice_new(cfqq)) 2369 if (cfq_cfqq_slice_new(cfqq))
2370 return 1; 2370 return true;
2371 if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched, 2371 if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched,
2372 cfqq->slice_end)) 2372 cfqq->slice_end))
2373 return 1; 2373 return true;
2374 2374
2375 return 0; 2375 return false;
2376} 2376}
2377 2377
2378static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq) 2378static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
@@ -3265,6 +3265,10 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
3265 if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq)) 3265 if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq))
3266 return true; 3266 return true;
3267 3267
3268 /* An idle queue should not be idle now for some reason */
3269 if (RB_EMPTY_ROOT(&cfqq->sort_list) && !cfq_should_idle(cfqd, cfqq))
3270 return true;
3271
3268 if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq)) 3272 if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq))
3269 return false; 3273 return false;
3270 3274
diff --git a/block/ioctl.c b/block/ioctl.c
index 3d866d0037f2..fefa9a496708 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -295,11 +295,12 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
295 return -EINVAL; 295 return -EINVAL;
296 if (get_user(n, (int __user *) arg)) 296 if (get_user(n, (int __user *) arg))
297 return -EFAULT; 297 return -EFAULT;
298 if (!(mode & FMODE_EXCL) && bd_claim(bdev, &bdev) < 0) 298 if (!(mode & FMODE_EXCL) &&
299 blkdev_get(bdev, mode | FMODE_EXCL, &bdev) < 0)
299 return -EBUSY; 300 return -EBUSY;
300 ret = set_blocksize(bdev, n); 301 ret = set_blocksize(bdev, n);
301 if (!(mode & FMODE_EXCL)) 302 if (!(mode & FMODE_EXCL))
302 bd_release(bdev); 303 blkdev_put(bdev, mode | FMODE_EXCL);
303 return ret; 304 return ret;
304 case BLKPG: 305 case BLKPG:
305 ret = blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg); 306 ret = blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg);
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 1ea1a34e78b2..3803a0348937 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -911,8 +911,6 @@ struct drbd_md {
911struct drbd_backing_dev { 911struct drbd_backing_dev {
912 struct block_device *backing_bdev; 912 struct block_device *backing_bdev;
913 struct block_device *md_bdev; 913 struct block_device *md_bdev;
914 struct file *lo_file;
915 struct file *md_file;
916 struct drbd_md md; 914 struct drbd_md md;
917 struct disk_conf dc; /* The user provided config... */ 915 struct disk_conf dc; /* The user provided config... */
918 sector_t known_size; /* last known size of that backing device */ 916 sector_t known_size; /* last known size of that backing device */
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 6be5401d0e88..29cd0dc9fe4f 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -3372,11 +3372,8 @@ void drbd_free_bc(struct drbd_backing_dev *ldev)
3372 if (ldev == NULL) 3372 if (ldev == NULL)
3373 return; 3373 return;
3374 3374
3375 bd_release(ldev->backing_bdev); 3375 blkdev_put(ldev->backing_bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
3376 bd_release(ldev->md_bdev); 3376 blkdev_put(ldev->md_bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
3377
3378 fput(ldev->lo_file);
3379 fput(ldev->md_file);
3380 3377
3381 kfree(ldev); 3378 kfree(ldev);
3382} 3379}
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 29e5c70e4e26..8cbfaa687d72 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -855,7 +855,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
855 sector_t max_possible_sectors; 855 sector_t max_possible_sectors;
856 sector_t min_md_device_sectors; 856 sector_t min_md_device_sectors;
857 struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */ 857 struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */
858 struct inode *inode, *inode2; 858 struct block_device *bdev;
859 struct lru_cache *resync_lru = NULL; 859 struct lru_cache *resync_lru = NULL;
860 union drbd_state ns, os; 860 union drbd_state ns, os;
861 unsigned int max_seg_s; 861 unsigned int max_seg_s;
@@ -907,46 +907,40 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
907 } 907 }
908 } 908 }
909 909
910 nbc->lo_file = filp_open(nbc->dc.backing_dev, O_RDWR, 0); 910 bdev = blkdev_get_by_path(nbc->dc.backing_dev,
911 if (IS_ERR(nbc->lo_file)) { 911 FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev);
912 if (IS_ERR(bdev)) {
912 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev, 913 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev,
913 PTR_ERR(nbc->lo_file)); 914 PTR_ERR(bdev));
914 nbc->lo_file = NULL;
915 retcode = ERR_OPEN_DISK; 915 retcode = ERR_OPEN_DISK;
916 goto fail; 916 goto fail;
917 } 917 }
918 nbc->backing_bdev = bdev;
918 919
919 inode = nbc->lo_file->f_dentry->d_inode; 920 /*
920 921 * meta_dev_idx >= 0: external fixed size, possibly multiple
921 if (!S_ISBLK(inode->i_mode)) { 922 * drbd sharing one meta device. TODO in that case, paranoia
922 retcode = ERR_DISK_NOT_BDEV; 923 * check that [md_bdev, meta_dev_idx] is not yet used by some
923 goto fail; 924 * other drbd minor! (if you use drbd.conf + drbdadm, that
924 } 925 * should check it for you already; but if you don't, or
925 926 * someone fooled it, we need to double check here)
926 nbc->md_file = filp_open(nbc->dc.meta_dev, O_RDWR, 0); 927 */
927 if (IS_ERR(nbc->md_file)) { 928 bdev = blkdev_get_by_path(nbc->dc.meta_dev,
929 FMODE_READ | FMODE_WRITE | FMODE_EXCL,
930 (nbc->dc.meta_dev_idx < 0) ?
931 (void *)mdev : (void *)drbd_m_holder);
932 if (IS_ERR(bdev)) {
928 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev, 933 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev,
929 PTR_ERR(nbc->md_file)); 934 PTR_ERR(bdev));
930 nbc->md_file = NULL;
931 retcode = ERR_OPEN_MD_DISK; 935 retcode = ERR_OPEN_MD_DISK;
932 goto fail; 936 goto fail;
933 } 937 }
938 nbc->md_bdev = bdev;
934 939
935 inode2 = nbc->md_file->f_dentry->d_inode; 940 if ((nbc->backing_bdev == nbc->md_bdev) !=
936 941 (nbc->dc.meta_dev_idx == DRBD_MD_INDEX_INTERNAL ||
937 if (!S_ISBLK(inode2->i_mode)) { 942 nbc->dc.meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) {
938 retcode = ERR_MD_NOT_BDEV; 943 retcode = ERR_MD_IDX_INVALID;
939 goto fail;
940 }
941
942 nbc->backing_bdev = inode->i_bdev;
943 if (bd_claim(nbc->backing_bdev, mdev)) {
944 printk(KERN_ERR "drbd: bd_claim(%p,%p); failed [%p;%p;%u]\n",
945 nbc->backing_bdev, mdev,
946 nbc->backing_bdev->bd_holder,
947 nbc->backing_bdev->bd_contains->bd_holder,
948 nbc->backing_bdev->bd_holders);
949 retcode = ERR_BDCLAIM_DISK;
950 goto fail; 944 goto fail;
951 } 945 }
952 946
@@ -955,28 +949,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
955 offsetof(struct bm_extent, lce)); 949 offsetof(struct bm_extent, lce));
956 if (!resync_lru) { 950 if (!resync_lru) {
957 retcode = ERR_NOMEM; 951 retcode = ERR_NOMEM;
958 goto release_bdev_fail; 952 goto fail;
959 }
960
961 /* meta_dev_idx >= 0: external fixed size,
962 * possibly multiple drbd sharing one meta device.
963 * TODO in that case, paranoia check that [md_bdev, meta_dev_idx] is
964 * not yet used by some other drbd minor!
965 * (if you use drbd.conf + drbdadm,
966 * that should check it for you already; but if you don't, or someone
967 * fooled it, we need to double check here) */
968 nbc->md_bdev = inode2->i_bdev;
969 if (bd_claim(nbc->md_bdev, (nbc->dc.meta_dev_idx < 0) ? (void *)mdev
970 : (void *) drbd_m_holder)) {
971 retcode = ERR_BDCLAIM_MD_DISK;
972 goto release_bdev_fail;
973 }
974
975 if ((nbc->backing_bdev == nbc->md_bdev) !=
976 (nbc->dc.meta_dev_idx == DRBD_MD_INDEX_INTERNAL ||
977 nbc->dc.meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) {
978 retcode = ERR_MD_IDX_INVALID;
979 goto release_bdev2_fail;
980 } 953 }
981 954
982 /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */ 955 /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */
@@ -987,7 +960,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
987 (unsigned long long) drbd_get_max_capacity(nbc), 960 (unsigned long long) drbd_get_max_capacity(nbc),
988 (unsigned long long) nbc->dc.disk_size); 961 (unsigned long long) nbc->dc.disk_size);
989 retcode = ERR_DISK_TO_SMALL; 962 retcode = ERR_DISK_TO_SMALL;
990 goto release_bdev2_fail; 963 goto fail;
991 } 964 }
992 965
993 if (nbc->dc.meta_dev_idx < 0) { 966 if (nbc->dc.meta_dev_idx < 0) {
@@ -1004,7 +977,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1004 dev_warn(DEV, "refusing attach: md-device too small, " 977 dev_warn(DEV, "refusing attach: md-device too small, "
1005 "at least %llu sectors needed for this meta-disk type\n", 978 "at least %llu sectors needed for this meta-disk type\n",
1006 (unsigned long long) min_md_device_sectors); 979 (unsigned long long) min_md_device_sectors);
1007 goto release_bdev2_fail; 980 goto fail;
1008 } 981 }
1009 982
1010 /* Make sure the new disk is big enough 983 /* Make sure the new disk is big enough
@@ -1012,7 +985,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1012 if (drbd_get_max_capacity(nbc) < 985 if (drbd_get_max_capacity(nbc) <
1013 drbd_get_capacity(mdev->this_bdev)) { 986 drbd_get_capacity(mdev->this_bdev)) {
1014 retcode = ERR_DISK_TO_SMALL; 987 retcode = ERR_DISK_TO_SMALL;
1015 goto release_bdev2_fail; 988 goto fail;
1016 } 989 }
1017 990
1018 nbc->known_size = drbd_get_capacity(nbc->backing_bdev); 991 nbc->known_size = drbd_get_capacity(nbc->backing_bdev);
@@ -1035,7 +1008,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1035 retcode = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE); 1008 retcode = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE);
1036 drbd_resume_io(mdev); 1009 drbd_resume_io(mdev);
1037 if (retcode < SS_SUCCESS) 1010 if (retcode < SS_SUCCESS)
1038 goto release_bdev2_fail; 1011 goto fail;
1039 1012
1040 if (!get_ldev_if_state(mdev, D_ATTACHING)) 1013 if (!get_ldev_if_state(mdev, D_ATTACHING))
1041 goto force_diskless; 1014 goto force_diskless;
@@ -1269,18 +1242,14 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1269 force_diskless: 1242 force_diskless:
1270 drbd_force_state(mdev, NS(disk, D_FAILED)); 1243 drbd_force_state(mdev, NS(disk, D_FAILED));
1271 drbd_md_sync(mdev); 1244 drbd_md_sync(mdev);
1272 release_bdev2_fail:
1273 if (nbc)
1274 bd_release(nbc->md_bdev);
1275 release_bdev_fail:
1276 if (nbc)
1277 bd_release(nbc->backing_bdev);
1278 fail: 1245 fail:
1279 if (nbc) { 1246 if (nbc) {
1280 if (nbc->lo_file) 1247 if (nbc->backing_bdev)
1281 fput(nbc->lo_file); 1248 blkdev_put(nbc->backing_bdev,
1282 if (nbc->md_file) 1249 FMODE_READ | FMODE_WRITE | FMODE_EXCL);
1283 fput(nbc->md_file); 1250 if (nbc->md_bdev)
1251 blkdev_put(nbc->md_bdev,
1252 FMODE_READ | FMODE_WRITE | FMODE_EXCL);
1284 kfree(nbc); 1253 kfree(nbc);
1285 } 1254 }
1286 lc_destroy(resync_lru); 1255 lc_destroy(resync_lru);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 19b3568e9326..77d70eebb6b2 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2296,15 +2296,12 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
2296 * so bdget() can't fail. 2296 * so bdget() can't fail.
2297 */ 2297 */
2298 bdget(pd->bdev->bd_dev); 2298 bdget(pd->bdev->bd_dev);
2299 if ((ret = blkdev_get(pd->bdev, FMODE_READ))) 2299 if ((ret = blkdev_get(pd->bdev, FMODE_READ | FMODE_EXCL, pd)))
2300 goto out; 2300 goto out;
2301 2301
2302 if ((ret = bd_claim(pd->bdev, pd)))
2303 goto out_putdev;
2304
2305 if ((ret = pkt_get_last_written(pd, &lba))) { 2302 if ((ret = pkt_get_last_written(pd, &lba))) {
2306 printk(DRIVER_NAME": pkt_get_last_written failed\n"); 2303 printk(DRIVER_NAME": pkt_get_last_written failed\n");
2307 goto out_unclaim; 2304 goto out_putdev;
2308 } 2305 }
2309 2306
2310 set_capacity(pd->disk, lba << 2); 2307 set_capacity(pd->disk, lba << 2);
@@ -2314,7 +2311,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
2314 q = bdev_get_queue(pd->bdev); 2311 q = bdev_get_queue(pd->bdev);
2315 if (write) { 2312 if (write) {
2316 if ((ret = pkt_open_write(pd))) 2313 if ((ret = pkt_open_write(pd)))
2317 goto out_unclaim; 2314 goto out_putdev;
2318 /* 2315 /*
2319 * Some CDRW drives can not handle writes larger than one packet, 2316 * Some CDRW drives can not handle writes larger than one packet,
2320 * even if the size is a multiple of the packet size. 2317 * even if the size is a multiple of the packet size.
@@ -2329,23 +2326,21 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
2329 } 2326 }
2330 2327
2331 if ((ret = pkt_set_segment_merging(pd, q))) 2328 if ((ret = pkt_set_segment_merging(pd, q)))
2332 goto out_unclaim; 2329 goto out_putdev;
2333 2330
2334 if (write) { 2331 if (write) {
2335 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) { 2332 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) {
2336 printk(DRIVER_NAME": not enough memory for buffers\n"); 2333 printk(DRIVER_NAME": not enough memory for buffers\n");
2337 ret = -ENOMEM; 2334 ret = -ENOMEM;
2338 goto out_unclaim; 2335 goto out_putdev;
2339 } 2336 }
2340 printk(DRIVER_NAME": %lukB available on disc\n", lba << 1); 2337 printk(DRIVER_NAME": %lukB available on disc\n", lba << 1);
2341 } 2338 }
2342 2339
2343 return 0; 2340 return 0;
2344 2341
2345out_unclaim:
2346 bd_release(pd->bdev);
2347out_putdev: 2342out_putdev:
2348 blkdev_put(pd->bdev, FMODE_READ); 2343 blkdev_put(pd->bdev, FMODE_READ | FMODE_EXCL);
2349out: 2344out:
2350 return ret; 2345 return ret;
2351} 2346}
@@ -2362,8 +2357,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2362 pkt_lock_door(pd, 0); 2357 pkt_lock_door(pd, 0);
2363 2358
2364 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2359 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2365 bd_release(pd->bdev); 2360 blkdev_put(pd->bdev, FMODE_READ | FMODE_EXCL);
2366 blkdev_put(pd->bdev, FMODE_READ);
2367 2361
2368 pkt_shrink_pktlist(pd); 2362 pkt_shrink_pktlist(pd);
2369} 2363}
@@ -2733,7 +2727,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2733 bdev = bdget(dev); 2727 bdev = bdget(dev);
2734 if (!bdev) 2728 if (!bdev)
2735 return -ENOMEM; 2729 return -ENOMEM;
2736 ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY); 2730 ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY, NULL);
2737 if (ret) 2731 if (ret)
2738 return ret; 2732 return ret;
2739 2733
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index f0863bec186f..d72433f2d310 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -120,7 +120,7 @@ static int i8k_smm(struct smm_regs *regs)
120 int eax = regs->eax; 120 int eax = regs->eax;
121 121
122#if defined(CONFIG_X86_64) 122#if defined(CONFIG_X86_64)
123 asm("pushq %%rax\n\t" 123 asm volatile("pushq %%rax\n\t"
124 "movl 0(%%rax),%%edx\n\t" 124 "movl 0(%%rax),%%edx\n\t"
125 "pushq %%rdx\n\t" 125 "pushq %%rdx\n\t"
126 "movl 4(%%rax),%%ebx\n\t" 126 "movl 4(%%rax),%%ebx\n\t"
@@ -142,11 +142,11 @@ static int i8k_smm(struct smm_regs *regs)
142 "lahf\n\t" 142 "lahf\n\t"
143 "shrl $8,%%eax\n\t" 143 "shrl $8,%%eax\n\t"
144 "andl $1,%%eax\n" 144 "andl $1,%%eax\n"
145 :"=a"(rc), "+m" (*regs) 145 :"=a"(rc)
146 : "a"(regs) 146 : "a"(regs)
147 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); 147 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
148#else 148#else
149 asm("pushl %%eax\n\t" 149 asm volatile("pushl %%eax\n\t"
150 "movl 0(%%eax),%%edx\n\t" 150 "movl 0(%%eax),%%edx\n\t"
151 "push %%edx\n\t" 151 "push %%edx\n\t"
152 "movl 4(%%eax),%%ebx\n\t" 152 "movl 4(%%eax),%%ebx\n\t"
@@ -168,7 +168,7 @@ static int i8k_smm(struct smm_regs *regs)
168 "lahf\n\t" 168 "lahf\n\t"
169 "shrl $8,%%eax\n\t" 169 "shrl $8,%%eax\n\t"
170 "andl $1,%%eax\n" 170 "andl $1,%%eax\n"
171 :"=a"(rc), "+m" (*regs) 171 :"=a"(rc)
172 : "a"(regs) 172 : "a"(regs)
173 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); 173 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
174#endif 174#endif
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index bfe25ea9766b..b4b9d5a47885 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -65,15 +65,12 @@ static int raw_open(struct inode *inode, struct file *filp)
65 if (!bdev) 65 if (!bdev)
66 goto out; 66 goto out;
67 igrab(bdev->bd_inode); 67 igrab(bdev->bd_inode);
68 err = blkdev_get(bdev, filp->f_mode); 68 err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open);
69 if (err) 69 if (err)
70 goto out; 70 goto out;
71 err = bd_claim(bdev, raw_open);
72 if (err)
73 goto out1;
74 err = set_blocksize(bdev, bdev_logical_block_size(bdev)); 71 err = set_blocksize(bdev, bdev_logical_block_size(bdev));
75 if (err) 72 if (err)
76 goto out2; 73 goto out1;
77 filp->f_flags |= O_DIRECT; 74 filp->f_flags |= O_DIRECT;
78 filp->f_mapping = bdev->bd_inode->i_mapping; 75 filp->f_mapping = bdev->bd_inode->i_mapping;
79 if (++raw_devices[minor].inuse == 1) 76 if (++raw_devices[minor].inuse == 1)
@@ -83,10 +80,8 @@ static int raw_open(struct inode *inode, struct file *filp)
83 mutex_unlock(&raw_mutex); 80 mutex_unlock(&raw_mutex);
84 return 0; 81 return 0;
85 82
86out2:
87 bd_release(bdev);
88out1: 83out1:
89 blkdev_put(bdev, filp->f_mode); 84 blkdev_put(bdev, filp->f_mode | FMODE_EXCL);
90out: 85out:
91 mutex_unlock(&raw_mutex); 86 mutex_unlock(&raw_mutex);
92 return err; 87 return err;
@@ -110,8 +105,7 @@ static int raw_release(struct inode *inode, struct file *filp)
110 } 105 }
111 mutex_unlock(&raw_mutex); 106 mutex_unlock(&raw_mutex);
112 107
113 bd_release(bdev); 108 blkdev_put(bdev, filp->f_mode | FMODE_EXCL);
114 blkdev_put(bdev, filp->f_mode);
115 return 0; 109 return 0;
116} 110}
117 111
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index fa9708c2d723..4033974d1bb3 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -4,7 +4,7 @@
4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si> 4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si>
5 5
6 Based on max6650.c: 6 Based on max6650.c:
7 Copyright (C) 2007 Hans J. Koch <hjk@linutronix.de> 7 Copyright (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
index 6669255aadcf..c9ed14eba5a6 100644
--- a/drivers/hwmon/lm93.c
+++ b/drivers/hwmon/lm93.c
@@ -20,7 +20,7 @@
20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org> 20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab 21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
22 22
23 Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> 23 Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH 24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
25 25
26 This program is free software; you can redistribute it and/or modify 26 This program is free software; you can redistribute it and/or modify
@@ -2629,7 +2629,7 @@ static void __exit lm93_exit(void)
2629} 2629}
2630 2630
2631MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, " 2631MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2632 "Hans J. Koch <hjk@linutronix.de"); 2632 "Hans J. Koch <hjk@hansjkoch.de>");
2633MODULE_DESCRIPTION("LM93 driver"); 2633MODULE_DESCRIPTION("LM93 driver");
2634MODULE_LICENSE("GPL"); 2634MODULE_LICENSE("GPL");
2635 2635
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 464340f25496..4546d82f024a 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -128,9 +128,12 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
128{ 128{
129 struct i2c_client *client = to_i2c_client(dev); 129 struct i2c_client *client = to_i2c_client(dev);
130 struct lm95241_data *data = i2c_get_clientdata(client); 130 struct lm95241_data *data = i2c_get_clientdata(client);
131 unsigned long val;
131 132
132 strict_strtol(buf, 10, &data->interval); 133 if (strict_strtoul(buf, 10, &val) < 0)
133 data->interval = data->interval * HZ / 1000; 134 return -EINVAL;
135
136 data->interval = val * HZ / 1000;
134 137
135 return count; 138 return count;
136} 139}
@@ -188,7 +191,9 @@ static ssize_t set_type##flag(struct device *dev, \
188 struct lm95241_data *data = i2c_get_clientdata(client); \ 191 struct lm95241_data *data = i2c_get_clientdata(client); \
189\ 192\
190 long val; \ 193 long val; \
191 strict_strtol(buf, 10, &val); \ 194\
195 if (strict_strtol(buf, 10, &val) < 0) \
196 return -EINVAL; \
192\ 197\
193 if ((val == 1) || (val == 2)) { \ 198 if ((val == 1) || (val == 2)) { \
194\ 199\
@@ -227,7 +232,9 @@ static ssize_t set_min##flag(struct device *dev, \
227 struct lm95241_data *data = i2c_get_clientdata(client); \ 232 struct lm95241_data *data = i2c_get_clientdata(client); \
228\ 233\
229 long val; \ 234 long val; \
230 strict_strtol(buf, 10, &val); \ 235\
236 if (strict_strtol(buf, 10, &val) < 0) \
237 return -EINVAL;\
231\ 238\
232 mutex_lock(&data->update_lock); \ 239 mutex_lock(&data->update_lock); \
233\ 240\
@@ -256,7 +263,9 @@ static ssize_t set_max##flag(struct device *dev, \
256 struct lm95241_data *data = i2c_get_clientdata(client); \ 263 struct lm95241_data *data = i2c_get_clientdata(client); \
257\ 264\
258 long val; \ 265 long val; \
259 strict_strtol(buf, 10, &val); \ 266\
267 if (strict_strtol(buf, 10, &val) < 0) \
268 return -EINVAL; \
260\ 269\
261 mutex_lock(&data->update_lock); \ 270 mutex_lock(&data->update_lock); \
262\ 271\
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index a0160ee5caef..9a11532ecae8 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -2,7 +2,7 @@
2 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware 2 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring. 3 * monitoring.
4 * 4 *
5 * (C) 2007 by Hans J. Koch <hjk@linutronix.de> 5 * (C) 2007 by Hans J. Koch <hjk@hansjkoch.de>
6 * 6 *
7 * based on code written by John Morris <john.morris@spirentcom.com> 7 * based on code written by John Morris <john.morris@spirentcom.com>
8 * Copyright (c) 2003 Spirent Communications 8 * Copyright (c) 2003 Spirent Communications
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 1d840aa83782..cdbc7448491e 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -165,10 +165,14 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
165 165
166#define W83795_REG_VID_CTRL 0x6A 166#define W83795_REG_VID_CTRL 0x6A
167 167
168#define W83795_REG_ALARM_CTRL 0x40
169#define ALARM_CTRL_RTSACS (1 << 7)
168#define W83795_REG_ALARM(index) (0x41 + (index)) 170#define W83795_REG_ALARM(index) (0x41 + (index))
171#define W83795_REG_CLR_CHASSIS 0x4D
169#define W83795_REG_BEEP(index) (0x50 + (index)) 172#define W83795_REG_BEEP(index) (0x50 + (index))
170 173
171#define W83795_REG_CLR_CHASSIS 0x4D 174#define W83795_REG_OVT_CFG 0x58
175#define OVT_CFG_SEL (1 << 7)
172 176
173 177
174#define W83795_REG_FCMS1 0x201 178#define W83795_REG_FCMS1 0x201
@@ -178,6 +182,14 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
178 182
179#define W83795_REG_TSS(index) (0x209 + (index)) 183#define W83795_REG_TSS(index) (0x209 + (index))
180 184
185#define TSS_MAP_RESERVED 0xff
186static const u8 tss_map[4][6] = {
187 { 0, 1, 2, 3, 4, 5},
188 { 6, 7, 8, 9, 0, 1},
189 {10, 11, 12, 13, 2, 3},
190 { 4, 5, 4, 5, TSS_MAP_RESERVED, TSS_MAP_RESERVED},
191};
192
181#define PWM_OUTPUT 0 193#define PWM_OUTPUT 0
182#define PWM_FREQ 1 194#define PWM_FREQ 1
183#define PWM_START 2 195#define PWM_START 2
@@ -369,6 +381,7 @@ struct w83795_data {
369 u8 setup_pwm[3]; /* Register value */ 381 u8 setup_pwm[3]; /* Register value */
370 382
371 u8 alarms[6]; /* Register value */ 383 u8 alarms[6]; /* Register value */
384 u8 enable_beep;
372 u8 beeps[6]; /* Register value */ 385 u8 beeps[6]; /* Register value */
373 386
374 char valid; 387 char valid;
@@ -499,8 +512,11 @@ static void w83795_update_limits(struct i2c_client *client)
499 } 512 }
500 513
501 /* Read beep settings */ 514 /* Read beep settings */
502 for (i = 0; i < ARRAY_SIZE(data->beeps); i++) 515 if (data->enable_beep) {
503 data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i)); 516 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
517 data->beeps[i] =
518 w83795_read(client, W83795_REG_BEEP(i));
519 }
504 520
505 data->valid_limits = 1; 521 data->valid_limits = 1;
506} 522}
@@ -577,6 +593,7 @@ static struct w83795_data *w83795_update_device(struct device *dev)
577 struct i2c_client *client = to_i2c_client(dev); 593 struct i2c_client *client = to_i2c_client(dev);
578 struct w83795_data *data = i2c_get_clientdata(client); 594 struct w83795_data *data = i2c_get_clientdata(client);
579 u16 tmp; 595 u16 tmp;
596 u8 intrusion;
580 int i; 597 int i;
581 598
582 mutex_lock(&data->update_lock); 599 mutex_lock(&data->update_lock);
@@ -648,9 +665,24 @@ static struct w83795_data *w83795_update_device(struct device *dev)
648 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); 665 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT));
649 } 666 }
650 667
651 /* update alarm */ 668 /* Update intrusion and alarms
669 * It is important to read intrusion first, because reading from
670 * register SMI STS6 clears the interrupt status temporarily. */
671 tmp = w83795_read(client, W83795_REG_ALARM_CTRL);
672 /* Switch to interrupt status for intrusion if needed */
673 if (tmp & ALARM_CTRL_RTSACS)
674 w83795_write(client, W83795_REG_ALARM_CTRL,
675 tmp & ~ALARM_CTRL_RTSACS);
676 intrusion = w83795_read(client, W83795_REG_ALARM(5)) & (1 << 6);
677 /* Switch to real-time alarms */
678 w83795_write(client, W83795_REG_ALARM_CTRL, tmp | ALARM_CTRL_RTSACS);
652 for (i = 0; i < ARRAY_SIZE(data->alarms); i++) 679 for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
653 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i)); 680 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i));
681 data->alarms[5] |= intrusion;
682 /* Restore original configuration if needed */
683 if (!(tmp & ALARM_CTRL_RTSACS))
684 w83795_write(client, W83795_REG_ALARM_CTRL,
685 tmp & ~ALARM_CTRL_RTSACS);
654 686
655 data->last_updated = jiffies; 687 data->last_updated = jiffies;
656 data->valid = 1; 688 data->valid = 1;
@@ -730,6 +762,10 @@ store_chassis_clear(struct device *dev,
730 val = w83795_read(client, W83795_REG_CLR_CHASSIS); 762 val = w83795_read(client, W83795_REG_CLR_CHASSIS);
731 val |= 0x80; 763 val |= 0x80;
732 w83795_write(client, W83795_REG_CLR_CHASSIS, val); 764 w83795_write(client, W83795_REG_CLR_CHASSIS, val);
765
766 /* Clear status and force cache refresh */
767 w83795_read(client, W83795_REG_ALARM(5));
768 data->valid = 0;
733 mutex_unlock(&data->update_lock); 769 mutex_unlock(&data->update_lock);
734 return count; 770 return count;
735} 771}
@@ -857,20 +893,20 @@ show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
857 int index = sensor_attr->index; 893 int index = sensor_attr->index;
858 u8 tmp; 894 u8 tmp;
859 895
860 if (1 == (data->pwm_fcms[0] & (1 << index))) { 896 /* Speed cruise mode */
897 if (data->pwm_fcms[0] & (1 << index)) {
861 tmp = 2; 898 tmp = 2;
862 goto out; 899 goto out;
863 } 900 }
901 /* Thermal cruise or SmartFan IV mode */
864 for (tmp = 0; tmp < 6; tmp++) { 902 for (tmp = 0; tmp < 6; tmp++) {
865 if (data->pwm_tfmr[tmp] & (1 << index)) { 903 if (data->pwm_tfmr[tmp] & (1 << index)) {
866 tmp = 3; 904 tmp = 3;
867 goto out; 905 goto out;
868 } 906 }
869 } 907 }
870 if (data->pwm_fomc & (1 << index)) 908 /* Manual mode */
871 tmp = 0; 909 tmp = 1;
872 else
873 tmp = 1;
874 910
875out: 911out:
876 return sprintf(buf, "%u\n", tmp); 912 return sprintf(buf, "%u\n", tmp);
@@ -890,23 +926,21 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
890 926
891 if (strict_strtoul(buf, 10, &val) < 0) 927 if (strict_strtoul(buf, 10, &val) < 0)
892 return -EINVAL; 928 return -EINVAL;
893 if (val > 2) 929 if (val < 1 || val > 2)
894 return -EINVAL; 930 return -EINVAL;
895 931
896 mutex_lock(&data->update_lock); 932 mutex_lock(&data->update_lock);
897 switch (val) { 933 switch (val) {
898 case 0:
899 case 1: 934 case 1:
935 /* Clear speed cruise mode bits */
900 data->pwm_fcms[0] &= ~(1 << index); 936 data->pwm_fcms[0] &= ~(1 << index);
901 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); 937 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]);
938 /* Clear thermal cruise mode bits */
902 for (i = 0; i < 6; i++) { 939 for (i = 0; i < 6; i++) {
903 data->pwm_tfmr[i] &= ~(1 << index); 940 data->pwm_tfmr[i] &= ~(1 << index);
904 w83795_write(client, W83795_REG_TFMR(i), 941 w83795_write(client, W83795_REG_TFMR(i),
905 data->pwm_tfmr[i]); 942 data->pwm_tfmr[i]);
906 } 943 }
907 data->pwm_fomc |= 1 << index;
908 data->pwm_fomc ^= val << index;
909 w83795_write(client, W83795_REG_FOMC, data->pwm_fomc);
910 break; 944 break;
911 case 2: 945 case 2:
912 data->pwm_fcms[0] |= (1 << index); 946 data->pwm_fcms[0] |= (1 << index);
@@ -918,23 +952,60 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
918} 952}
919 953
920static ssize_t 954static ssize_t
955show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf)
956{
957 struct w83795_data *data = w83795_update_pwm_config(dev);
958 int index = to_sensor_dev_attr_2(attr)->index;
959 unsigned int mode;
960
961 if (data->pwm_fomc & (1 << index))
962 mode = 0; /* DC */
963 else
964 mode = 1; /* PWM */
965
966 return sprintf(buf, "%u\n", mode);
967}
968
969/*
970 * Check whether a given temperature source can ever be useful.
971 * Returns the number of selectable temperature channels which are
972 * enabled.
973 */
974static int w83795_tss_useful(const struct w83795_data *data, int tsrc)
975{
976 int useful = 0, i;
977
978 for (i = 0; i < 4; i++) {
979 if (tss_map[i][tsrc] == TSS_MAP_RESERVED)
980 continue;
981 if (tss_map[i][tsrc] < 6) /* Analog */
982 useful += (data->has_temp >> tss_map[i][tsrc]) & 1;
983 else /* Digital */
984 useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1;
985 }
986
987 return useful;
988}
989
990static ssize_t
921show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) 991show_temp_src(struct device *dev, struct device_attribute *attr, char *buf)
922{ 992{
923 struct sensor_device_attribute_2 *sensor_attr = 993 struct sensor_device_attribute_2 *sensor_attr =
924 to_sensor_dev_attr_2(attr); 994 to_sensor_dev_attr_2(attr);
925 struct w83795_data *data = w83795_update_pwm_config(dev); 995 struct w83795_data *data = w83795_update_pwm_config(dev);
926 int index = sensor_attr->index; 996 int index = sensor_attr->index;
927 u8 val = index / 2; 997 u8 tmp = data->temp_src[index / 2];
928 u8 tmp = data->temp_src[val];
929 998
930 if (index & 1) 999 if (index & 1)
931 val = 4; 1000 tmp >>= 4; /* Pick high nibble */
932 else 1001 else
933 val = 0; 1002 tmp &= 0x0f; /* Pick low nibble */
934 tmp >>= val;
935 tmp &= 0x0f;
936 1003
937 return sprintf(buf, "%u\n", tmp); 1004 /* Look-up the actual temperature channel number */
1005 if (tmp >= 4 || tss_map[tmp][index] == TSS_MAP_RESERVED)
1006 return -EINVAL; /* Shouldn't happen */
1007
1008 return sprintf(buf, "%u\n", (unsigned int)tss_map[tmp][index] + 1);
938} 1009}
939 1010
940static ssize_t 1011static ssize_t
@@ -946,12 +1017,21 @@ store_temp_src(struct device *dev, struct device_attribute *attr,
946 struct sensor_device_attribute_2 *sensor_attr = 1017 struct sensor_device_attribute_2 *sensor_attr =
947 to_sensor_dev_attr_2(attr); 1018 to_sensor_dev_attr_2(attr);
948 int index = sensor_attr->index; 1019 int index = sensor_attr->index;
949 unsigned long tmp; 1020 int tmp;
1021 unsigned long channel;
950 u8 val = index / 2; 1022 u8 val = index / 2;
951 1023
952 if (strict_strtoul(buf, 10, &tmp) < 0) 1024 if (strict_strtoul(buf, 10, &channel) < 0 ||
1025 channel < 1 || channel > 14)
1026 return -EINVAL;
1027
1028 /* Check if request can be fulfilled */
1029 for (tmp = 0; tmp < 4; tmp++) {
1030 if (tss_map[tmp][index] == channel - 1)
1031 break;
1032 }
1033 if (tmp == 4) /* No match */
953 return -EINVAL; 1034 return -EINVAL;
954 tmp = SENSORS_LIMIT(tmp, 0, 15);
955 1035
956 mutex_lock(&data->update_lock); 1036 mutex_lock(&data->update_lock);
957 if (index & 1) { 1037 if (index & 1) {
@@ -1515,7 +1595,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1515 1595
1516#define NOT_USED -1 1596#define NOT_USED -1
1517 1597
1518/* Don't change the attribute order, _max and _min are accessed by index 1598/* Don't change the attribute order, _max, _min and _beep are accessed by index
1519 * somewhere else in the code */ 1599 * somewhere else in the code */
1520#define SENSOR_ATTR_IN(index) { \ 1600#define SENSOR_ATTR_IN(index) { \
1521 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ 1601 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
@@ -1530,6 +1610,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1530 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1610 show_alarm_beep, store_beep, BEEP_ENABLE, \
1531 index + ((index > 14) ? 1 : 0)) } 1611 index + ((index > 14) ? 1 : 0)) }
1532 1612
1613/* Don't change the attribute order, _beep is accessed by index
1614 * somewhere else in the code */
1533#define SENSOR_ATTR_FAN(index) { \ 1615#define SENSOR_ATTR_FAN(index) { \
1534 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ 1616 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
1535 NULL, FAN_INPUT, index - 1), \ 1617 NULL, FAN_INPUT, index - 1), \
@@ -1553,9 +1635,13 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1553 show_pwm, store_pwm, PWM_FREQ, index - 1), \ 1635 show_pwm, store_pwm, PWM_FREQ, index - 1), \
1554 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ 1636 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \
1555 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ 1637 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \
1638 SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \
1639 show_pwm_mode, NULL, NOT_USED, index - 1), \
1556 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ 1640 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \
1557 show_fanin, store_fanin, FANIN_TARGET, index - 1) } 1641 show_fanin, store_fanin, FANIN_TARGET, index - 1) }
1558 1642
1643/* Don't change the attribute order, _beep is accessed by index
1644 * somewhere else in the code */
1559#define SENSOR_ATTR_DTS(index) { \ 1645#define SENSOR_ATTR_DTS(index) { \
1560 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ 1646 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \
1561 show_dts_mode, NULL, NOT_USED, index - 7), \ 1647 show_dts_mode, NULL, NOT_USED, index - 7), \
@@ -1574,6 +1660,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1574 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1660 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1575 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } 1661 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) }
1576 1662
1663/* Don't change the attribute order, _beep is accessed by index
1664 * somewhere else in the code */
1577#define SENSOR_ATTR_TEMP(index) { \ 1665#define SENSOR_ATTR_TEMP(index) { \
1578 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ 1666 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \
1579 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ 1667 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
@@ -1593,8 +1681,6 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1593 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1681 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1594 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1682 show_alarm_beep, store_beep, BEEP_ENABLE, \
1595 index + (index > 4 ? 11 : 17)), \ 1683 index + (index > 4 ? 11 : 17)), \
1596 SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \
1597 show_temp_src, store_temp_src, NOT_USED, index - 1), \
1598 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ 1684 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
1599 show_temp_pwm_enable, store_temp_pwm_enable, \ 1685 show_temp_pwm_enable, store_temp_pwm_enable, \
1600 TEMP_PWM_ENABLE, index - 1), \ 1686 TEMP_PWM_ENABLE, index - 1), \
@@ -1680,7 +1766,7 @@ static const struct sensor_device_attribute_2 w83795_fan[][4] = {
1680 SENSOR_ATTR_FAN(14), 1766 SENSOR_ATTR_FAN(14),
1681}; 1767};
1682 1768
1683static const struct sensor_device_attribute_2 w83795_temp[][29] = { 1769static const struct sensor_device_attribute_2 w83795_temp[][28] = {
1684 SENSOR_ATTR_TEMP(1), 1770 SENSOR_ATTR_TEMP(1),
1685 SENSOR_ATTR_TEMP(2), 1771 SENSOR_ATTR_TEMP(2),
1686 SENSOR_ATTR_TEMP(3), 1772 SENSOR_ATTR_TEMP(3),
@@ -1700,7 +1786,7 @@ static const struct sensor_device_attribute_2 w83795_dts[][8] = {
1700 SENSOR_ATTR_DTS(14), 1786 SENSOR_ATTR_DTS(14),
1701}; 1787};
1702 1788
1703static const struct sensor_device_attribute_2 w83795_pwm[][7] = { 1789static const struct sensor_device_attribute_2 w83795_pwm[][8] = {
1704 SENSOR_ATTR_PWM(1), 1790 SENSOR_ATTR_PWM(1),
1705 SENSOR_ATTR_PWM(2), 1791 SENSOR_ATTR_PWM(2),
1706 SENSOR_ATTR_PWM(3), 1792 SENSOR_ATTR_PWM(3),
@@ -1711,13 +1797,24 @@ static const struct sensor_device_attribute_2 w83795_pwm[][7] = {
1711 SENSOR_ATTR_PWM(8), 1797 SENSOR_ATTR_PWM(8),
1712}; 1798};
1713 1799
1800static const struct sensor_device_attribute_2 w83795_tss[6] = {
1801 SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO,
1802 show_temp_src, store_temp_src, NOT_USED, 0),
1803 SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO,
1804 show_temp_src, store_temp_src, NOT_USED, 1),
1805 SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO,
1806 show_temp_src, store_temp_src, NOT_USED, 2),
1807 SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO,
1808 show_temp_src, store_temp_src, NOT_USED, 3),
1809 SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO,
1810 show_temp_src, store_temp_src, NOT_USED, 4),
1811 SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO,
1812 show_temp_src, store_temp_src, NOT_USED, 5),
1813};
1814
1714static const struct sensor_device_attribute_2 sda_single_files[] = { 1815static const struct sensor_device_attribute_2 sda_single_files[] = {
1715 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, 1816 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep,
1716 store_chassis_clear, ALARM_STATUS, 46), 1817 store_chassis_clear, ALARM_STATUS, 46),
1717 SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep,
1718 store_beep, BEEP_ENABLE, 46),
1719 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep,
1720 store_beep, BEEP_ENABLE, 47),
1721#ifdef CONFIG_SENSORS_W83795_FANCTRL 1818#ifdef CONFIG_SENSORS_W83795_FANCTRL
1722 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, 1819 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin,
1723 store_fanin, FANIN_TOL, NOT_USED), 1820 store_fanin, FANIN_TOL, NOT_USED),
@@ -1730,6 +1827,13 @@ static const struct sensor_device_attribute_2 sda_single_files[] = {
1730#endif 1827#endif
1731}; 1828};
1732 1829
1830static const struct sensor_device_attribute_2 sda_beep_files[] = {
1831 SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep,
1832 store_beep, BEEP_ENABLE, 46),
1833 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep,
1834 store_beep, BEEP_ENABLE, 47),
1835};
1836
1733/* 1837/*
1734 * Driver interface 1838 * Driver interface
1735 */ 1839 */
@@ -1859,6 +1963,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1859 if (!(data->has_in & (1 << i))) 1963 if (!(data->has_in & (1 << i)))
1860 continue; 1964 continue;
1861 for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { 1965 for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) {
1966 if (j == 4 && !data->enable_beep)
1967 continue;
1862 err = fn(dev, &w83795_in[i][j].dev_attr); 1968 err = fn(dev, &w83795_in[i][j].dev_attr);
1863 if (err) 1969 if (err)
1864 return err; 1970 return err;
@@ -1869,18 +1975,37 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1869 if (!(data->has_fan & (1 << i))) 1975 if (!(data->has_fan & (1 << i)))
1870 continue; 1976 continue;
1871 for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { 1977 for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) {
1978 if (j == 3 && !data->enable_beep)
1979 continue;
1872 err = fn(dev, &w83795_fan[i][j].dev_attr); 1980 err = fn(dev, &w83795_fan[i][j].dev_attr);
1873 if (err) 1981 if (err)
1874 return err; 1982 return err;
1875 } 1983 }
1876 } 1984 }
1877 1985
1986 for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) {
1987 j = w83795_tss_useful(data, i);
1988 if (!j)
1989 continue;
1990 err = fn(dev, &w83795_tss[i].dev_attr);
1991 if (err)
1992 return err;
1993 }
1994
1878 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { 1995 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1879 err = fn(dev, &sda_single_files[i].dev_attr); 1996 err = fn(dev, &sda_single_files[i].dev_attr);
1880 if (err) 1997 if (err)
1881 return err; 1998 return err;
1882 } 1999 }
1883 2000
2001 if (data->enable_beep) {
2002 for (i = 0; i < ARRAY_SIZE(sda_beep_files); i++) {
2003 err = fn(dev, &sda_beep_files[i].dev_attr);
2004 if (err)
2005 return err;
2006 }
2007 }
2008
1884#ifdef CONFIG_SENSORS_W83795_FANCTRL 2009#ifdef CONFIG_SENSORS_W83795_FANCTRL
1885 for (i = 0; i < data->has_pwm; i++) { 2010 for (i = 0; i < data->has_pwm; i++) {
1886 for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) { 2011 for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) {
@@ -1899,6 +2024,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1899#else 2024#else
1900 for (j = 0; j < 8; j++) { 2025 for (j = 0; j < 8; j++) {
1901#endif 2026#endif
2027 if (j == 7 && !data->enable_beep)
2028 continue;
1902 err = fn(dev, &w83795_temp[i][j].dev_attr); 2029 err = fn(dev, &w83795_temp[i][j].dev_attr);
1903 if (err) 2030 if (err)
1904 return err; 2031 return err;
@@ -1910,6 +2037,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1910 if (!(data->has_dts & (1 << i))) 2037 if (!(data->has_dts & (1 << i)))
1911 continue; 2038 continue;
1912 for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { 2039 for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) {
2040 if (j == 7 && !data->enable_beep)
2041 continue;
1913 err = fn(dev, &w83795_dts[i][j].dev_attr); 2042 err = fn(dev, &w83795_dts[i][j].dev_attr);
1914 if (err) 2043 if (err)
1915 return err; 2044 return err;
@@ -2049,6 +2178,18 @@ static int w83795_probe(struct i2c_client *client,
2049 else 2178 else
2050 data->has_pwm = 2; 2179 data->has_pwm = 2;
2051 2180
2181 /* Check if BEEP pin is available */
2182 if (data->chip_type == w83795g) {
2183 /* The W83795G has a dedicated BEEP pin */
2184 data->enable_beep = 1;
2185 } else {
2186 /* The W83795ADG has a shared pin for OVT# and BEEP, so you
2187 * can't have both */
2188 tmp = w83795_read(client, W83795_REG_OVT_CFG);
2189 if ((tmp & OVT_CFG_SEL) == 0)
2190 data->enable_beep = 1;
2191 }
2192
2052 err = w83795_handle_files(dev, device_create_file); 2193 err = w83795_handle_files(dev, device_create_file);
2053 if (err) 2194 if (err)
2054 goto exit_remove; 2195 goto exit_remove;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d231f683f576..6b4cc567645b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -848,6 +848,18 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
848 goto out_list; 848 goto out_list;
849 } 849 }
850 850
851 /* Sanity checks */
852 if (unlikely(adap->name[0] == '\0')) {
853 pr_err("i2c-core: Attempt to register an adapter with "
854 "no name!\n");
855 return -EINVAL;
856 }
857 if (unlikely(!adap->algo)) {
858 pr_err("i2c-core: Attempt to register adapter '%s' with "
859 "no algo!\n", adap->name);
860 return -EINVAL;
861 }
862
851 rt_mutex_init(&adap->bus_lock); 863 rt_mutex_init(&adap->bus_lock);
852 mutex_init(&adap->userspace_clients_lock); 864 mutex_init(&adap->userspace_clients_lock);
853 INIT_LIST_HEAD(&adap->userspace_clients); 865 INIT_LIST_HEAD(&adap->userspace_clients);
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index d32a4843fc3a..d7a4833be416 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -120,7 +120,6 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
120 snprintf(priv->adap.name, sizeof(priv->adap.name), 120 snprintf(priv->adap.name, sizeof(priv->adap.name),
121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); 121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
122 priv->adap.owner = THIS_MODULE; 122 priv->adap.owner = THIS_MODULE;
123 priv->adap.id = parent->id;
124 priv->adap.algo = &priv->algo; 123 priv->adap.algo = &priv->algo;
125 priv->adap.algo_data = priv; 124 priv->adap.algo_data = priv;
126 priv->adap.dev.parent = &parent->dev; 125 priv->adap.dev.parent = &parent->dev;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 90267f8d64ee..67150c32986c 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -325,15 +325,18 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev,
325 325
326 BUG_ON(d->dm_dev.bdev); 326 BUG_ON(d->dm_dev.bdev);
327 327
328 bdev = open_by_devnum(dev, d->dm_dev.mode); 328 bdev = blkdev_get_by_dev(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr);
329 if (IS_ERR(bdev)) 329 if (IS_ERR(bdev))
330 return PTR_ERR(bdev); 330 return PTR_ERR(bdev);
331 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md)); 331
332 if (r) 332 r = bd_link_disk_holder(bdev, dm_disk(md));
333 blkdev_put(bdev, d->dm_dev.mode); 333 if (r) {
334 else 334 blkdev_put(bdev, d->dm_dev.mode | FMODE_EXCL);
335 d->dm_dev.bdev = bdev; 335 return r;
336 return r; 336 }
337
338 d->dm_dev.bdev = bdev;
339 return 0;
337} 340}
338 341
339/* 342/*
@@ -344,8 +347,7 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
344 if (!d->dm_dev.bdev) 347 if (!d->dm_dev.bdev)
345 return; 348 return;
346 349
347 bd_release_from_disk(d->dm_dev.bdev, dm_disk(md)); 350 blkdev_put(d->dm_dev.bdev, d->dm_dev.mode | FMODE_EXCL);
348 blkdev_put(d->dm_dev.bdev, d->dm_dev.mode);
349 d->dm_dev.bdev = NULL; 351 d->dm_dev.bdev = NULL;
350} 352}
351 353
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 7cb1352f7e7a..0a2b5516bc21 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -990,8 +990,8 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
990 if (r == DM_MAPIO_REMAPPED) { 990 if (r == DM_MAPIO_REMAPPED) {
991 /* the bio has been remapped so dispatch it */ 991 /* the bio has been remapped so dispatch it */
992 992
993 trace_block_remap(bdev_get_queue(clone->bi_bdev), clone, 993 trace_block_bio_remap(bdev_get_queue(clone->bi_bdev), clone,
994 tio->io->bio->bi_bdev->bd_dev, sector); 994 tio->io->bio->bi_bdev->bd_dev, sector);
995 995
996 generic_make_request(clone); 996 generic_make_request(clone);
997 } else if (r < 0 || r == DM_MAPIO_REQUEUE) { 997 } else if (r < 0 || r == DM_MAPIO_REQUEUE) {
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 324a3663fcda..3bacccab1b8c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1880,7 +1880,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1880 rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); 1880 rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
1881 1881
1882 list_add_rcu(&rdev->same_set, &mddev->disks); 1882 list_add_rcu(&rdev->same_set, &mddev->disks);
1883 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); 1883 bd_link_disk_holder(rdev->bdev, mddev->gendisk);
1884 1884
1885 /* May as well allow recovery to be retried once */ 1885 /* May as well allow recovery to be retried once */
1886 mddev->recovery_disabled = 0; 1886 mddev->recovery_disabled = 0;
@@ -1907,7 +1907,6 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
1907 MD_BUG(); 1907 MD_BUG();
1908 return; 1908 return;
1909 } 1909 }
1910 bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk);
1911 list_del_rcu(&rdev->same_set); 1910 list_del_rcu(&rdev->same_set);
1912 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); 1911 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
1913 rdev->mddev = NULL; 1912 rdev->mddev = NULL;
@@ -1935,19 +1934,13 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared)
1935 struct block_device *bdev; 1934 struct block_device *bdev;
1936 char b[BDEVNAME_SIZE]; 1935 char b[BDEVNAME_SIZE];
1937 1936
1938 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 1937 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
1938 shared ? (mdk_rdev_t *)lock_rdev : rdev);
1939 if (IS_ERR(bdev)) { 1939 if (IS_ERR(bdev)) {
1940 printk(KERN_ERR "md: could not open %s.\n", 1940 printk(KERN_ERR "md: could not open %s.\n",
1941 __bdevname(dev, b)); 1941 __bdevname(dev, b));
1942 return PTR_ERR(bdev); 1942 return PTR_ERR(bdev);
1943 } 1943 }
1944 err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev);
1945 if (err) {
1946 printk(KERN_ERR "md: could not bd_claim %s.\n",
1947 bdevname(bdev, b));
1948 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1949 return err;
1950 }
1951 if (!shared) 1944 if (!shared)
1952 set_bit(AllReserved, &rdev->flags); 1945 set_bit(AllReserved, &rdev->flags);
1953 rdev->bdev = bdev; 1946 rdev->bdev = bdev;
@@ -1960,8 +1953,7 @@ static void unlock_rdev(mdk_rdev_t *rdev)
1960 rdev->bdev = NULL; 1953 rdev->bdev = NULL;
1961 if (!bdev) 1954 if (!bdev)
1962 MD_BUG(); 1955 MD_BUG();
1963 bd_release(bdev); 1956 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1964 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1965} 1957}
1966 1958
1967void md_autodetect_dev(dev_t dev); 1959void md_autodetect_dev(dev_t dev);
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 3d88542612ea..74ee172b5bc9 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -391,7 +391,6 @@ static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, in
391 391
392/*****************************************************************************/ 392/*****************************************************************************/
393/* i2c-adapter helper functions */ 393/* i2c-adapter helper functions */
394#include <linux/i2c-id.h>
395 394
396/* exported algorithm data */ 395/* exported algorithm data */
397static struct i2c_algorithm saa7146_algo = { 396static struct i2c_algorithm saa7146_algo = {
diff --git a/drivers/media/video/imx074.c b/drivers/media/video/imx074.c
index 380e459f899d..27b5dfdfbb93 100644
--- a/drivers/media/video/imx074.c
+++ b/drivers/media/video/imx074.c
@@ -451,7 +451,6 @@ static int imx074_probe(struct i2c_client *client,
451 ret = imx074_video_probe(icd, client); 451 ret = imx074_video_probe(icd, client);
452 if (ret < 0) { 452 if (ret < 0) {
453 icd->ops = NULL; 453 icd->ops = NULL;
454 i2c_set_clientdata(client, NULL);
455 kfree(priv); 454 kfree(priv);
456 return ret; 455 return ret;
457 } 456 }
@@ -468,7 +467,6 @@ static int imx074_remove(struct i2c_client *client)
468 icd->ops = NULL; 467 icd->ops = NULL;
469 if (icl->free_bus) 468 if (icl->free_bus)
470 icl->free_bus(icl); 469 icl->free_bus(icl);
471 i2c_set_clientdata(client, NULL);
472 client->driver = NULL; 470 client->driver = NULL;
473 kfree(priv); 471 kfree(priv);
474 472
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 5a000c65ae98..ce4a75375909 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -44,7 +44,6 @@
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/i2c-id.h>
48#include <linux/workqueue.h> 47#include <linux/workqueue.h>
49 48
50#include <media/ir-core.h> 49#include <media/ir-core.h>
diff --git a/drivers/media/video/ov6650.c b/drivers/media/video/ov6650.c
index 31f19373bbae..cf93de988068 100644
--- a/drivers/media/video/ov6650.c
+++ b/drivers/media/video/ov6650.c
@@ -1174,7 +1174,6 @@ static int ov6650_probe(struct i2c_client *client,
1174 1174
1175 if (ret) { 1175 if (ret) {
1176 icd->ops = NULL; 1176 icd->ops = NULL;
1177 i2c_set_clientdata(client, NULL);
1178 kfree(priv); 1177 kfree(priv);
1179 } 1178 }
1180 1179
@@ -1185,7 +1184,6 @@ static int ov6650_remove(struct i2c_client *client)
1185{ 1184{
1186 struct ov6650 *priv = to_ov6650(client); 1185 struct ov6650 *priv = to_ov6650(client);
1187 1186
1188 i2c_set_clientdata(client, NULL);
1189 kfree(priv); 1187 kfree(priv);
1190 return 0; 1188 return 0;
1191} 1189}
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c
index 0ed09358027e..644d4cd071cc 100644
--- a/drivers/misc/apds9802als.c
+++ b/drivers/misc/apds9802als.c
@@ -251,7 +251,6 @@ static int apds9802als_probe(struct i2c_client *client,
251 251
252 return res; 252 return res;
253als_error1: 253als_error1:
254 i2c_set_clientdata(client, NULL);
255 kfree(data); 254 kfree(data);
256 return res; 255 return res;
257} 256}
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 2cf0cc6a4189..f29a6f9df6e7 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
224 if (dev->blkdev) { 224 if (dev->blkdev) {
225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
226 0, -1); 226 0, -1);
227 close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE); 227 blkdev_put(dev->blkdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
228 } 228 }
229 229
230 kfree(dev); 230 kfree(dev);
@@ -234,6 +234,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
234/* FIXME: ensure that mtd->size % erase_size == 0 */ 234/* FIXME: ensure that mtd->size % erase_size == 0 */
235static struct block2mtd_dev *add_device(char *devname, int erase_size) 235static struct block2mtd_dev *add_device(char *devname, int erase_size)
236{ 236{
237 const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
237 struct block_device *bdev; 238 struct block_device *bdev;
238 struct block2mtd_dev *dev; 239 struct block2mtd_dev *dev;
239 char *name; 240 char *name;
@@ -246,7 +247,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
246 return NULL; 247 return NULL;
247 248
248 /* Get a handle on the device */ 249 /* Get a handle on the device */
249 bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL); 250 bdev = blkdev_get_by_path(devname, mode, dev);
250#ifndef MODULE 251#ifndef MODULE
251 if (IS_ERR(bdev)) { 252 if (IS_ERR(bdev)) {
252 253
@@ -254,9 +255,8 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
254 to resolve the device name by other means. */ 255 to resolve the device name by other means. */
255 256
256 dev_t devt = name_to_dev_t(devname); 257 dev_t devt = name_to_dev_t(devname);
257 if (devt) { 258 if (devt)
258 bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ); 259 bdev = blkdev_get_by_dev(devt, mode, dev);
259 }
260 } 260 }
261#endif 261#endif
262 262
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 5624db8c9ad0..003170ea2e39 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -64,17 +64,57 @@ void pci_bus_remove_resources(struct pci_bus *bus)
64 } 64 }
65} 65}
66 66
67static bool pci_bus_resource_better(struct resource *res1, bool pos1,
68 struct resource *res2, bool pos2)
69{
70 /* If exactly one is positive decode, always prefer that one */
71 if (pos1 != pos2)
72 return pos1 ? true : false;
73
74 /* Prefer the one that contains the highest address */
75 if (res1->end != res2->end)
76 return (res1->end > res2->end) ? true : false;
77
78 /* Otherwise, prefer the one with highest "center of gravity" */
79 if (res1->start != res2->start)
80 return (res1->start > res2->start) ? true : false;
81
82 /* Otherwise, choose one arbitrarily (but consistently) */
83 return (res1 > res2) ? true : false;
84}
85
86static bool pci_bus_resource_positive(struct pci_bus *bus, struct resource *res)
87{
88 struct pci_bus_resource *bus_res;
89
90 /*
91 * This relies on the fact that pci_bus.resource[] refers to P2P or
92 * CardBus bridge base/limit registers, which are always positively
93 * decoded. The pci_bus.resources list contains host bridge or
94 * subtractively decoded resources.
95 */
96 list_for_each_entry(bus_res, &bus->resources, list) {
97 if (bus_res->res == res)
98 return (bus_res->flags & PCI_SUBTRACTIVE_DECODE) ?
99 false : true;
100 }
101 return true;
102}
103
67/* 104/*
68 * Find the highest-address bus resource below the cursor "res". If the 105 * Find the next-best bus resource after the cursor "res". If the cursor is
69 * cursor is NULL, return the highest resource. 106 * NULL, return the best resource. "Best" means that we prefer positive
107 * decode regions over subtractive decode, then those at higher addresses.
70 */ 108 */
71static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus, 109static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus,
72 unsigned int type, 110 unsigned int type,
73 struct resource *res) 111 struct resource *res)
74{ 112{
113 bool res_pos, r_pos, prev_pos = false;
75 struct resource *r, *prev = NULL; 114 struct resource *r, *prev = NULL;
76 int i; 115 int i;
77 116
117 res_pos = pci_bus_resource_positive(bus, res);
78 pci_bus_for_each_resource(bus, r, i) { 118 pci_bus_for_each_resource(bus, r, i) {
79 if (!r) 119 if (!r)
80 continue; 120 continue;
@@ -82,26 +122,14 @@ static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus,
82 if ((r->flags & IORESOURCE_TYPE_BITS) != type) 122 if ((r->flags & IORESOURCE_TYPE_BITS) != type)
83 continue; 123 continue;
84 124
85 /* If this resource is at or past the cursor, skip it */ 125 r_pos = pci_bus_resource_positive(bus, r);
86 if (res) { 126 if (!res || pci_bus_resource_better(res, res_pos, r, r_pos)) {
87 if (r == res) 127 if (!prev || pci_bus_resource_better(r, r_pos,
88 continue; 128 prev, prev_pos)) {
89 if (r->end > res->end) 129 prev = r;
90 continue; 130 prev_pos = r_pos;
91 if (r->end == res->end && r->start > res->start) 131 }
92 continue;
93 } 132 }
94
95 if (!prev)
96 prev = r;
97
98 /*
99 * A small resource is higher than a large one that ends at
100 * the same address.
101 */
102 if (r->end > prev->end ||
103 (r->end == prev->end && r->start > prev->start))
104 prev = r;
105 } 133 }
106 134
107 return prev; 135 return prev;
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index 5becbdee4027..2850e64dedae 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -276,6 +276,12 @@ int __init ibmphp_access_ebda (void)
276 276
277 for (;;) { 277 for (;;) {
278 offset = next_offset; 278 offset = next_offset;
279
280 /* Make sure what we read is still in the mapped section */
281 if (WARN(offset > (ebda_sz * 1024 - 4),
282 "ibmphp_ebda: next read is beyond ebda_sz\n"))
283 break;
284
279 next_offset = readw (io_mem + offset); /* offset of next blk */ 285 next_offset = readw (io_mem + offset); /* offset of next blk */
280 286
281 offset += 2; 287 offset += 2;
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index b5a7d9bfcb24..95712a375cd5 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -705,17 +705,21 @@ void pci_remove_legacy_files(struct pci_bus *b)
705 705
706#ifdef HAVE_PCI_MMAP 706#ifdef HAVE_PCI_MMAP
707 707
708int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma) 708int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
709 enum pci_mmap_api mmap_api)
709{ 710{
710 unsigned long nr, start, size; 711 unsigned long nr, start, size, pci_start;
711 712
713 if (pci_resource_len(pdev, resno) == 0)
714 return 0;
712 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 715 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
713 start = vma->vm_pgoff; 716 start = vma->vm_pgoff;
714 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; 717 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
715 if (start < size && size - start >= nr) 718 pci_start = (mmap_api == PCI_MMAP_SYSFS) ?
719 pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0;
720 if (start >= pci_start && start < pci_start + size &&
721 start + nr <= pci_start + size)
716 return 1; 722 return 1;
717 WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",
718 current->comm, start, start+nr, pci_name(pdev), resno, size);
719 return 0; 723 return 0;
720} 724}
721 725
@@ -745,8 +749,15 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
745 if (i >= PCI_ROM_RESOURCE) 749 if (i >= PCI_ROM_RESOURCE)
746 return -ENODEV; 750 return -ENODEV;
747 751
748 if (!pci_mmap_fits(pdev, i, vma)) 752 if (!pci_mmap_fits(pdev, i, vma, PCI_MMAP_SYSFS)) {
753 WARN(1, "process \"%s\" tried to map 0x%08lx bytes "
754 "at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n",
755 current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff,
756 pci_name(pdev), i,
757 (u64)pci_resource_start(pdev, i),
758 (u64)pci_resource_len(pdev, i));
749 return -EINVAL; 759 return -EINVAL;
760 }
750 761
751 /* pci_mmap_page_range() expects the same kind of entry as coming 762 /* pci_mmap_page_range() expects the same kind of entry as coming
752 * from /proc/bus/pci/ which is a "user visible" value. If this is 763 * from /proc/bus/pci/ which is a "user visible" value. If this is
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e98c8104297b..710c8a29be0d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1007,6 +1007,18 @@ static int __pci_enable_device_flags(struct pci_dev *dev,
1007 int err; 1007 int err;
1008 int i, bars = 0; 1008 int i, bars = 0;
1009 1009
1010 /*
1011 * Power state could be unknown at this point, either due to a fresh
1012 * boot or a device removal call. So get the current power state
1013 * so that things like MSI message writing will behave as expected
1014 * (e.g. if the device really is in D0 at enable time).
1015 */
1016 if (dev->pm_cap) {
1017 u16 pmcsr;
1018 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1019 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
1020 }
1021
1010 if (atomic_add_return(1, &dev->enable_cnt) > 1) 1022 if (atomic_add_return(1, &dev->enable_cnt) > 1)
1011 return 0; /* already enabled */ 1023 return 0; /* already enabled */
1012 1024
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index f5c7c382765f..7d33f6673868 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -22,8 +22,13 @@ extern void pci_remove_firmware_label_files(struct pci_dev *pdev);
22#endif 22#endif
23extern void pci_cleanup_rom(struct pci_dev *dev); 23extern void pci_cleanup_rom(struct pci_dev *dev);
24#ifdef HAVE_PCI_MMAP 24#ifdef HAVE_PCI_MMAP
25enum pci_mmap_api {
26 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
27 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
28};
25extern int pci_mmap_fits(struct pci_dev *pdev, int resno, 29extern int pci_mmap_fits(struct pci_dev *pdev, int resno,
26 struct vm_area_struct *vma); 30 struct vm_area_struct *vmai,
31 enum pci_mmap_api mmap_api);
27#endif 32#endif
28int pci_probe_reset_function(struct pci_dev *dev); 33int pci_probe_reset_function(struct pci_dev *dev);
29 34
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 297b72c880a1..ea00647f4732 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -257,7 +257,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
257 257
258 /* Make sure the caller is mapping a real resource for this device */ 258 /* Make sure the caller is mapping a real resource for this device */
259 for (i = 0; i < PCI_ROM_RESOURCE; i++) { 259 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
260 if (pci_mmap_fits(dev, i, vma)) 260 if (pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS))
261 break; 261 break;
262 } 262 }
263 263
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 5efbd5990ff8..06e41ed93230 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -761,7 +761,7 @@ err_unmap:
761 clk_put(rtc->clk); 761 clk_put(rtc->clk);
762 iounmap(rtc->regbase); 762 iounmap(rtc->regbase);
763err_badmap: 763err_badmap:
764 release_resource(rtc->res); 764 release_mem_region(rtc->res->start, rtc->regsize);
765err_badres: 765err_badres:
766 kfree(rtc); 766 kfree(rtc);
767 767
@@ -786,7 +786,7 @@ static int __exit sh_rtc_remove(struct platform_device *pdev)
786 } 786 }
787 787
788 iounmap(rtc->regbase); 788 iounmap(rtc->regbase);
789 release_resource(rtc->res); 789 release_mem_region(rtc->res->start, rtc->regsize);
790 790
791 clk_disable(rtc->clk); 791 clk_disable(rtc->clk);
792 clk_put(rtc->clk); 792 clk_put(rtc->clk);
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index 30a1ca3d08b7..5505bc07e1e7 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -103,7 +103,7 @@ int dasd_scan_partitions(struct dasd_block *block)
103 struct block_device *bdev; 103 struct block_device *bdev;
104 104
105 bdev = bdget_disk(block->gdp, 0); 105 bdev = bdget_disk(block->gdp, 0);
106 if (!bdev || blkdev_get(bdev, FMODE_READ) < 0) 106 if (!bdev || blkdev_get(bdev, FMODE_READ, NULL) < 0)
107 return -ENODEV; 107 return -ENODEV;
108 /* 108 /*
109 * See fs/partition/check.c:register_disk,rescan_partitions 109 * See fs/partition/check.c:register_disk,rescan_partitions
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index 09615b51d591..cb12a8e1466b 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -571,7 +571,7 @@ long clk_round_parent(struct clk *clk, unsigned long target,
571 *best_freq = freq_max; 571 *best_freq = freq_max;
572 } 572 }
573 573
574 pr_debug("too low freq %lu, error %lu\n", freq->frequency, 574 pr_debug("too low freq %u, error %lu\n", freq->frequency,
575 target - freq_max); 575 target - freq_max);
576 576
577 if (!error) 577 if (!error)
@@ -591,7 +591,7 @@ long clk_round_parent(struct clk *clk, unsigned long target,
591 *best_freq = freq_min; 591 *best_freq = freq_min;
592 } 592 }
593 593
594 pr_debug("too high freq %lu, error %lu\n", freq->frequency, 594 pr_debug("too high freq %u, error %lu\n", freq->frequency,
595 freq_min - target); 595 freq_min - target);
596 596
597 if (!error) 597 if (!error)
diff --git a/drivers/sh/intc/virq.c b/drivers/sh/intc/virq.c
index e5bf5d3c698e..4e0ff7181164 100644
--- a/drivers/sh/intc/virq.c
+++ b/drivers/sh/intc/virq.c
@@ -215,7 +215,7 @@ restart:
215 entry = radix_tree_deref_slot((void **)entries[i]); 215 entry = radix_tree_deref_slot((void **)entries[i]);
216 if (unlikely(!entry)) 216 if (unlikely(!entry))
217 continue; 217 continue;
218 if (unlikely(entry == RADIX_TREE_RETRY)) 218 if (radix_tree_deref_retry(entry))
219 goto restart; 219 goto restart;
220 220
221 irq = create_irq(); 221 irq = create_irq();
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index 75aa7a36307d..4ca45ec7fd84 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -17,7 +17,6 @@
17#include <linux/console.h> 17#include <linux/console.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/i2c-id.h>
21#include <linux/pci.h> 20#include <linux/pci.h>
22#include <linux/pci_ids.h> 21#include <linux/pci_ids.h>
23#include <linux/interrupt.h> 22#include <linux/interrupt.h>
@@ -733,7 +732,6 @@ static int dcon_probe(struct i2c_client *client, const struct i2c_device_id *id)
733 edev: 732 edev:
734 platform_device_unregister(dcon_device); 733 platform_device_unregister(dcon_device);
735 dcon_device = NULL; 734 dcon_device = NULL;
736 i2c_set_clientdata(client, NULL);
737 eirq: 735 eirq:
738 free_irq(DCON_IRQ, &dcon_driver); 736 free_irq(DCON_IRQ, &dcon_driver);
739 einit: 737 einit:
@@ -757,8 +755,6 @@ static int dcon_remove(struct i2c_client *client)
757 platform_device_unregister(dcon_device); 755 platform_device_unregister(dcon_device);
758 cancel_work_sync(&dcon_work); 756 cancel_work_sync(&dcon_work);
759 757
760 i2c_set_clientdata(client, NULL);
761
762 return 0; 758 return 0;
763} 759}
764 760
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 3b513bafaf2a..b015561fd602 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -543,7 +543,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
543 ro = curlun->initially_ro; 543 ro = curlun->initially_ro;
544 if (!ro) { 544 if (!ro) {
545 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); 545 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
546 if (-EROFS == PTR_ERR(filp)) 546 if (PTR_ERR(filp) == -EROFS || PTR_ERR(filp) == -EACCES)
547 ro = 1; 547 ro = 1;
548 } 548 }
549 if (ro) 549 if (ro)
@@ -558,10 +558,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
558 558
559 if (filp->f_path.dentry) 559 if (filp->f_path.dentry)
560 inode = filp->f_path.dentry->d_inode; 560 inode = filp->f_path.dentry->d_inode;
561 if (inode && S_ISBLK(inode->i_mode)) { 561 if (!inode || (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
562 if (bdev_read_only(inode->i_bdev))
563 ro = 1;
564 } else if (!inode || !S_ISREG(inode->i_mode)) {
565 LINFO(curlun, "invalid file type: %s\n", filename); 562 LINFO(curlun, "invalid file type: %s\n", filename);
566 goto out; 563 goto out;
567 } 564 }
diff --git a/drivers/video/omap2/vram.c b/drivers/video/omap2/vram.c
index fed2a72bc6b6..2fd7e5271be9 100644
--- a/drivers/video/omap2/vram.c
+++ b/drivers/video/omap2/vram.c
@@ -554,9 +554,15 @@ void __init omap_vram_reserve_sdram_memblock(void)
554 size = PAGE_ALIGN(size); 554 size = PAGE_ALIGN(size);
555 555
556 if (paddr) { 556 if (paddr) {
557 if ((paddr & ~PAGE_MASK) || 557 if (paddr & ~PAGE_MASK) {
558 !memblock_is_region_memory(paddr, size)) { 558 pr_err("VRAM start address 0x%08x not page aligned\n",
559 pr_err("Illegal SDRAM region for VRAM\n"); 559 paddr);
560 return;
561 }
562
563 if (!memblock_is_region_memory(paddr, size)) {
564 pr_err("Illegal SDRAM region 0x%08x..0x%08x for VRAM\n",
565 paddr, paddr + size - 1);
560 return; 566 return;
561 } 567 }
562 568
@@ -570,9 +576,12 @@ void __init omap_vram_reserve_sdram_memblock(void)
570 return; 576 return;
571 } 577 }
572 } else { 578 } else {
573 paddr = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_REAL_LIMIT); 579 paddr = memblock_alloc(size, PAGE_SIZE);
574 } 580 }
575 581
582 memblock_free(paddr, size);
583 memblock_remove(paddr, size);
584
576 omap_vram_add_region(paddr, size); 585 omap_vram_add_region(paddr, size);
577 586
578 pr_info("Reserving %u bytes SDRAM for VRAM\n", size); 587 pr_info("Reserving %u bytes SDRAM for VRAM\n", size);
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index a0e22ac483a3..167400e2a182 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -94,7 +94,6 @@ static int __devinit riva_setup_i2c_bus(struct riva_i2c_chan *chan,
94 94
95 strcpy(chan->adapter.name, name); 95 strcpy(chan->adapter.name, name);
96 chan->adapter.owner = THIS_MODULE; 96 chan->adapter.owner = THIS_MODULE;
97 chan->adapter.id = I2C_HW_B_RIVA;
98 chan->adapter.class = i2c_class; 97 chan->adapter.class = i2c_class;
99 chan->adapter.algo_data = &chan->algo; 98 chan->adapter.algo_data = &chan->algo;
100 chan->adapter.dev.parent = &chan->par->pdev->dev; 99 chan->adapter.dev.parent = &chan->par->pdev->dev;
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
index 55b3077ff6ff..d7df10315d8d 100644
--- a/drivers/video/sh_mobile_hdmi.c
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -1071,6 +1071,10 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1071 if (!hdmi->info) 1071 if (!hdmi->info)
1072 goto out; 1072 goto out;
1073 1073
1074 hdmi->monspec.modedb_len = 0;
1075 fb_destroy_modedb(hdmi->monspec.modedb);
1076 hdmi->monspec.modedb = NULL;
1077
1074 acquire_console_sem(); 1078 acquire_console_sem();
1075 1079
1076 /* HDMI disconnect */ 1080 /* HDMI disconnect */
@@ -1078,7 +1082,6 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1078 1082
1079 release_console_sem(); 1083 release_console_sem();
1080 pm_runtime_put(hdmi->dev); 1084 pm_runtime_put(hdmi->dev);
1081 fb_destroy_modedb(hdmi->monspec.modedb);
1082 } 1085 }
1083 1086
1084out: 1087out:
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 50963739a409..9b1364723c65 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -115,15 +115,16 @@ static const struct fb_videomode default_720p = {
115 .xres = 1280, 115 .xres = 1280,
116 .yres = 720, 116 .yres = 720,
117 117
118 .left_margin = 200, 118 .left_margin = 220,
119 .right_margin = 88, 119 .right_margin = 110,
120 .hsync_len = 48, 120 .hsync_len = 40,
121 121
122 .upper_margin = 20, 122 .upper_margin = 20,
123 .lower_margin = 5, 123 .lower_margin = 5,
124 .vsync_len = 5, 124 .vsync_len = 5,
125 125
126 .pixclock = 13468, 126 .pixclock = 13468,
127 .refresh = 60,
127 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT, 128 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
128}; 129};
129 130
@@ -1197,6 +1198,7 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1197 const struct fb_videomode *mode = cfg->lcd_cfg; 1198 const struct fb_videomode *mode = cfg->lcd_cfg;
1198 unsigned long max_size = 0; 1199 unsigned long max_size = 0;
1199 int k; 1200 int k;
1201 int num_cfg;
1200 1202
1201 ch->info = framebuffer_alloc(0, &pdev->dev); 1203 ch->info = framebuffer_alloc(0, &pdev->dev);
1202 if (!ch->info) { 1204 if (!ch->info) {
@@ -1232,8 +1234,14 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1232 info->fix = sh_mobile_lcdc_fix; 1234 info->fix = sh_mobile_lcdc_fix;
1233 info->fix.smem_len = max_size * (cfg->bpp / 8) * 2; 1235 info->fix.smem_len = max_size * (cfg->bpp / 8) * 2;
1234 1236
1235 if (!mode) 1237 if (!mode) {
1236 mode = &default_720p; 1238 mode = &default_720p;
1239 num_cfg = 1;
1240 } else {
1241 num_cfg = ch->cfg.num_cfg;
1242 }
1243
1244 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
1237 1245
1238 fb_videomode_to_var(var, mode); 1246 fb_videomode_to_var(var, mode);
1239 /* Default Y virtual resolution is 2x panel size */ 1247 /* Default Y virtual resolution is 2x panel size */
@@ -1281,10 +1289,6 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1281 1289
1282 for (i = 0; i < j; i++) { 1290 for (i = 0; i < j; i++) {
1283 struct sh_mobile_lcdc_chan *ch = priv->ch + i; 1291 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1284 const struct fb_videomode *mode = ch->cfg.lcd_cfg;
1285
1286 if (!mode)
1287 mode = &default_720p;
1288 1292
1289 info = ch->info; 1293 info = ch->info;
1290 1294
@@ -1297,7 +1301,6 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1297 } 1301 }
1298 } 1302 }
1299 1303
1300 fb_videomode_to_modelist(mode, ch->cfg.num_cfg, &info->modelist);
1301 error = register_framebuffer(info); 1304 error = register_framebuffer(info);
1302 if (error < 0) 1305 if (error < 0)
1303 goto err1; 1306 goto err1;
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index b52f8e4ef1fd..3dde12b0ab06 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -4181,6 +4181,9 @@ static void __devinit
4181sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize, 4181sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
4182 unsigned int min) 4182 unsigned int min)
4183{ 4183{
4184 if (*mapsize < (min << 20))
4185 return;
4186
4184 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize)); 4187 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize));
4185 4188
4186 if(!ivideo->video_vbase) { 4189 if(!ivideo->video_vbase) {
@@ -4514,7 +4517,7 @@ sisfb_post_sis300(struct pci_dev *pdev)
4514 } else { 4517 } else {
4515#endif 4518#endif
4516 /* Need to map max FB size for finding out about RAM size */ 4519 /* Need to map max FB size for finding out about RAM size */
4517 mapsize = 64 << 20; 4520 mapsize = ivideo->video_size;
4518 sisfb_post_map_vram(ivideo, &mapsize, 4); 4521 sisfb_post_map_vram(ivideo, &mapsize, 4);
4519 4522
4520 if(ivideo->video_vbase) { 4523 if(ivideo->video_vbase) {
@@ -4680,7 +4683,7 @@ sisfb_post_xgi_ramsize(struct sis_video_info *ivideo)
4680 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04)); 4683 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04));
4681 4684
4682 /* Need to map max FB size for finding out about RAM size */ 4685 /* Need to map max FB size for finding out about RAM size */
4683 mapsize = 256 << 20; 4686 mapsize = ivideo->video_size;
4684 sisfb_post_map_vram(ivideo, &mapsize, 32); 4687 sisfb_post_map_vram(ivideo, &mapsize, 32);
4685 4688
4686 if(!ivideo->video_vbase) { 4689 if(!ivideo->video_vbase) {
@@ -5936,6 +5939,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5936 } 5939 }
5937 5940
5938 ivideo->video_base = pci_resource_start(pdev, 0); 5941 ivideo->video_base = pci_resource_start(pdev, 0);
5942 ivideo->video_size = pci_resource_len(pdev, 0);
5939 ivideo->mmio_base = pci_resource_start(pdev, 1); 5943 ivideo->mmio_base = pci_resource_start(pdev, 1);
5940 ivideo->mmio_size = pci_resource_len(pdev, 1); 5944 ivideo->mmio_size = pci_resource_len(pdev, 1);
5941 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30; 5945 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 06e8ff12b97c..c1c1b8c3fb99 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -426,9 +426,6 @@ static void init_once(void *foo)
426 mutex_init(&bdev->bd_mutex); 426 mutex_init(&bdev->bd_mutex);
427 INIT_LIST_HEAD(&bdev->bd_inodes); 427 INIT_LIST_HEAD(&bdev->bd_inodes);
428 INIT_LIST_HEAD(&bdev->bd_list); 428 INIT_LIST_HEAD(&bdev->bd_list);
429#ifdef CONFIG_SYSFS
430 INIT_LIST_HEAD(&bdev->bd_holder_list);
431#endif
432 inode_init_once(&ei->vfs_inode); 429 inode_init_once(&ei->vfs_inode);
433 /* Initialize mutex for freeze. */ 430 /* Initialize mutex for freeze. */
434 mutex_init(&bdev->bd_fsfreeze_mutex); 431 mutex_init(&bdev->bd_fsfreeze_mutex);
@@ -663,7 +660,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
663 else if (bdev->bd_contains == bdev) 660 else if (bdev->bd_contains == bdev)
664 return true; /* is a whole device which isn't held */ 661 return true; /* is a whole device which isn't held */
665 662
666 else if (whole->bd_holder == bd_claim) 663 else if (whole->bd_holder == bd_may_claim)
667 return true; /* is a partition of a device that is being partitioned */ 664 return true; /* is a partition of a device that is being partitioned */
668 else if (whole->bd_holder != NULL) 665 else if (whole->bd_holder != NULL)
669 return false; /* is a partition of a held device */ 666 return false; /* is a partition of a held device */
@@ -775,439 +772,87 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
775 } 772 }
776} 773}
777 774
778/* releases bdev_lock */
779static void __bd_abort_claiming(struct block_device *whole, void *holder)
780{
781 BUG_ON(whole->bd_claiming != holder);
782 whole->bd_claiming = NULL;
783 wake_up_bit(&whole->bd_claiming, 0);
784
785 spin_unlock(&bdev_lock);
786 bdput(whole);
787}
788
789/**
790 * bd_abort_claiming - abort claiming a block device
791 * @whole: whole block device returned by bd_start_claiming()
792 * @holder: holder trying to claim @bdev
793 *
794 * Abort a claiming block started by bd_start_claiming(). Note that
795 * @whole is not the block device to be claimed but the whole device
796 * returned by bd_start_claiming().
797 *
798 * CONTEXT:
799 * Grabs and releases bdev_lock.
800 */
801static void bd_abort_claiming(struct block_device *whole, void *holder)
802{
803 spin_lock(&bdev_lock);
804 __bd_abort_claiming(whole, holder); /* releases bdev_lock */
805}
806
807/* increment holders when we have a legitimate claim. requires bdev_lock */
808static void __bd_claim(struct block_device *bdev, struct block_device *whole,
809 void *holder)
810{
811 /* note that for a whole device bd_holders
812 * will be incremented twice, and bd_holder will
813 * be set to bd_claim before being set to holder
814 */
815 whole->bd_holders++;
816 whole->bd_holder = bd_claim;
817 bdev->bd_holders++;
818 bdev->bd_holder = holder;
819}
820
821/**
822 * bd_finish_claiming - finish claiming a block device
823 * @bdev: block device of interest (passed to bd_start_claiming())
824 * @whole: whole block device returned by bd_start_claiming()
825 * @holder: holder trying to claim @bdev
826 *
827 * Finish a claiming block started by bd_start_claiming().
828 *
829 * CONTEXT:
830 * Grabs and releases bdev_lock.
831 */
832static void bd_finish_claiming(struct block_device *bdev,
833 struct block_device *whole, void *holder)
834{
835 spin_lock(&bdev_lock);
836 BUG_ON(!bd_may_claim(bdev, whole, holder));
837 __bd_claim(bdev, whole, holder);
838 __bd_abort_claiming(whole, holder); /* not actually an abort */
839}
840
841/**
842 * bd_claim - claim a block device
843 * @bdev: block device to claim
844 * @holder: holder trying to claim @bdev
845 *
846 * Try to claim @bdev which must have been opened successfully.
847 *
848 * CONTEXT:
849 * Might sleep.
850 *
851 * RETURNS:
852 * 0 if successful, -EBUSY if @bdev is already claimed.
853 */
854int bd_claim(struct block_device *bdev, void *holder)
855{
856 struct block_device *whole = bdev->bd_contains;
857 int res;
858
859 might_sleep();
860
861 spin_lock(&bdev_lock);
862 res = bd_prepare_to_claim(bdev, whole, holder);
863 if (res == 0)
864 __bd_claim(bdev, whole, holder);
865 spin_unlock(&bdev_lock);
866
867 return res;
868}
869EXPORT_SYMBOL(bd_claim);
870
871void bd_release(struct block_device *bdev)
872{
873 spin_lock(&bdev_lock);
874 if (!--bdev->bd_contains->bd_holders)
875 bdev->bd_contains->bd_holder = NULL;
876 if (!--bdev->bd_holders)
877 bdev->bd_holder = NULL;
878 spin_unlock(&bdev_lock);
879}
880
881EXPORT_SYMBOL(bd_release);
882
883#ifdef CONFIG_SYSFS 775#ifdef CONFIG_SYSFS
884/*
885 * Functions for bd_claim_by_kobject / bd_release_from_kobject
886 *
887 * If a kobject is passed to bd_claim_by_kobject()
888 * and the kobject has a parent directory,
889 * following symlinks are created:
890 * o from the kobject to the claimed bdev
891 * o from "holders" directory of the bdev to the parent of the kobject
892 * bd_release_from_kobject() removes these symlinks.
893 *
894 * Example:
895 * If /dev/dm-0 maps to /dev/sda, kobject corresponding to
896 * /sys/block/dm-0/slaves is passed to bd_claim_by_kobject(), then:
897 * /sys/block/dm-0/slaves/sda --> /sys/block/sda
898 * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
899 */
900
901static int add_symlink(struct kobject *from, struct kobject *to) 776static int add_symlink(struct kobject *from, struct kobject *to)
902{ 777{
903 if (!from || !to)
904 return 0;
905 return sysfs_create_link(from, to, kobject_name(to)); 778 return sysfs_create_link(from, to, kobject_name(to));
906} 779}
907 780
908static void del_symlink(struct kobject *from, struct kobject *to) 781static void del_symlink(struct kobject *from, struct kobject *to)
909{ 782{
910 if (!from || !to)
911 return;
912 sysfs_remove_link(from, kobject_name(to)); 783 sysfs_remove_link(from, kobject_name(to));
913} 784}
914 785
915/*
916 * 'struct bd_holder' contains pointers to kobjects symlinked by
917 * bd_claim_by_kobject.
918 * It's connected to bd_holder_list which is protected by bdev->bd_sem.
919 */
920struct bd_holder {
921 struct list_head list; /* chain of holders of the bdev */
922 int count; /* references from the holder */
923 struct kobject *sdir; /* holder object, e.g. "/block/dm-0/slaves" */
924 struct kobject *hdev; /* e.g. "/block/dm-0" */
925 struct kobject *hdir; /* e.g. "/block/sda/holders" */
926 struct kobject *sdev; /* e.g. "/block/sda" */
927};
928
929/*
930 * Get references of related kobjects at once.
931 * Returns 1 on success. 0 on failure.
932 *
933 * Should call bd_holder_release_dirs() after successful use.
934 */
935static int bd_holder_grab_dirs(struct block_device *bdev,
936 struct bd_holder *bo)
937{
938 if (!bdev || !bo)
939 return 0;
940
941 bo->sdir = kobject_get(bo->sdir);
942 if (!bo->sdir)
943 return 0;
944
945 bo->hdev = kobject_get(bo->sdir->parent);
946 if (!bo->hdev)
947 goto fail_put_sdir;
948
949 bo->sdev = kobject_get(&part_to_dev(bdev->bd_part)->kobj);
950 if (!bo->sdev)
951 goto fail_put_hdev;
952
953 bo->hdir = kobject_get(bdev->bd_part->holder_dir);
954 if (!bo->hdir)
955 goto fail_put_sdev;
956
957 return 1;
958
959fail_put_sdev:
960 kobject_put(bo->sdev);
961fail_put_hdev:
962 kobject_put(bo->hdev);
963fail_put_sdir:
964 kobject_put(bo->sdir);
965
966 return 0;
967}
968
969/* Put references of related kobjects at once. */
970static void bd_holder_release_dirs(struct bd_holder *bo)
971{
972 kobject_put(bo->hdir);
973 kobject_put(bo->sdev);
974 kobject_put(bo->hdev);
975 kobject_put(bo->sdir);
976}
977
978static struct bd_holder *alloc_bd_holder(struct kobject *kobj)
979{
980 struct bd_holder *bo;
981
982 bo = kzalloc(sizeof(*bo), GFP_KERNEL);
983 if (!bo)
984 return NULL;
985
986 bo->count = 1;
987 bo->sdir = kobj;
988
989 return bo;
990}
991
992static void free_bd_holder(struct bd_holder *bo)
993{
994 kfree(bo);
995}
996
997/**
998 * find_bd_holder - find matching struct bd_holder from the block device
999 *
1000 * @bdev: struct block device to be searched
1001 * @bo: target struct bd_holder
1002 *
1003 * Returns matching entry with @bo in @bdev->bd_holder_list.
1004 * If found, increment the reference count and return the pointer.
1005 * If not found, returns NULL.
1006 */
1007static struct bd_holder *find_bd_holder(struct block_device *bdev,
1008 struct bd_holder *bo)
1009{
1010 struct bd_holder *tmp;
1011
1012 list_for_each_entry(tmp, &bdev->bd_holder_list, list)
1013 if (tmp->sdir == bo->sdir) {
1014 tmp->count++;
1015 return tmp;
1016 }
1017
1018 return NULL;
1019}
1020
1021/** 786/**
1022 * add_bd_holder - create sysfs symlinks for bd_claim() relationship 787 * bd_link_disk_holder - create symlinks between holding disk and slave bdev
1023 * 788 * @bdev: the claimed slave bdev
1024 * @bdev: block device to be bd_claimed 789 * @disk: the holding disk
1025 * @bo: preallocated and initialized by alloc_bd_holder()
1026 * 790 *
1027 * Add @bo to @bdev->bd_holder_list, create symlinks. 791 * This functions creates the following sysfs symlinks.
1028 *
1029 * Returns 0 if symlinks are created.
1030 * Returns -ve if something fails.
1031 */
1032static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
1033{
1034 int err;
1035
1036 if (!bo)
1037 return -EINVAL;
1038
1039 if (!bd_holder_grab_dirs(bdev, bo))
1040 return -EBUSY;
1041
1042 err = add_symlink(bo->sdir, bo->sdev);
1043 if (err)
1044 return err;
1045
1046 err = add_symlink(bo->hdir, bo->hdev);
1047 if (err) {
1048 del_symlink(bo->sdir, bo->sdev);
1049 return err;
1050 }
1051
1052 list_add_tail(&bo->list, &bdev->bd_holder_list);
1053 return 0;
1054}
1055
1056/**
1057 * del_bd_holder - delete sysfs symlinks for bd_claim() relationship
1058 * 792 *
1059 * @bdev: block device to be bd_claimed 793 * - from "slaves" directory of the holder @disk to the claimed @bdev
1060 * @kobj: holder's kobject 794 * - from "holders" directory of the @bdev to the holder @disk
1061 * 795 *
1062 * If there is matching entry with @kobj in @bdev->bd_holder_list 796 * For example, if /dev/dm-0 maps to /dev/sda and disk for dm-0 is
1063 * and no other bd_claim() from the same kobject, 797 * passed to bd_link_disk_holder(), then:
1064 * remove the struct bd_holder from the list, delete symlinks for it.
1065 * 798 *
1066 * Returns a pointer to the struct bd_holder when it's removed from the list 799 * /sys/block/dm-0/slaves/sda --> /sys/block/sda
1067 * and ready to be freed. 800 * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
1068 * Returns NULL if matching claim isn't found or there is other bd_claim()
1069 * by the same kobject.
1070 */
1071static struct bd_holder *del_bd_holder(struct block_device *bdev,
1072 struct kobject *kobj)
1073{
1074 struct bd_holder *bo;
1075
1076 list_for_each_entry(bo, &bdev->bd_holder_list, list) {
1077 if (bo->sdir == kobj) {
1078 bo->count--;
1079 BUG_ON(bo->count < 0);
1080 if (!bo->count) {
1081 list_del(&bo->list);
1082 del_symlink(bo->sdir, bo->sdev);
1083 del_symlink(bo->hdir, bo->hdev);
1084 bd_holder_release_dirs(bo);
1085 return bo;
1086 }
1087 break;
1088 }
1089 }
1090
1091 return NULL;
1092}
1093
1094/**
1095 * bd_claim_by_kobject - bd_claim() with additional kobject signature
1096 * 801 *
1097 * @bdev: block device to be claimed 802 * The caller must have claimed @bdev before calling this function and
1098 * @holder: holder's signature 803 * ensure that both @bdev and @disk are valid during the creation and
1099 * @kobj: holder's kobject 804 * lifetime of these symlinks.
1100 * 805 *
1101 * Do bd_claim() and if it succeeds, create sysfs symlinks between 806 * CONTEXT:
1102 * the bdev and the holder's kobject. 807 * Might sleep.
1103 * Use bd_release_from_kobject() when relesing the claimed bdev.
1104 * 808 *
1105 * Returns 0 on success. (same as bd_claim()) 809 * RETURNS:
1106 * Returns errno on failure. 810 * 0 on success, -errno on failure.
1107 */ 811 */
1108static int bd_claim_by_kobject(struct block_device *bdev, void *holder, 812int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
1109 struct kobject *kobj)
1110{ 813{
1111 int err; 814 int ret = 0;
1112 struct bd_holder *bo, *found;
1113
1114 if (!kobj)
1115 return -EINVAL;
1116
1117 bo = alloc_bd_holder(kobj);
1118 if (!bo)
1119 return -ENOMEM;
1120 815
1121 mutex_lock(&bdev->bd_mutex); 816 mutex_lock(&bdev->bd_mutex);
1122 817
1123 err = bd_claim(bdev, holder); 818 WARN_ON_ONCE(!bdev->bd_holder || bdev->bd_holder_disk);
1124 if (err)
1125 goto fail;
1126 819
1127 found = find_bd_holder(bdev, bo); 820 /* FIXME: remove the following once add_disk() handles errors */
1128 if (found) 821 if (WARN_ON(!disk->slave_dir || !bdev->bd_part->holder_dir))
1129 goto fail; 822 goto out_unlock;
1130 823
1131 err = add_bd_holder(bdev, bo); 824 ret = add_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
1132 if (err) 825 if (ret)
1133 bd_release(bdev); 826 goto out_unlock;
1134 else
1135 bo = NULL;
1136fail:
1137 mutex_unlock(&bdev->bd_mutex);
1138 free_bd_holder(bo);
1139 return err;
1140}
1141 827
1142/** 828 ret = add_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj);
1143 * bd_release_from_kobject - bd_release() with additional kobject signature 829 if (ret) {
1144 * 830 del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
1145 * @bdev: block device to be released 831 goto out_unlock;
1146 * @kobj: holder's kobject 832 }
1147 *
1148 * Do bd_release() and remove sysfs symlinks created by bd_claim_by_kobject().
1149 */
1150static void bd_release_from_kobject(struct block_device *bdev,
1151 struct kobject *kobj)
1152{
1153 if (!kobj)
1154 return;
1155 833
1156 mutex_lock(&bdev->bd_mutex); 834 bdev->bd_holder_disk = disk;
1157 bd_release(bdev); 835out_unlock:
1158 free_bd_holder(del_bd_holder(bdev, kobj));
1159 mutex_unlock(&bdev->bd_mutex); 836 mutex_unlock(&bdev->bd_mutex);
837 return ret;
1160} 838}
839EXPORT_SYMBOL_GPL(bd_link_disk_holder);
1161 840
1162/** 841static void bd_unlink_disk_holder(struct block_device *bdev)
1163 * bd_claim_by_disk - wrapper function for bd_claim_by_kobject()
1164 *
1165 * @bdev: block device to be claimed
1166 * @holder: holder's signature
1167 * @disk: holder's gendisk
1168 *
1169 * Call bd_claim_by_kobject() with getting @disk->slave_dir.
1170 */
1171int bd_claim_by_disk(struct block_device *bdev, void *holder,
1172 struct gendisk *disk)
1173{ 842{
1174 return bd_claim_by_kobject(bdev, holder, kobject_get(disk->slave_dir)); 843 struct gendisk *disk = bdev->bd_holder_disk;
1175}
1176EXPORT_SYMBOL_GPL(bd_claim_by_disk);
1177 844
1178/** 845 bdev->bd_holder_disk = NULL;
1179 * bd_release_from_disk - wrapper function for bd_release_from_kobject() 846 if (!disk)
1180 * 847 return;
1181 * @bdev: block device to be claimed
1182 * @disk: holder's gendisk
1183 *
1184 * Call bd_release_from_kobject() and put @disk->slave_dir.
1185 */
1186void bd_release_from_disk(struct block_device *bdev, struct gendisk *disk)
1187{
1188 bd_release_from_kobject(bdev, disk->slave_dir);
1189 kobject_put(disk->slave_dir);
1190}
1191EXPORT_SYMBOL_GPL(bd_release_from_disk);
1192#endif
1193 848
1194/* 849 del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
1195 * Tries to open block device by device number. Use it ONLY if you 850 del_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj);
1196 * really do not have anything better - i.e. when you are behind a
1197 * truly sucky interface and all you are given is a device number. _Never_
1198 * to be used for internal purposes. If you ever need it - reconsider
1199 * your API.
1200 */
1201struct block_device *open_by_devnum(dev_t dev, fmode_t mode)
1202{
1203 struct block_device *bdev = bdget(dev);
1204 int err = -ENOMEM;
1205 if (bdev)
1206 err = blkdev_get(bdev, mode);
1207 return err ? ERR_PTR(err) : bdev;
1208} 851}
1209 852#else
1210EXPORT_SYMBOL(open_by_devnum); 853static inline void bd_unlink_disk_holder(struct block_device *bdev)
854{ }
855#endif
1211 856
1212/** 857/**
1213 * flush_disk - invalidates all buffer-cache entries on a disk 858 * flush_disk - invalidates all buffer-cache entries on a disk
@@ -1469,17 +1114,156 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1469 return ret; 1114 return ret;
1470} 1115}
1471 1116
1472int blkdev_get(struct block_device *bdev, fmode_t mode) 1117/**
1118 * blkdev_get - open a block device
1119 * @bdev: block_device to open
1120 * @mode: FMODE_* mask
1121 * @holder: exclusive holder identifier
1122 *
1123 * Open @bdev with @mode. If @mode includes %FMODE_EXCL, @bdev is
1124 * open with exclusive access. Specifying %FMODE_EXCL with %NULL
1125 * @holder is invalid. Exclusive opens may nest for the same @holder.
1126 *
1127 * On success, the reference count of @bdev is unchanged. On failure,
1128 * @bdev is put.
1129 *
1130 * CONTEXT:
1131 * Might sleep.
1132 *
1133 * RETURNS:
1134 * 0 on success, -errno on failure.
1135 */
1136int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
1473{ 1137{
1474 return __blkdev_get(bdev, mode, 0); 1138 struct block_device *whole = NULL;
1139 int res;
1140
1141 WARN_ON_ONCE((mode & FMODE_EXCL) && !holder);
1142
1143 if ((mode & FMODE_EXCL) && holder) {
1144 whole = bd_start_claiming(bdev, holder);
1145 if (IS_ERR(whole)) {
1146 bdput(bdev);
1147 return PTR_ERR(whole);
1148 }
1149 }
1150
1151 res = __blkdev_get(bdev, mode, 0);
1152
1153 /* __blkdev_get() may alter read only status, check it afterwards */
1154 if (!res && (mode & FMODE_WRITE) && bdev_read_only(bdev)) {
1155 __blkdev_put(bdev, mode, 0);
1156 res = -EACCES;
1157 }
1158
1159 if (whole) {
1160 /* finish claiming */
1161 spin_lock(&bdev_lock);
1162
1163 if (res == 0) {
1164 BUG_ON(!bd_may_claim(bdev, whole, holder));
1165 /*
1166 * Note that for a whole device bd_holders
1167 * will be incremented twice, and bd_holder
1168 * will be set to bd_may_claim before being
1169 * set to holder
1170 */
1171 whole->bd_holders++;
1172 whole->bd_holder = bd_may_claim;
1173 bdev->bd_holders++;
1174 bdev->bd_holder = holder;
1175 }
1176
1177 /* tell others that we're done */
1178 BUG_ON(whole->bd_claiming != holder);
1179 whole->bd_claiming = NULL;
1180 wake_up_bit(&whole->bd_claiming, 0);
1181
1182 spin_unlock(&bdev_lock);
1183 bdput(whole);
1184 }
1185
1186 return res;
1475} 1187}
1476EXPORT_SYMBOL(blkdev_get); 1188EXPORT_SYMBOL(blkdev_get);
1477 1189
1190/**
1191 * blkdev_get_by_path - open a block device by name
1192 * @path: path to the block device to open
1193 * @mode: FMODE_* mask
1194 * @holder: exclusive holder identifier
1195 *
1196 * Open the blockdevice described by the device file at @path. @mode
1197 * and @holder are identical to blkdev_get().
1198 *
1199 * On success, the returned block_device has reference count of one.
1200 *
1201 * CONTEXT:
1202 * Might sleep.
1203 *
1204 * RETURNS:
1205 * Pointer to block_device on success, ERR_PTR(-errno) on failure.
1206 */
1207struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
1208 void *holder)
1209{
1210 struct block_device *bdev;
1211 int err;
1212
1213 bdev = lookup_bdev(path);
1214 if (IS_ERR(bdev))
1215 return bdev;
1216
1217 err = blkdev_get(bdev, mode, holder);
1218 if (err)
1219 return ERR_PTR(err);
1220
1221 return bdev;
1222}
1223EXPORT_SYMBOL(blkdev_get_by_path);
1224
1225/**
1226 * blkdev_get_by_dev - open a block device by device number
1227 * @dev: device number of block device to open
1228 * @mode: FMODE_* mask
1229 * @holder: exclusive holder identifier
1230 *
1231 * Open the blockdevice described by device number @dev. @mode and
1232 * @holder are identical to blkdev_get().
1233 *
1234 * Use it ONLY if you really do not have anything better - i.e. when
1235 * you are behind a truly sucky interface and all you are given is a
1236 * device number. _Never_ to be used for internal purposes. If you
1237 * ever need it - reconsider your API.
1238 *
1239 * On success, the returned block_device has reference count of one.
1240 *
1241 * CONTEXT:
1242 * Might sleep.
1243 *
1244 * RETURNS:
1245 * Pointer to block_device on success, ERR_PTR(-errno) on failure.
1246 */
1247struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
1248{
1249 struct block_device *bdev;
1250 int err;
1251
1252 bdev = bdget(dev);
1253 if (!bdev)
1254 return ERR_PTR(-ENOMEM);
1255
1256 err = blkdev_get(bdev, mode, holder);
1257 if (err)
1258 return ERR_PTR(err);
1259
1260 return bdev;
1261}
1262EXPORT_SYMBOL(blkdev_get_by_dev);
1263
1478static int blkdev_open(struct inode * inode, struct file * filp) 1264static int blkdev_open(struct inode * inode, struct file * filp)
1479{ 1265{
1480 struct block_device *whole = NULL;
1481 struct block_device *bdev; 1266 struct block_device *bdev;
1482 int res;
1483 1267
1484 /* 1268 /*
1485 * Preserve backwards compatibility and allow large file access 1269 * Preserve backwards compatibility and allow large file access
@@ -1500,26 +1284,9 @@ static int blkdev_open(struct inode * inode, struct file * filp)
1500 if (bdev == NULL) 1284 if (bdev == NULL)
1501 return -ENOMEM; 1285 return -ENOMEM;
1502 1286
1503 if (filp->f_mode & FMODE_EXCL) {
1504 whole = bd_start_claiming(bdev, filp);
1505 if (IS_ERR(whole)) {
1506 bdput(bdev);
1507 return PTR_ERR(whole);
1508 }
1509 }
1510
1511 filp->f_mapping = bdev->bd_inode->i_mapping; 1287 filp->f_mapping = bdev->bd_inode->i_mapping;
1512 1288
1513 res = blkdev_get(bdev, filp->f_mode); 1289 return blkdev_get(bdev, filp->f_mode, filp);
1514
1515 if (whole) {
1516 if (res == 0)
1517 bd_finish_claiming(bdev, whole, filp);
1518 else
1519 bd_abort_claiming(whole, filp);
1520 }
1521
1522 return res;
1523} 1290}
1524 1291
1525static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) 1292static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
@@ -1533,6 +1300,7 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
1533 bdev->bd_part_count--; 1300 bdev->bd_part_count--;
1534 1301
1535 if (!--bdev->bd_openers) { 1302 if (!--bdev->bd_openers) {
1303 WARN_ON_ONCE(bdev->bd_holders);
1536 sync_blockdev(bdev); 1304 sync_blockdev(bdev);
1537 kill_bdev(bdev); 1305 kill_bdev(bdev);
1538 } 1306 }
@@ -1563,6 +1331,34 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
1563 1331
1564int blkdev_put(struct block_device *bdev, fmode_t mode) 1332int blkdev_put(struct block_device *bdev, fmode_t mode)
1565{ 1333{
1334 if (mode & FMODE_EXCL) {
1335 bool bdev_free;
1336
1337 /*
1338 * Release a claim on the device. The holder fields
1339 * are protected with bdev_lock. bd_mutex is to
1340 * synchronize disk_holder unlinking.
1341 */
1342 mutex_lock(&bdev->bd_mutex);
1343 spin_lock(&bdev_lock);
1344
1345 WARN_ON_ONCE(--bdev->bd_holders < 0);
1346 WARN_ON_ONCE(--bdev->bd_contains->bd_holders < 0);
1347
1348 /* bd_contains might point to self, check in a separate step */
1349 if ((bdev_free = !bdev->bd_holders))
1350 bdev->bd_holder = NULL;
1351 if (!bdev->bd_contains->bd_holders)
1352 bdev->bd_contains->bd_holder = NULL;
1353
1354 spin_unlock(&bdev_lock);
1355
1356 /* if this was the last claim, holder link should go too */
1357 if (bdev_free)
1358 bd_unlink_disk_holder(bdev);
1359
1360 mutex_unlock(&bdev->bd_mutex);
1361 }
1566 return __blkdev_put(bdev, mode, 0); 1362 return __blkdev_put(bdev, mode, 0);
1567} 1363}
1568EXPORT_SYMBOL(blkdev_put); 1364EXPORT_SYMBOL(blkdev_put);
@@ -1570,8 +1366,7 @@ EXPORT_SYMBOL(blkdev_put);
1570static int blkdev_close(struct inode * inode, struct file * filp) 1366static int blkdev_close(struct inode * inode, struct file * filp)
1571{ 1367{
1572 struct block_device *bdev = I_BDEV(filp->f_mapping->host); 1368 struct block_device *bdev = I_BDEV(filp->f_mapping->host);
1573 if (bdev->bd_holder == filp) 1369
1574 bd_release(bdev);
1575 return blkdev_put(bdev, filp->f_mode); 1370 return blkdev_put(bdev, filp->f_mode);
1576} 1371}
1577 1372
@@ -1716,67 +1511,6 @@ fail:
1716} 1511}
1717EXPORT_SYMBOL(lookup_bdev); 1512EXPORT_SYMBOL(lookup_bdev);
1718 1513
1719/**
1720 * open_bdev_exclusive - open a block device by name and set it up for use
1721 *
1722 * @path: special file representing the block device
1723 * @mode: FMODE_... combination to pass be used
1724 * @holder: owner for exclusion
1725 *
1726 * Open the blockdevice described by the special file at @path, claim it
1727 * for the @holder.
1728 */
1729struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder)
1730{
1731 struct block_device *bdev, *whole;
1732 int error;
1733
1734 bdev = lookup_bdev(path);
1735 if (IS_ERR(bdev))
1736 return bdev;
1737
1738 whole = bd_start_claiming(bdev, holder);
1739 if (IS_ERR(whole)) {
1740 bdput(bdev);
1741 return whole;
1742 }
1743
1744 error = blkdev_get(bdev, mode);
1745 if (error)
1746 goto out_abort_claiming;
1747
1748 error = -EACCES;
1749 if ((mode & FMODE_WRITE) && bdev_read_only(bdev))
1750 goto out_blkdev_put;
1751
1752 bd_finish_claiming(bdev, whole, holder);
1753 return bdev;
1754
1755out_blkdev_put:
1756 blkdev_put(bdev, mode);
1757out_abort_claiming:
1758 bd_abort_claiming(whole, holder);
1759 return ERR_PTR(error);
1760}
1761
1762EXPORT_SYMBOL(open_bdev_exclusive);
1763
1764/**
1765 * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive()
1766 *
1767 * @bdev: blockdevice to close
1768 * @mode: mode, must match that used to open.
1769 *
1770 * This is the counterpart to open_bdev_exclusive().
1771 */
1772void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
1773{
1774 bd_release(bdev);
1775 blkdev_put(bdev, mode);
1776}
1777
1778EXPORT_SYMBOL(close_bdev_exclusive);
1779
1780int __invalidate_device(struct block_device *bdev) 1514int __invalidate_device(struct block_device *bdev)
1781{ 1515{
1782 struct super_block *sb = get_super(bdev); 1516 struct super_block *sb = get_super(bdev);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cc04dc1445d6..95324e9f9280 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -489,7 +489,7 @@ again:
489 continue; 489 continue;
490 490
491 if (device->bdev) { 491 if (device->bdev) {
492 close_bdev_exclusive(device->bdev, device->mode); 492 blkdev_put(device->bdev, device->mode);
493 device->bdev = NULL; 493 device->bdev = NULL;
494 fs_devices->open_devices--; 494 fs_devices->open_devices--;
495 } 495 }
@@ -523,7 +523,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
523 523
524 list_for_each_entry(device, &fs_devices->devices, dev_list) { 524 list_for_each_entry(device, &fs_devices->devices, dev_list) {
525 if (device->bdev) { 525 if (device->bdev) {
526 close_bdev_exclusive(device->bdev, device->mode); 526 blkdev_put(device->bdev, device->mode);
527 fs_devices->open_devices--; 527 fs_devices->open_devices--;
528 } 528 }
529 if (device->writeable) { 529 if (device->writeable) {
@@ -580,13 +580,15 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
580 int seeding = 1; 580 int seeding = 1;
581 int ret = 0; 581 int ret = 0;
582 582
583 flags |= FMODE_EXCL;
584
583 list_for_each_entry(device, head, dev_list) { 585 list_for_each_entry(device, head, dev_list) {
584 if (device->bdev) 586 if (device->bdev)
585 continue; 587 continue;
586 if (!device->name) 588 if (!device->name)
587 continue; 589 continue;
588 590
589 bdev = open_bdev_exclusive(device->name, flags, holder); 591 bdev = blkdev_get_by_path(device->name, flags, holder);
590 if (IS_ERR(bdev)) { 592 if (IS_ERR(bdev)) {
591 printk(KERN_INFO "open %s failed\n", device->name); 593 printk(KERN_INFO "open %s failed\n", device->name);
592 goto error; 594 goto error;
@@ -638,7 +640,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
638error_brelse: 640error_brelse:
639 brelse(bh); 641 brelse(bh);
640error_close: 642error_close:
641 close_bdev_exclusive(bdev, FMODE_READ); 643 blkdev_put(bdev, flags);
642error: 644error:
643 continue; 645 continue;
644 } 646 }
@@ -684,7 +686,8 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
684 686
685 mutex_lock(&uuid_mutex); 687 mutex_lock(&uuid_mutex);
686 688
687 bdev = open_bdev_exclusive(path, flags, holder); 689 flags |= FMODE_EXCL;
690 bdev = blkdev_get_by_path(path, flags, holder);
688 691
689 if (IS_ERR(bdev)) { 692 if (IS_ERR(bdev)) {
690 ret = PTR_ERR(bdev); 693 ret = PTR_ERR(bdev);
@@ -716,7 +719,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
716 719
717 brelse(bh); 720 brelse(bh);
718error_close: 721error_close:
719 close_bdev_exclusive(bdev, flags); 722 blkdev_put(bdev, flags);
720error: 723error:
721 mutex_unlock(&uuid_mutex); 724 mutex_unlock(&uuid_mutex);
722 return ret; 725 return ret;
@@ -1179,8 +1182,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1179 goto out; 1182 goto out;
1180 } 1183 }
1181 } else { 1184 } else {
1182 bdev = open_bdev_exclusive(device_path, FMODE_READ, 1185 bdev = blkdev_get_by_path(device_path, FMODE_READ | FMODE_EXCL,
1183 root->fs_info->bdev_holder); 1186 root->fs_info->bdev_holder);
1184 if (IS_ERR(bdev)) { 1187 if (IS_ERR(bdev)) {
1185 ret = PTR_ERR(bdev); 1188 ret = PTR_ERR(bdev);
1186 goto out; 1189 goto out;
@@ -1244,7 +1247,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1244 root->fs_info->fs_devices->latest_bdev = next_device->bdev; 1247 root->fs_info->fs_devices->latest_bdev = next_device->bdev;
1245 1248
1246 if (device->bdev) { 1249 if (device->bdev) {
1247 close_bdev_exclusive(device->bdev, device->mode); 1250 blkdev_put(device->bdev, device->mode);
1248 device->bdev = NULL; 1251 device->bdev = NULL;
1249 device->fs_devices->open_devices--; 1252 device->fs_devices->open_devices--;
1250 } 1253 }
@@ -1287,7 +1290,7 @@ error_brelse:
1287 brelse(bh); 1290 brelse(bh);
1288error_close: 1291error_close:
1289 if (bdev) 1292 if (bdev)
1290 close_bdev_exclusive(bdev, FMODE_READ); 1293 blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
1291out: 1294out:
1292 mutex_unlock(&root->fs_info->volume_mutex); 1295 mutex_unlock(&root->fs_info->volume_mutex);
1293 mutex_unlock(&uuid_mutex); 1296 mutex_unlock(&uuid_mutex);
@@ -1439,7 +1442,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1439 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) 1442 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
1440 return -EINVAL; 1443 return -EINVAL;
1441 1444
1442 bdev = open_bdev_exclusive(device_path, 0, root->fs_info->bdev_holder); 1445 bdev = blkdev_get_by_path(device_path, FMODE_EXCL,
1446 root->fs_info->bdev_holder);
1443 if (IS_ERR(bdev)) 1447 if (IS_ERR(bdev))
1444 return PTR_ERR(bdev); 1448 return PTR_ERR(bdev);
1445 1449
@@ -1565,7 +1569,7 @@ out:
1565 mutex_unlock(&root->fs_info->volume_mutex); 1569 mutex_unlock(&root->fs_info->volume_mutex);
1566 return ret; 1570 return ret;
1567error: 1571error:
1568 close_bdev_exclusive(bdev, 0); 1572 blkdev_put(bdev, FMODE_EXCL);
1569 if (seeding_dev) { 1573 if (seeding_dev) {
1570 mutex_unlock(&uuid_mutex); 1574 mutex_unlock(&uuid_mutex);
1571 up_write(&sb->s_umount); 1575 up_write(&sb->s_umount);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2b638b6e4eea..856e75770304 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -49,7 +49,7 @@ struct btrfs_device {
49 49
50 struct block_device *bdev; 50 struct block_device *bdev;
51 51
52 /* the mode sent to open_bdev_exclusive */ 52 /* the mode sent to blkdev_get */
53 fmode_t mode; 53 fmode_t mode;
54 54
55 char *name; 55 char *name;
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 2fedaf8b5012..123720ba786d 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -347,7 +347,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb)
347 struct block_device *bdev; 347 struct block_device *bdev;
348 char b[BDEVNAME_SIZE]; 348 char b[BDEVNAME_SIZE];
349 349
350 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 350 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
351 if (IS_ERR(bdev)) 351 if (IS_ERR(bdev))
352 goto fail; 352 goto fail;
353 return bdev; 353 return bdev;
@@ -364,8 +364,7 @@ fail:
364 */ 364 */
365static int ext3_blkdev_put(struct block_device *bdev) 365static int ext3_blkdev_put(struct block_device *bdev)
366{ 366{
367 bd_release(bdev); 367 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
368 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
369} 368}
370 369
371static int ext3_blkdev_remove(struct ext3_sb_info *sbi) 370static int ext3_blkdev_remove(struct ext3_sb_info *sbi)
@@ -2136,13 +2135,6 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
2136 if (bdev == NULL) 2135 if (bdev == NULL)
2137 return NULL; 2136 return NULL;
2138 2137
2139 if (bd_claim(bdev, sb)) {
2140 ext3_msg(sb, KERN_ERR,
2141 "error: failed to claim external journal device");
2142 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2143 return NULL;
2144 }
2145
2146 blocksize = sb->s_blocksize; 2138 blocksize = sb->s_blocksize;
2147 hblock = bdev_logical_block_size(bdev); 2139 hblock = bdev_logical_block_size(bdev);
2148 if (blocksize < hblock) { 2140 if (blocksize < hblock) {
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 61182fe6254e..bd63e6927219 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -647,7 +647,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
647 struct block_device *bdev; 647 struct block_device *bdev;
648 char b[BDEVNAME_SIZE]; 648 char b[BDEVNAME_SIZE];
649 649
650 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 650 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
651 if (IS_ERR(bdev)) 651 if (IS_ERR(bdev))
652 goto fail; 652 goto fail;
653 return bdev; 653 return bdev;
@@ -663,8 +663,7 @@ fail:
663 */ 663 */
664static int ext4_blkdev_put(struct block_device *bdev) 664static int ext4_blkdev_put(struct block_device *bdev)
665{ 665{
666 bd_release(bdev); 666 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
667 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
668} 667}
669 668
670static int ext4_blkdev_remove(struct ext4_sb_info *sbi) 669static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
@@ -3758,13 +3757,6 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
3758 if (bdev == NULL) 3757 if (bdev == NULL)
3759 return NULL; 3758 return NULL;
3760 3759
3761 if (bd_claim(bdev, sb)) {
3762 ext4_msg(sb, KERN_ERR,
3763 "failed to claim external journal device");
3764 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
3765 return NULL;
3766 }
3767
3768 blocksize = sb->s_blocksize; 3760 blocksize = sb->s_blocksize;
3769 hblock = bdev_logical_block_size(bdev); 3761 hblock = bdev_logical_block_size(bdev);
3770 if (blocksize < hblock) { 3762 if (blocksize < hblock) {
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index 06d582732d34..5ab3839dfcb9 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -138,10 +138,8 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
138 struct gfs2_inum_host *inum) 138 struct gfs2_inum_host *inum)
139{ 139{
140 struct gfs2_sbd *sdp = sb->s_fs_info; 140 struct gfs2_sbd *sdp = sb->s_fs_info;
141 struct gfs2_holder i_gh;
142 struct inode *inode; 141 struct inode *inode;
143 struct dentry *dentry; 142 struct dentry *dentry;
144 int error;
145 143
146 inode = gfs2_ilookup(sb, inum->no_addr); 144 inode = gfs2_ilookup(sb, inum->no_addr);
147 if (inode) { 145 if (inode) {
@@ -152,52 +150,16 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
152 goto out_inode; 150 goto out_inode;
153 } 151 }
154 152
155 error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops, 153 inode = gfs2_lookup_by_inum(sdp, inum->no_addr, &inum->no_formal_ino,
156 LM_ST_SHARED, LM_FLAG_ANY, &i_gh); 154 GFS2_BLKST_DINODE);
157 if (error) 155 if (IS_ERR(inode))
158 return ERR_PTR(error); 156 return ERR_CAST(inode);
159
160 error = gfs2_check_blk_type(sdp, inum->no_addr, GFS2_BLKST_DINODE);
161 if (error)
162 goto fail;
163
164 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, inum->no_addr, 0);
165 if (IS_ERR(inode)) {
166 error = PTR_ERR(inode);
167 goto fail;
168 }
169
170 error = gfs2_inode_refresh(GFS2_I(inode));
171 if (error) {
172 iput(inode);
173 goto fail;
174 }
175
176 /* Pick up the works we bypass in gfs2_inode_lookup */
177 if (inode->i_state & I_NEW)
178 gfs2_set_iop(inode);
179
180 if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) {
181 iput(inode);
182 goto fail;
183 }
184
185 error = -EIO;
186 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM) {
187 iput(inode);
188 goto fail;
189 }
190
191 gfs2_glock_dq_uninit(&i_gh);
192 157
193out_inode: 158out_inode:
194 dentry = d_obtain_alias(inode); 159 dentry = d_obtain_alias(inode);
195 if (!IS_ERR(dentry)) 160 if (!IS_ERR(dentry))
196 dentry->d_op = &gfs2_dops; 161 dentry->d_op = &gfs2_dops;
197 return dentry; 162 return dentry;
198fail:
199 gfs2_glock_dq_uninit(&i_gh);
200 return ERR_PTR(error);
201} 163}
202 164
203static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, 165static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid,
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 87778857f099..f92c17704169 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -686,21 +686,20 @@ static void delete_work_func(struct work_struct *work)
686{ 686{
687 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete); 687 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
688 struct gfs2_sbd *sdp = gl->gl_sbd; 688 struct gfs2_sbd *sdp = gl->gl_sbd;
689 struct gfs2_inode *ip = NULL; 689 struct gfs2_inode *ip;
690 struct inode *inode; 690 struct inode *inode;
691 u64 no_addr = 0; 691 u64 no_addr = gl->gl_name.ln_number;
692
693 ip = gl->gl_object;
694 /* Note: Unsafe to dereference ip as we don't hold right refs/locks */
692 695
693 spin_lock(&gl->gl_spin);
694 ip = (struct gfs2_inode *)gl->gl_object;
695 if (ip) 696 if (ip)
696 no_addr = ip->i_no_addr;
697 spin_unlock(&gl->gl_spin);
698 if (ip) {
699 inode = gfs2_ilookup(sdp->sd_vfs, no_addr); 697 inode = gfs2_ilookup(sdp->sd_vfs, no_addr);
700 if (inode) { 698 else
701 d_prune_aliases(inode); 699 inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);
702 iput(inode); 700 if (inode && !IS_ERR(inode)) {
703 } 701 d_prune_aliases(inode);
702 iput(inode);
704 } 703 }
705 gfs2_glock_put(gl); 704 gfs2_glock_put(gl);
706} 705}
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 06370f8bd8cf..e1213f7f9217 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -73,49 +73,6 @@ static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
73 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr); 73 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);
74} 74}
75 75
76struct gfs2_skip_data {
77 u64 no_addr;
78 int skipped;
79};
80
81static int iget_skip_test(struct inode *inode, void *opaque)
82{
83 struct gfs2_inode *ip = GFS2_I(inode);
84 struct gfs2_skip_data *data = opaque;
85
86 if (ip->i_no_addr == data->no_addr) {
87 if (inode->i_state & (I_FREEING|I_WILL_FREE)){
88 data->skipped = 1;
89 return 0;
90 }
91 return 1;
92 }
93 return 0;
94}
95
96static int iget_skip_set(struct inode *inode, void *opaque)
97{
98 struct gfs2_inode *ip = GFS2_I(inode);
99 struct gfs2_skip_data *data = opaque;
100
101 if (data->skipped)
102 return 1;
103 inode->i_ino = (unsigned long)(data->no_addr);
104 ip->i_no_addr = data->no_addr;
105 return 0;
106}
107
108static struct inode *gfs2_iget_skip(struct super_block *sb,
109 u64 no_addr)
110{
111 struct gfs2_skip_data data;
112 unsigned long hash = (unsigned long)no_addr;
113
114 data.no_addr = no_addr;
115 data.skipped = 0;
116 return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data);
117}
118
119/** 76/**
120 * GFS2 lookup code fills in vfs inode contents based on info obtained 77 * GFS2 lookup code fills in vfs inode contents based on info obtained
121 * from directory entry inside gfs2_inode_lookup(). This has caused issues 78 * from directory entry inside gfs2_inode_lookup(). This has caused issues
@@ -243,93 +200,54 @@ fail:
243 return ERR_PTR(error); 200 return ERR_PTR(error);
244} 201}
245 202
246/** 203struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
247 * gfs2_process_unlinked_inode - Lookup an unlinked inode for reclamation 204 u64 *no_formal_ino, unsigned int blktype)
248 * and try to reclaim it by doing iput.
249 *
250 * This function assumes no rgrp locks are currently held.
251 *
252 * @sb: The super block
253 * no_addr: The inode number
254 *
255 */
256
257void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr)
258{ 205{
259 struct gfs2_sbd *sdp; 206 struct super_block *sb = sdp->sd_vfs;
260 struct gfs2_inode *ip; 207 struct gfs2_holder i_gh;
261 struct gfs2_glock *io_gl = NULL;
262 int error;
263 struct gfs2_holder gh;
264 struct inode *inode; 208 struct inode *inode;
209 int error;
265 210
266 inode = gfs2_iget_skip(sb, no_addr); 211 error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,
267 212 LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
268 if (!inode) 213 if (error)
269 return; 214 return ERR_PTR(error);
270
271 /* If it's not a new inode, someone's using it, so leave it alone. */
272 if (!(inode->i_state & I_NEW)) {
273 iput(inode);
274 return;
275 }
276
277 ip = GFS2_I(inode);
278 sdp = GFS2_SB(inode);
279 ip->i_no_formal_ino = -1;
280 215
281 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); 216 error = gfs2_check_blk_type(sdp, no_addr, blktype);
282 if (unlikely(error)) 217 if (error)
283 goto fail; 218 goto fail;
284 ip->i_gl->gl_object = ip;
285 219
286 error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 220 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0);
287 if (unlikely(error)) 221 if (IS_ERR(inode))
288 goto fail_put; 222 goto fail;
289
290 set_bit(GIF_INVALID, &ip->i_flags);
291 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, LM_FLAG_TRY | GL_EXACT,
292 &ip->i_iopen_gh);
293 if (unlikely(error))
294 goto fail_iopen;
295 223
296 ip->i_iopen_gh.gh_gl->gl_object = ip; 224 error = gfs2_inode_refresh(GFS2_I(inode));
297 gfs2_glock_put(io_gl); 225 if (error)
298 io_gl = NULL; 226 goto fail_iput;
299 227
300 inode->i_mode = DT2IF(DT_UNKNOWN); 228 /* Pick up the works we bypass in gfs2_inode_lookup */
229 if (inode->i_state & I_NEW)
230 gfs2_set_iop(inode);
301 231
302 /* 232 /* Two extra checks for NFS only */
303 * We must read the inode in order to work out its type in 233 if (no_formal_ino) {
304 * this case. Note that this doesn't happen often as we normally 234 error = -ESTALE;
305 * know the type beforehand. This code path only occurs during 235 if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
306 * unlinked inode recovery (where it is safe to do this glock, 236 goto fail_iput;
307 * which is not true in the general case).
308 */
309 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY,
310 &gh);
311 if (unlikely(error))
312 goto fail_glock;
313 237
314 /* Inode is now uptodate */ 238 error = -EIO;
315 gfs2_glock_dq_uninit(&gh); 239 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
316 gfs2_set_iop(inode); 240 goto fail_iput;
317 241
318 /* The iput will cause it to be deleted. */ 242 error = 0;
319 iput(inode); 243 }
320 return;
321 244
322fail_glock:
323 gfs2_glock_dq(&ip->i_iopen_gh);
324fail_iopen:
325 if (io_gl)
326 gfs2_glock_put(io_gl);
327fail_put:
328 ip->i_gl->gl_object = NULL;
329 gfs2_glock_put(ip->i_gl);
330fail: 245fail:
331 iget_failed(inode); 246 gfs2_glock_dq_uninit(&i_gh);
332 return; 247 return error ? ERR_PTR(error) : inode;
248fail_iput:
249 iput(inode);
250 goto fail;
333} 251}
334 252
335static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) 253static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 6720d7d5fbc6..d8499fadcc53 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -99,7 +99,9 @@ err:
99extern void gfs2_set_iop(struct inode *inode); 99extern void gfs2_set_iop(struct inode *inode);
100extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, 100extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type,
101 u64 no_addr, u64 no_formal_ino); 101 u64 no_addr, u64 no_formal_ino);
102extern void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr); 102extern struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
103 u64 *no_formal_ino,
104 unsigned int blktype);
103extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr); 105extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr);
104 106
105extern int gfs2_inode_refresh(struct gfs2_inode *ip); 107extern int gfs2_inode_refresh(struct gfs2_inode *ip);
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 3eb1393f7b81..bc56ccf98ffd 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1268,7 +1268,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1268{ 1268{
1269 struct block_device *bdev; 1269 struct block_device *bdev;
1270 struct super_block *s; 1270 struct super_block *s;
1271 fmode_t mode = FMODE_READ; 1271 fmode_t mode = FMODE_READ | FMODE_EXCL;
1272 int error; 1272 int error;
1273 struct gfs2_args args; 1273 struct gfs2_args args;
1274 struct gfs2_sbd *sdp; 1274 struct gfs2_sbd *sdp;
@@ -1276,7 +1276,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1276 if (!(flags & MS_RDONLY)) 1276 if (!(flags & MS_RDONLY))
1277 mode |= FMODE_WRITE; 1277 mode |= FMODE_WRITE;
1278 1278
1279 bdev = open_bdev_exclusive(dev_name, mode, fs_type); 1279 bdev = blkdev_get_by_path(dev_name, mode, fs_type);
1280 if (IS_ERR(bdev)) 1280 if (IS_ERR(bdev))
1281 return ERR_CAST(bdev); 1281 return ERR_CAST(bdev);
1282 1282
@@ -1298,7 +1298,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1298 goto error_bdev; 1298 goto error_bdev;
1299 1299
1300 if (s->s_root) 1300 if (s->s_root)
1301 close_bdev_exclusive(bdev, mode); 1301 blkdev_put(bdev, mode);
1302 1302
1303 memset(&args, 0, sizeof(args)); 1303 memset(&args, 0, sizeof(args));
1304 args.ar_quota = GFS2_QUOTA_DEFAULT; 1304 args.ar_quota = GFS2_QUOTA_DEFAULT;
@@ -1342,7 +1342,7 @@ error_super:
1342 deactivate_locked_super(s); 1342 deactivate_locked_super(s);
1343 return ERR_PTR(error); 1343 return ERR_PTR(error);
1344error_bdev: 1344error_bdev:
1345 close_bdev_exclusive(bdev, mode); 1345 blkdev_put(bdev, mode);
1346 return ERR_PTR(error); 1346 return ERR_PTR(error);
1347} 1347}
1348 1348
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index bef3ab6cf5c1..33c8407b876f 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -963,17 +963,18 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al)
963 * The inode, if one has been found, in inode. 963 * The inode, if one has been found, in inode.
964 */ 964 */
965 965
966static u64 try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, 966static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip)
967 u64 skip)
968{ 967{
969 u32 goal = 0, block; 968 u32 goal = 0, block;
970 u64 no_addr; 969 u64 no_addr;
971 struct gfs2_sbd *sdp = rgd->rd_sbd; 970 struct gfs2_sbd *sdp = rgd->rd_sbd;
972 unsigned int n; 971 unsigned int n;
972 struct gfs2_glock *gl;
973 struct gfs2_inode *ip;
974 int error;
975 int found = 0;
973 976
974 for(;;) { 977 while (goal < rgd->rd_data) {
975 if (goal >= rgd->rd_data)
976 break;
977 down_write(&sdp->sd_log_flush_lock); 978 down_write(&sdp->sd_log_flush_lock);
978 n = 1; 979 n = 1;
979 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 980 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED,
@@ -990,11 +991,32 @@ static u64 try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked,
990 if (no_addr == skip) 991 if (no_addr == skip)
991 continue; 992 continue;
992 *last_unlinked = no_addr; 993 *last_unlinked = no_addr;
993 return no_addr; 994
995 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl);
996 if (error)
997 continue;
998
999 /* If the inode is already in cache, we can ignore it here
1000 * because the existing inode disposal code will deal with
1001 * it when all refs have gone away. Accessing gl_object like
1002 * this is not safe in general. Here it is ok because we do
1003 * not dereference the pointer, and we only need an approx
1004 * answer to whether it is NULL or not.
1005 */
1006 ip = gl->gl_object;
1007
1008 if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
1009 gfs2_glock_put(gl);
1010 else
1011 found++;
1012
1013 /* Limit reclaim to sensible number of tasks */
1014 if (found > 2*NR_CPUS)
1015 return;
994 } 1016 }
995 1017
996 rgd->rd_flags &= ~GFS2_RDF_CHECK; 1018 rgd->rd_flags &= ~GFS2_RDF_CHECK;
997 return 0; 1019 return;
998} 1020}
999 1021
1000/** 1022/**
@@ -1075,11 +1097,9 @@ static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd)
1075 * Try to acquire rgrp in way which avoids contending with others. 1097 * Try to acquire rgrp in way which avoids contending with others.
1076 * 1098 *
1077 * Returns: errno 1099 * Returns: errno
1078 * unlinked: the block address of an unlinked block to be reclaimed
1079 */ 1100 */
1080 1101
1081static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked, 1102static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1082 u64 *last_unlinked)
1083{ 1103{
1084 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1104 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1085 struct gfs2_rgrpd *rgd, *begin = NULL; 1105 struct gfs2_rgrpd *rgd, *begin = NULL;
@@ -1089,7 +1109,6 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1089 int loops = 0; 1109 int loops = 0;
1090 int error, rg_locked; 1110 int error, rg_locked;
1091 1111
1092 *unlinked = 0;
1093 rgd = gfs2_blk2rgrpd(sdp, ip->i_goal); 1112 rgd = gfs2_blk2rgrpd(sdp, ip->i_goal);
1094 1113
1095 while (rgd) { 1114 while (rgd) {
@@ -1106,17 +1125,10 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1106 case 0: 1125 case 0:
1107 if (try_rgrp_fit(rgd, al)) 1126 if (try_rgrp_fit(rgd, al))
1108 goto out; 1127 goto out;
1109 /* If the rg came in already locked, there's no 1128 if (rgd->rd_flags & GFS2_RDF_CHECK)
1110 way we can recover from a failed try_rgrp_unlink 1129 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);
1111 because that would require an iput which can only
1112 happen after the rgrp is unlocked. */
1113 if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK)
1114 *unlinked = try_rgrp_unlink(rgd, last_unlinked,
1115 ip->i_no_addr);
1116 if (!rg_locked) 1130 if (!rg_locked)
1117 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1131 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1118 if (*unlinked)
1119 return -EAGAIN;
1120 /* fall through */ 1132 /* fall through */
1121 case GLR_TRYFAILED: 1133 case GLR_TRYFAILED:
1122 rgd = recent_rgrp_next(rgd); 1134 rgd = recent_rgrp_next(rgd);
@@ -1145,13 +1157,10 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1145 case 0: 1157 case 0:
1146 if (try_rgrp_fit(rgd, al)) 1158 if (try_rgrp_fit(rgd, al))
1147 goto out; 1159 goto out;
1148 if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK) 1160 if (rgd->rd_flags & GFS2_RDF_CHECK)
1149 *unlinked = try_rgrp_unlink(rgd, last_unlinked, 1161 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);
1150 ip->i_no_addr);
1151 if (!rg_locked) 1162 if (!rg_locked)
1152 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1163 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1153 if (*unlinked)
1154 return -EAGAIN;
1155 break; 1164 break;
1156 1165
1157 case GLR_TRYFAILED: 1166 case GLR_TRYFAILED:
@@ -1204,12 +1213,12 @@ int gfs2_inplace_reserve_i(struct gfs2_inode *ip, int hold_rindex,
1204 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1213 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1205 struct gfs2_alloc *al = ip->i_alloc; 1214 struct gfs2_alloc *al = ip->i_alloc;
1206 int error = 0; 1215 int error = 0;
1207 u64 last_unlinked = NO_BLOCK, unlinked; 1216 u64 last_unlinked = NO_BLOCK;
1217 int tries = 0;
1208 1218
1209 if (gfs2_assert_warn(sdp, al->al_requested)) 1219 if (gfs2_assert_warn(sdp, al->al_requested))
1210 return -EINVAL; 1220 return -EINVAL;
1211 1221
1212try_again:
1213 if (hold_rindex) { 1222 if (hold_rindex) {
1214 /* We need to hold the rindex unless the inode we're using is 1223 /* We need to hold the rindex unless the inode we're using is
1215 the rindex itself, in which case it's already held. */ 1224 the rindex itself, in which case it's already held. */
@@ -1218,31 +1227,23 @@ try_again:
1218 else if (!sdp->sd_rgrps) /* We may not have the rindex read 1227 else if (!sdp->sd_rgrps) /* We may not have the rindex read
1219 in, so: */ 1228 in, so: */
1220 error = gfs2_ri_update_special(ip); 1229 error = gfs2_ri_update_special(ip);
1230 if (error)
1231 return error;
1221 } 1232 }
1222 1233
1223 if (error) 1234 do {
1224 return error; 1235 error = get_local_rgrp(ip, &last_unlinked);
1236 /* If there is no space, flushing the log may release some */
1237 if (error)
1238 gfs2_log_flush(sdp, NULL);
1239 } while (error && tries++ < 3);
1225 1240
1226 /* Find an rgrp suitable for allocation. If it encounters any unlinked
1227 dinodes along the way, error will equal -EAGAIN and unlinked will
1228 contains it block address. We then need to look up that inode and
1229 try to free it, and try the allocation again. */
1230 error = get_local_rgrp(ip, &unlinked, &last_unlinked);
1231 if (error) { 1241 if (error) {
1232 if (hold_rindex && ip != GFS2_I(sdp->sd_rindex)) 1242 if (hold_rindex && ip != GFS2_I(sdp->sd_rindex))
1233 gfs2_glock_dq_uninit(&al->al_ri_gh); 1243 gfs2_glock_dq_uninit(&al->al_ri_gh);
1234 if (error != -EAGAIN) 1244 return error;
1235 return error;
1236
1237 gfs2_process_unlinked_inode(ip->i_inode.i_sb, unlinked);
1238 /* regardless of whether or not gfs2_process_unlinked_inode
1239 was successful, we don't want to repeat it again. */
1240 last_unlinked = unlinked;
1241 gfs2_log_flush(sdp, NULL);
1242 error = 0;
1243
1244 goto try_again;
1245 } 1245 }
1246
1246 /* no error, so we have the rgrp set in the inode's allocation. */ 1247 /* no error, so we have the rgrp set in the inode's allocation. */
1247 al->al_file = file; 1248 al->al_file = file;
1248 al->al_line = line; 1249 al->al_line = line;
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index e1b8493b9aaa..278e3fb40b71 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1120,16 +1120,13 @@ int lmLogOpen(struct super_block *sb)
1120 * file systems to log may have n-to-1 relationship; 1120 * file systems to log may have n-to-1 relationship;
1121 */ 1121 */
1122 1122
1123 bdev = open_by_devnum(sbi->logdev, FMODE_READ|FMODE_WRITE); 1123 bdev = blkdev_get_by_dev(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
1124 log);
1124 if (IS_ERR(bdev)) { 1125 if (IS_ERR(bdev)) {
1125 rc = -PTR_ERR(bdev); 1126 rc = -PTR_ERR(bdev);
1126 goto free; 1127 goto free;
1127 } 1128 }
1128 1129
1129 if ((rc = bd_claim(bdev, log))) {
1130 goto close;
1131 }
1132
1133 log->bdev = bdev; 1130 log->bdev = bdev;
1134 memcpy(log->uuid, sbi->loguuid, sizeof(log->uuid)); 1131 memcpy(log->uuid, sbi->loguuid, sizeof(log->uuid));
1135 1132
@@ -1137,7 +1134,7 @@ int lmLogOpen(struct super_block *sb)
1137 * initialize log: 1134 * initialize log:
1138 */ 1135 */
1139 if ((rc = lmLogInit(log))) 1136 if ((rc = lmLogInit(log)))
1140 goto unclaim; 1137 goto close;
1141 1138
1142 list_add(&log->journal_list, &jfs_external_logs); 1139 list_add(&log->journal_list, &jfs_external_logs);
1143 1140
@@ -1163,11 +1160,8 @@ journal_found:
1163 list_del(&log->journal_list); 1160 list_del(&log->journal_list);
1164 lbmLogShutdown(log); 1161 lbmLogShutdown(log);
1165 1162
1166 unclaim:
1167 bd_release(bdev);
1168
1169 close: /* close external log device */ 1163 close: /* close external log device */
1170 blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 1164 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1171 1165
1172 free: /* free log descriptor */ 1166 free: /* free log descriptor */
1173 mutex_unlock(&jfs_log_mutex); 1167 mutex_unlock(&jfs_log_mutex);
@@ -1512,8 +1506,7 @@ int lmLogClose(struct super_block *sb)
1512 bdev = log->bdev; 1506 bdev = log->bdev;
1513 rc = lmLogShutdown(log); 1507 rc = lmLogShutdown(log);
1514 1508
1515 bd_release(bdev); 1509 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1516 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1517 1510
1518 kfree(log); 1511 kfree(log);
1519 1512
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 92ca6fbe09bd..723bc5bca09a 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -300,7 +300,7 @@ static int bdev_write_sb(struct super_block *sb, struct page *page)
300 300
301static void bdev_put_device(struct logfs_super *s) 301static void bdev_put_device(struct logfs_super *s)
302{ 302{
303 close_bdev_exclusive(s->s_bdev, FMODE_READ|FMODE_WRITE); 303 blkdev_put(s->s_bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
304} 304}
305 305
306static int bdev_can_write_buf(struct super_block *sb, u64 ofs) 306static int bdev_can_write_buf(struct super_block *sb, u64 ofs)
@@ -325,13 +325,14 @@ int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type,
325{ 325{
326 struct block_device *bdev; 326 struct block_device *bdev;
327 327
328 bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, type); 328 bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
329 type);
329 if (IS_ERR(bdev)) 330 if (IS_ERR(bdev))
330 return PTR_ERR(bdev); 331 return PTR_ERR(bdev);
331 332
332 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { 333 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
333 int mtdnr = MINOR(bdev->bd_dev); 334 int mtdnr = MINOR(bdev->bd_dev);
334 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE); 335 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
335 return logfs_get_sb_mtd(p, mtdnr); 336 return logfs_get_sb_mtd(p, mtdnr);
336 } 337 }
337 338
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index f804d41ec9d3..0030640e2d72 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -1147,14 +1147,14 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1147{ 1147{
1148 struct nilfs_super_data sd; 1148 struct nilfs_super_data sd;
1149 struct super_block *s; 1149 struct super_block *s;
1150 fmode_t mode = FMODE_READ; 1150 fmode_t mode = FMODE_READ | FMODE_EXCL;
1151 struct dentry *root_dentry; 1151 struct dentry *root_dentry;
1152 int err, s_new = false; 1152 int err, s_new = false;
1153 1153
1154 if (!(flags & MS_RDONLY)) 1154 if (!(flags & MS_RDONLY))
1155 mode |= FMODE_WRITE; 1155 mode |= FMODE_WRITE;
1156 1156
1157 sd.bdev = open_bdev_exclusive(dev_name, mode, fs_type); 1157 sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type);
1158 if (IS_ERR(sd.bdev)) 1158 if (IS_ERR(sd.bdev))
1159 return ERR_CAST(sd.bdev); 1159 return ERR_CAST(sd.bdev);
1160 1160
@@ -1233,7 +1233,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1233 } 1233 }
1234 1234
1235 if (!s_new) 1235 if (!s_new)
1236 close_bdev_exclusive(sd.bdev, mode); 1236 blkdev_put(sd.bdev, mode);
1237 1237
1238 return root_dentry; 1238 return root_dentry;
1239 1239
@@ -1242,7 +1242,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1242 1242
1243 failed: 1243 failed:
1244 if (!s_new) 1244 if (!s_new)
1245 close_bdev_exclusive(sd.bdev, mode); 1245 blkdev_put(sd.bdev, mode);
1246 return ERR_PTR(err); 1246 return ERR_PTR(err);
1247} 1247}
1248 1248
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 52c7557f3e25..d0a2721eaceb 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1674,7 +1674,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1674 goto out; 1674 goto out;
1675 1675
1676 reg->hr_bdev = I_BDEV(filp->f_mapping->host); 1676 reg->hr_bdev = I_BDEV(filp->f_mapping->host);
1677 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ); 1677 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, NULL);
1678 if (ret) { 1678 if (ret) {
1679 reg->hr_bdev = NULL; 1679 reg->hr_bdev = NULL;
1680 goto out; 1680 goto out;
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index d8408217e3bd..1efea3615589 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -159,7 +159,9 @@ struct ocfs2_lock_res {
159 char l_name[OCFS2_LOCK_ID_MAX_LEN]; 159 char l_name[OCFS2_LOCK_ID_MAX_LEN];
160 unsigned int l_ro_holders; 160 unsigned int l_ro_holders;
161 unsigned int l_ex_holders; 161 unsigned int l_ex_holders;
162 unsigned char l_level; 162 char l_level;
163 char l_requested;
164 char l_blocking;
163 165
164 /* Data packed - type enum ocfs2_lock_type */ 166 /* Data packed - type enum ocfs2_lock_type */
165 unsigned char l_type; 167 unsigned char l_type;
@@ -169,8 +171,6 @@ struct ocfs2_lock_res {
169 unsigned char l_action; 171 unsigned char l_action;
170 /* Data packed - enum type ocfs2_unlock_action */ 172 /* Data packed - enum type ocfs2_unlock_action */
171 unsigned char l_unlock_action; 173 unsigned char l_unlock_action;
172 unsigned char l_requested;
173 unsigned char l_blocking;
174 unsigned int l_pending_gen; 174 unsigned int l_pending_gen;
175 175
176 spinlock_t l_lock; 176 spinlock_t l_lock;
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 0a8b0ad0c7e2..bdf8d3cc95a4 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -237,6 +237,13 @@ ssize_t part_size_show(struct device *dev,
237 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects); 237 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
238} 238}
239 239
240ssize_t part_ro_show(struct device *dev,
241 struct device_attribute *attr, char *buf)
242{
243 struct hd_struct *p = dev_to_part(dev);
244 return sprintf(buf, "%d\n", p->policy ? 1 : 0);
245}
246
240ssize_t part_alignment_offset_show(struct device *dev, 247ssize_t part_alignment_offset_show(struct device *dev,
241 struct device_attribute *attr, char *buf) 248 struct device_attribute *attr, char *buf)
242{ 249{
@@ -312,6 +319,7 @@ ssize_t part_fail_store(struct device *dev,
312static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL); 319static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
313static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); 320static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
314static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); 321static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
322static DEVICE_ATTR(ro, S_IRUGO, part_ro_show, NULL);
315static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); 323static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL);
316static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show, 324static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show,
317 NULL); 325 NULL);
@@ -326,6 +334,7 @@ static struct attribute *part_attrs[] = {
326 &dev_attr_partition.attr, 334 &dev_attr_partition.attr,
327 &dev_attr_start.attr, 335 &dev_attr_start.attr,
328 &dev_attr_size.attr, 336 &dev_attr_size.attr,
337 &dev_attr_ro.attr,
329 &dev_attr_alignment_offset.attr, 338 &dev_attr_alignment_offset.attr,
330 &dev_attr_discard_alignment.attr, 339 &dev_attr_discard_alignment.attr,
331 &dev_attr_stat.attr, 340 &dev_attr_stat.attr,
@@ -549,7 +558,7 @@ void register_disk(struct gendisk *disk)
549 goto exit; 558 goto exit;
550 559
551 bdev->bd_invalidated = 1; 560 bdev->bd_invalidated = 1;
552 err = blkdev_get(bdev, FMODE_READ); 561 err = blkdev_get(bdev, FMODE_READ, NULL);
553 if (err < 0) 562 if (err < 0)
554 goto exit; 563 goto exit;
555 blkdev_put(bdev, FMODE_READ); 564 blkdev_put(bdev, FMODE_READ);
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 076c8b194682..e2fce519c0f2 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2552,8 +2552,6 @@ static int release_journal_dev(struct super_block *super,
2552 result = 0; 2552 result = 0;
2553 2553
2554 if (journal->j_dev_bd != NULL) { 2554 if (journal->j_dev_bd != NULL) {
2555 if (journal->j_dev_bd->bd_dev != super->s_dev)
2556 bd_release(journal->j_dev_bd);
2557 result = blkdev_put(journal->j_dev_bd, journal->j_dev_mode); 2555 result = blkdev_put(journal->j_dev_bd, journal->j_dev_mode);
2558 journal->j_dev_bd = NULL; 2556 journal->j_dev_bd = NULL;
2559 } 2557 }
@@ -2571,7 +2569,7 @@ static int journal_init_dev(struct super_block *super,
2571{ 2569{
2572 int result; 2570 int result;
2573 dev_t jdev; 2571 dev_t jdev;
2574 fmode_t blkdev_mode = FMODE_READ | FMODE_WRITE; 2572 fmode_t blkdev_mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
2575 char b[BDEVNAME_SIZE]; 2573 char b[BDEVNAME_SIZE];
2576 2574
2577 result = 0; 2575 result = 0;
@@ -2585,7 +2583,10 @@ static int journal_init_dev(struct super_block *super,
2585 2583
2586 /* there is no "jdev" option and journal is on separate device */ 2584 /* there is no "jdev" option and journal is on separate device */
2587 if ((!jdev_name || !jdev_name[0])) { 2585 if ((!jdev_name || !jdev_name[0])) {
2588 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode); 2586 if (jdev == super->s_dev)
2587 blkdev_mode &= ~FMODE_EXCL;
2588 journal->j_dev_bd = blkdev_get_by_dev(jdev, blkdev_mode,
2589 journal);
2589 journal->j_dev_mode = blkdev_mode; 2590 journal->j_dev_mode = blkdev_mode;
2590 if (IS_ERR(journal->j_dev_bd)) { 2591 if (IS_ERR(journal->j_dev_bd)) {
2591 result = PTR_ERR(journal->j_dev_bd); 2592 result = PTR_ERR(journal->j_dev_bd);
@@ -2594,22 +2595,14 @@ static int journal_init_dev(struct super_block *super,
2594 "cannot init journal device '%s': %i", 2595 "cannot init journal device '%s': %i",
2595 __bdevname(jdev, b), result); 2596 __bdevname(jdev, b), result);
2596 return result; 2597 return result;
2597 } else if (jdev != super->s_dev) { 2598 } else if (jdev != super->s_dev)
2598 result = bd_claim(journal->j_dev_bd, journal);
2599 if (result) {
2600 blkdev_put(journal->j_dev_bd, blkdev_mode);
2601 return result;
2602 }
2603
2604 set_blocksize(journal->j_dev_bd, super->s_blocksize); 2599 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2605 }
2606 2600
2607 return 0; 2601 return 0;
2608 } 2602 }
2609 2603
2610 journal->j_dev_mode = blkdev_mode; 2604 journal->j_dev_mode = blkdev_mode;
2611 journal->j_dev_bd = open_bdev_exclusive(jdev_name, 2605 journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, journal);
2612 blkdev_mode, journal);
2613 if (IS_ERR(journal->j_dev_bd)) { 2606 if (IS_ERR(journal->j_dev_bd)) {
2614 result = PTR_ERR(journal->j_dev_bd); 2607 result = PTR_ERR(journal->j_dev_bd);
2615 journal->j_dev_bd = NULL; 2608 journal->j_dev_bd = NULL;
diff --git a/fs/super.c b/fs/super.c
index ca696155cd9a..5d9a4497849a 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -766,13 +766,13 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
766{ 766{
767 struct block_device *bdev; 767 struct block_device *bdev;
768 struct super_block *s; 768 struct super_block *s;
769 fmode_t mode = FMODE_READ; 769 fmode_t mode = FMODE_READ | FMODE_EXCL;
770 int error = 0; 770 int error = 0;
771 771
772 if (!(flags & MS_RDONLY)) 772 if (!(flags & MS_RDONLY))
773 mode |= FMODE_WRITE; 773 mode |= FMODE_WRITE;
774 774
775 bdev = open_bdev_exclusive(dev_name, mode, fs_type); 775 bdev = blkdev_get_by_path(dev_name, mode, fs_type);
776 if (IS_ERR(bdev)) 776 if (IS_ERR(bdev))
777 return ERR_CAST(bdev); 777 return ERR_CAST(bdev);
778 778
@@ -801,13 +801,13 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
801 801
802 /* 802 /*
803 * s_umount nests inside bd_mutex during 803 * s_umount nests inside bd_mutex during
804 * __invalidate_device(). close_bdev_exclusive() 804 * __invalidate_device(). blkdev_put() acquires
805 * acquires bd_mutex and can't be called under 805 * bd_mutex and can't be called under s_umount. Drop
806 * s_umount. Drop s_umount temporarily. This is safe 806 * s_umount temporarily. This is safe as we're
807 * as we're holding an active reference. 807 * holding an active reference.
808 */ 808 */
809 up_write(&s->s_umount); 809 up_write(&s->s_umount);
810 close_bdev_exclusive(bdev, mode); 810 blkdev_put(bdev, mode);
811 down_write(&s->s_umount); 811 down_write(&s->s_umount);
812 } else { 812 } else {
813 char b[BDEVNAME_SIZE]; 813 char b[BDEVNAME_SIZE];
@@ -831,7 +831,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
831error_s: 831error_s:
832 error = PTR_ERR(s); 832 error = PTR_ERR(s);
833error_bdev: 833error_bdev:
834 close_bdev_exclusive(bdev, mode); 834 blkdev_put(bdev, mode);
835error: 835error:
836 return ERR_PTR(error); 836 return ERR_PTR(error);
837} 837}
@@ -862,7 +862,8 @@ void kill_block_super(struct super_block *sb)
862 bdev->bd_super = NULL; 862 bdev->bd_super = NULL;
863 generic_shutdown_super(sb); 863 generic_shutdown_super(sb);
864 sync_blockdev(bdev); 864 sync_blockdev(bdev);
865 close_bdev_exclusive(bdev, mode); 865 WARN_ON_ONCE(!(mode & FMODE_EXCL));
866 blkdev_put(bdev, mode | FMODE_EXCL);
866} 867}
867 868
868EXPORT_SYMBOL(kill_block_super); 869EXPORT_SYMBOL(kill_block_super);
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 064f964d4f3c..2d2ce7f651a7 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -606,7 +606,8 @@ xfs_blkdev_get(
606{ 606{
607 int error = 0; 607 int error = 0;
608 608
609 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp); 609 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
610 mp);
610 if (IS_ERR(*bdevp)) { 611 if (IS_ERR(*bdevp)) {
611 error = PTR_ERR(*bdevp); 612 error = PTR_ERR(*bdevp);
612 printk("XFS: Invalid device [%s], error=%d\n", name, error); 613 printk("XFS: Invalid device [%s], error=%d\n", name, error);
@@ -620,7 +621,7 @@ xfs_blkdev_put(
620 struct block_device *bdev) 621 struct block_device *bdev)
621{ 622{
622 if (bdev) 623 if (bdev)
623 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE); 624 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
624} 625}
625 626
626/* 627/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 334d68a17108..f48501563917 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -663,7 +663,7 @@ struct block_device {
663 void * bd_holder; 663 void * bd_holder;
664 int bd_holders; 664 int bd_holders;
665#ifdef CONFIG_SYSFS 665#ifdef CONFIG_SYSFS
666 struct list_head bd_holder_list; 666 struct gendisk * bd_holder_disk; /* for sysfs slave linkng */
667#endif 667#endif
668 struct block_device * bd_contains; 668 struct block_device * bd_contains;
669 unsigned bd_block_size; 669 unsigned bd_block_size;
@@ -2006,7 +2006,6 @@ extern struct block_device *bdgrab(struct block_device *bdev);
2006extern void bd_set_size(struct block_device *, loff_t size); 2006extern void bd_set_size(struct block_device *, loff_t size);
2007extern void bd_forget(struct inode *inode); 2007extern void bd_forget(struct inode *inode);
2008extern void bdput(struct block_device *); 2008extern void bdput(struct block_device *);
2009extern struct block_device *open_by_devnum(dev_t, fmode_t);
2010extern void invalidate_bdev(struct block_device *); 2009extern void invalidate_bdev(struct block_device *);
2011extern int sync_blockdev(struct block_device *bdev); 2010extern int sync_blockdev(struct block_device *bdev);
2012extern struct super_block *freeze_bdev(struct block_device *); 2011extern struct super_block *freeze_bdev(struct block_device *);
@@ -2037,16 +2036,20 @@ extern const struct file_operations def_fifo_fops;
2037extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); 2036extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
2038extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); 2037extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
2039extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 2038extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
2040extern int blkdev_get(struct block_device *, fmode_t); 2039extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
2041extern int blkdev_put(struct block_device *, fmode_t); 2040extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
2042extern int bd_claim(struct block_device *, void *); 2041 void *holder);
2043extern void bd_release(struct block_device *); 2042extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
2043 void *holder);
2044extern int blkdev_put(struct block_device *bdev, fmode_t mode);
2044#ifdef CONFIG_SYSFS 2045#ifdef CONFIG_SYSFS
2045extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *); 2046extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
2046extern void bd_release_from_disk(struct block_device *, struct gendisk *);
2047#else 2047#else
2048#define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder) 2048static inline int bd_link_disk_holder(struct block_device *bdev,
2049#define bd_release_from_disk(bdev, disk) bd_release(bdev) 2049 struct gendisk *disk)
2050{
2051 return 0;
2052}
2050#endif 2053#endif
2051#endif 2054#endif
2052 2055
@@ -2082,8 +2085,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
2082extern const char *__bdevname(dev_t, char *buffer); 2085extern const char *__bdevname(dev_t, char *buffer);
2083extern const char *bdevname(struct block_device *bdev, char *buffer); 2086extern const char *bdevname(struct block_device *bdev, char *buffer);
2084extern struct block_device *lookup_bdev(const char *); 2087extern struct block_device *lookup_bdev(const char *);
2085extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
2086extern void close_bdev_exclusive(struct block_device *, fmode_t);
2087extern void blkdev_show(struct seq_file *,off_t); 2088extern void blkdev_show(struct seq_file *,off_t);
2088 2089
2089#else 2090#else
diff --git a/include/linux/fsl-diu-fb.h b/include/linux/fsl-diu-fb.h
index fc295d7ea463..781d4671415f 100644
--- a/include/linux/fsl-diu-fb.h
+++ b/include/linux/fsl-diu-fb.h
@@ -54,7 +54,6 @@ struct aoi_display_offset {
54}; 54};
55 55
56#define MFB_SET_CHROMA_KEY _IOW('M', 1, struct mfb_chroma_key) 56#define MFB_SET_CHROMA_KEY _IOW('M', 1, struct mfb_chroma_key)
57#define MFB_WAIT_FOR_VSYNC _IOW('F', 0x20, u_int32_t)
58#define MFB_SET_BRIGHTNESS _IOW('M', 3, __u8) 57#define MFB_SET_BRIGHTNESS _IOW('M', 3, __u8)
59 58
60#define MFB_SET_ALPHA 0x80014d00 59#define MFB_SET_ALPHA 0x80014d00
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index e844a0b18695..4bef5c557160 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -32,28 +32,6 @@
32 */ 32 */
33 33
34/* --- Bit algorithm adapters */ 34/* --- Bit algorithm adapters */
35#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */
36#define I2C_HW_B_RIVA 0x010010 /* Riva based graphics cards */
37#define I2C_HW_B_ZR36067 0x010019 /* Zoran-36057/36067 based boards */
38#define I2C_HW_B_CX2388x 0x01001b /* connexant 2388x based tv cards */ 35#define I2C_HW_B_CX2388x 0x01001b /* connexant 2388x based tv cards */
39#define I2C_HW_B_EM28XX 0x01001f /* em28xx video capture cards */
40#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */
41#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */
42#define I2C_HW_B_AU0828 0x010023 /* auvitek au0828 usb bridge */
43#define I2C_HW_B_CX231XX 0x010024 /* Conexant CX231XX USB based cards */
44#define I2C_HW_B_HDPVR 0x010025 /* Hauppauge HD PVR */
45
46/* --- SGI adapters */
47#define I2C_HW_SGI_VINO 0x160000
48
49/* --- SMBus only adapters */
50#define I2C_HW_SMBUS_W9968CF 0x04000d
51#define I2C_HW_SMBUS_OV511 0x04000e /* OV511(+) USB 1.1 webcam ICs */
52#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */
53#define I2C_HW_SMBUS_CAFE 0x040012 /* Marvell 88ALP01 "CAFE" cam */
54
55/* --- Miscellaneous adapters */
56#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */
57#define I2C_HW_SAA7134 0x090000 /* SAA7134 video decoder bus */
58 36
59#endif /* LINUX_I2C_ID_H */ 37#endif /* LINUX_I2C_ID_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 889b35abaeda..56cfe23ffb39 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -353,7 +353,7 @@ struct i2c_algorithm {
353 */ 353 */
354struct i2c_adapter { 354struct i2c_adapter {
355 struct module *owner; 355 struct module *owner;
356 unsigned int id; 356 unsigned int id __deprecated;
357 unsigned int class; /* classes to allow probing for */ 357 unsigned int class; /* classes to allow probing for */
358 const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 358 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
359 void *algo_data; 359 void *algo_data;
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index fc3da9e4da19..b6de9a6f7018 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -17,13 +17,11 @@
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/log2.h> 18#include <linux/log2.h>
19#include <linux/typecheck.h> 19#include <linux/typecheck.h>
20#include <linux/printk.h>
20#include <linux/dynamic_debug.h> 21#include <linux/dynamic_debug.h>
21#include <asm/byteorder.h> 22#include <asm/byteorder.h>
22#include <asm/bug.h> 23#include <asm/bug.h>
23 24
24extern const char linux_banner[];
25extern const char linux_proc_banner[];
26
27#define USHRT_MAX ((u16)(~0U)) 25#define USHRT_MAX ((u16)(~0U))
28#define SHRT_MAX ((s16)(USHRT_MAX>>1)) 26#define SHRT_MAX ((s16)(USHRT_MAX>>1))
29#define SHRT_MIN ((s16)(-SHRT_MAX - 1)) 27#define SHRT_MIN ((s16)(-SHRT_MAX - 1))
@@ -110,31 +108,6 @@ extern const char linux_proc_banner[];
110 */ 108 */
111#define lower_32_bits(n) ((u32)(n)) 109#define lower_32_bits(n) ((u32)(n))
112 110
113#define KERN_EMERG "<0>" /* system is unusable */
114#define KERN_ALERT "<1>" /* action must be taken immediately */
115#define KERN_CRIT "<2>" /* critical conditions */
116#define KERN_ERR "<3>" /* error conditions */
117#define KERN_WARNING "<4>" /* warning conditions */
118#define KERN_NOTICE "<5>" /* normal but significant condition */
119#define KERN_INFO "<6>" /* informational */
120#define KERN_DEBUG "<7>" /* debug-level messages */
121
122/* Use the default kernel loglevel */
123#define KERN_DEFAULT "<d>"
124/*
125 * Annotation for a "continued" line of log printout (only done after a
126 * line that had no enclosing \n). Only to be used by core/arch code
127 * during early bootup (a continued line is not SMP-safe otherwise).
128 */
129#define KERN_CONT "<c>"
130
131extern int console_printk[];
132
133#define console_loglevel (console_printk[0])
134#define default_message_loglevel (console_printk[1])
135#define minimum_console_loglevel (console_printk[2])
136#define default_console_loglevel (console_printk[3])
137
138struct completion; 111struct completion;
139struct pt_regs; 112struct pt_regs;
140struct user; 113struct user;
@@ -187,11 +160,6 @@ static inline void might_fault(void)
187} 160}
188#endif 161#endif
189 162
190struct va_format {
191 const char *fmt;
192 va_list *va;
193};
194
195extern struct atomic_notifier_head panic_notifier_list; 163extern struct atomic_notifier_head panic_notifier_list;
196extern long (*panic_blink)(int state); 164extern long (*panic_blink)(int state);
197NORET_TYPE void panic(const char * fmt, ...) 165NORET_TYPE void panic(const char * fmt, ...)
@@ -245,115 +213,8 @@ extern int func_ptr_is_kernel_text(void *ptr);
245struct pid; 213struct pid;
246extern struct pid *session_of_pgrp(struct pid *pgrp); 214extern struct pid *session_of_pgrp(struct pid *pgrp);
247 215
248/*
249 * FW_BUG
250 * Add this to a message where you are sure the firmware is buggy or behaves
251 * really stupid or out of spec. Be aware that the responsible BIOS developer
252 * should be able to fix this issue or at least get a concrete idea of the
253 * problem by reading your message without the need of looking at the kernel
254 * code.
255 *
256 * Use it for definite and high priority BIOS bugs.
257 *
258 * FW_WARN
259 * Use it for not that clear (e.g. could the kernel messed up things already?)
260 * and medium priority BIOS bugs.
261 *
262 * FW_INFO
263 * Use this one if you want to tell the user or vendor about something
264 * suspicious, but generally harmless related to the firmware.
265 *
266 * Use it for information or very low priority BIOS bugs.
267 */
268#define FW_BUG "[Firmware Bug]: "
269#define FW_WARN "[Firmware Warn]: "
270#define FW_INFO "[Firmware Info]: "
271
272/*
273 * HW_ERR
274 * Add this to a message for hardware errors, so that user can report
275 * it to hardware vendor instead of LKML or software vendor.
276 */
277#define HW_ERR "[Hardware Error]: "
278
279#ifdef CONFIG_PRINTK
280asmlinkage int vprintk(const char *fmt, va_list args)
281 __attribute__ ((format (printf, 1, 0)));
282asmlinkage int printk(const char * fmt, ...)
283 __attribute__ ((format (printf, 1, 2))) __cold;
284
285/*
286 * Please don't use printk_ratelimit(), because it shares ratelimiting state
287 * with all other unrelated printk_ratelimit() callsites. Instead use
288 * printk_ratelimited() or plain old __ratelimit().
289 */
290extern int __printk_ratelimit(const char *func);
291#define printk_ratelimit() __printk_ratelimit(__func__)
292extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
293 unsigned int interval_msec);
294
295extern int printk_delay_msec;
296extern int dmesg_restrict;
297
298/*
299 * Print a one-time message (analogous to WARN_ONCE() et al):
300 */
301#define printk_once(x...) ({ \
302 static bool __print_once; \
303 \
304 if (!__print_once) { \
305 __print_once = true; \
306 printk(x); \
307 } \
308})
309
310void log_buf_kexec_setup(void);
311#else
312static inline int vprintk(const char *s, va_list args)
313 __attribute__ ((format (printf, 1, 0)));
314static inline int vprintk(const char *s, va_list args) { return 0; }
315static inline int printk(const char *s, ...)
316 __attribute__ ((format (printf, 1, 2)));
317static inline int __cold printk(const char *s, ...) { return 0; }
318static inline int printk_ratelimit(void) { return 0; }
319static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
320 unsigned int interval_msec) \
321 { return false; }
322
323/* No effect, but we still get type checking even in the !PRINTK case: */
324#define printk_once(x...) printk(x)
325
326static inline void log_buf_kexec_setup(void)
327{
328}
329#endif
330
331/*
332 * Dummy printk for disabled debugging statements to use whilst maintaining
333 * gcc's format and side-effect checking.
334 */
335static inline __attribute__ ((format (printf, 1, 2)))
336int no_printk(const char *s, ...) { return 0; }
337
338extern int printk_needs_cpu(int cpu);
339extern void printk_tick(void);
340
341extern void asmlinkage __attribute__((format(printf, 1, 2)))
342 early_printk(const char *fmt, ...);
343
344unsigned long int_sqrt(unsigned long); 216unsigned long int_sqrt(unsigned long);
345 217
346static inline void console_silent(void)
347{
348 console_loglevel = 0;
349}
350
351static inline void console_verbose(void)
352{
353 if (console_loglevel)
354 console_loglevel = 15;
355}
356
357extern void bust_spinlocks(int yes); 218extern void bust_spinlocks(int yes);
358extern void wake_up_klogd(void); 219extern void wake_up_klogd(void);
359extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 220extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
@@ -390,22 +251,6 @@ extern enum system_states {
390#define TAINT_CRAP 10 251#define TAINT_CRAP 10
391#define TAINT_FIRMWARE_WORKAROUND 11 252#define TAINT_FIRMWARE_WORKAROUND 11
392 253
393extern void dump_stack(void) __cold;
394
395enum {
396 DUMP_PREFIX_NONE,
397 DUMP_PREFIX_ADDRESS,
398 DUMP_PREFIX_OFFSET
399};
400extern void hex_dump_to_buffer(const void *buf, size_t len,
401 int rowsize, int groupsize,
402 char *linebuf, size_t linebuflen, bool ascii);
403extern void print_hex_dump(const char *level, const char *prefix_str,
404 int prefix_type, int rowsize, int groupsize,
405 const void *buf, size_t len, bool ascii);
406extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
407 const void *buf, size_t len);
408
409extern const char hex_asc[]; 254extern const char hex_asc[];
410#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] 255#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
411#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] 256#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
@@ -419,94 +264,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
419 264
420extern int hex_to_bin(char ch); 265extern int hex_to_bin(char ch);
421 266
422#ifndef pr_fmt
423#define pr_fmt(fmt) fmt
424#endif
425
426#define pr_emerg(fmt, ...) \
427 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
428#define pr_alert(fmt, ...) \
429 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
430#define pr_crit(fmt, ...) \
431 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
432#define pr_err(fmt, ...) \
433 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
434#define pr_warning(fmt, ...) \
435 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
436#define pr_warn pr_warning
437#define pr_notice(fmt, ...) \
438 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
439#define pr_info(fmt, ...) \
440 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
441#define pr_cont(fmt, ...) \
442 printk(KERN_CONT fmt, ##__VA_ARGS__)
443
444/* pr_devel() should produce zero code unless DEBUG is defined */
445#ifdef DEBUG
446#define pr_devel(fmt, ...) \
447 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
448#else
449#define pr_devel(fmt, ...) \
450 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
451#endif
452
453/* If you are writing a driver, please use dev_dbg instead */
454#if defined(DEBUG)
455#define pr_debug(fmt, ...) \
456 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
457#elif defined(CONFIG_DYNAMIC_DEBUG)
458/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
459#define pr_debug(fmt, ...) \
460 dynamic_pr_debug(fmt, ##__VA_ARGS__)
461#else
462#define pr_debug(fmt, ...) \
463 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
464#endif
465
466/*
467 * ratelimited messages with local ratelimit_state,
468 * no local ratelimit_state used in the !PRINTK case
469 */
470#ifdef CONFIG_PRINTK
471#define printk_ratelimited(fmt, ...) ({ \
472 static DEFINE_RATELIMIT_STATE(_rs, \
473 DEFAULT_RATELIMIT_INTERVAL, \
474 DEFAULT_RATELIMIT_BURST); \
475 \
476 if (__ratelimit(&_rs)) \
477 printk(fmt, ##__VA_ARGS__); \
478})
479#else
480/* No effect, but we still get type checking even in the !PRINTK case: */
481#define printk_ratelimited printk
482#endif
483
484#define pr_emerg_ratelimited(fmt, ...) \
485 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
486#define pr_alert_ratelimited(fmt, ...) \
487 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
488#define pr_crit_ratelimited(fmt, ...) \
489 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
490#define pr_err_ratelimited(fmt, ...) \
491 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
492#define pr_warning_ratelimited(fmt, ...) \
493 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
494#define pr_warn_ratelimited pr_warning_ratelimited
495#define pr_notice_ratelimited(fmt, ...) \
496 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
497#define pr_info_ratelimited(fmt, ...) \
498 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
499/* no pr_cont_ratelimited, don't do that... */
500/* If you are writing a driver, please use dev_dbg instead */
501#if defined(DEBUG)
502#define pr_debug_ratelimited(fmt, ...) \
503 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
504#else
505#define pr_debug_ratelimited(fmt, ...) \
506 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
507 ##__VA_ARGS__); 0; })
508#endif
509
510/* 267/*
511 * General tracing related utility functions - trace_printk(), 268 * General tracing related utility functions - trace_printk(),
512 * tracing_on/tracing_off and tracing_start()/tracing_stop 269 * tracing_on/tracing_off and tracing_start()/tracing_stop
diff --git a/include/linux/printk.h b/include/linux/printk.h
new file mode 100644
index 000000000000..b772ca5fbdf0
--- /dev/null
+++ b/include/linux/printk.h
@@ -0,0 +1,248 @@
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
4extern const char linux_banner[];
5extern const char linux_proc_banner[];
6
7#define KERN_EMERG "<0>" /* system is unusable */
8#define KERN_ALERT "<1>" /* action must be taken immediately */
9#define KERN_CRIT "<2>" /* critical conditions */
10#define KERN_ERR "<3>" /* error conditions */
11#define KERN_WARNING "<4>" /* warning conditions */
12#define KERN_NOTICE "<5>" /* normal but significant condition */
13#define KERN_INFO "<6>" /* informational */
14#define KERN_DEBUG "<7>" /* debug-level messages */
15
16/* Use the default kernel loglevel */
17#define KERN_DEFAULT "<d>"
18/*
19 * Annotation for a "continued" line of log printout (only done after a
20 * line that had no enclosing \n). Only to be used by core/arch code
21 * during early bootup (a continued line is not SMP-safe otherwise).
22 */
23#define KERN_CONT "<c>"
24
25extern int console_printk[];
26
27#define console_loglevel (console_printk[0])
28#define default_message_loglevel (console_printk[1])
29#define minimum_console_loglevel (console_printk[2])
30#define default_console_loglevel (console_printk[3])
31
32struct va_format {
33 const char *fmt;
34 va_list *va;
35};
36
37/*
38 * FW_BUG
39 * Add this to a message where you are sure the firmware is buggy or behaves
40 * really stupid or out of spec. Be aware that the responsible BIOS developer
41 * should be able to fix this issue or at least get a concrete idea of the
42 * problem by reading your message without the need of looking at the kernel
43 * code.
44 *
45 * Use it for definite and high priority BIOS bugs.
46 *
47 * FW_WARN
48 * Use it for not that clear (e.g. could the kernel messed up things already?)
49 * and medium priority BIOS bugs.
50 *
51 * FW_INFO
52 * Use this one if you want to tell the user or vendor about something
53 * suspicious, but generally harmless related to the firmware.
54 *
55 * Use it for information or very low priority BIOS bugs.
56 */
57#define FW_BUG "[Firmware Bug]: "
58#define FW_WARN "[Firmware Warn]: "
59#define FW_INFO "[Firmware Info]: "
60
61/*
62 * HW_ERR
63 * Add this to a message for hardware errors, so that user can report
64 * it to hardware vendor instead of LKML or software vendor.
65 */
66#define HW_ERR "[Hardware Error]: "
67
68#ifdef CONFIG_PRINTK
69asmlinkage int vprintk(const char *fmt, va_list args)
70 __attribute__ ((format (printf, 1, 0)));
71asmlinkage int printk(const char * fmt, ...)
72 __attribute__ ((format (printf, 1, 2))) __cold;
73
74/*
75 * Please don't use printk_ratelimit(), because it shares ratelimiting state
76 * with all other unrelated printk_ratelimit() callsites. Instead use
77 * printk_ratelimited() or plain old __ratelimit().
78 */
79extern int __printk_ratelimit(const char *func);
80#define printk_ratelimit() __printk_ratelimit(__func__)
81extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
82 unsigned int interval_msec);
83
84extern int printk_delay_msec;
85extern int dmesg_restrict;
86
87/*
88 * Print a one-time message (analogous to WARN_ONCE() et al):
89 */
90#define printk_once(x...) ({ \
91 static bool __print_once; \
92 \
93 if (!__print_once) { \
94 __print_once = true; \
95 printk(x); \
96 } \
97})
98
99void log_buf_kexec_setup(void);
100#else
101static inline int vprintk(const char *s, va_list args)
102 __attribute__ ((format (printf, 1, 0)));
103static inline int vprintk(const char *s, va_list args) { return 0; }
104static inline int printk(const char *s, ...)
105 __attribute__ ((format (printf, 1, 2)));
106static inline int __cold printk(const char *s, ...) { return 0; }
107static inline int printk_ratelimit(void) { return 0; }
108static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
109 unsigned int interval_msec) \
110 { return false; }
111
112/* No effect, but we still get type checking even in the !PRINTK case: */
113#define printk_once(x...) printk(x)
114
115static inline void log_buf_kexec_setup(void)
116{
117}
118#endif
119
120/*
121 * Dummy printk for disabled debugging statements to use whilst maintaining
122 * gcc's format and side-effect checking.
123 */
124static inline __attribute__ ((format (printf, 1, 2)))
125int no_printk(const char *s, ...) { return 0; }
126
127extern int printk_needs_cpu(int cpu);
128extern void printk_tick(void);
129
130extern void asmlinkage __attribute__((format(printf, 1, 2)))
131 early_printk(const char *fmt, ...);
132
133static inline void console_silent(void)
134{
135 console_loglevel = 0;
136}
137
138static inline void console_verbose(void)
139{
140 if (console_loglevel)
141 console_loglevel = 15;
142}
143
144extern void dump_stack(void) __cold;
145
146enum {
147 DUMP_PREFIX_NONE,
148 DUMP_PREFIX_ADDRESS,
149 DUMP_PREFIX_OFFSET
150};
151extern void hex_dump_to_buffer(const void *buf, size_t len,
152 int rowsize, int groupsize,
153 char *linebuf, size_t linebuflen, bool ascii);
154extern void print_hex_dump(const char *level, const char *prefix_str,
155 int prefix_type, int rowsize, int groupsize,
156 const void *buf, size_t len, bool ascii);
157extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
158 const void *buf, size_t len);
159
160#ifndef pr_fmt
161#define pr_fmt(fmt) fmt
162#endif
163
164#define pr_emerg(fmt, ...) \
165 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
166#define pr_alert(fmt, ...) \
167 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
168#define pr_crit(fmt, ...) \
169 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
170#define pr_err(fmt, ...) \
171 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
172#define pr_warning(fmt, ...) \
173 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
174#define pr_warn pr_warning
175#define pr_notice(fmt, ...) \
176 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
177#define pr_info(fmt, ...) \
178 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
179#define pr_cont(fmt, ...) \
180 printk(KERN_CONT fmt, ##__VA_ARGS__)
181
182/* pr_devel() should produce zero code unless DEBUG is defined */
183#ifdef DEBUG
184#define pr_devel(fmt, ...) \
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#else
187#define pr_devel(fmt, ...) \
188 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
189#endif
190
191/* If you are writing a driver, please use dev_dbg instead */
192#if defined(DEBUG)
193#define pr_debug(fmt, ...) \
194 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
195#elif defined(CONFIG_DYNAMIC_DEBUG)
196/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
197#define pr_debug(fmt, ...) \
198 dynamic_pr_debug(fmt, ##__VA_ARGS__)
199#else
200#define pr_debug(fmt, ...) \
201 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
202#endif
203
204/*
205 * ratelimited messages with local ratelimit_state,
206 * no local ratelimit_state used in the !PRINTK case
207 */
208#ifdef CONFIG_PRINTK
209#define printk_ratelimited(fmt, ...) ({ \
210 static DEFINE_RATELIMIT_STATE(_rs, \
211 DEFAULT_RATELIMIT_INTERVAL, \
212 DEFAULT_RATELIMIT_BURST); \
213 \
214 if (__ratelimit(&_rs)) \
215 printk(fmt, ##__VA_ARGS__); \
216})
217#else
218/* No effect, but we still get type checking even in the !PRINTK case: */
219#define printk_ratelimited printk
220#endif
221
222#define pr_emerg_ratelimited(fmt, ...) \
223 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
224#define pr_alert_ratelimited(fmt, ...) \
225 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
226#define pr_crit_ratelimited(fmt, ...) \
227 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
228#define pr_err_ratelimited(fmt, ...) \
229 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
230#define pr_warning_ratelimited(fmt, ...) \
231 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
232#define pr_warn_ratelimited pr_warning_ratelimited
233#define pr_notice_ratelimited(fmt, ...) \
234 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
235#define pr_info_ratelimited(fmt, ...) \
236 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
237/* no pr_cont_ratelimited, don't do that... */
238/* If you are writing a driver, please use dev_dbg instead */
239#if defined(DEBUG)
240#define pr_debug_ratelimited(fmt, ...) \
241 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
242#else
243#define pr_debug_ratelimited(fmt, ...) \
244 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
245 ##__VA_ARGS__); 0; })
246#endif
247
248#endif
diff --git a/include/linux/security.h b/include/linux/security.h
index b8246a8df7d2..fd4d55fb8845 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -77,7 +77,6 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
77extern int cap_task_setscheduler(struct task_struct *p); 77extern int cap_task_setscheduler(struct task_struct *p);
78extern int cap_task_setioprio(struct task_struct *p, int ioprio); 78extern int cap_task_setioprio(struct task_struct *p, int ioprio);
79extern int cap_task_setnice(struct task_struct *p, int nice); 79extern int cap_task_setnice(struct task_struct *p, int nice);
80extern int cap_syslog(int type, bool from_file);
81extern int cap_vm_enough_memory(struct mm_struct *mm, long pages); 80extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
82 81
83struct msghdr; 82struct msghdr;
@@ -1388,7 +1387,7 @@ struct security_operations {
1388 int (*sysctl) (struct ctl_table *table, int op); 1387 int (*sysctl) (struct ctl_table *table, int op);
1389 int (*quotactl) (int cmds, int type, int id, struct super_block *sb); 1388 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
1390 int (*quota_on) (struct dentry *dentry); 1389 int (*quota_on) (struct dentry *dentry);
1391 int (*syslog) (int type, bool from_file); 1390 int (*syslog) (int type);
1392 int (*settime) (struct timespec *ts, struct timezone *tz); 1391 int (*settime) (struct timespec *ts, struct timezone *tz);
1393 int (*vm_enough_memory) (struct mm_struct *mm, long pages); 1392 int (*vm_enough_memory) (struct mm_struct *mm, long pages);
1394 1393
@@ -1671,7 +1670,7 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap);
1671int security_sysctl(struct ctl_table *table, int op); 1670int security_sysctl(struct ctl_table *table, int op);
1672int security_quotactl(int cmds, int type, int id, struct super_block *sb); 1671int security_quotactl(int cmds, int type, int id, struct super_block *sb);
1673int security_quota_on(struct dentry *dentry); 1672int security_quota_on(struct dentry *dentry);
1674int security_syslog(int type, bool from_file); 1673int security_syslog(int type);
1675int security_settime(struct timespec *ts, struct timezone *tz); 1674int security_settime(struct timespec *ts, struct timezone *tz);
1676int security_vm_enough_memory(long pages); 1675int security_vm_enough_memory(long pages);
1677int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); 1676int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
@@ -1901,9 +1900,9 @@ static inline int security_quota_on(struct dentry *dentry)
1901 return 0; 1900 return 0;
1902} 1901}
1903 1902
1904static inline int security_syslog(int type, bool from_file) 1903static inline int security_syslog(int type)
1905{ 1904{
1906 return cap_syslog(type, from_file); 1905 return 0;
1907} 1906}
1908 1907
1909static inline int security_settime(struct timespec *ts, struct timezone *tz) 1908static inline int security_settime(struct timespec *ts, struct timezone *tz)
diff --git a/include/linux/sh_intc.h b/include/linux/sh_intc.h
index f656d1a43dc0..5812fefbcedf 100644
--- a/include/linux/sh_intc.h
+++ b/include/linux/sh_intc.h
@@ -79,7 +79,7 @@ struct intc_hw_desc {
79 unsigned int nr_subgroups; 79 unsigned int nr_subgroups;
80}; 80};
81 81
82#define _INTC_ARRAY(a) a, a == NULL ? 0 : sizeof(a)/sizeof(*a) 82#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a)
83 83
84#define INTC_HW_DESC(vectors, groups, mask_regs, \ 84#define INTC_HW_DESC(vectors, groups, mask_regs, \
85 prio_regs, sense_regs, ack_regs) \ 85 prio_regs, sense_regs, ack_regs) \
diff --git a/include/trace/events/block.h b/include/trace/events/block.h
index d8ce278515c3..b56c65dc105d 100644
--- a/include/trace/events/block.h
+++ b/include/trace/events/block.h
@@ -486,16 +486,16 @@ TRACE_EVENT(block_split,
486); 486);
487 487
488/** 488/**
489 * block_remap - map request for a partition to the raw device 489 * block_bio_remap - map request for a logical device to the raw device
490 * @q: queue holding the operation 490 * @q: queue holding the operation
491 * @bio: revised operation 491 * @bio: revised operation
492 * @dev: device for the operation 492 * @dev: device for the operation
493 * @from: original sector for the operation 493 * @from: original sector for the operation
494 * 494 *
495 * An operation for a partition on a block device has been mapped to the 495 * An operation for a logical device has been mapped to the
496 * raw block device. 496 * raw block device.
497 */ 497 */
498TRACE_EVENT(block_remap, 498TRACE_EVENT(block_bio_remap,
499 499
500 TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev, 500 TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
501 sector_t from), 501 sector_t from),
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index a0e4a86ccf94..b019609d1b45 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -223,7 +223,7 @@ static int swsusp_swap_check(void)
223 return res; 223 return res;
224 224
225 root_swap = res; 225 root_swap = res;
226 res = blkdev_get(hib_resume_bdev, FMODE_WRITE); 226 res = blkdev_get(hib_resume_bdev, FMODE_WRITE, NULL);
227 if (res) 227 if (res)
228 return res; 228 return res;
229 229
@@ -907,7 +907,8 @@ int swsusp_check(void)
907{ 907{
908 int error; 908 int error;
909 909
910 hib_resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ); 910 hib_resume_bdev = blkdev_get_by_dev(swsusp_resume_device,
911 FMODE_READ, NULL);
911 if (!IS_ERR(hib_resume_bdev)) { 912 if (!IS_ERR(hib_resume_bdev)) {
912 set_blocksize(hib_resume_bdev, PAGE_SIZE); 913 set_blocksize(hib_resume_bdev, PAGE_SIZE);
913 clear_page(swsusp_header); 914 clear_page(swsusp_header);
diff --git a/kernel/printk.c b/kernel/printk.c
index 38e7d5868d60..9a2264fc42ca 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -274,7 +274,20 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
274 char c; 274 char c;
275 int error = 0; 275 int error = 0;
276 276
277 error = security_syslog(type, from_file); 277 /*
278 * If this is from /proc/kmsg we only do the capabilities checks
279 * at open time.
280 */
281 if (type == SYSLOG_ACTION_OPEN || !from_file) {
282 if (dmesg_restrict && !capable(CAP_SYS_ADMIN))
283 return -EPERM;
284 if ((type != SYSLOG_ACTION_READ_ALL &&
285 type != SYSLOG_ACTION_SIZE_BUFFER) &&
286 !capable(CAP_SYS_ADMIN))
287 return -EPERM;
288 }
289
290 error = security_syslog(type);
278 if (error) 291 if (error)
279 return error; 292 return error;
280 293
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 7b8ec0281548..2b8e2ee7c0ef 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -887,7 +887,7 @@ static void blk_add_trace_split(void *ignore,
887} 887}
888 888
889/** 889/**
890 * blk_add_trace_remap - Add a trace for a remap operation 890 * blk_add_trace_bio_remap - Add a trace for a bio-remap operation
891 * @ignore: trace callback data parameter (not used) 891 * @ignore: trace callback data parameter (not used)
892 * @q: queue the io is for 892 * @q: queue the io is for
893 * @bio: the source bio 893 * @bio: the source bio
@@ -899,9 +899,9 @@ static void blk_add_trace_split(void *ignore,
899 * it spans a stripe (or similar). Add a trace for that action. 899 * it spans a stripe (or similar). Add a trace for that action.
900 * 900 *
901 **/ 901 **/
902static void blk_add_trace_remap(void *ignore, 902static void blk_add_trace_bio_remap(void *ignore,
903 struct request_queue *q, struct bio *bio, 903 struct request_queue *q, struct bio *bio,
904 dev_t dev, sector_t from) 904 dev_t dev, sector_t from)
905{ 905{
906 struct blk_trace *bt = q->blk_trace; 906 struct blk_trace *bt = q->blk_trace;
907 struct blk_io_trace_remap r; 907 struct blk_io_trace_remap r;
@@ -1016,7 +1016,7 @@ static void blk_register_tracepoints(void)
1016 WARN_ON(ret); 1016 WARN_ON(ret);
1017 ret = register_trace_block_split(blk_add_trace_split, NULL); 1017 ret = register_trace_block_split(blk_add_trace_split, NULL);
1018 WARN_ON(ret); 1018 WARN_ON(ret);
1019 ret = register_trace_block_remap(blk_add_trace_remap, NULL); 1019 ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1020 WARN_ON(ret); 1020 WARN_ON(ret);
1021 ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); 1021 ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1022 WARN_ON(ret); 1022 WARN_ON(ret);
@@ -1025,7 +1025,7 @@ static void blk_register_tracepoints(void)
1025static void blk_unregister_tracepoints(void) 1025static void blk_unregister_tracepoints(void)
1026{ 1026{
1027 unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); 1027 unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1028 unregister_trace_block_remap(blk_add_trace_remap, NULL); 1028 unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1029 unregister_trace_block_split(blk_add_trace_split, NULL); 1029 unregister_trace_block_split(blk_add_trace_split, NULL);
1030 unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); 1030 unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL);
1031 unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); 1031 unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL);
diff --git a/mm/slub.c b/mm/slub.c
index 8fd5401bb071..981fb730aa04 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3273,9 +3273,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
3273 kfree(n); 3273 kfree(n);
3274 kfree(s); 3274 kfree(s);
3275 } 3275 }
3276err:
3276 up_write(&slub_lock); 3277 up_write(&slub_lock);
3277 3278
3278err:
3279 if (flags & SLAB_PANIC) 3279 if (flags & SLAB_PANIC)
3280 panic("Cannot create slabcache %s\n", name); 3280 panic("Cannot create slabcache %s\n", name);
3281 else 3281 else
@@ -3862,6 +3862,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
3862 x += sprintf(buf + x, " N%d=%lu", 3862 x += sprintf(buf + x, " N%d=%lu",
3863 node, nodes[node]); 3863 node, nodes[node]);
3864#endif 3864#endif
3865 up_read(&slub_lock);
3865 kfree(nodes); 3866 kfree(nodes);
3866 return x + sprintf(buf + x, "\n"); 3867 return x + sprintf(buf + x, "\n");
3867} 3868}
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 67ddaaf98c74..b6adcfbf6f48 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1677,7 +1677,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1677 if (S_ISBLK(inode->i_mode)) { 1677 if (S_ISBLK(inode->i_mode)) {
1678 struct block_device *bdev = I_BDEV(inode); 1678 struct block_device *bdev = I_BDEV(inode);
1679 set_blocksize(bdev, p->old_block_size); 1679 set_blocksize(bdev, p->old_block_size);
1680 bd_release(bdev); 1680 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
1681 } else { 1681 } else {
1682 mutex_lock(&inode->i_mutex); 1682 mutex_lock(&inode->i_mutex);
1683 inode->i_flags &= ~S_SWAPFILE; 1683 inode->i_flags &= ~S_SWAPFILE;
@@ -1939,7 +1939,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
1939 error = -EINVAL; 1939 error = -EINVAL;
1940 if (S_ISBLK(inode->i_mode)) { 1940 if (S_ISBLK(inode->i_mode)) {
1941 bdev = I_BDEV(inode); 1941 bdev = I_BDEV(inode);
1942 error = bd_claim(bdev, sys_swapon); 1942 error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL,
1943 sys_swapon);
1943 if (error < 0) { 1944 if (error < 0) {
1944 bdev = NULL; 1945 bdev = NULL;
1945 error = -EINVAL; 1946 error = -EINVAL;
@@ -2136,7 +2137,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
2136bad_swap: 2137bad_swap:
2137 if (bdev) { 2138 if (bdev) {
2138 set_blocksize(bdev, p->old_block_size); 2139 set_blocksize(bdev, p->old_block_size);
2139 bd_release(bdev); 2140 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
2140 } 2141 }
2141 destroy_swap_extents(p); 2142 destroy_swap_extents(p);
2142 swap_cgroup_swapoff(type); 2143 swap_cgroup_swapoff(type);
diff --git a/security/capability.c b/security/capability.c
index 30ae00fbecd5..c773635ca3a0 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -17,6 +17,11 @@ static int cap_sysctl(ctl_table *table, int op)
17 return 0; 17 return 0;
18} 18}
19 19
20static int cap_syslog(int type)
21{
22 return 0;
23}
24
20static int cap_quotactl(int cmds, int type, int id, struct super_block *sb) 25static int cap_quotactl(int cmds, int type, int id, struct super_block *sb)
21{ 26{
22 return 0; 27 return 0;
diff --git a/security/commoncap.c b/security/commoncap.c
index 04b80f9912bf..64c2ed9c9015 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -27,7 +27,6 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/prctl.h> 28#include <linux/prctl.h>
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30#include <linux/syslog.h>
31 30
32/* 31/*
33 * If a non-root user executes a setuid-root binary in 32 * If a non-root user executes a setuid-root binary in
@@ -884,26 +883,6 @@ error:
884} 883}
885 884
886/** 885/**
887 * cap_syslog - Determine whether syslog function is permitted
888 * @type: Function requested
889 * @from_file: Whether this request came from an open file (i.e. /proc)
890 *
891 * Determine whether the current process is permitted to use a particular
892 * syslog function, returning 0 if permission is granted, -ve if not.
893 */
894int cap_syslog(int type, bool from_file)
895{
896 if (type != SYSLOG_ACTION_OPEN && from_file)
897 return 0;
898 if (dmesg_restrict && !capable(CAP_SYS_ADMIN))
899 return -EPERM;
900 if ((type != SYSLOG_ACTION_READ_ALL &&
901 type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
902 return -EPERM;
903 return 0;
904}
905
906/**
907 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted 886 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted
908 * @mm: The VM space in which the new mapping is to be made 887 * @mm: The VM space in which the new mapping is to be made
909 * @pages: The size of the mapping 888 * @pages: The size of the mapping
diff --git a/security/security.c b/security/security.c
index 3ef5e2a7a741..1b798d3df710 100644
--- a/security/security.c
+++ b/security/security.c
@@ -197,9 +197,9 @@ int security_quota_on(struct dentry *dentry)
197 return security_ops->quota_on(dentry); 197 return security_ops->quota_on(dentry);
198} 198}
199 199
200int security_syslog(int type, bool from_file) 200int security_syslog(int type)
201{ 201{
202 return security_ops->syslog(type, from_file); 202 return security_ops->syslog(type);
203} 203}
204 204
205int security_settime(struct timespec *ts, struct timezone *tz) 205int security_settime(struct timespec *ts, struct timezone *tz)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index d9154cf90ae1..65fa8bf596f5 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1973,14 +1973,10 @@ static int selinux_quota_on(struct dentry *dentry)
1973 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON); 1973 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON);
1974} 1974}
1975 1975
1976static int selinux_syslog(int type, bool from_file) 1976static int selinux_syslog(int type)
1977{ 1977{
1978 int rc; 1978 int rc;
1979 1979
1980 rc = cap_syslog(type, from_file);
1981 if (rc)
1982 return rc;
1983
1984 switch (type) { 1980 switch (type) {
1985 case SYSLOG_ACTION_READ_ALL: /* Read last kernel messages */ 1981 case SYSLOG_ACTION_READ_ALL: /* Read last kernel messages */
1986 case SYSLOG_ACTION_SIZE_BUFFER: /* Return size of the log buffer */ 1982 case SYSLOG_ACTION_SIZE_BUFFER: /* Return size of the log buffer */
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index bc39f4067af6..489a85afa477 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -157,15 +157,11 @@ static int smack_ptrace_traceme(struct task_struct *ptp)
157 * 157 *
158 * Returns 0 on success, error code otherwise. 158 * Returns 0 on success, error code otherwise.
159 */ 159 */
160static int smack_syslog(int type, bool from_file) 160static int smack_syslog(int typefrom_file)
161{ 161{
162 int rc; 162 int rc = 0;
163 char *sp = current_security(); 163 char *sp = current_security();
164 164
165 rc = cap_syslog(type, from_file);
166 if (rc != 0)
167 return rc;
168
169 if (capable(CAP_MAC_OVERRIDE)) 165 if (capable(CAP_MAC_OVERRIDE))
170 return 0; 166 return 0;
171 167