aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-13 01:45:43 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-13 01:45:43 -0500
commit5cbb3d216e2041700231bcfc383ee5f8b7fc8b74 (patch)
treea738fa82dbcefa9bd283c08bc67f38827be63937
parent9bc9ccd7db1c9f043f75380b5a5b94912046a60e (diff)
parent4e9b45a19241354daec281d7a785739829b52359 (diff)
Merge branch 'akpm' (patches from Andrew Morton)
Merge first patch-bomb from Andrew Morton: "Quite a lot of other stuff is banked up awaiting further next->mainline merging, but this batch contains: - Lots of random misc patches - OCFS2 - Most of MM - backlight updates - lib/ updates - printk updates - checkpatch updates - epoll tweaking - rtc updates - hfs - hfsplus - documentation - procfs - update gcov to gcc-4.7 format - IPC" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (269 commits) ipc, msg: fix message length check for negative values ipc/util.c: remove unnecessary work pending test devpts: plug the memory leak in kill_sb ./Makefile: export initial ramdisk compression config option init/Kconfig: add option to disable kernel compression drivers: w1: make w1_slave::flags long to avoid memory corruption drivers/w1/masters/ds1wm.cuse dev_get_platdata() drivers/memstick/core/ms_block.c: fix unreachable state in h_msb_read_page() drivers/memstick/core/mspro_block.c: fix attributes array allocation drivers/pps/clients/pps-gpio.c: remove redundant of_match_ptr kernel/panic.c: reduce 1 byte usage for print tainted buffer gcov: reuse kbasename helper kernel/gcov/fs.c: use pr_warn() kernel/module.c: use pr_foo() gcov: compile specific gcov implementation based on gcc version gcov: add support for gcc 4.7 gcov format gcov: move gcov structs definitions to a gcc version specific file kernel/taskstats.c: return -ENOMEM when alloc memory fails in add_del_listener() kernel/taskstats.c: add nla_nest_cancel() for failure processing between nla_nest_start() and nla_nest_end() kernel/sysctl_binary.c: use scnprintf() instead of snprintf() ...
-rw-r--r--CREDITS7
-rw-r--r--Documentation/ABI/README13
-rw-r--r--Documentation/backlight/lp855x-driver.txt5
-rw-r--r--Documentation/cgroups/memory.txt10
-rw-r--r--Documentation/cpu-hotplug.txt2
-rw-r--r--Documentation/devicetree/bindings/video/backlight/lp855x.txt29
-rw-r--r--Documentation/filesystems/proc.txt1
-rw-r--r--Documentation/filesystems/vfat.txt2
-rw-r--r--Documentation/gcov.txt4
-rw-r--r--Documentation/kernel-parameters.txt6
-rw-r--r--Documentation/sysctl/kernel.txt25
-rw-r--r--Documentation/sysctl/vm.txt15
-rw-r--r--Documentation/trace/tracepoints.txt5
-rw-r--r--Documentation/vm/zswap.txt8
-rw-r--r--MAINTAINERS5
-rw-r--r--Makefile16
-rw-r--r--arch/alpha/include/uapi/asm/errno.h2
-rw-r--r--arch/arm/kernel/module.c2
-rw-r--r--arch/arm/mach-davinci/sram.c9
-rw-r--r--arch/arm64/kernel/module.c2
-rw-r--r--arch/cris/include/asm/io.h1
-rw-r--r--arch/ia64/include/asm/processor.h2
-rw-r--r--arch/ia64/mm/init.c4
-rw-r--r--arch/metag/kernel/dma.c4
-rw-r--r--arch/metag/mm/init.c2
-rw-r--r--arch/microblaze/mm/consistent.c7
-rw-r--r--arch/mips/include/uapi/asm/errno.h2
-rw-r--r--arch/parisc/include/uapi/asm/errno.h2
-rw-r--r--arch/parisc/kernel/module.c2
-rw-r--r--arch/powerpc/mm/dma-noncoherent.c4
-rw-r--r--arch/powerpc/mm/hugetlbpage.c2
-rw-r--r--arch/powerpc/mm/numa.c3
-rw-r--r--arch/s390/kernel/module.c2
-rw-r--r--arch/s390/mm/mmap.c9
-rw-r--r--arch/sh/include/asm/fpu.h2
-rw-r--r--arch/sh/include/asm/processor_32.h10
-rw-r--r--arch/sh/include/asm/processor_64.h10
-rw-r--r--arch/sh/kernel/cpu/fpu.c2
-rw-r--r--arch/sh/kernel/process_32.c6
-rw-r--r--arch/sh/kernel/process_64.c4
-rw-r--r--arch/sh/mm/init.c2
-rw-r--r--arch/sparc/include/uapi/asm/errno.h2
-rw-r--r--arch/sparc/kernel/module.c2
-rw-r--r--arch/x86/include/asm/fpu-internal.h10
-rw-r--r--arch/x86/include/asm/processor.h9
-rw-r--r--arch/x86/kernel/i387.c2
-rw-r--r--arch/x86/kernel/module.c2
-rw-r--r--arch/x86/kernel/process_32.c4
-rw-r--r--arch/x86/kernel/process_64.c2
-rw-r--r--arch/x86/kernel/setup.c9
-rw-r--r--arch/x86/kernel/traps.c2
-rw-r--r--arch/x86/mm/init.c125
-rw-r--r--arch/x86/mm/numa.c11
-rw-r--r--drivers/char/Kconfig10
-rw-r--r--drivers/char/hpet.c24
-rw-r--r--drivers/dma/mmp_tdma.c7
-rw-r--r--drivers/iommu/omap-iopgtable.h2
-rw-r--r--drivers/media/platform/coda.c5
-rw-r--r--drivers/memstick/core/ms_block.c2
-rw-r--r--drivers/memstick/core/mspro_block.c4
-rw-r--r--drivers/message/i2o/driver.c16
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c3
-rw-r--r--drivers/pps/clients/pps-gpio.c2
-rw-r--r--drivers/rtc/Kconfig20
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/rtc-88pm80x.c8
-rw-r--r--drivers/rtc/rtc-88pm860x.c2
-rw-r--r--drivers/rtc/rtc-as3722.c275
-rw-r--r--drivers/rtc/rtc-at91rm9200.c28
-rw-r--r--drivers/rtc/rtc-cmos.c3
-rw-r--r--drivers/rtc/rtc-da9055.c2
-rw-r--r--drivers/rtc/rtc-ds1305.c2
-rw-r--r--drivers/rtc/rtc-ds1307.c10
-rw-r--r--drivers/rtc/rtc-ds2404.c2
-rw-r--r--drivers/rtc/rtc-ep93xx.c6
-rw-r--r--drivers/rtc/rtc-isl1208.c42
-rw-r--r--drivers/rtc/rtc-m48t59.c20
-rw-r--r--drivers/rtc/rtc-m48t86.c8
-rw-r--r--drivers/rtc/rtc-max6900.c9
-rw-r--r--drivers/rtc/rtc-mrst.c2
-rw-r--r--drivers/rtc/rtc-omap.c2
-rw-r--r--drivers/rtc/rtc-pcf2123.c2
-rw-r--r--drivers/rtc/rtc-pl030.c9
-rw-r--r--drivers/rtc/rtc-pl031.c2
-rw-r--r--drivers/rtc/rtc-puv3.c22
-rw-r--r--drivers/rtc/rtc-rs5c348.c4
-rw-r--r--drivers/rtc/rtc-s5m.c635
-rw-r--r--drivers/rtc/rtc-sh.c5
-rw-r--r--drivers/rtc/rtc-sirfsoc.c27
-rw-r--r--drivers/rtc/rtc-snvs.c2
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c2
-rw-r--r--drivers/rtc/rtc-tps65910.c1
-rw-r--r--drivers/rtc/rtc-v3020.c2
-rw-r--r--drivers/rtc/rtc-vr41xx.c4
-rw-r--r--drivers/rtc/rtc-vt8500.c4
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_errno.h2
-rw-r--r--drivers/uio/uio_pruss.c6
-rw-r--r--drivers/video/acornfb.c4
-rw-r--r--drivers/video/backlight/88pm860x_bl.c18
-rw-r--r--drivers/video/backlight/Kconfig10
-rw-r--r--drivers/video/backlight/Makefile2
-rw-r--r--drivers/video/backlight/aat2870_bl.c13
-rw-r--r--drivers/video/backlight/adp5520_bl.c11
-rw-r--r--drivers/video/backlight/adp8860_bl.c17
-rw-r--r--drivers/video/backlight/adp8870_bl.c17
-rw-r--r--drivers/video/backlight/ams369fg06.c24
-rw-r--r--drivers/video/backlight/as3711_bl.c26
-rw-r--r--drivers/video/backlight/atmel-pwm-bl.c96
-rw-r--r--drivers/video/backlight/bd6107.c6
-rw-r--r--drivers/video/backlight/corgi_lcd.c30
-rw-r--r--drivers/video/backlight/cr_bllcd.c13
-rw-r--r--drivers/video/backlight/da903x_bl.c16
-rw-r--r--drivers/video/backlight/da9052_bl.c6
-rw-r--r--drivers/video/backlight/ep93xx_bl.c13
-rw-r--r--drivers/video/backlight/generic_bl.c8
-rw-r--r--drivers/video/backlight/gpio_backlight.c17
-rw-r--r--drivers/video/backlight/hx8357.c20
-rw-r--r--drivers/video/backlight/ili922x.c7
-rw-r--r--drivers/video/backlight/ili9320.c15
-rw-r--r--drivers/video/backlight/kb3886_bl.c20
-rw-r--r--drivers/video/backlight/l4f00242t03.c6
-rw-r--r--drivers/video/backlight/ld9040.c23
-rw-r--r--drivers/video/backlight/ld9040_gamma.h4
-rw-r--r--drivers/video/backlight/lm3533_bl.c12
-rw-r--r--drivers/video/backlight/lm3630_bl.c475
-rw-r--r--drivers/video/backlight/lm3630a_bl.c483
-rw-r--r--drivers/video/backlight/lm3639_bl.c13
-rw-r--r--drivers/video/backlight/lms283gf05.c17
-rw-r--r--drivers/video/backlight/lms501kf03.c8
-rw-r--r--drivers/video/backlight/lp855x_bl.c41
-rw-r--r--drivers/video/backlight/lp8788_bl.c2
-rw-r--r--drivers/video/backlight/ltv350qv.c11
-rw-r--r--drivers/video/backlight/lv5207lp.c9
-rw-r--r--drivers/video/backlight/max8925_bl.c17
-rw-r--r--drivers/video/backlight/omap1_bl.c2
-rw-r--r--drivers/video/backlight/pandora_bl.c12
-rw-r--r--drivers/video/backlight/pcf50633-backlight.c15
-rw-r--r--drivers/video/backlight/platform_lcd.c22
-rw-r--r--drivers/video/backlight/pwm_bl.c2
-rw-r--r--drivers/video/backlight/s6e63m0.c22
-rw-r--r--drivers/video/backlight/tdo24m.c14
-rw-r--r--drivers/video/backlight/tosa_bl.c2
-rw-r--r--drivers/video/backlight/tps65217_bl.c17
-rw-r--r--drivers/video/backlight/wm831x_bl.c21
-rw-r--r--drivers/w1/masters/ds1wm.c12
-rw-r--r--drivers/w1/w1.c10
-rw-r--r--drivers/w1/w1.h2
-rw-r--r--fs/cramfs/Kconfig5
-rw-r--r--fs/debugfs/inode.c3
-rw-r--r--fs/devpts/inode.c1
-rw-r--r--fs/eventpoll.c145
-rw-r--r--fs/exec.c6
-rw-r--r--fs/fs-writeback.c33
-rw-r--r--fs/hfs/btree.h5
-rw-r--r--fs/hfsplus/btree.c112
-rw-r--r--fs/hfsplus/hfsplus_fs.h10
-rw-r--r--fs/hfsplus/hfsplus_raw.h11
-rw-r--r--fs/hfsplus/super.c2
-rw-r--r--fs/hfsplus/xattr.c207
-rw-r--r--fs/ocfs2/alloc.c2
-rw-r--r--fs/ocfs2/aops.c32
-rw-r--r--fs/ocfs2/buffer_head_io.c4
-rw-r--r--fs/ocfs2/cluster/heartbeat.c40
-rw-r--r--fs/ocfs2/cluster/masklog.h3
-rw-r--r--fs/ocfs2/dir.c12
-rw-r--r--fs/ocfs2/dlm/dlmmaster.c8
-rw-r--r--fs/ocfs2/dlm/dlmrecovery.c7
-rw-r--r--fs/ocfs2/file.c5
-rw-r--r--fs/ocfs2/journal.h3
-rw-r--r--fs/ocfs2/move_extents.c11
-rw-r--r--fs/ocfs2/namei.c2
-rw-r--r--fs/ocfs2/refcounttree.c20
-rw-r--r--fs/ocfs2/resize.c12
-rw-r--r--fs/ocfs2/stackglue.c8
-rw-r--r--fs/ocfs2/suballoc.c4
-rw-r--r--fs/ocfs2/super.c4
-rw-r--r--fs/ocfs2/xattr.c28
-rw-r--r--fs/proc/Kconfig4
-rw-r--r--fs/proc/inode.c16
-rw-r--r--fs/proc/kcore.c3
-rw-r--r--fs/proc/meminfo.c5
-rw-r--r--fs/proc/task_mmu.c17
-rw-r--r--fs/sync.c15
-rw-r--r--fs/xfs/xfs_super.c2
-rw-r--r--include/asm-generic/bitops/find.h12
-rw-r--r--include/linux/binfmts.h3
-rw-r--r--include/linux/compat.h4
-rw-r--r--include/linux/genalloc.h2
-rw-r--r--include/linux/init.h6
-rw-r--r--include/linux/jump_label.h4
-rw-r--r--include/linux/kernel-page-flags.h1
-rw-r--r--include/linux/list.h79
-rw-r--r--include/linux/memblock.h24
-rw-r--r--include/linux/memory_hotplug.h11
-rw-r--r--include/linux/mempolicy.h5
-rw-r--r--include/linux/mfd/samsung/core.h1
-rw-r--r--include/linux/mfd/samsung/rtc.h11
-rw-r--r--include/linux/mm.h4
-rw-r--r--include/linux/mman.h2
-rw-r--r--include/linux/msg.h6
-rw-r--r--include/linux/oom.h5
-rw-r--r--include/linux/platform_data/lm3630_bl.h57
-rw-r--r--include/linux/platform_data/lm3630a_bl.h65
-rw-r--r--include/linux/platform_data/lp855x.h19
-rw-r--r--include/linux/rbtree.h16
-rw-r--r--include/linux/sched.h13
-rw-r--r--include/linux/syscalls.h4
-rw-r--r--include/linux/vm_event_item.h1
-rw-r--r--include/linux/writeback.h2
-rw-r--r--include/trace/events/kmem.h10
-rw-r--r--include/trace/events/writeback.h6
-rw-r--r--include/uapi/asm-generic/errno.h2
-rw-r--r--init/Kconfig8
-rw-r--r--init/do_mounts.c2
-rw-r--r--init/do_mounts_rd.c12
-rw-r--r--init/main.c40
-rw-r--r--ipc/msgutil.c20
-rw-r--r--ipc/util.c4
-rw-r--r--ipc/util.h4
-rw-r--r--kernel/cpu.c29
-rw-r--r--kernel/delayacct.c7
-rw-r--r--kernel/events/core.c3
-rw-r--r--kernel/gcov/Kconfig30
-rw-r--r--kernel/gcov/Makefile32
-rw-r--r--kernel/gcov/base.c32
-rw-r--r--kernel/gcov/fs.c52
-rw-r--r--kernel/gcov/gcc_3_4.c115
-rw-r--r--kernel/gcov/gcc_4_7.c560
-rw-r--r--kernel/gcov/gcov.h65
-rw-r--r--kernel/kprobes.c4
-rw-r--r--kernel/kthread.c73
-rw-r--r--kernel/module.c103
-rw-r--r--kernel/panic.c2
-rw-r--r--kernel/printk/printk.c35
-rw-r--r--kernel/ptrace.c3
-rw-r--r--kernel/sys.c1
-rw-r--r--kernel/sysctl.c5
-rw-r--r--kernel/sysctl_binary.c6
-rw-r--r--kernel/taskstats.c16
-rw-r--r--lib/Kconfig.debug9
-rw-r--r--lib/Makefile2
-rw-r--r--lib/debugobjects.c2
-rw-r--r--lib/digsig.c2
-rw-r--r--lib/genalloc.c28
-rw-r--r--lib/percpu_test.c138
-rw-r--r--lib/show_mem.c39
-rw-r--r--lib/vsprintf.c35
-rw-r--r--mm/Kconfig17
-rw-r--r--mm/bootmem.c8
-rw-r--r--mm/compaction.c7
-rw-r--r--mm/huge_memory.c78
-rw-r--r--mm/kmemleak.c4
-rw-r--r--mm/ksm.c4
-rw-r--r--mm/memblock.c124
-rw-r--r--mm/memcontrol.c97
-rw-r--r--mm/memory-failure.c36
-rw-r--r--mm/memory.c2
-rw-r--r--mm/memory_hotplug.c65
-rw-r--r--mm/mempolicy.c62
-rw-r--r--mm/mmap.c16
-rw-r--r--mm/mprotect.c10
-rw-r--r--mm/nobootmem.c25
-rw-r--r--mm/nommu.c3
-rw-r--r--mm/page_alloc.c34
-rw-r--r--mm/readahead.c8
-rw-r--r--mm/slab.c2
-rw-r--r--mm/slab.h6
-rw-r--r--mm/slab_common.c2
-rw-r--r--mm/slub.c2
-rw-r--r--mm/sparse.c53
-rw-r--r--mm/swapfile.c16
-rw-r--r--mm/util.c13
-rw-r--r--mm/vmalloc.c48
-rw-r--r--mm/vmstat.c22
-rw-r--r--mm/zswap.c195
-rwxr-xr-xscripts/checkpatch.pl166
-rw-r--r--scripts/docproc.c14
-rw-r--r--scripts/gen_initramfs_list.sh24
-rwxr-xr-xscripts/kernel-doc6
-rw-r--r--scripts/mod/modpost.c15
-rw-r--r--scripts/sortextable.c24
-rw-r--r--scripts/sortextable.h26
-rw-r--r--sound/soc/davinci/davinci-pcm.c3
-rw-r--r--sound/soc/pxa/mmp-pcm.c3
-rw-r--r--tools/vm/page-types.c32
-rw-r--r--usr/Makefile23
-rw-r--r--usr/gen_init_cpio.c27
287 files changed, 5004 insertions, 2378 deletions
diff --git a/CREDITS b/CREDITS
index b928516eea90..4fc997d58ab2 100644
--- a/CREDITS
+++ b/CREDITS
@@ -2576,7 +2576,7 @@ S: Toronto, Ontario
2576S: Canada 2576S: Canada
2577 2577
2578N: Zwane Mwaikambo 2578N: Zwane Mwaikambo
2579E: zwane@arm.linux.org.uk 2579E: zwanem@gmail.com
2580D: Various driver hacking 2580D: Various driver hacking
2581D: Lowlevel x86 kernel hacking 2581D: Lowlevel x86 kernel hacking
2582D: General debugging 2582D: General debugging
@@ -2895,6 +2895,11 @@ S: Framewood Road
2895S: Wexham SL3 6PJ 2895S: Wexham SL3 6PJ
2896S: United Kingdom 2896S: United Kingdom
2897 2897
2898N: Richard Purdie
2899E: rpurdie@rpsys.net
2900D: Backlight subsystem maintainer
2901S: United Kingdom
2902
2898N: Daniel Quinlan 2903N: Daniel Quinlan
2899E: quinlan@pathname.com 2904E: quinlan@pathname.com
2900W: http://www.pathname.com/~quinlan/ 2905W: http://www.pathname.com/~quinlan/
diff --git a/Documentation/ABI/README b/Documentation/ABI/README
index 10069828568b..1fafc4b0753b 100644
--- a/Documentation/ABI/README
+++ b/Documentation/ABI/README
@@ -72,3 +72,16 @@ kernel tree without going through the obsolete state first.
72 72
73It's up to the developer to place their interfaces in the category they 73It's up to the developer to place their interfaces in the category they
74wish for it to start out in. 74wish for it to start out in.
75
76
77Notable bits of non-ABI, which should not under any circumstances be considered
78stable:
79
80- Kconfig. Userspace should not rely on the presence or absence of any
81 particular Kconfig symbol, in /proc/config.gz, in the copy of .config
82 commonly installed to /boot, or in any invocation of the kernel build
83 process.
84
85- Kernel-internal symbols. Do not rely on the presence, absence, location, or
86 type of any kernel symbol, either in System.map files or the kernel binary
87 itself. See Documentation/stable_api_nonsense.txt.
diff --git a/Documentation/backlight/lp855x-driver.txt b/Documentation/backlight/lp855x-driver.txt
index 1c732f0c6758..01bce243d3d7 100644
--- a/Documentation/backlight/lp855x-driver.txt
+++ b/Documentation/backlight/lp855x-driver.txt
@@ -4,7 +4,8 @@ Kernel driver lp855x
4Backlight driver for LP855x ICs 4Backlight driver for LP855x ICs
5 5
6Supported chips: 6Supported chips:
7 Texas Instruments LP8550, LP8551, LP8552, LP8553, LP8556 and LP8557 7 Texas Instruments LP8550, LP8551, LP8552, LP8553, LP8555, LP8556 and
8 LP8557
8 9
9Author: Milo(Woogyom) Kim <milo.kim@ti.com> 10Author: Milo(Woogyom) Kim <milo.kim@ti.com>
10 11
@@ -24,7 +25,7 @@ Value : pwm based or register based
24 25
252) chip_id 262) chip_id
26The lp855x chip id. 27The lp855x chip id.
27Value : lp8550/lp8551/lp8552/lp8553/lp8556/lp8557 28Value : lp8550/lp8551/lp8552/lp8553/lp8555/lp8556/lp8557
28 29
29Platform data for lp855x 30Platform data for lp855x
30------------------------ 31------------------------
diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt
index 8af4ad121828..e2bc132608fd 100644
--- a/Documentation/cgroups/memory.txt
+++ b/Documentation/cgroups/memory.txt
@@ -573,15 +573,19 @@ an memcg since the pages are allowed to be allocated from any physical
573node. One of the use cases is evaluating application performance by 573node. One of the use cases is evaluating application performance by
574combining this information with the application's CPU allocation. 574combining this information with the application's CPU allocation.
575 575
576We export "total", "file", "anon" and "unevictable" pages per-node for 576Each memcg's numa_stat file includes "total", "file", "anon" and "unevictable"
577each memcg. The ouput format of memory.numa_stat is: 577per-node page counts including "hierarchical_<counter>" which sums up all
578hierarchical children's values in addition to the memcg's own value.
579
580The ouput format of memory.numa_stat is:
578 581
579total=<total pages> N0=<node 0 pages> N1=<node 1 pages> ... 582total=<total pages> N0=<node 0 pages> N1=<node 1 pages> ...
580file=<total file pages> N0=<node 0 pages> N1=<node 1 pages> ... 583file=<total file pages> N0=<node 0 pages> N1=<node 1 pages> ...
581anon=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ... 584anon=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ...
582unevictable=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ... 585unevictable=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ...
586hierarchical_<counter>=<counter pages> N0=<node 0 pages> N1=<node 1 pages> ...
583 587
584And we have total = file + anon + unevictable. 588The "total" count is sum of file + anon + unevictable.
585 589
5866. Hierarchy support 5906. Hierarchy support
587 591
diff --git a/Documentation/cpu-hotplug.txt b/Documentation/cpu-hotplug.txt
index 786dc82f98ce..8cb9938cc47e 100644
--- a/Documentation/cpu-hotplug.txt
+++ b/Documentation/cpu-hotplug.txt
@@ -5,7 +5,7 @@
5 Rusty Russell <rusty@rustcorp.com.au> 5 Rusty Russell <rusty@rustcorp.com.au>
6 Srivatsa Vaddagiri <vatsa@in.ibm.com> 6 Srivatsa Vaddagiri <vatsa@in.ibm.com>
7 i386: 7 i386:
8 Zwane Mwaikambo <zwane@arm.linux.org.uk> 8 Zwane Mwaikambo <zwanem@gmail.com>
9 ppc64: 9 ppc64:
10 Nathan Lynch <nathanl@austin.ibm.com> 10 Nathan Lynch <nathanl@austin.ibm.com>
11 Joel Schopp <jschopp@austin.ibm.com> 11 Joel Schopp <jschopp@austin.ibm.com>
diff --git a/Documentation/devicetree/bindings/video/backlight/lp855x.txt b/Documentation/devicetree/bindings/video/backlight/lp855x.txt
index 1482103d288f..96e83a56048e 100644
--- a/Documentation/devicetree/bindings/video/backlight/lp855x.txt
+++ b/Documentation/devicetree/bindings/video/backlight/lp855x.txt
@@ -2,7 +2,7 @@ lp855x bindings
2 2
3Required properties: 3Required properties:
4 - compatible: "ti,lp8550", "ti,lp8551", "ti,lp8552", "ti,lp8553", 4 - compatible: "ti,lp8550", "ti,lp8551", "ti,lp8552", "ti,lp8553",
5 "ti,lp8556", "ti,lp8557" 5 "ti,lp8555", "ti,lp8556", "ti,lp8557"
6 - reg: I2C slave address (u8) 6 - reg: I2C slave address (u8)
7 - dev-ctrl: Value of DEVICE CONTROL register (u8). It depends on the device. 7 - dev-ctrl: Value of DEVICE CONTROL register (u8). It depends on the device.
8 8
@@ -15,6 +15,33 @@ Optional properties:
15 15
16Example: 16Example:
17 17
18 /* LP8555 */
19 backlight@2c {
20 compatible = "ti,lp8555";
21 reg = <0x2c>;
22
23 dev-ctrl = /bits/ 8 <0x00>;
24 pwm-period = <10000>;
25
26 /* 4V OV, 4 output LED0 string enabled */
27 rom_14h {
28 rom-addr = /bits/ 8 <0x14>;
29 rom-val = /bits/ 8 <0xcf>;
30 };
31
32 /* Heavy smoothing, 24ms ramp time step */
33 rom_15h {
34 rom-addr = /bits/ 8 <0x15>;
35 rom-val = /bits/ 8 <0xc7>;
36 };
37
38 /* 4 output LED1 string enabled */
39 rom_19h {
40 rom-addr = /bits/ 8 <0x19>;
41 rom-val = /bits/ 8 <0x0f>;
42 };
43 };
44
18 /* LP8556 */ 45 /* LP8556 */
19 backlight@2c { 46 backlight@2c {
20 compatible = "ti,lp8556"; 47 compatible = "ti,lp8556";
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 823c95faebd2..22d89aa37218 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -460,6 +460,7 @@ manner. The codes are the following:
460 nl - non-linear mapping 460 nl - non-linear mapping
461 ar - architecture specific flag 461 ar - architecture specific flag
462 dd - do not include area into core dump 462 dd - do not include area into core dump
463 sd - soft-dirty flag
463 mm - mixed map area 464 mm - mixed map area
464 hg - huge page advise flag 465 hg - huge page advise flag
465 nh - no-huge page advise flag 466 nh - no-huge page advise flag
diff --git a/Documentation/filesystems/vfat.txt b/Documentation/filesystems/vfat.txt
index aa1f459fa6cf..4a93e98b290a 100644
--- a/Documentation/filesystems/vfat.txt
+++ b/Documentation/filesystems/vfat.txt
@@ -307,7 +307,7 @@ the following:
307 307
308 <proceeding files...> 308 <proceeding files...>
309 <slot #3, id = 0x43, characters = "h is long"> 309 <slot #3, id = 0x43, characters = "h is long">
310 <slot #2, id = 0x02, characters = "xtension which"> 310 <slot #2, id = 0x02, characters = "xtension whic">
311 <slot #1, id = 0x01, characters = "My Big File.E"> 311 <slot #1, id = 0x01, characters = "My Big File.E">
312 <directory entry, name = "MYBIGFIL.EXT"> 312 <directory entry, name = "MYBIGFIL.EXT">
313 313
diff --git a/Documentation/gcov.txt b/Documentation/gcov.txt
index e7ca6478cd93..7b727783db7e 100644
--- a/Documentation/gcov.txt
+++ b/Documentation/gcov.txt
@@ -50,6 +50,10 @@ Configure the kernel with:
50 CONFIG_DEBUG_FS=y 50 CONFIG_DEBUG_FS=y
51 CONFIG_GCOV_KERNEL=y 51 CONFIG_GCOV_KERNEL=y
52 52
53select the gcc's gcov format, default is autodetect based on gcc version:
54
55 CONFIG_GCOV_FORMAT_AUTODETECT=y
56
53and to get coverage data for the entire kernel: 57and to get coverage data for the entire kernel:
54 58
55 CONFIG_GCOV_PROFILE_ALL=y 59 CONFIG_GCOV_PROFILE_ALL=y
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index fd3ecedc084d..9ca3e74a10e1 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1070,6 +1070,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
1070 VIA, nVidia) 1070 VIA, nVidia)
1071 verbose: show contents of HPET registers during setup 1071 verbose: show contents of HPET registers during setup
1072 1072
1073 hpet_mmap= [X86, HPET_MMAP] Allow userspace to mmap HPET
1074 registers. Default set by CONFIG_HPET_MMAP_DEFAULT.
1075
1073 hugepages= [HW,X86-32,IA-64] HugeTLB pages to allocate at boot. 1076 hugepages= [HW,X86-32,IA-64] HugeTLB pages to allocate at boot.
1074 hugepagesz= [HW,IA-64,PPC,X86-64] The size of the HugeTLB pages. 1077 hugepagesz= [HW,IA-64,PPC,X86-64] The size of the HugeTLB pages.
1075 On x86-64 and powerpc, this option can be specified 1078 On x86-64 and powerpc, this option can be specified
@@ -1775,6 +1778,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
1775 that the amount of memory usable for all allocations 1778 that the amount of memory usable for all allocations
1776 is not too small. 1779 is not too small.
1777 1780
1781 movable_node [KNL,X86] Boot-time switch to enable the effects
1782 of CONFIG_MOVABLE_NODE=y. See mm/Kconfig for details.
1783
1778 MTD_Partition= [MTD] 1784 MTD_Partition= [MTD]
1779 Format: <name>,<region-number>,<size>,<offset> 1785 Format: <name>,<region-number>,<size>,<offset>
1780 1786
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 4273b2d71a27..26b7ee491df8 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -290,13 +290,24 @@ Default value is "/sbin/hotplug".
290kptr_restrict: 290kptr_restrict:
291 291
292This toggle indicates whether restrictions are placed on 292This toggle indicates whether restrictions are placed on
293exposing kernel addresses via /proc and other interfaces. When 293exposing kernel addresses via /proc and other interfaces.
294kptr_restrict is set to (0), there are no restrictions. When 294
295kptr_restrict is set to (1), the default, kernel pointers 295When kptr_restrict is set to (0), the default, there are no restrictions.
296printed using the %pK format specifier will be replaced with 0's 296
297unless the user has CAP_SYSLOG. When kptr_restrict is set to 297When kptr_restrict is set to (1), kernel pointers printed using the %pK
298(2), kernel pointers printed using %pK will be replaced with 0's 298format specifier will be replaced with 0's unless the user has CAP_SYSLOG
299regardless of privileges. 299and effective user and group ids are equal to the real ids. This is
300because %pK checks are done at read() time rather than open() time, so
301if permissions are elevated between the open() and the read() (e.g via
302a setuid binary) then %pK will not leak kernel pointers to unprivileged
303users. Note, this is a temporary solution only. The correct long-term
304solution is to do the permission checks at open() time. Consider removing
305world read permissions from files that use %pK, and using dmesg_restrict
306to protect against uses of %pK in dmesg(8) if leaking kernel pointer
307values to unprivileged users is a concern.
308
309When kptr_restrict is set to (2), kernel pointers printed using
310%pK will be replaced with 0's regardless of privileges.
300 311
301============================================================== 312==============================================================
302 313
diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt
index 79a797eb3e87..1fbd4eb7b64a 100644
--- a/Documentation/sysctl/vm.txt
+++ b/Documentation/sysctl/vm.txt
@@ -119,8 +119,11 @@ other appears as 0 when read.
119 119
120dirty_background_ratio 120dirty_background_ratio
121 121
122Contains, as a percentage of total system memory, the number of pages at which 122Contains, as a percentage of total available memory that contains free pages
123the background kernel flusher threads will start writing out dirty data. 123and reclaimable pages, the number of pages at which the background kernel
124flusher threads will start writing out dirty data.
125
126The total avaiable memory is not equal to total system memory.
124 127
125============================================================== 128==============================================================
126 129
@@ -151,9 +154,11 @@ interval will be written out next time a flusher thread wakes up.
151 154
152dirty_ratio 155dirty_ratio
153 156
154Contains, as a percentage of total system memory, the number of pages at which 157Contains, as a percentage of total available memory that contains free pages
155a process which is generating disk writes will itself start writing out dirty 158and reclaimable pages, the number of pages at which a process which is
156data. 159generating disk writes will itself start writing out dirty data.
160
161The total avaiable memory is not equal to total system memory.
157 162
158============================================================== 163==============================================================
159 164
diff --git a/Documentation/trace/tracepoints.txt b/Documentation/trace/tracepoints.txt
index ac4170dd0f24..6b018b53177a 100644
--- a/Documentation/trace/tracepoints.txt
+++ b/Documentation/trace/tracepoints.txt
@@ -114,3 +114,8 @@ core kernel image or in modules.
114If the tracepoint has to be used in kernel modules, an 114If the tracepoint has to be used in kernel modules, an
115EXPORT_TRACEPOINT_SYMBOL_GPL() or EXPORT_TRACEPOINT_SYMBOL() can be 115EXPORT_TRACEPOINT_SYMBOL_GPL() or EXPORT_TRACEPOINT_SYMBOL() can be
116used to export the defined tracepoints. 116used to export the defined tracepoints.
117
118Note: The convenience macro TRACE_EVENT provides an alternative way to
119 define tracepoints. Check http://lwn.net/Articles/379903,
120 http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362
121 for a series of articles with more details.
diff --git a/Documentation/vm/zswap.txt b/Documentation/vm/zswap.txt
index 7e492d8aaeaf..00c3d31e7971 100644
--- a/Documentation/vm/zswap.txt
+++ b/Documentation/vm/zswap.txt
@@ -8,7 +8,7 @@ significant performance improvement if reads from the compressed cache are
8faster than reads from a swap device. 8faster than reads from a swap device.
9 9
10NOTE: Zswap is a new feature as of v3.11 and interacts heavily with memory 10NOTE: Zswap is a new feature as of v3.11 and interacts heavily with memory
11reclaim. This interaction has not be fully explored on the large set of 11reclaim. This interaction has not been fully explored on the large set of
12potential configurations and workloads that exist. For this reason, zswap 12potential configurations and workloads that exist. For this reason, zswap
13is a work in progress and should be considered experimental. 13is a work in progress and should be considered experimental.
14 14
@@ -23,7 +23,7 @@ Some potential benefits:
23    drastically reducing life-shortening writes. 23    drastically reducing life-shortening writes.
24 24
25Zswap evicts pages from compressed cache on an LRU basis to the backing swap 25Zswap evicts pages from compressed cache on an LRU basis to the backing swap
26device when the compressed pool reaches it size limit. This requirement had 26device when the compressed pool reaches its size limit. This requirement had
27been identified in prior community discussions. 27been identified in prior community discussions.
28 28
29To enabled zswap, the "enabled" attribute must be set to 1 at boot time. e.g. 29To enabled zswap, the "enabled" attribute must be set to 1 at boot time. e.g.
@@ -37,7 +37,7 @@ the backing swap device in the case that the compressed pool is full.
37 37
38Zswap makes use of zbud for the managing the compressed memory pool. Each 38Zswap makes use of zbud for the managing the compressed memory pool. Each
39allocation in zbud is not directly accessible by address. Rather, a handle is 39allocation in zbud is not directly accessible by address. Rather, a handle is
40return by the allocation routine and that handle must be mapped before being 40returned by the allocation routine and that handle must be mapped before being
41accessed. The compressed memory pool grows on demand and shrinks as compressed 41accessed. The compressed memory pool grows on demand and shrinks as compressed
42pages are freed. The pool is not preallocated. 42pages are freed. The pool is not preallocated.
43 43
@@ -56,7 +56,7 @@ in the swap_map goes to 0) the swap code calls the zswap invalidate function,
56via frontswap, to free the compressed entry. 56via frontswap, to free the compressed entry.
57 57
58Zswap seeks to be simple in its policies. Sysfs attributes allow for one user 58Zswap seeks to be simple in its policies. Sysfs attributes allow for one user
59controlled policies: 59controlled policy:
60* max_pool_percent - The maximum percentage of memory that the compressed 60* max_pool_percent - The maximum percentage of memory that the compressed
61 pool can occupy. 61 pool can occupy.
62 62
diff --git a/MAINTAINERS b/MAINTAINERS
index 051e4dc5b70f..5cfa91b1974a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1661,7 +1661,6 @@ S: Maintained
1661F: drivers/net/wireless/b43legacy/ 1661F: drivers/net/wireless/b43legacy/
1662 1662
1663BACKLIGHT CLASS/SUBSYSTEM 1663BACKLIGHT CLASS/SUBSYSTEM
1664M: Richard Purdie <rpurdie@rpsys.net>
1665M: Jingoo Han <jg1.han@samsung.com> 1664M: Jingoo Han <jg1.han@samsung.com>
1666S: Maintained 1665S: Maintained
1667F: drivers/video/backlight/ 1666F: drivers/video/backlight/
@@ -2373,7 +2372,7 @@ F: kernel/cpuset.c
2373 2372
2374CRAMFS FILESYSTEM 2373CRAMFS FILESYSTEM
2375W: http://sourceforge.net/projects/cramfs/ 2374W: http://sourceforge.net/projects/cramfs/
2376S: Orphan 2375S: Orphan / Obsolete
2377F: Documentation/filesystems/cramfs.txt 2376F: Documentation/filesystems/cramfs.txt
2378F: fs/cramfs/ 2377F: fs/cramfs/
2379 2378
@@ -7320,7 +7319,7 @@ S: Odd Fixes
7320F: drivers/media/usb/tlg2300/ 7319F: drivers/media/usb/tlg2300/
7321 7320
7322SC1200 WDT DRIVER 7321SC1200 WDT DRIVER
7323M: Zwane Mwaikambo <zwane@arm.linux.org.uk> 7322M: Zwane Mwaikambo <zwanem@gmail.com>
7324S: Maintained 7323S: Maintained
7325F: drivers/watchdog/sc1200wdt.c 7324F: drivers/watchdog/sc1200wdt.c
7326 7325
diff --git a/Makefile b/Makefile
index 67077ad6edbb..606a66cdcdb8 100644
--- a/Makefile
+++ b/Makefile
@@ -720,6 +720,22 @@ mod_strip_cmd = true
720endif # INSTALL_MOD_STRIP 720endif # INSTALL_MOD_STRIP
721export mod_strip_cmd 721export mod_strip_cmd
722 722
723# Select initial ramdisk compression format, default is gzip(1).
724# This shall be used by the dracut(8) tool while creating an initramfs image.
725#
726INITRD_COMPRESS=gzip
727ifeq ($(CONFIG_RD_BZIP2), y)
728 INITRD_COMPRESS=bzip2
729else ifeq ($(CONFIG_RD_LZMA), y)
730 INITRD_COMPRESS=lzma
731else ifeq ($(CONFIG_RD_XZ), y)
732 INITRD_COMPRESS=xz
733else ifeq ($(CONFIG_RD_LZO), y)
734 INITRD_COMPRESS=lzo
735else ifeq ($(CONFIG_RD_LZ4), y)
736 INITRD_COMPRESS=lz4
737endif
738export INITRD_COMPRESS
723 739
724ifdef CONFIG_MODULE_SIG_ALL 740ifdef CONFIG_MODULE_SIG_ALL
725MODSECKEY = ./signing_key.priv 741MODSECKEY = ./signing_key.priv
diff --git a/arch/alpha/include/uapi/asm/errno.h b/arch/alpha/include/uapi/asm/errno.h
index e5f29ca28180..17f92aa76b2f 100644
--- a/arch/alpha/include/uapi/asm/errno.h
+++ b/arch/alpha/include/uapi/asm/errno.h
@@ -43,7 +43,7 @@
43 43
44#define EUSERS 68 /* Too many users */ 44#define EUSERS 68 /* Too many users */
45#define EDQUOT 69 /* Quota exceeded */ 45#define EDQUOT 69 /* Quota exceeded */
46#define ESTALE 70 /* Stale NFS file handle */ 46#define ESTALE 70 /* Stale file handle */
47#define EREMOTE 71 /* Object is remote */ 47#define EREMOTE 71 /* Object is remote */
48 48
49#define ENOLCK 77 /* No record locks available */ 49#define ENOLCK 77 /* No record locks available */
diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index 084dc8896986..c9dfff3b8008 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -40,7 +40,7 @@
40void *module_alloc(unsigned long size) 40void *module_alloc(unsigned long size)
41{ 41{
42 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 42 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
43 GFP_KERNEL, PAGE_KERNEL_EXEC, -1, 43 GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
44 __builtin_return_address(0)); 44 __builtin_return_address(0));
45} 45}
46#endif 46#endif
diff --git a/arch/arm/mach-davinci/sram.c b/arch/arm/mach-davinci/sram.c
index f18928b073f5..8540dddf1fbd 100644
--- a/arch/arm/mach-davinci/sram.c
+++ b/arch/arm/mach-davinci/sram.c
@@ -25,7 +25,6 @@ struct gen_pool *sram_get_gen_pool(void)
25 25
26void *sram_alloc(size_t len, dma_addr_t *dma) 26void *sram_alloc(size_t len, dma_addr_t *dma)
27{ 27{
28 unsigned long vaddr;
29 dma_addr_t dma_base = davinci_soc_info.sram_dma; 28 dma_addr_t dma_base = davinci_soc_info.sram_dma;
30 29
31 if (dma) 30 if (dma)
@@ -33,13 +32,7 @@ void *sram_alloc(size_t len, dma_addr_t *dma)
33 if (!sram_pool || (dma && !dma_base)) 32 if (!sram_pool || (dma && !dma_base))
34 return NULL; 33 return NULL;
35 34
36 vaddr = gen_pool_alloc(sram_pool, len); 35 return gen_pool_dma_alloc(sram_pool, len, dma);
37 if (!vaddr)
38 return NULL;
39
40 if (dma)
41 *dma = gen_pool_virt_to_phys(sram_pool, vaddr);
42 return (void *)vaddr;
43 36
44} 37}
45EXPORT_SYMBOL(sram_alloc); 38EXPORT_SYMBOL(sram_alloc);
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 2c28a6cf93e6..e2ad0d87721f 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -29,7 +29,7 @@
29void *module_alloc(unsigned long size) 29void *module_alloc(unsigned long size)
30{ 30{
31 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 31 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
32 GFP_KERNEL, PAGE_KERNEL_EXEC, -1, 32 GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
33 __builtin_return_address(0)); 33 __builtin_return_address(0));
34} 34}
35 35
diff --git a/arch/cris/include/asm/io.h b/arch/cris/include/asm/io.h
index 5d3047e5563b..4353cf239a13 100644
--- a/arch/cris/include/asm/io.h
+++ b/arch/cris/include/asm/io.h
@@ -3,6 +3,7 @@
3 3
4#include <asm/page.h> /* for __va, __pa */ 4#include <asm/page.h> /* for __va, __pa */
5#include <arch/io.h> 5#include <arch/io.h>
6#include <asm-generic/iomap.h>
6#include <linux/kernel.h> 7#include <linux/kernel.h>
7 8
8struct cris_io_operations 9struct cris_io_operations
diff --git a/arch/ia64/include/asm/processor.h b/arch/ia64/include/asm/processor.h
index e0a899a1a8a6..5a84b3a50741 100644
--- a/arch/ia64/include/asm/processor.h
+++ b/arch/ia64/include/asm/processor.h
@@ -319,7 +319,7 @@ struct thread_struct {
319 regs->loadrs = 0; \ 319 regs->loadrs = 0; \
320 regs->r8 = get_dumpable(current->mm); /* set "don't zap registers" flag */ \ 320 regs->r8 = get_dumpable(current->mm); /* set "don't zap registers" flag */ \
321 regs->r12 = new_sp - 16; /* allocate 16 byte scratch area */ \ 321 regs->r12 = new_sp - 16; /* allocate 16 byte scratch area */ \
322 if (unlikely(!get_dumpable(current->mm))) { \ 322 if (unlikely(get_dumpable(current->mm) != SUID_DUMP_USER)) { \
323 /* \ 323 /* \
324 * Zap scratch regs to avoid leaking bits between processes with different \ 324 * Zap scratch regs to avoid leaking bits between processes with different \
325 * uid/privileges. \ 325 * uid/privileges. \
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index b6f7f43424ec..88504abf5704 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -357,9 +357,7 @@ int vmemmap_find_next_valid_pfn(int node, int i)
357 357
358 end_address = (unsigned long) &vmem_map[pgdat->node_start_pfn + i]; 358 end_address = (unsigned long) &vmem_map[pgdat->node_start_pfn + i];
359 end_address = PAGE_ALIGN(end_address); 359 end_address = PAGE_ALIGN(end_address);
360 360 stop_address = (unsigned long) &vmem_map[pgdat_end_pfn(pgdat)];
361 stop_address = (unsigned long) &vmem_map[
362 pgdat->node_start_pfn + pgdat->node_spanned_pages];
363 361
364 do { 362 do {
365 pgd_t *pgd; 363 pgd_t *pgd;
diff --git a/arch/metag/kernel/dma.c b/arch/metag/kernel/dma.c
index 8c00dedadc54..db589ad5dbc4 100644
--- a/arch/metag/kernel/dma.c
+++ b/arch/metag/kernel/dma.c
@@ -305,9 +305,7 @@ void dma_free_coherent(struct device *dev, size_t size,
305 305
306 if (pfn_valid(pfn)) { 306 if (pfn_valid(pfn)) {
307 struct page *page = pfn_to_page(pfn); 307 struct page *page = pfn_to_page(pfn);
308 ClearPageReserved(page); 308 __free_reserved_page(page);
309
310 __free_page(page);
311 continue; 309 continue;
312 } 310 }
313 } 311 }
diff --git a/arch/metag/mm/init.c b/arch/metag/mm/init.c
index 249fff66add3..3cd6288f65c2 100644
--- a/arch/metag/mm/init.c
+++ b/arch/metag/mm/init.c
@@ -148,7 +148,7 @@ static void __init bootmem_init_one_node(unsigned int nid)
148 if (!p->node_spanned_pages) 148 if (!p->node_spanned_pages)
149 return; 149 return;
150 150
151 end_pfn = p->node_start_pfn + p->node_spanned_pages; 151 end_pfn = pgdat_end_pfn(p);
152#ifdef CONFIG_HIGHMEM 152#ifdef CONFIG_HIGHMEM
153 if (end_pfn > max_low_pfn) 153 if (end_pfn > max_low_pfn)
154 end_pfn = max_low_pfn; 154 end_pfn = max_low_pfn;
diff --git a/arch/microblaze/mm/consistent.c b/arch/microblaze/mm/consistent.c
index 5226b09cbbb2..dbbf2246a260 100644
--- a/arch/microblaze/mm/consistent.c
+++ b/arch/microblaze/mm/consistent.c
@@ -176,8 +176,7 @@ void consistent_free(size_t size, void *vaddr)
176 page = virt_to_page(vaddr); 176 page = virt_to_page(vaddr);
177 177
178 do { 178 do {
179 ClearPageReserved(page); 179 __free_reserved_page(page);
180 __free_page(page);
181 page++; 180 page++;
182 } while (size -= PAGE_SIZE); 181 } while (size -= PAGE_SIZE);
183#else 182#else
@@ -194,9 +193,7 @@ void consistent_free(size_t size, void *vaddr)
194 pte_clear(&init_mm, (unsigned int)vaddr, ptep); 193 pte_clear(&init_mm, (unsigned int)vaddr, ptep);
195 if (pfn_valid(pfn)) { 194 if (pfn_valid(pfn)) {
196 page = pfn_to_page(pfn); 195 page = pfn_to_page(pfn);
197 196 __free_reserved_page(page);
198 ClearPageReserved(page);
199 __free_page(page);
200 } 197 }
201 } 198 }
202 vaddr += PAGE_SIZE; 199 vaddr += PAGE_SIZE;
diff --git a/arch/mips/include/uapi/asm/errno.h b/arch/mips/include/uapi/asm/errno.h
index 31575e2fd1bd..02d645d7aa9a 100644
--- a/arch/mips/include/uapi/asm/errno.h
+++ b/arch/mips/include/uapi/asm/errno.h
@@ -102,7 +102,7 @@
102#define EWOULDBLOCK EAGAIN /* Operation would block */ 102#define EWOULDBLOCK EAGAIN /* Operation would block */
103#define EALREADY 149 /* Operation already in progress */ 103#define EALREADY 149 /* Operation already in progress */
104#define EINPROGRESS 150 /* Operation now in progress */ 104#define EINPROGRESS 150 /* Operation now in progress */
105#define ESTALE 151 /* Stale NFS file handle */ 105#define ESTALE 151 /* Stale file handle */
106#define ECANCELED 158 /* AIO operation canceled */ 106#define ECANCELED 158 /* AIO operation canceled */
107 107
108/* 108/*
diff --git a/arch/parisc/include/uapi/asm/errno.h b/arch/parisc/include/uapi/asm/errno.h
index 135ad6047e51..f3a8aa554841 100644
--- a/arch/parisc/include/uapi/asm/errno.h
+++ b/arch/parisc/include/uapi/asm/errno.h
@@ -37,7 +37,7 @@
37#define EBADMSG 67 /* Not a data message */ 37#define EBADMSG 67 /* Not a data message */
38#define EUSERS 68 /* Too many users */ 38#define EUSERS 68 /* Too many users */
39#define EDQUOT 69 /* Quota exceeded */ 39#define EDQUOT 69 /* Quota exceeded */
40#define ESTALE 70 /* Stale NFS file handle */ 40#define ESTALE 70 /* Stale file handle */
41#define EREMOTE 71 /* Object is remote */ 41#define EREMOTE 71 /* Object is remote */
42#define EOVERFLOW 72 /* Value too large for defined data type */ 42#define EOVERFLOW 72 /* Value too large for defined data type */
43 43
diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
index 2a625fb063e1..50dfafc3f2c1 100644
--- a/arch/parisc/kernel/module.c
+++ b/arch/parisc/kernel/module.c
@@ -219,7 +219,7 @@ void *module_alloc(unsigned long size)
219 * init_data correctly */ 219 * init_data correctly */
220 return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, 220 return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
221 GFP_KERNEL | __GFP_HIGHMEM, 221 GFP_KERNEL | __GFP_HIGHMEM,
222 PAGE_KERNEL_RWX, -1, 222 PAGE_KERNEL_RWX, NUMA_NO_NODE,
223 __builtin_return_address(0)); 223 __builtin_return_address(0));
224} 224}
225 225
diff --git a/arch/powerpc/mm/dma-noncoherent.c b/arch/powerpc/mm/dma-noncoherent.c
index 6747eece84af..7b6c10750179 100644
--- a/arch/powerpc/mm/dma-noncoherent.c
+++ b/arch/powerpc/mm/dma-noncoherent.c
@@ -287,9 +287,7 @@ void __dma_free_coherent(size_t size, void *vaddr)
287 pte_clear(&init_mm, addr, ptep); 287 pte_clear(&init_mm, addr, ptep);
288 if (pfn_valid(pfn)) { 288 if (pfn_valid(pfn)) {
289 struct page *page = pfn_to_page(pfn); 289 struct page *page = pfn_to_page(pfn);
290 290 __free_reserved_page(page);
291 ClearPageReserved(page);
292 __free_page(page);
293 } 291 }
294 } 292 }
295 addr += PAGE_SIZE; 293 addr += PAGE_SIZE;
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index d67db4bd672d..90bb6d9409bf 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -633,8 +633,6 @@ static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
633 633
634/* 634/*
635 * This function frees user-level page tables of a process. 635 * This function frees user-level page tables of a process.
636 *
637 * Must be called with pagetable lock held.
638 */ 636 */
639void hugetlb_free_pgd_range(struct mmu_gather *tlb, 637void hugetlb_free_pgd_range(struct mmu_gather *tlb,
640 unsigned long addr, unsigned long end, 638 unsigned long addr, unsigned long end,
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 33d67844062c..078d3e00a616 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -938,8 +938,7 @@ static void __init mark_reserved_regions_for_nid(int nid)
938 unsigned long start_pfn = physbase >> PAGE_SHIFT; 938 unsigned long start_pfn = physbase >> PAGE_SHIFT;
939 unsigned long end_pfn = PFN_UP(physbase + size); 939 unsigned long end_pfn = PFN_UP(physbase + size);
940 struct node_active_region node_ar; 940 struct node_active_region node_ar;
941 unsigned long node_end_pfn = node->node_start_pfn + 941 unsigned long node_end_pfn = pgdat_end_pfn(node);
942 node->node_spanned_pages;
943 942
944 /* 943 /*
945 * Check to make sure that this memblock.reserved area is 944 * Check to make sure that this memblock.reserved area is
diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
index 7845e15a17df..b89b59158b95 100644
--- a/arch/s390/kernel/module.c
+++ b/arch/s390/kernel/module.c
@@ -50,7 +50,7 @@ void *module_alloc(unsigned long size)
50 if (PAGE_ALIGN(size) > MODULES_LEN) 50 if (PAGE_ALIGN(size) > MODULES_LEN)
51 return NULL; 51 return NULL;
52 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 52 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
53 GFP_KERNEL, PAGE_KERNEL, -1, 53 GFP_KERNEL, PAGE_KERNEL, NUMA_NO_NODE,
54 __builtin_return_address(0)); 54 __builtin_return_address(0));
55} 55}
56#endif 56#endif
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index 6bcb045d2bd2..9b436c21195e 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -64,6 +64,11 @@ static unsigned long mmap_rnd(void)
64 return (get_random_int() & 0x7ffUL) << PAGE_SHIFT; 64 return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
65} 65}
66 66
67static unsigned long mmap_base_legacy(void)
68{
69 return TASK_UNMAPPED_BASE + mmap_rnd();
70}
71
67static inline unsigned long mmap_base(void) 72static inline unsigned long mmap_base(void)
68{ 73{
69 unsigned long gap = rlimit(RLIMIT_STACK); 74 unsigned long gap = rlimit(RLIMIT_STACK);
@@ -89,7 +94,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
89 * bit is set, or if the expected stack growth is unlimited: 94 * bit is set, or if the expected stack growth is unlimited:
90 */ 95 */
91 if (mmap_is_legacy()) { 96 if (mmap_is_legacy()) {
92 mm->mmap_base = TASK_UNMAPPED_BASE; 97 mm->mmap_base = mmap_base_legacy();
93 mm->get_unmapped_area = arch_get_unmapped_area; 98 mm->get_unmapped_area = arch_get_unmapped_area;
94 } else { 99 } else {
95 mm->mmap_base = mmap_base(); 100 mm->mmap_base = mmap_base();
@@ -164,7 +169,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
164 * bit is set, or if the expected stack growth is unlimited: 169 * bit is set, or if the expected stack growth is unlimited:
165 */ 170 */
166 if (mmap_is_legacy()) { 171 if (mmap_is_legacy()) {
167 mm->mmap_base = TASK_UNMAPPED_BASE; 172 mm->mmap_base = mmap_base_legacy();
168 mm->get_unmapped_area = s390_get_unmapped_area; 173 mm->get_unmapped_area = s390_get_unmapped_area;
169 } else { 174 } else {
170 mm->mmap_base = mmap_base(); 175 mm->mmap_base = mmap_base();
diff --git a/arch/sh/include/asm/fpu.h b/arch/sh/include/asm/fpu.h
index 06c4281aab65..09fc2bc8a790 100644
--- a/arch/sh/include/asm/fpu.h
+++ b/arch/sh/include/asm/fpu.h
@@ -46,7 +46,7 @@ static inline void __unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
46 save_fpu(tsk); 46 save_fpu(tsk);
47 release_fpu(regs); 47 release_fpu(regs);
48 } else 48 } else
49 tsk->fpu_counter = 0; 49 tsk->thread.fpu_counter = 0;
50} 50}
51 51
52static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs) 52static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
diff --git a/arch/sh/include/asm/processor_32.h b/arch/sh/include/asm/processor_32.h
index e699a12cdcca..18e0377f72bb 100644
--- a/arch/sh/include/asm/processor_32.h
+++ b/arch/sh/include/asm/processor_32.h
@@ -111,6 +111,16 @@ struct thread_struct {
111 111
112 /* Extended processor state */ 112 /* Extended processor state */
113 union thread_xstate *xstate; 113 union thread_xstate *xstate;
114
115 /*
116 * fpu_counter contains the number of consecutive context switches
117 * that the FPU is used. If this is over a threshold, the lazy fpu
118 * saving becomes unlazy to save the trap. This is an unsigned char
119 * so that after 256 times the counter wraps and the behavior turns
120 * lazy again; this to deal with bursty apps that only use FPU for
121 * a short time
122 */
123 unsigned char fpu_counter;
114}; 124};
115 125
116#define INIT_THREAD { \ 126#define INIT_THREAD { \
diff --git a/arch/sh/include/asm/processor_64.h b/arch/sh/include/asm/processor_64.h
index 1cc7d3197143..eedd4f625d07 100644
--- a/arch/sh/include/asm/processor_64.h
+++ b/arch/sh/include/asm/processor_64.h
@@ -126,6 +126,16 @@ struct thread_struct {
126 126
127 /* floating point info */ 127 /* floating point info */
128 union thread_xstate *xstate; 128 union thread_xstate *xstate;
129
130 /*
131 * fpu_counter contains the number of consecutive context switches
132 * that the FPU is used. If this is over a threshold, the lazy fpu
133 * saving becomes unlazy to save the trap. This is an unsigned char
134 * so that after 256 times the counter wraps and the behavior turns
135 * lazy again; this to deal with bursty apps that only use FPU for
136 * a short time
137 */
138 unsigned char fpu_counter;
129}; 139};
130 140
131#define INIT_MMAP \ 141#define INIT_MMAP \
diff --git a/arch/sh/kernel/cpu/fpu.c b/arch/sh/kernel/cpu/fpu.c
index f8f7af51c128..4e332244ea75 100644
--- a/arch/sh/kernel/cpu/fpu.c
+++ b/arch/sh/kernel/cpu/fpu.c
@@ -44,7 +44,7 @@ void __fpu_state_restore(void)
44 restore_fpu(tsk); 44 restore_fpu(tsk);
45 45
46 task_thread_info(tsk)->status |= TS_USEDFPU; 46 task_thread_info(tsk)->status |= TS_USEDFPU;
47 tsk->fpu_counter++; 47 tsk->thread.fpu_counter++;
48} 48}
49 49
50void fpu_state_restore(struct pt_regs *regs) 50void fpu_state_restore(struct pt_regs *regs)
diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c
index ebd3933005b4..2885fc9d9dcd 100644
--- a/arch/sh/kernel/process_32.c
+++ b/arch/sh/kernel/process_32.c
@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
156#endif 156#endif
157 ti->addr_limit = KERNEL_DS; 157 ti->addr_limit = KERNEL_DS;
158 ti->status &= ~TS_USEDFPU; 158 ti->status &= ~TS_USEDFPU;
159 p->fpu_counter = 0; 159 p->thread.fpu_counter = 0;
160 return 0; 160 return 0;
161 } 161 }
162 *childregs = *current_pt_regs(); 162 *childregs = *current_pt_regs();
@@ -189,7 +189,7 @@ __switch_to(struct task_struct *prev, struct task_struct *next)
189 unlazy_fpu(prev, task_pt_regs(prev)); 189 unlazy_fpu(prev, task_pt_regs(prev));
190 190
191 /* we're going to use this soon, after a few expensive things */ 191 /* we're going to use this soon, after a few expensive things */
192 if (next->fpu_counter > 5) 192 if (next->thread.fpu_counter > 5)
193 prefetch(next_t->xstate); 193 prefetch(next_t->xstate);
194 194
195#ifdef CONFIG_MMU 195#ifdef CONFIG_MMU
@@ -207,7 +207,7 @@ __switch_to(struct task_struct *prev, struct task_struct *next)
207 * restore of the math state immediately to avoid the trap; the 207 * restore of the math state immediately to avoid the trap; the
208 * chances of needing FPU soon are obviously high now 208 * chances of needing FPU soon are obviously high now
209 */ 209 */
210 if (next->fpu_counter > 5) 210 if (next->thread.fpu_counter > 5)
211 __fpu_state_restore(); 211 __fpu_state_restore();
212 212
213 return prev; 213 return prev;
diff --git a/arch/sh/kernel/process_64.c b/arch/sh/kernel/process_64.c
index 174d124b419e..e2062e643341 100644
--- a/arch/sh/kernel/process_64.c
+++ b/arch/sh/kernel/process_64.c
@@ -374,7 +374,7 @@ asmlinkage void ret_from_kernel_thread(void);
374int copy_thread(unsigned long clone_flags, unsigned long usp, 374int copy_thread(unsigned long clone_flags, unsigned long usp,
375 unsigned long arg, struct task_struct *p) 375 unsigned long arg, struct task_struct *p)
376{ 376{
377 struct pt_regs *childregs, *regs = current_pt_regs(); 377 struct pt_regs *childregs;
378 378
379#ifdef CONFIG_SH_FPU 379#ifdef CONFIG_SH_FPU
380 /* can't happen for a kernel thread */ 380 /* can't happen for a kernel thread */
@@ -393,7 +393,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
393 if (unlikely(p->flags & PF_KTHREAD)) { 393 if (unlikely(p->flags & PF_KTHREAD)) {
394 memset(childregs, 0, sizeof(struct pt_regs)); 394 memset(childregs, 0, sizeof(struct pt_regs));
395 childregs->regs[2] = (unsigned long)arg; 395 childregs->regs[2] = (unsigned long)arg;
396 childregs->regs[3] = (unsigned long)fn; 396 childregs->regs[3] = (unsigned long)usp;
397 childregs->sr = (1 << 30); /* not user_mode */ 397 childregs->sr = (1 << 30); /* not user_mode */
398 childregs->sr |= SR_FD; /* Invalidate FPU flag */ 398 childregs->sr |= SR_FD; /* Invalidate FPU flag */
399 p->thread.pc = (unsigned long) ret_from_kernel_thread; 399 p->thread.pc = (unsigned long) ret_from_kernel_thread;
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 33890fd267cb..2d089fe2cba9 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -231,7 +231,7 @@ static void __init bootmem_init_one_node(unsigned int nid)
231 if (!p->node_spanned_pages) 231 if (!p->node_spanned_pages)
232 return; 232 return;
233 233
234 end_pfn = p->node_start_pfn + p->node_spanned_pages; 234 end_pfn = pgdat_end_pfn(p);
235 235
236 total_pages = bootmem_bootmap_pages(p->node_spanned_pages); 236 total_pages = bootmem_bootmap_pages(p->node_spanned_pages);
237 237
diff --git a/arch/sparc/include/uapi/asm/errno.h b/arch/sparc/include/uapi/asm/errno.h
index c351aba997b7..20423e172853 100644
--- a/arch/sparc/include/uapi/asm/errno.h
+++ b/arch/sparc/include/uapi/asm/errno.h
@@ -40,7 +40,7 @@
40#define EPROCLIM 67 /* SUNOS: Too many processes */ 40#define EPROCLIM 67 /* SUNOS: Too many processes */
41#define EUSERS 68 /* Too many users */ 41#define EUSERS 68 /* Too many users */
42#define EDQUOT 69 /* Quota exceeded */ 42#define EDQUOT 69 /* Quota exceeded */
43#define ESTALE 70 /* Stale NFS file handle */ 43#define ESTALE 70 /* Stale file handle */
44#define EREMOTE 71 /* Object is remote */ 44#define EREMOTE 71 /* Object is remote */
45#define ENOSTR 72 /* Device not a stream */ 45#define ENOSTR 72 /* Device not a stream */
46#define ETIME 73 /* Timer expired */ 46#define ETIME 73 /* Timer expired */
diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c
index 4435488ebe25..97655e0fd243 100644
--- a/arch/sparc/kernel/module.c
+++ b/arch/sparc/kernel/module.c
@@ -29,7 +29,7 @@ static void *module_map(unsigned long size)
29 if (PAGE_ALIGN(size) > MODULES_LEN) 29 if (PAGE_ALIGN(size) > MODULES_LEN)
30 return NULL; 30 return NULL;
31 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 31 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
32 GFP_KERNEL, PAGE_KERNEL, -1, 32 GFP_KERNEL, PAGE_KERNEL, NUMA_NO_NODE,
33 __builtin_return_address(0)); 33 __builtin_return_address(0));
34} 34}
35#else 35#else
diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
index 4d0bda7b11e3..c49a613c6452 100644
--- a/arch/x86/include/asm/fpu-internal.h
+++ b/arch/x86/include/asm/fpu-internal.h
@@ -365,7 +365,7 @@ static inline void drop_fpu(struct task_struct *tsk)
365 * Forget coprocessor state.. 365 * Forget coprocessor state..
366 */ 366 */
367 preempt_disable(); 367 preempt_disable();
368 tsk->fpu_counter = 0; 368 tsk->thread.fpu_counter = 0;
369 __drop_fpu(tsk); 369 __drop_fpu(tsk);
370 clear_used_math(); 370 clear_used_math();
371 preempt_enable(); 371 preempt_enable();
@@ -424,7 +424,7 @@ static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct ta
424 * or if the past 5 consecutive context-switches used math. 424 * or if the past 5 consecutive context-switches used math.
425 */ 425 */
426 fpu.preload = tsk_used_math(new) && (use_eager_fpu() || 426 fpu.preload = tsk_used_math(new) && (use_eager_fpu() ||
427 new->fpu_counter > 5); 427 new->thread.fpu_counter > 5);
428 if (__thread_has_fpu(old)) { 428 if (__thread_has_fpu(old)) {
429 if (!__save_init_fpu(old)) 429 if (!__save_init_fpu(old))
430 cpu = ~0; 430 cpu = ~0;
@@ -433,16 +433,16 @@ static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct ta
433 433
434 /* Don't change CR0.TS if we just switch! */ 434 /* Don't change CR0.TS if we just switch! */
435 if (fpu.preload) { 435 if (fpu.preload) {
436 new->fpu_counter++; 436 new->thread.fpu_counter++;
437 __thread_set_has_fpu(new); 437 __thread_set_has_fpu(new);
438 prefetch(new->thread.fpu.state); 438 prefetch(new->thread.fpu.state);
439 } else if (!use_eager_fpu()) 439 } else if (!use_eager_fpu())
440 stts(); 440 stts();
441 } else { 441 } else {
442 old->fpu_counter = 0; 442 old->thread.fpu_counter = 0;
443 old->thread.fpu.last_cpu = ~0; 443 old->thread.fpu.last_cpu = ~0;
444 if (fpu.preload) { 444 if (fpu.preload) {
445 new->fpu_counter++; 445 new->thread.fpu_counter++;
446 if (!use_eager_fpu() && fpu_lazy_restore(new, cpu)) 446 if (!use_eager_fpu() && fpu_lazy_restore(new, cpu))
447 fpu.preload = 0; 447 fpu.preload = 0;
448 else 448 else
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 987c75ecc334..7b034a4057f9 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -488,6 +488,15 @@ struct thread_struct {
488 unsigned long iopl; 488 unsigned long iopl;
489 /* Max allowed port in the bitmap, in bytes: */ 489 /* Max allowed port in the bitmap, in bytes: */
490 unsigned io_bitmap_max; 490 unsigned io_bitmap_max;
491 /*
492 * fpu_counter contains the number of consecutive context switches
493 * that the FPU is used. If this is over a threshold, the lazy fpu
494 * saving becomes unlazy to save the trap. This is an unsigned char
495 * so that after 256 times the counter wraps and the behavior turns
496 * lazy again; this to deal with bursty apps that only use FPU for
497 * a short time
498 */
499 unsigned char fpu_counter;
491}; 500};
492 501
493/* 502/*
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 5d576ab34403..e8368c6dd2a2 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -100,7 +100,7 @@ void unlazy_fpu(struct task_struct *tsk)
100 __save_init_fpu(tsk); 100 __save_init_fpu(tsk);
101 __thread_fpu_end(tsk); 101 __thread_fpu_end(tsk);
102 } else 102 } else
103 tsk->fpu_counter = 0; 103 tsk->thread.fpu_counter = 0;
104 preempt_enable(); 104 preempt_enable();
105} 105}
106EXPORT_SYMBOL(unlazy_fpu); 106EXPORT_SYMBOL(unlazy_fpu);
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 216a4d754b0c..18be189368bb 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -49,7 +49,7 @@ void *module_alloc(unsigned long size)
49 return NULL; 49 return NULL;
50 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 50 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
51 GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC, 51 GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
52 -1, __builtin_return_address(0)); 52 NUMA_NO_NODE, __builtin_return_address(0));
53} 53}
54 54
55#ifdef CONFIG_X86_32 55#ifdef CONFIG_X86_32
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index c2ec1aa6d454..6f1236c29c4b 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -153,7 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
153 childregs->orig_ax = -1; 153 childregs->orig_ax = -1;
154 childregs->cs = __KERNEL_CS | get_kernel_rpl(); 154 childregs->cs = __KERNEL_CS | get_kernel_rpl();
155 childregs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED; 155 childregs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED;
156 p->fpu_counter = 0; 156 p->thread.fpu_counter = 0;
157 p->thread.io_bitmap_ptr = NULL; 157 p->thread.io_bitmap_ptr = NULL;
158 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps)); 158 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
159 return 0; 159 return 0;
@@ -166,7 +166,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
166 p->thread.ip = (unsigned long) ret_from_fork; 166 p->thread.ip = (unsigned long) ret_from_fork;
167 task_user_gs(p) = get_user_gs(current_pt_regs()); 167 task_user_gs(p) = get_user_gs(current_pt_regs());
168 168
169 p->fpu_counter = 0; 169 p->thread.fpu_counter = 0;
170 p->thread.io_bitmap_ptr = NULL; 170 p->thread.io_bitmap_ptr = NULL;
171 tsk = current; 171 tsk = current;
172 err = -ENOMEM; 172 err = -ENOMEM;
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 45ab4d6fc8a7..10fe4c189621 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -163,7 +163,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
163 p->thread.sp = (unsigned long) childregs; 163 p->thread.sp = (unsigned long) childregs;
164 p->thread.usersp = me->thread.usersp; 164 p->thread.usersp = me->thread.usersp;
165 set_tsk_thread_flag(p, TIF_FORK); 165 set_tsk_thread_flag(p, TIF_FORK);
166 p->fpu_counter = 0; 166 p->thread.fpu_counter = 0;
167 p->thread.io_bitmap_ptr = NULL; 167 p->thread.io_bitmap_ptr = NULL;
168 168
169 savesegment(gs, p->thread.gsindex); 169 savesegment(gs, p->thread.gsindex);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 918d489fa53d..cb233bc9dee3 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1121,8 +1121,6 @@ void __init setup_arch(char **cmdline_p)
1121 acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start); 1121 acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
1122#endif 1122#endif
1123 1123
1124 reserve_crashkernel();
1125
1126 vsmp_init(); 1124 vsmp_init();
1127 1125
1128 io_delay_init(); 1126 io_delay_init();
@@ -1135,6 +1133,13 @@ void __init setup_arch(char **cmdline_p)
1135 early_acpi_boot_init(); 1133 early_acpi_boot_init();
1136 1134
1137 initmem_init(); 1135 initmem_init();
1136
1137 /*
1138 * Reserve memory for crash kernel after SRAT is parsed so that it
1139 * won't consume hotpluggable memory.
1140 */
1141 reserve_crashkernel();
1142
1138 memblock_find_dma_reserve(); 1143 memblock_find_dma_reserve();
1139 1144
1140#ifdef CONFIG_KVM_GUEST 1145#ifdef CONFIG_KVM_GUEST
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 729aa779ff75..996ce2313ce6 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -653,7 +653,7 @@ void math_state_restore(void)
653 return; 653 return;
654 } 654 }
655 655
656 tsk->fpu_counter++; 656 tsk->thread.fpu_counter++;
657} 657}
658EXPORT_SYMBOL_GPL(math_state_restore); 658EXPORT_SYMBOL_GPL(math_state_restore);
659 659
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index ce32017c5e38..f97130618113 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -53,12 +53,12 @@ __ref void *alloc_low_pages(unsigned int num)
53 if ((pgt_buf_end + num) > pgt_buf_top || !can_use_brk_pgt) { 53 if ((pgt_buf_end + num) > pgt_buf_top || !can_use_brk_pgt) {
54 unsigned long ret; 54 unsigned long ret;
55 if (min_pfn_mapped >= max_pfn_mapped) 55 if (min_pfn_mapped >= max_pfn_mapped)
56 panic("alloc_low_page: ran out of memory"); 56 panic("alloc_low_pages: ran out of memory");
57 ret = memblock_find_in_range(min_pfn_mapped << PAGE_SHIFT, 57 ret = memblock_find_in_range(min_pfn_mapped << PAGE_SHIFT,
58 max_pfn_mapped << PAGE_SHIFT, 58 max_pfn_mapped << PAGE_SHIFT,
59 PAGE_SIZE * num , PAGE_SIZE); 59 PAGE_SIZE * num , PAGE_SIZE);
60 if (!ret) 60 if (!ret)
61 panic("alloc_low_page: can not alloc memory"); 61 panic("alloc_low_pages: can not alloc memory");
62 memblock_reserve(ret, PAGE_SIZE * num); 62 memblock_reserve(ret, PAGE_SIZE * num);
63 pfn = ret >> PAGE_SHIFT; 63 pfn = ret >> PAGE_SHIFT;
64 } else { 64 } else {
@@ -418,27 +418,27 @@ static unsigned long __init get_new_step_size(unsigned long step_size)
418 return step_size << 5; 418 return step_size << 5;
419} 419}
420 420
421void __init init_mem_mapping(void) 421/**
422 * memory_map_top_down - Map [map_start, map_end) top down
423 * @map_start: start address of the target memory range
424 * @map_end: end address of the target memory range
425 *
426 * This function will setup direct mapping for memory range
427 * [map_start, map_end) in top-down. That said, the page tables
428 * will be allocated at the end of the memory, and we map the
429 * memory in top-down.
430 */
431static void __init memory_map_top_down(unsigned long map_start,
432 unsigned long map_end)
422{ 433{
423 unsigned long end, real_end, start, last_start; 434 unsigned long real_end, start, last_start;
424 unsigned long step_size; 435 unsigned long step_size;
425 unsigned long addr; 436 unsigned long addr;
426 unsigned long mapped_ram_size = 0; 437 unsigned long mapped_ram_size = 0;
427 unsigned long new_mapped_ram_size; 438 unsigned long new_mapped_ram_size;
428 439
429 probe_page_size_mask();
430
431#ifdef CONFIG_X86_64
432 end = max_pfn << PAGE_SHIFT;
433#else
434 end = max_low_pfn << PAGE_SHIFT;
435#endif
436
437 /* the ISA range is always mapped regardless of memory holes */
438 init_memory_mapping(0, ISA_END_ADDRESS);
439
440 /* xen has big range in reserved near end of ram, skip it at first.*/ 440 /* xen has big range in reserved near end of ram, skip it at first.*/
441 addr = memblock_find_in_range(ISA_END_ADDRESS, end, PMD_SIZE, PMD_SIZE); 441 addr = memblock_find_in_range(map_start, map_end, PMD_SIZE, PMD_SIZE);
442 real_end = addr + PMD_SIZE; 442 real_end = addr + PMD_SIZE;
443 443
444 /* step_size need to be small so pgt_buf from BRK could cover it */ 444 /* step_size need to be small so pgt_buf from BRK could cover it */
@@ -453,13 +453,13 @@ void __init init_mem_mapping(void)
453 * end of RAM in [min_pfn_mapped, max_pfn_mapped) used as new pages 453 * end of RAM in [min_pfn_mapped, max_pfn_mapped) used as new pages
454 * for page table. 454 * for page table.
455 */ 455 */
456 while (last_start > ISA_END_ADDRESS) { 456 while (last_start > map_start) {
457 if (last_start > step_size) { 457 if (last_start > step_size) {
458 start = round_down(last_start - 1, step_size); 458 start = round_down(last_start - 1, step_size);
459 if (start < ISA_END_ADDRESS) 459 if (start < map_start)
460 start = ISA_END_ADDRESS; 460 start = map_start;
461 } else 461 } else
462 start = ISA_END_ADDRESS; 462 start = map_start;
463 new_mapped_ram_size = init_range_memory_mapping(start, 463 new_mapped_ram_size = init_range_memory_mapping(start,
464 last_start); 464 last_start);
465 last_start = start; 465 last_start = start;
@@ -470,8 +470,89 @@ void __init init_mem_mapping(void)
470 mapped_ram_size += new_mapped_ram_size; 470 mapped_ram_size += new_mapped_ram_size;
471 } 471 }
472 472
473 if (real_end < end) 473 if (real_end < map_end)
474 init_range_memory_mapping(real_end, end); 474 init_range_memory_mapping(real_end, map_end);
475}
476
477/**
478 * memory_map_bottom_up - Map [map_start, map_end) bottom up
479 * @map_start: start address of the target memory range
480 * @map_end: end address of the target memory range
481 *
482 * This function will setup direct mapping for memory range
483 * [map_start, map_end) in bottom-up. Since we have limited the
484 * bottom-up allocation above the kernel, the page tables will
485 * be allocated just above the kernel and we map the memory
486 * in [map_start, map_end) in bottom-up.
487 */
488static void __init memory_map_bottom_up(unsigned long map_start,
489 unsigned long map_end)
490{
491 unsigned long next, new_mapped_ram_size, start;
492 unsigned long mapped_ram_size = 0;
493 /* step_size need to be small so pgt_buf from BRK could cover it */
494 unsigned long step_size = PMD_SIZE;
495
496 start = map_start;
497 min_pfn_mapped = start >> PAGE_SHIFT;
498
499 /*
500 * We start from the bottom (@map_start) and go to the top (@map_end).
501 * The memblock_find_in_range() gets us a block of RAM from the
502 * end of RAM in [min_pfn_mapped, max_pfn_mapped) used as new pages
503 * for page table.
504 */
505 while (start < map_end) {
506 if (map_end - start > step_size) {
507 next = round_up(start + 1, step_size);
508 if (next > map_end)
509 next = map_end;
510 } else
511 next = map_end;
512
513 new_mapped_ram_size = init_range_memory_mapping(start, next);
514 start = next;
515
516 if (new_mapped_ram_size > mapped_ram_size)
517 step_size = get_new_step_size(step_size);
518 mapped_ram_size += new_mapped_ram_size;
519 }
520}
521
522void __init init_mem_mapping(void)
523{
524 unsigned long end;
525
526 probe_page_size_mask();
527
528#ifdef CONFIG_X86_64
529 end = max_pfn << PAGE_SHIFT;
530#else
531 end = max_low_pfn << PAGE_SHIFT;
532#endif
533
534 /* the ISA range is always mapped regardless of memory holes */
535 init_memory_mapping(0, ISA_END_ADDRESS);
536
537 /*
538 * If the allocation is in bottom-up direction, we setup direct mapping
539 * in bottom-up, otherwise we setup direct mapping in top-down.
540 */
541 if (memblock_bottom_up()) {
542 unsigned long kernel_end = __pa_symbol(_end);
543
544 /*
545 * we need two separate calls here. This is because we want to
546 * allocate page tables above the kernel. So we first map
547 * [kernel_end, end) to make memory above the kernel be mapped
548 * as soon as possible. And then use page tables allocated above
549 * the kernel to map [ISA_END_ADDRESS, kernel_end).
550 */
551 memory_map_bottom_up(kernel_end, end);
552 memory_map_bottom_up(ISA_END_ADDRESS, kernel_end);
553 } else {
554 memory_map_top_down(ISA_END_ADDRESS, end);
555 }
475 556
476#ifdef CONFIG_X86_64 557#ifdef CONFIG_X86_64
477 if (max_pfn > max_low_pfn) { 558 if (max_pfn > max_low_pfn) {
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 8bf93bae1f13..24aec58d6afd 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -567,6 +567,17 @@ static int __init numa_init(int (*init_func)(void))
567 ret = init_func(); 567 ret = init_func();
568 if (ret < 0) 568 if (ret < 0)
569 return ret; 569 return ret;
570
571 /*
572 * We reset memblock back to the top-down direction
573 * here because if we configured ACPI_NUMA, we have
574 * parsed SRAT in init_func(). It is ok to have the
575 * reset here even if we did't configure ACPI_NUMA
576 * or acpi numa init fails and fallbacks to dummy
577 * numa init.
578 */
579 memblock_set_bottom_up(false);
580
570 ret = numa_cleanup_meminfo(&numa_meminfo); 581 ret = numa_cleanup_meminfo(&numa_meminfo);
571 if (ret < 0) 582 if (ret < 0)
572 return ret; 583 return ret;
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 14219972c745..fa3243d71c76 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -522,10 +522,16 @@ config HPET_MMAP
522 If you say Y here, user applications will be able to mmap 522 If you say Y here, user applications will be able to mmap
523 the HPET registers. 523 the HPET registers.
524 524
525config HPET_MMAP_DEFAULT
526 bool "Enable HPET MMAP access by default"
527 default y
528 depends on HPET_MMAP
529 help
525 In some hardware implementations, the page containing HPET 530 In some hardware implementations, the page containing HPET
526 registers may also contain other things that shouldn't be 531 registers may also contain other things that shouldn't be
527 exposed to the user. If this applies to your hardware, 532 exposed to the user. This option selects the default (if
528 say N here. 533 kernel parameter hpet_mmap is not set) user access to the
534 registers for applications that require it.
529 535
530config HANGCHECK_TIMER 536config HANGCHECK_TIMER
531 tristate "Hangcheck timer" 537 tristate "Hangcheck timer"
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index dca5834685cf..5d9c31dfc905 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -367,12 +367,29 @@ static unsigned int hpet_poll(struct file *file, poll_table * wait)
367 return 0; 367 return 0;
368} 368}
369 369
370#ifdef CONFIG_HPET_MMAP
371#ifdef CONFIG_HPET_MMAP_DEFAULT
372static int hpet_mmap_enabled = 1;
373#else
374static int hpet_mmap_enabled = 0;
375#endif
376
377static __init int hpet_mmap_enable(char *str)
378{
379 get_option(&str, &hpet_mmap_enabled);
380 pr_info("HPET mmap %s\n", hpet_mmap_enabled ? "enabled" : "disabled");
381 return 1;
382}
383__setup("hpet_mmap", hpet_mmap_enable);
384
370static int hpet_mmap(struct file *file, struct vm_area_struct *vma) 385static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
371{ 386{
372#ifdef CONFIG_HPET_MMAP
373 struct hpet_dev *devp; 387 struct hpet_dev *devp;
374 unsigned long addr; 388 unsigned long addr;
375 389
390 if (!hpet_mmap_enabled)
391 return -EACCES;
392
376 devp = file->private_data; 393 devp = file->private_data;
377 addr = devp->hd_hpets->hp_hpet_phys; 394 addr = devp->hd_hpets->hp_hpet_phys;
378 395
@@ -381,10 +398,13 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
381 398
382 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 399 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
383 return vm_iomap_memory(vma, addr, PAGE_SIZE); 400 return vm_iomap_memory(vma, addr, PAGE_SIZE);
401}
384#else 402#else
403static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
404{
385 return -ENOSYS; 405 return -ENOSYS;
386#endif
387} 406}
407#endif
388 408
389static int hpet_fasync(int fd, struct file *file, int on) 409static int hpet_fasync(int fd, struct file *file, int on)
390{ 410{
diff --git a/drivers/dma/mmp_tdma.c b/drivers/dma/mmp_tdma.c
index 38cb517fb2eb..d3b6358e5a27 100644
--- a/drivers/dma/mmp_tdma.c
+++ b/drivers/dma/mmp_tdma.c
@@ -350,12 +350,7 @@ struct mmp_tdma_desc *mmp_tdma_alloc_descriptor(struct mmp_tdma_chan *tdmac)
350 if (!gpool) 350 if (!gpool)
351 return NULL; 351 return NULL;
352 352
353 tdmac->desc_arr = (void *)gen_pool_alloc(gpool, size); 353 tdmac->desc_arr = gen_pool_dma_alloc(gpool, size, &tdmac->desc_arr_phys);
354 if (!tdmac->desc_arr)
355 return NULL;
356
357 tdmac->desc_arr_phys = gen_pool_virt_to_phys(gpool,
358 (unsigned long)tdmac->desc_arr);
359 354
360 return tdmac->desc_arr; 355 return tdmac->desc_arr;
361} 356}
diff --git a/drivers/iommu/omap-iopgtable.h b/drivers/iommu/omap-iopgtable.h
index f4003d568a92..b6f9a51746ca 100644
--- a/drivers/iommu/omap-iopgtable.h
+++ b/drivers/iommu/omap-iopgtable.h
@@ -95,4 +95,4 @@ static inline phys_addr_t omap_iommu_translate(u32 d, u32 va, u32 mask)
95#define iopte_offset(iopgd, da) (iopgd_page_vaddr(iopgd) + iopte_index(da)) 95#define iopte_offset(iopgd, da) (iopgd_page_vaddr(iopgd) + iopte_index(da))
96 96
97#define to_iommu(dev) \ 97#define to_iommu(dev) \
98 ((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))) 98 (platform_get_drvdata(to_platform_device(dev)))
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 449d2fec9e87..4993610051ee 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -3232,13 +3232,12 @@ static int coda_probe(struct platform_device *pdev)
3232 dev->iram_size = CODA7_IRAM_SIZE; 3232 dev->iram_size = CODA7_IRAM_SIZE;
3233 break; 3233 break;
3234 } 3234 }
3235 dev->iram_vaddr = gen_pool_alloc(dev->iram_pool, dev->iram_size); 3235 dev->iram_vaddr = (unsigned long)gen_pool_dma_alloc(dev->iram_pool,
3236 dev->iram_size, (dma_addr_t *)&dev->iram_paddr);
3236 if (!dev->iram_vaddr) { 3237 if (!dev->iram_vaddr) {
3237 dev_err(&pdev->dev, "unable to alloc iram\n"); 3238 dev_err(&pdev->dev, "unable to alloc iram\n");
3238 return -ENOMEM; 3239 return -ENOMEM;
3239 } 3240 }
3240 dev->iram_paddr = gen_pool_virt_to_phys(dev->iram_pool,
3241 dev->iram_vaddr);
3242 3241
3243 platform_set_drvdata(pdev, dev); 3242 platform_set_drvdata(pdev, dev);
3244 3243
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 08e70232062f..9188ef5d677e 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -401,7 +401,7 @@ again:
401 sizeof(struct ms_status_register))) 401 sizeof(struct ms_status_register)))
402 return 0; 402 return 0;
403 403
404 msb->state = MSB_RP_RECEIVE_OOB_READ; 404 msb->state = MSB_RP_RECIVE_STATUS_REG;
405 return 0; 405 return 0;
406 406
407 case MSB_RP_RECIVE_STATUS_REG: 407 case MSB_RP_RECIVE_STATUS_REG:
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index f4176ca3a794..fc145d202c46 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -1023,8 +1023,8 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1023 } else 1023 } else
1024 attr_count = attr->count; 1024 attr_count = attr->count;
1025 1025
1026 msb->attr_group.attrs = kzalloc((attr_count + 1) 1026 msb->attr_group.attrs = kcalloc(attr_count + 1,
1027 * sizeof(struct attribute), 1027 sizeof(*msb->attr_group.attrs),
1028 GFP_KERNEL); 1028 GFP_KERNEL);
1029 if (!msb->attr_group.attrs) { 1029 if (!msb->attr_group.attrs) {
1030 rc = -ENOMEM; 1030 rc = -ENOMEM;
diff --git a/drivers/message/i2o/driver.c b/drivers/message/i2o/driver.c
index b6b92d760510..1b18a0d1d05b 100644
--- a/drivers/message/i2o/driver.c
+++ b/drivers/message/i2o/driver.c
@@ -105,7 +105,8 @@ int i2o_driver_register(struct i2o_driver *drv)
105 osm_err("too many drivers registered, increase " 105 osm_err("too many drivers registered, increase "
106 "max_drivers\n"); 106 "max_drivers\n");
107 spin_unlock_irqrestore(&i2o_drivers_lock, flags); 107 spin_unlock_irqrestore(&i2o_drivers_lock, flags);
108 return -EFAULT; 108 rc = -EFAULT;
109 goto out;
109 } 110 }
110 111
111 drv->context = i; 112 drv->context = i;
@@ -124,11 +125,14 @@ int i2o_driver_register(struct i2o_driver *drv)
124 } 125 }
125 126
126 rc = driver_register(&drv->driver); 127 rc = driver_register(&drv->driver);
127 if (rc) { 128 if (rc)
128 if (drv->event) { 129 goto out;
129 destroy_workqueue(drv->event_queue); 130
130 drv->event_queue = NULL; 131 return 0;
131 } 132out:
133 if (drv->event_queue) {
134 destroy_workqueue(drv->event_queue);
135 drv->event_queue = NULL;
132 } 136 }
133 137
134 return rc; 138 return rc;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
index 9fbeee522d2c..32c92abf5094 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
@@ -1217,9 +1217,6 @@ static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
1217 ETH_VLAN_FILTER_CLASSIFY, config); 1217 ETH_VLAN_FILTER_CLASSIFY, config);
1218} 1218}
1219 1219
1220#define list_next_entry(pos, member) \
1221 list_entry((pos)->member.next, typeof(*(pos)), member)
1222
1223/** 1220/**
1224 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element 1221 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1225 * 1222 *
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index 9966124ad988..f41bacfdc3dc 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -201,7 +201,7 @@ static struct platform_driver pps_gpio_driver = {
201 .driver = { 201 .driver = {
202 .name = PPS_GPIO_NAME, 202 .name = PPS_GPIO_NAME,
203 .owner = THIS_MODULE, 203 .owner = THIS_MODULE,
204 .of_match_table = of_match_ptr(pps_gpio_dt_ids), 204 .of_match_table = pps_gpio_dt_ids,
205 }, 205 },
206}; 206};
207 207
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 9654aa3c05cb..15f166a470a7 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -153,6 +153,16 @@ config RTC_DRV_88PM80X
153 This driver can also be built as a module. If so, the module 153 This driver can also be built as a module. If so, the module
154 will be called rtc-88pm80x. 154 will be called rtc-88pm80x.
155 155
156config RTC_DRV_AS3722
157 tristate "ams AS3722 RTC driver"
158 depends on MFD_AS3722
159 help
160 If you say yes here you get support for the RTC of ams AS3722 PMIC
161 chips.
162
163 This driver can also be built as a module. If so, the module
164 will be called rtc-as3722.
165
156config RTC_DRV_DS1307 166config RTC_DRV_DS1307
157 tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025" 167 tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025"
158 help 168 help
@@ -497,6 +507,16 @@ config RTC_DRV_RV3029C2
497 This driver can also be built as a module. If so, the module 507 This driver can also be built as a module. If so, the module
498 will be called rtc-rv3029c2. 508 will be called rtc-rv3029c2.
499 509
510config RTC_DRV_S5M
511 tristate "Samsung S5M series"
512 depends on MFD_SEC_CORE
513 help
514 If you say yes here you will get support for the
515 RTC of Samsung S5M PMIC series.
516
517 This driver can also be built as a module. If so, the module
518 will be called rtc-s5m.
519
500endif # I2C 520endif # I2C
501 521
502comment "SPI RTC drivers" 522comment "SPI RTC drivers"
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 2dff3d2009b5..27b4bd884066 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_RTC_DRV_88PM860X) += rtc-88pm860x.o
20obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o 20obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o
21obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o 21obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o
22obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o 22obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o
23obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
23obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o 24obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
24obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o 25obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
25obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o 26obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
@@ -107,6 +108,7 @@ obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o
107obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o 108obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
108obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o 109obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
109obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o 110obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
111obj-$(CONFIG_RTC_DRV_S5M) += rtc-s5m.o
110obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 112obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
111obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 113obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
112obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o 114obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 354c937a5866..0916089c7c3e 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -251,14 +251,15 @@ static SIMPLE_DEV_PM_OPS(pm80x_rtc_pm_ops, pm80x_rtc_suspend, pm80x_rtc_resume);
251static int pm80x_rtc_probe(struct platform_device *pdev) 251static int pm80x_rtc_probe(struct platform_device *pdev)
252{ 252{
253 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); 253 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
254 struct pm80x_platform_data *pm80x_pdata; 254 struct pm80x_platform_data *pm80x_pdata =
255 dev_get_platdata(pdev->dev.parent);
255 struct pm80x_rtc_pdata *pdata = NULL; 256 struct pm80x_rtc_pdata *pdata = NULL;
256 struct pm80x_rtc_info *info; 257 struct pm80x_rtc_info *info;
257 struct rtc_time tm; 258 struct rtc_time tm;
258 unsigned long ticks = 0; 259 unsigned long ticks = 0;
259 int ret; 260 int ret;
260 261
261 pdata = pdev->dev.platform_data; 262 pdata = dev_get_platdata(&pdev->dev);
262 if (pdata == NULL) 263 if (pdata == NULL)
263 dev_warn(&pdev->dev, "No platform data!\n"); 264 dev_warn(&pdev->dev, "No platform data!\n");
264 265
@@ -326,8 +327,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
326 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_RTC1_USE_XO, 327 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_RTC1_USE_XO,
327 PM800_RTC1_USE_XO); 328 PM800_RTC1_USE_XO);
328 329
329 if (pdev->dev.parent->platform_data) { 330 if (pm80x_pdata) {
330 pm80x_pdata = pdev->dev.parent->platform_data;
331 pdata = pm80x_pdata->rtc; 331 pdata = pm80x_pdata->rtc;
332 if (pdata) 332 if (pdata)
333 info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup; 333 info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup;
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index 4e30c85728e5..816504846cdd 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -316,7 +316,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
316 unsigned long ticks = 0; 316 unsigned long ticks = 0;
317 int ret; 317 int ret;
318 318
319 pdata = pdev->dev.platform_data; 319 pdata = dev_get_platdata(&pdev->dev);
320 320
321 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info), 321 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info),
322 GFP_KERNEL); 322 GFP_KERNEL);
diff --git a/drivers/rtc/rtc-as3722.c b/drivers/rtc/rtc-as3722.c
new file mode 100644
index 000000000000..9cfa8170a2d6
--- /dev/null
+++ b/drivers/rtc/rtc-as3722.c
@@ -0,0 +1,275 @@
1/*
2 * rtc-as3722.c - Real Time Clock driver for ams AS3722 PMICs
3 *
4 * Copyright (C) 2013 ams AG
5 * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
6 *
7 * Author: Florian Lobmaier <florian.lobmaier@ams.com>
8 * Author: Laxman Dewangan <ldewangan@nvidia.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/bcd.h>
22#include <linux/completion.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/ioctl.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/mfd/as3722.h>
29#include <linux/platform_device.h>
30#include <linux/rtc.h>
31#include <linux/time.h>
32
33#define AS3722_RTC_START_YEAR 2000
34struct as3722_rtc {
35 struct rtc_device *rtc;
36 struct device *dev;
37 struct as3722 *as3722;
38 int alarm_irq;
39 bool irq_enable;
40};
41
42static void as3722_time_to_reg(u8 *rbuff, struct rtc_time *tm)
43{
44 rbuff[0] = bin2bcd(tm->tm_sec);
45 rbuff[1] = bin2bcd(tm->tm_min);
46 rbuff[2] = bin2bcd(tm->tm_hour);
47 rbuff[3] = bin2bcd(tm->tm_mday);
48 rbuff[4] = bin2bcd(tm->tm_mon);
49 rbuff[5] = bin2bcd(tm->tm_year - (AS3722_RTC_START_YEAR - 1900));
50}
51
52static void as3722_reg_to_time(u8 *rbuff, struct rtc_time *tm)
53{
54 tm->tm_sec = bcd2bin(rbuff[0] & 0x7F);
55 tm->tm_min = bcd2bin(rbuff[1] & 0x7F);
56 tm->tm_hour = bcd2bin(rbuff[2] & 0x3F);
57 tm->tm_mday = bcd2bin(rbuff[3] & 0x3F);
58 tm->tm_mon = bcd2bin(rbuff[4] & 0x1F);
59 tm->tm_year = (AS3722_RTC_START_YEAR - 1900) + bcd2bin(rbuff[5] & 0x7F);
60 return;
61}
62
63static int as3722_rtc_read_time(struct device *dev, struct rtc_time *tm)
64{
65 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
66 struct as3722 *as3722 = as3722_rtc->as3722;
67 u8 as_time_array[6];
68 int ret;
69
70 ret = as3722_block_read(as3722, AS3722_RTC_SECOND_REG,
71 6, as_time_array);
72 if (ret < 0) {
73 dev_err(dev, "RTC_SECOND reg block read failed %d\n", ret);
74 return ret;
75 }
76 as3722_reg_to_time(as_time_array, tm);
77 return 0;
78}
79
80static int as3722_rtc_set_time(struct device *dev, struct rtc_time *tm)
81{
82 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
83 struct as3722 *as3722 = as3722_rtc->as3722;
84 u8 as_time_array[6];
85 int ret;
86
87 if (tm->tm_year < (AS3722_RTC_START_YEAR - 1900))
88 return -EINVAL;
89
90 as3722_time_to_reg(as_time_array, tm);
91 ret = as3722_block_write(as3722, AS3722_RTC_SECOND_REG, 6,
92 as_time_array);
93 if (ret < 0)
94 dev_err(dev, "RTC_SECOND reg block write failed %d\n", ret);
95 return ret;
96}
97
98static int as3722_rtc_alarm_irq_enable(struct device *dev,
99 unsigned int enabled)
100{
101 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
102
103 if (enabled && !as3722_rtc->irq_enable) {
104 enable_irq(as3722_rtc->alarm_irq);
105 as3722_rtc->irq_enable = true;
106 } else if (!enabled && as3722_rtc->irq_enable) {
107 disable_irq(as3722_rtc->alarm_irq);
108 as3722_rtc->irq_enable = false;
109 }
110 return 0;
111}
112
113static int as3722_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
114{
115 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
116 struct as3722 *as3722 = as3722_rtc->as3722;
117 u8 as_time_array[6];
118 int ret;
119
120 ret = as3722_block_read(as3722, AS3722_RTC_ALARM_SECOND_REG, 6,
121 as_time_array);
122 if (ret < 0) {
123 dev_err(dev, "RTC_ALARM_SECOND block read failed %d\n", ret);
124 return ret;
125 }
126
127 as3722_reg_to_time(as_time_array, &alrm->time);
128 return 0;
129}
130
131static int as3722_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
132{
133 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
134 struct as3722 *as3722 = as3722_rtc->as3722;
135 u8 as_time_array[6];
136 int ret;
137
138 if (alrm->time.tm_year < (AS3722_RTC_START_YEAR - 1900))
139 return -EINVAL;
140
141 ret = as3722_rtc_alarm_irq_enable(dev, 0);
142 if (ret < 0) {
143 dev_err(dev, "Disable RTC alarm failed\n");
144 return ret;
145 }
146
147 as3722_time_to_reg(as_time_array, &alrm->time);
148 ret = as3722_block_write(as3722, AS3722_RTC_ALARM_SECOND_REG, 6,
149 as_time_array);
150 if (ret < 0) {
151 dev_err(dev, "RTC_ALARM_SECOND block write failed %d\n", ret);
152 return ret;
153 }
154
155 if (alrm->enabled)
156 ret = as3722_rtc_alarm_irq_enable(dev, alrm->enabled);
157 return ret;
158}
159
160static irqreturn_t as3722_alarm_irq(int irq, void *data)
161{
162 struct as3722_rtc *as3722_rtc = data;
163
164 rtc_update_irq(as3722_rtc->rtc, 1, RTC_IRQF | RTC_AF);
165 return IRQ_HANDLED;
166}
167
168static const struct rtc_class_ops as3722_rtc_ops = {
169 .read_time = as3722_rtc_read_time,
170 .set_time = as3722_rtc_set_time,
171 .read_alarm = as3722_rtc_read_alarm,
172 .set_alarm = as3722_rtc_set_alarm,
173 .alarm_irq_enable = as3722_rtc_alarm_irq_enable,
174};
175
176static int as3722_rtc_probe(struct platform_device *pdev)
177{
178 struct as3722 *as3722 = dev_get_drvdata(pdev->dev.parent);
179 struct as3722_rtc *as3722_rtc;
180 int ret;
181
182 as3722_rtc = devm_kzalloc(&pdev->dev, sizeof(*as3722_rtc), GFP_KERNEL);
183 if (!as3722_rtc)
184 return -ENOMEM;
185
186 as3722_rtc->as3722 = as3722;
187 as3722_rtc->dev = &pdev->dev;
188 platform_set_drvdata(pdev, as3722_rtc);
189
190 /* Enable the RTC to make sure it is running. */
191 ret = as3722_update_bits(as3722, AS3722_RTC_CONTROL_REG,
192 AS3722_RTC_ON | AS3722_RTC_ALARM_WAKEUP_EN,
193 AS3722_RTC_ON | AS3722_RTC_ALARM_WAKEUP_EN);
194 if (ret < 0) {
195 dev_err(&pdev->dev, "RTC_CONTROL reg write failed: %d\n", ret);
196 return ret;
197 }
198
199 device_init_wakeup(&pdev->dev, 1);
200
201 as3722_rtc->rtc = rtc_device_register("as3722", &pdev->dev,
202 &as3722_rtc_ops, THIS_MODULE);
203 if (IS_ERR(as3722_rtc->rtc)) {
204 ret = PTR_ERR(as3722_rtc->rtc);
205 dev_err(&pdev->dev, "RTC register failed: %d\n", ret);
206 return ret;
207 }
208
209 as3722_rtc->alarm_irq = platform_get_irq(pdev, 0);
210 dev_info(&pdev->dev, "RTC interrupt %d\n", as3722_rtc->alarm_irq);
211
212 ret = request_threaded_irq(as3722_rtc->alarm_irq, NULL,
213 as3722_alarm_irq, IRQF_ONESHOT | IRQF_EARLY_RESUME,
214 "rtc-alarm", as3722_rtc);
215 if (ret < 0) {
216 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
217 as3722_rtc->alarm_irq, ret);
218 goto scrub;
219 }
220 disable_irq(as3722_rtc->alarm_irq);
221 return 0;
222scrub:
223 rtc_device_unregister(as3722_rtc->rtc);
224 return ret;
225}
226
227static int as3722_rtc_remove(struct platform_device *pdev)
228{
229 struct as3722_rtc *as3722_rtc = platform_get_drvdata(pdev);
230
231 free_irq(as3722_rtc->alarm_irq, as3722_rtc);
232 rtc_device_unregister(as3722_rtc->rtc);
233 return 0;
234}
235
236#ifdef CONFIG_PM_SLEEP
237static int as3722_rtc_suspend(struct device *dev)
238{
239 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
240
241 if (device_may_wakeup(dev))
242 enable_irq_wake(as3722_rtc->alarm_irq);
243
244 return 0;
245}
246
247static int as3722_rtc_resume(struct device *dev)
248{
249 struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
250
251 if (device_may_wakeup(dev))
252 disable_irq_wake(as3722_rtc->alarm_irq);
253 return 0;
254}
255#endif
256
257static const struct dev_pm_ops as3722_rtc_pm_ops = {
258 SET_SYSTEM_SLEEP_PM_OPS(as3722_rtc_suspend, as3722_rtc_resume)
259};
260
261static struct platform_driver as3722_rtc_driver = {
262 .probe = as3722_rtc_probe,
263 .remove = as3722_rtc_remove,
264 .driver = {
265 .name = "as3722-rtc",
266 .pm = &as3722_rtc_pm_ops,
267 },
268};
269module_platform_driver(as3722_rtc_driver);
270
271MODULE_DESCRIPTION("RTC driver for AS3722 PMICs");
272MODULE_ALIAS("platform:as3722-rtc");
273MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
274MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
275MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 741892632ae0..8b2cd8a5a2ff 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -376,7 +376,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
376 return -ENXIO; 376 return -ENXIO;
377 } 377 }
378 378
379 at91_rtc_regs = ioremap(regs->start, resource_size(regs)); 379 at91_rtc_regs = devm_ioremap(&pdev->dev, regs->start,
380 resource_size(regs));
380 if (!at91_rtc_regs) { 381 if (!at91_rtc_regs) {
381 dev_err(&pdev->dev, "failed to map registers, aborting.\n"); 382 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
382 return -ENOMEM; 383 return -ENOMEM;
@@ -390,12 +391,12 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
390 AT91_RTC_SECEV | AT91_RTC_TIMEV | 391 AT91_RTC_SECEV | AT91_RTC_TIMEV |
391 AT91_RTC_CALEV); 392 AT91_RTC_CALEV);
392 393
393 ret = request_irq(irq, at91_rtc_interrupt, 394 ret = devm_request_irq(&pdev->dev, irq, at91_rtc_interrupt,
394 IRQF_SHARED, 395 IRQF_SHARED,
395 "at91_rtc", pdev); 396 "at91_rtc", pdev);
396 if (ret) { 397 if (ret) {
397 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); 398 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq);
398 goto err_unmap; 399 return ret;
399 } 400 }
400 401
401 /* cpu init code should really have flagged this device as 402 /* cpu init code should really have flagged this device as
@@ -404,23 +405,14 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
404 if (!device_can_wakeup(&pdev->dev)) 405 if (!device_can_wakeup(&pdev->dev))
405 device_init_wakeup(&pdev->dev, 1); 406 device_init_wakeup(&pdev->dev, 1);
406 407
407 rtc = rtc_device_register(pdev->name, &pdev->dev, 408 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
408 &at91_rtc_ops, THIS_MODULE); 409 &at91_rtc_ops, THIS_MODULE);
409 if (IS_ERR(rtc)) { 410 if (IS_ERR(rtc))
410 ret = PTR_ERR(rtc); 411 return PTR_ERR(rtc);
411 goto err_free_irq;
412 }
413 platform_set_drvdata(pdev, rtc); 412 platform_set_drvdata(pdev, rtc);
414 413
415 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n"); 414 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n");
416 return 0; 415 return 0;
417
418err_free_irq:
419 free_irq(irq, pdev);
420err_unmap:
421 iounmap(at91_rtc_regs);
422
423 return ret;
424} 416}
425 417
426/* 418/*
@@ -428,16 +420,10 @@ err_unmap:
428 */ 420 */
429static int __exit at91_rtc_remove(struct platform_device *pdev) 421static int __exit at91_rtc_remove(struct platform_device *pdev)
430{ 422{
431 struct rtc_device *rtc = platform_get_drvdata(pdev);
432
433 /* Disable all interrupts */ 423 /* Disable all interrupts */
434 at91_rtc_write_idr(AT91_RTC_ACKUPD | AT91_RTC_ALARM | 424 at91_rtc_write_idr(AT91_RTC_ACKUPD | AT91_RTC_ALARM |
435 AT91_RTC_SECEV | AT91_RTC_TIMEV | 425 AT91_RTC_SECEV | AT91_RTC_TIMEV |
436 AT91_RTC_CALEV); 426 AT91_RTC_CALEV);
437 free_irq(irq, pdev);
438
439 rtc_device_unregister(rtc);
440 iounmap(at91_rtc_regs);
441 427
442 return 0; 428 return 0;
443} 429}
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 24e733c98f8b..f14876256a4a 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -595,7 +595,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
595static int INITSECTION 595static int INITSECTION
596cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) 596cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
597{ 597{
598 struct cmos_rtc_board_info *info = dev->platform_data; 598 struct cmos_rtc_board_info *info = dev_get_platdata(dev);
599 int retval = 0; 599 int retval = 0;
600 unsigned char rtc_control; 600 unsigned char rtc_control;
601 unsigned address_space; 601 unsigned address_space;
@@ -789,7 +789,6 @@ static void __exit cmos_do_remove(struct device *dev)
789 cmos->iomem = NULL; 789 cmos->iomem = NULL;
790 790
791 cmos->dev = NULL; 791 cmos->dev = NULL;
792 dev_set_drvdata(dev, NULL);
793} 792}
794 793
795#ifdef CONFIG_PM 794#ifdef CONFIG_PM
diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c
index e00642b61076..48cb2ac3bd3e 100644
--- a/drivers/rtc/rtc-da9055.c
+++ b/drivers/rtc/rtc-da9055.c
@@ -278,7 +278,7 @@ static int da9055_rtc_probe(struct platform_device *pdev)
278 return -ENOMEM; 278 return -ENOMEM;
279 279
280 rtc->da9055 = dev_get_drvdata(pdev->dev.parent); 280 rtc->da9055 = dev_get_drvdata(pdev->dev.parent);
281 pdata = rtc->da9055->dev->platform_data; 281 pdata = dev_get_platdata(rtc->da9055->dev);
282 platform_set_drvdata(pdev, rtc); 282 platform_set_drvdata(pdev, rtc);
283 283
284 ret = da9055_rtc_device_init(rtc->da9055, pdata); 284 ret = da9055_rtc_device_init(rtc->da9055, pdata);
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index dd6170acde95..80f323731ee2 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -606,7 +606,7 @@ static int ds1305_probe(struct spi_device *spi)
606 struct ds1305 *ds1305; 606 struct ds1305 *ds1305;
607 int status; 607 int status;
608 u8 addr, value; 608 u8 addr, value;
609 struct ds1305_platform_data *pdata = spi->dev.platform_data; 609 struct ds1305_platform_data *pdata = dev_get_platdata(&spi->dev);
610 bool write_ctrl = false; 610 bool write_ctrl = false;
611 611
612 /* Sanity check board setup data. This may be hooked up 612 /* Sanity check board setup data. This may be hooked up
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index ca18fd1433b3..4e75345a559a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -670,9 +670,9 @@ static int ds1307_probe(struct i2c_client *client,
670 int tmp; 670 int tmp;
671 const struct chip_desc *chip = &chips[id->driver_data]; 671 const struct chip_desc *chip = &chips[id->driver_data];
672 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 672 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
673 int want_irq = false; 673 bool want_irq = false;
674 unsigned char *buf; 674 unsigned char *buf;
675 struct ds1307_platform_data *pdata = client->dev.platform_data; 675 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
676 static const int bbsqi_bitpos[] = { 676 static const int bbsqi_bitpos[] = {
677 [ds_1337] = 0, 677 [ds_1337] = 0,
678 [ds_1339] = DS1339_BIT_BBSQI, 678 [ds_1339] = DS1339_BIT_BBSQI,
@@ -956,7 +956,7 @@ read_rtc:
956 GFP_KERNEL); 956 GFP_KERNEL);
957 if (!ds1307->nvram) { 957 if (!ds1307->nvram) {
958 err = -ENOMEM; 958 err = -ENOMEM;
959 goto exit; 959 goto err_irq;
960 } 960 }
961 ds1307->nvram->attr.name = "nvram"; 961 ds1307->nvram->attr.name = "nvram";
962 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 962 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
@@ -967,13 +967,15 @@ read_rtc:
967 ds1307->nvram_offset = chip->nvram_offset; 967 ds1307->nvram_offset = chip->nvram_offset;
968 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); 968 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram);
969 if (err) 969 if (err)
970 goto exit; 970 goto err_irq;
971 set_bit(HAS_NVRAM, &ds1307->flags); 971 set_bit(HAS_NVRAM, &ds1307->flags);
972 dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size); 972 dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size);
973 } 973 }
974 974
975 return 0; 975 return 0;
976 976
977err_irq:
978 free_irq(client->irq, client);
977exit: 979exit:
978 return err; 980 return err;
979} 981}
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 2ca5a23aba8a..fc209dc4e245 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -224,7 +224,7 @@ static const struct rtc_class_ops ds2404_rtc_ops = {
224 224
225static int rtc_probe(struct platform_device *pdev) 225static int rtc_probe(struct platform_device *pdev)
226{ 226{
227 struct ds2404_platform_data *pdata = pdev->dev.platform_data; 227 struct ds2404_platform_data *pdata = dev_get_platdata(&pdev->dev);
228 struct ds2404 *chip; 228 struct ds2404 *chip;
229 int retval = -EBUSY; 229 int retval = -EBUSY;
230 230
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 580e7b56bde8..5e4f5dc40ba5 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -42,7 +42,7 @@ struct ep93xx_rtc {
42static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, 42static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
43 unsigned short *delete) 43 unsigned short *delete)
44{ 44{
45 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; 45 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
46 unsigned long comp; 46 unsigned long comp;
47 47
48 comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP); 48 comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
@@ -60,7 +60,7 @@ static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
60 60
61static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) 61static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
62{ 62{
63 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; 63 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
64 unsigned long time; 64 unsigned long time;
65 65
66 time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); 66 time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
@@ -71,7 +71,7 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
71 71
72static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) 72static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
73{ 73{
74 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; 74 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
75 75
76 __raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD); 76 __raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
77 return 0; 77 return 0;
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index c016ad81767a..c3c549d511b9 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -144,11 +144,7 @@ isl1208_i2c_validate_client(struct i2c_client *client)
144static int 144static int
145isl1208_i2c_get_sr(struct i2c_client *client) 145isl1208_i2c_get_sr(struct i2c_client *client)
146{ 146{
147 int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR); 147 return i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
148 if (sr < 0)
149 return -EIO;
150
151 return sr;
152} 148}
153 149
154static int 150static int
@@ -647,10 +643,11 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
647 "chip found, driver version " DRV_VERSION "\n"); 643 "chip found, driver version " DRV_VERSION "\n");
648 644
649 if (client->irq > 0) { 645 if (client->irq > 0) {
650 rc = request_threaded_irq(client->irq, NULL, 646 rc = devm_request_threaded_irq(&client->dev, client->irq, NULL,
651 isl1208_rtc_interrupt, 647 isl1208_rtc_interrupt,
652 IRQF_SHARED, 648 IRQF_SHARED,
653 isl1208_driver.driver.name, client); 649 isl1208_driver.driver.name,
650 client);
654 if (!rc) { 651 if (!rc) {
655 device_init_wakeup(&client->dev, 1); 652 device_init_wakeup(&client->dev, 1);
656 enable_irq_wake(client->irq); 653 enable_irq_wake(client->irq);
@@ -662,20 +659,18 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
662 } 659 }
663 } 660 }
664 661
665 rtc = rtc_device_register(isl1208_driver.driver.name, 662 rtc = devm_rtc_device_register(&client->dev, isl1208_driver.driver.name,
666 &client->dev, &isl1208_rtc_ops, 663 &isl1208_rtc_ops,
667 THIS_MODULE); 664 THIS_MODULE);
668 if (IS_ERR(rtc)) { 665 if (IS_ERR(rtc))
669 rc = PTR_ERR(rtc); 666 return PTR_ERR(rtc);
670 goto exit_free_irq;
671 }
672 667
673 i2c_set_clientdata(client, rtc); 668 i2c_set_clientdata(client, rtc);
674 669
675 rc = isl1208_i2c_get_sr(client); 670 rc = isl1208_i2c_get_sr(client);
676 if (rc < 0) { 671 if (rc < 0) {
677 dev_err(&client->dev, "reading status failed\n"); 672 dev_err(&client->dev, "reading status failed\n");
678 goto exit_unregister; 673 return rc;
679 } 674 }
680 675
681 if (rc & ISL1208_REG_SR_RTCF) 676 if (rc & ISL1208_REG_SR_RTCF)
@@ -684,28 +679,15 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
684 679
685 rc = sysfs_create_group(&client->dev.kobj, &isl1208_rtc_sysfs_files); 680 rc = sysfs_create_group(&client->dev.kobj, &isl1208_rtc_sysfs_files);
686 if (rc) 681 if (rc)
687 goto exit_unregister; 682 return rc;
688 683
689 return 0; 684 return 0;
690
691exit_unregister:
692 rtc_device_unregister(rtc);
693exit_free_irq:
694 if (client->irq)
695 free_irq(client->irq, client);
696
697 return rc;
698} 685}
699 686
700static int 687static int
701isl1208_remove(struct i2c_client *client) 688isl1208_remove(struct i2c_client *client)
702{ 689{
703 struct rtc_device *rtc = i2c_get_clientdata(client);
704
705 sysfs_remove_group(&client->dev.kobj, &isl1208_rtc_sysfs_files); 690 sysfs_remove_group(&client->dev.kobj, &isl1208_rtc_sysfs_files);
706 rtc_device_unregister(rtc);
707 if (client->irq)
708 free_irq(client->irq, client);
709 691
710 return 0; 692 return 0;
711} 693}
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index fcb03291f145..11880c1e9dac 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -68,7 +68,7 @@ m48t59_mem_readb(struct device *dev, u32 ofs)
68static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) 68static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
69{ 69{
70 struct platform_device *pdev = to_platform_device(dev); 70 struct platform_device *pdev = to_platform_device(dev);
71 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 71 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
72 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 72 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
73 unsigned long flags; 73 unsigned long flags;
74 u8 val; 74 u8 val;
@@ -111,7 +111,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) 111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
112{ 112{
113 struct platform_device *pdev = to_platform_device(dev); 113 struct platform_device *pdev = to_platform_device(dev);
114 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 114 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
115 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 115 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
116 unsigned long flags; 116 unsigned long flags;
117 u8 val = 0; 117 u8 val = 0;
@@ -158,7 +158,7 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
158static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) 158static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
159{ 159{
160 struct platform_device *pdev = to_platform_device(dev); 160 struct platform_device *pdev = to_platform_device(dev);
161 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 161 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
162 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 162 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
163 struct rtc_time *tm = &alrm->time; 163 struct rtc_time *tm = &alrm->time;
164 unsigned long flags; 164 unsigned long flags;
@@ -205,7 +205,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
205static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 205static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
206{ 206{
207 struct platform_device *pdev = to_platform_device(dev); 207 struct platform_device *pdev = to_platform_device(dev);
208 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 208 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
209 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 209 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
210 struct rtc_time *tm = &alrm->time; 210 struct rtc_time *tm = &alrm->time;
211 u8 mday, hour, min, sec; 211 u8 mday, hour, min, sec;
@@ -266,7 +266,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
266static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 266static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
267{ 267{
268 struct platform_device *pdev = to_platform_device(dev); 268 struct platform_device *pdev = to_platform_device(dev);
269 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 269 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
270 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 270 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
271 unsigned long flags; 271 unsigned long flags;
272 272
@@ -283,7 +283,7 @@ static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
283static int m48t59_rtc_proc(struct device *dev, struct seq_file *seq) 283static int m48t59_rtc_proc(struct device *dev, struct seq_file *seq)
284{ 284{
285 struct platform_device *pdev = to_platform_device(dev); 285 struct platform_device *pdev = to_platform_device(dev);
286 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 286 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
287 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 287 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
288 unsigned long flags; 288 unsigned long flags;
289 u8 val; 289 u8 val;
@@ -304,7 +304,7 @@ static irqreturn_t m48t59_rtc_interrupt(int irq, void *dev_id)
304{ 304{
305 struct device *dev = (struct device *)dev_id; 305 struct device *dev = (struct device *)dev_id;
306 struct platform_device *pdev = to_platform_device(dev); 306 struct platform_device *pdev = to_platform_device(dev);
307 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 307 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
308 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 308 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
309 u8 event; 309 u8 event;
310 310
@@ -340,7 +340,7 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj,
340{ 340{
341 struct device *dev = container_of(kobj, struct device, kobj); 341 struct device *dev = container_of(kobj, struct device, kobj);
342 struct platform_device *pdev = to_platform_device(dev); 342 struct platform_device *pdev = to_platform_device(dev);
343 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 343 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
344 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 344 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
345 ssize_t cnt = 0; 345 ssize_t cnt = 0;
346 unsigned long flags; 346 unsigned long flags;
@@ -360,7 +360,7 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj,
360{ 360{
361 struct device *dev = container_of(kobj, struct device, kobj); 361 struct device *dev = container_of(kobj, struct device, kobj);
362 struct platform_device *pdev = to_platform_device(dev); 362 struct platform_device *pdev = to_platform_device(dev);
363 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 363 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
364 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 364 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
365 ssize_t cnt = 0; 365 ssize_t cnt = 0;
366 unsigned long flags; 366 unsigned long flags;
@@ -385,7 +385,7 @@ static struct bin_attribute m48t59_nvram_attr = {
385 385
386static int m48t59_rtc_probe(struct platform_device *pdev) 386static int m48t59_rtc_probe(struct platform_device *pdev)
387{ 387{
388 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 388 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
389 struct m48t59_private *m48t59 = NULL; 389 struct m48t59_private *m48t59 = NULL;
390 struct resource *res; 390 struct resource *res;
391 int ret = -ENOMEM; 391 int ret = -ENOMEM;
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 2d30314fa07f..32f64c942621 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -46,7 +46,7 @@ static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
46{ 46{
47 unsigned char reg; 47 unsigned char reg;
48 struct platform_device *pdev = to_platform_device(dev); 48 struct platform_device *pdev = to_platform_device(dev);
49 struct m48t86_ops *ops = pdev->dev.platform_data; 49 struct m48t86_ops *ops = dev_get_platdata(&pdev->dev);
50 50
51 reg = ops->readbyte(M48T86_REG_B); 51 reg = ops->readbyte(M48T86_REG_B);
52 52
@@ -84,7 +84,7 @@ static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm)
84{ 84{
85 unsigned char reg; 85 unsigned char reg;
86 struct platform_device *pdev = to_platform_device(dev); 86 struct platform_device *pdev = to_platform_device(dev);
87 struct m48t86_ops *ops = pdev->dev.platform_data; 87 struct m48t86_ops *ops = dev_get_platdata(&pdev->dev);
88 88
89 reg = ops->readbyte(M48T86_REG_B); 89 reg = ops->readbyte(M48T86_REG_B);
90 90
@@ -123,7 +123,7 @@ static int m48t86_rtc_proc(struct device *dev, struct seq_file *seq)
123{ 123{
124 unsigned char reg; 124 unsigned char reg;
125 struct platform_device *pdev = to_platform_device(dev); 125 struct platform_device *pdev = to_platform_device(dev);
126 struct m48t86_ops *ops = pdev->dev.platform_data; 126 struct m48t86_ops *ops = dev_get_platdata(&pdev->dev);
127 127
128 reg = ops->readbyte(M48T86_REG_B); 128 reg = ops->readbyte(M48T86_REG_B);
129 129
@@ -147,7 +147,7 @@ static const struct rtc_class_ops m48t86_rtc_ops = {
147static int m48t86_rtc_probe(struct platform_device *dev) 147static int m48t86_rtc_probe(struct platform_device *dev)
148{ 148{
149 unsigned char reg; 149 unsigned char reg;
150 struct m48t86_ops *ops = dev->dev.platform_data; 150 struct m48t86_ops *ops = dev_get_platdata(&dev->dev);
151 struct rtc_device *rtc; 151 struct rtc_device *rtc;
152 152
153 rtc = devm_rtc_device_register(&dev->dev, "m48t86", 153 rtc = devm_rtc_device_register(&dev->dev, "m48t86",
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index 55969b1b771a..4804985b876e 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -164,14 +164,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
164 164
165static int max6900_i2c_clear_write_protect(struct i2c_client *client) 165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
166{ 166{
167 int rc; 167 return i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0);
168 rc = i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0);
169 if (rc < 0) {
170 dev_err(&client->dev, "%s: control register write failed\n",
171 __func__);
172 return -EIO;
173 }
174 return 0;
175} 168}
176 169
177static int 170static int
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c
index 315209d9b407..e2436d140175 100644
--- a/drivers/rtc/rtc-mrst.c
+++ b/drivers/rtc/rtc-mrst.c
@@ -380,7 +380,6 @@ static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem,
380cleanup1: 380cleanup1:
381 rtc_device_unregister(mrst_rtc.rtc); 381 rtc_device_unregister(mrst_rtc.rtc);
382cleanup0: 382cleanup0:
383 dev_set_drvdata(dev, NULL);
384 mrst_rtc.dev = NULL; 383 mrst_rtc.dev = NULL;
385 release_mem_region(iomem->start, resource_size(iomem)); 384 release_mem_region(iomem->start, resource_size(iomem));
386 dev_err(dev, "rtc-mrst: unable to initialise\n"); 385 dev_err(dev, "rtc-mrst: unable to initialise\n");
@@ -412,7 +411,6 @@ static void rtc_mrst_do_remove(struct device *dev)
412 mrst->iomem = NULL; 411 mrst->iomem = NULL;
413 412
414 mrst->dev = NULL; 413 mrst->dev = NULL;
415 dev_set_drvdata(dev, NULL);
416} 414}
417 415
418#ifdef CONFIG_PM 416#ifdef CONFIG_PM
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index c7d97ee59327..26de5f8c2ae4 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -553,7 +553,7 @@ static struct platform_driver omap_rtc_driver = {
553 .name = DRIVER_NAME, 553 .name = DRIVER_NAME,
554 .owner = THIS_MODULE, 554 .owner = THIS_MODULE,
555 .pm = &omap_rtc_pm_ops, 555 .pm = &omap_rtc_pm_ops,
556 .of_match_table = of_match_ptr(omap_rtc_of_match), 556 .of_match_table = omap_rtc_of_match,
557 }, 557 },
558 .id_table = omap_rtc_devtype, 558 .id_table = omap_rtc_devtype,
559}; 559};
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 1725b5090e33..d1953bb244c5 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -327,7 +327,7 @@ kfree_exit:
327 327
328static int pcf2123_remove(struct spi_device *spi) 328static int pcf2123_remove(struct spi_device *spi)
329{ 329{
330 struct pcf2123_plat_data *pdata = spi->dev.platform_data; 330 struct pcf2123_plat_data *pdata = dev_get_platdata(&spi->dev);
331 int i; 331 int i;
332 332
333 if (pdata) { 333 if (pdata) {
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
index 22bacdbf9139..f85a1a93e669 100644
--- a/drivers/rtc/rtc-pl030.c
+++ b/drivers/rtc/rtc-pl030.c
@@ -106,7 +106,7 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id)
106 if (ret) 106 if (ret)
107 goto err_req; 107 goto err_req;
108 108
109 rtc = kmalloc(sizeof(*rtc), GFP_KERNEL); 109 rtc = devm_kzalloc(&dev->dev, sizeof(*rtc), GFP_KERNEL);
110 if (!rtc) { 110 if (!rtc) {
111 ret = -ENOMEM; 111 ret = -ENOMEM;
112 goto err_rtc; 112 goto err_rtc;
@@ -115,7 +115,7 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id)
115 rtc->base = ioremap(dev->res.start, resource_size(&dev->res)); 115 rtc->base = ioremap(dev->res.start, resource_size(&dev->res));
116 if (!rtc->base) { 116 if (!rtc->base) {
117 ret = -ENOMEM; 117 ret = -ENOMEM;
118 goto err_map; 118 goto err_rtc;
119 } 119 }
120 120
121 __raw_writel(0, rtc->base + RTC_CR); 121 __raw_writel(0, rtc->base + RTC_CR);
@@ -141,8 +141,6 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id)
141 free_irq(dev->irq[0], rtc); 141 free_irq(dev->irq[0], rtc);
142 err_irq: 142 err_irq:
143 iounmap(rtc->base); 143 iounmap(rtc->base);
144 err_map:
145 kfree(rtc);
146 err_rtc: 144 err_rtc:
147 amba_release_regions(dev); 145 amba_release_regions(dev);
148 err_req: 146 err_req:
@@ -153,14 +151,11 @@ static int pl030_remove(struct amba_device *dev)
153{ 151{
154 struct pl030_rtc *rtc = amba_get_drvdata(dev); 152 struct pl030_rtc *rtc = amba_get_drvdata(dev);
155 153
156 amba_set_drvdata(dev, NULL);
157
158 writel(0, rtc->base + RTC_CR); 154 writel(0, rtc->base + RTC_CR);
159 155
160 free_irq(dev->irq[0], rtc); 156 free_irq(dev->irq[0], rtc);
161 rtc_device_unregister(rtc->rtc); 157 rtc_device_unregister(rtc->rtc);
162 iounmap(rtc->base); 158 iounmap(rtc->base);
163 kfree(rtc);
164 amba_release_regions(dev); 159 amba_release_regions(dev);
165 160
166 return 0; 161 return 0;
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index e3b25712b659..99181fff88fd 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -305,7 +305,6 @@ static int pl031_remove(struct amba_device *adev)
305{ 305{
306 struct pl031_local *ldata = dev_get_drvdata(&adev->dev); 306 struct pl031_local *ldata = dev_get_drvdata(&adev->dev);
307 307
308 amba_set_drvdata(adev, NULL);
309 free_irq(adev->irq[0], ldata); 308 free_irq(adev->irq[0], ldata);
310 rtc_device_unregister(ldata->rtc); 309 rtc_device_unregister(ldata->rtc);
311 iounmap(ldata->base); 310 iounmap(ldata->base);
@@ -391,7 +390,6 @@ out_no_irq:
391 rtc_device_unregister(ldata->rtc); 390 rtc_device_unregister(ldata->rtc);
392out_no_rtc: 391out_no_rtc:
393 iounmap(ldata->base); 392 iounmap(ldata->base);
394 amba_set_drvdata(adev, NULL);
395out_no_remap: 393out_no_remap:
396 kfree(ldata); 394 kfree(ldata);
397out: 395out:
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 402732cfb32a..1ecfe3bd92ac 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -53,11 +53,11 @@ static irqreturn_t puv3_rtc_tickirq(int irq, void *id)
53} 53}
54 54
55/* Update control registers */ 55/* Update control registers */
56static void puv3_rtc_setaie(int to) 56static void puv3_rtc_setaie(struct device *dev, int to)
57{ 57{
58 unsigned int tmp; 58 unsigned int tmp;
59 59
60 pr_debug("%s: aie=%d\n", __func__, to); 60 dev_dbg(dev, "%s: aie=%d\n", __func__, to);
61 61
62 tmp = readl(RTC_RTSR) & ~RTC_RTSR_ALE; 62 tmp = readl(RTC_RTSR) & ~RTC_RTSR_ALE;
63 63
@@ -71,7 +71,7 @@ static int puv3_rtc_setpie(struct device *dev, int enabled)
71{ 71{
72 unsigned int tmp; 72 unsigned int tmp;
73 73
74 pr_debug("%s: pie=%d\n", __func__, enabled); 74 dev_debug(dev, "%s: pie=%d\n", __func__, enabled);
75 75
76 spin_lock_irq(&puv3_rtc_pie_lock); 76 spin_lock_irq(&puv3_rtc_pie_lock);
77 tmp = readl(RTC_RTSR) & ~RTC_RTSR_HZE; 77 tmp = readl(RTC_RTSR) & ~RTC_RTSR_HZE;
@@ -90,7 +90,7 @@ static int puv3_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
90{ 90{
91 rtc_time_to_tm(readl(RTC_RCNR), rtc_tm); 91 rtc_time_to_tm(readl(RTC_RCNR), rtc_tm);
92 92
93 pr_debug("read time %02x.%02x.%02x %02x/%02x/%02x\n", 93 dev_dbg(dev, "read time %02x.%02x.%02x %02x/%02x/%02x\n",
94 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 94 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
95 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 95 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
96 96
@@ -101,7 +101,7 @@ static int puv3_rtc_settime(struct device *dev, struct rtc_time *tm)
101{ 101{
102 unsigned long rtc_count = 0; 102 unsigned long rtc_count = 0;
103 103
104 pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n", 104 dev_dbg(dev, "set time %02d.%02d.%02d %02d/%02d/%02d\n",
105 tm->tm_year, tm->tm_mon, tm->tm_mday, 105 tm->tm_year, tm->tm_mon, tm->tm_mday,
106 tm->tm_hour, tm->tm_min, tm->tm_sec); 106 tm->tm_hour, tm->tm_min, tm->tm_sec);
107 107
@@ -119,7 +119,7 @@ static int puv3_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
119 119
120 alrm->enabled = readl(RTC_RTSR) & RTC_RTSR_ALE; 120 alrm->enabled = readl(RTC_RTSR) & RTC_RTSR_ALE;
121 121
122 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n", 122 dev_dbg(dev, "read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
123 alrm->enabled, 123 alrm->enabled,
124 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 124 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
125 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 125 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
@@ -132,7 +132,7 @@ static int puv3_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
132 struct rtc_time *tm = &alrm->time; 132 struct rtc_time *tm = &alrm->time;
133 unsigned long rtcalarm_count = 0; 133 unsigned long rtcalarm_count = 0;
134 134
135 pr_debug("puv3_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n", 135 dev_dbg(dev, "puv3_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
136 alrm->enabled, 136 alrm->enabled,
137 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff, 137 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff,
138 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec); 138 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);
@@ -140,7 +140,7 @@ static int puv3_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
140 rtc_tm_to_time(tm, &rtcalarm_count); 140 rtc_tm_to_time(tm, &rtcalarm_count);
141 writel(rtcalarm_count, RTC_RTAR); 141 writel(rtcalarm_count, RTC_RTAR);
142 142
143 puv3_rtc_setaie(alrm->enabled); 143 puv3_rtc_setaie(&dev->dev, alrm->enabled);
144 144
145 if (alrm->enabled) 145 if (alrm->enabled)
146 enable_irq_wake(puv3_rtc_alarmno); 146 enable_irq_wake(puv3_rtc_alarmno);
@@ -227,7 +227,7 @@ static int puv3_rtc_remove(struct platform_device *dev)
227 rtc_device_unregister(rtc); 227 rtc_device_unregister(rtc);
228 228
229 puv3_rtc_setpie(&dev->dev, 0); 229 puv3_rtc_setpie(&dev->dev, 0);
230 puv3_rtc_setaie(0); 230 puv3_rtc_setaie(&dev->dev, 0);
231 231
232 release_resource(puv3_rtc_mem); 232 release_resource(puv3_rtc_mem);
233 kfree(puv3_rtc_mem); 233 kfree(puv3_rtc_mem);
@@ -241,7 +241,7 @@ static int puv3_rtc_probe(struct platform_device *pdev)
241 struct resource *res; 241 struct resource *res;
242 int ret; 242 int ret;
243 243
244 pr_debug("%s: probe=%p\n", __func__, pdev); 244 dev_dbg(&pdev->dev, "%s: probe=%p\n", __func__, pdev);
245 245
246 /* find the IRQs */ 246 /* find the IRQs */
247 puv3_rtc_tickno = platform_get_irq(pdev, 1); 247 puv3_rtc_tickno = platform_get_irq(pdev, 1);
@@ -256,7 +256,7 @@ static int puv3_rtc_probe(struct platform_device *pdev)
256 return -ENOENT; 256 return -ENOENT;
257 } 257 }
258 258
259 pr_debug("PKUnity_rtc: tick irq %d, alarm irq %d\n", 259 dev_dbg(&pdev->dev, "PKUnity_rtc: tick irq %d, alarm irq %d\n",
260 puv3_rtc_tickno, puv3_rtc_alarmno); 260 puv3_rtc_tickno, puv3_rtc_alarmno);
261 261
262 /* get the memory region */ 262 /* get the memory region */
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index f7a90a116a39..090a101c1c81 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -64,7 +64,7 @@ static int
64rs5c348_rtc_set_time(struct device *dev, struct rtc_time *tm) 64rs5c348_rtc_set_time(struct device *dev, struct rtc_time *tm)
65{ 65{
66 struct spi_device *spi = to_spi_device(dev); 66 struct spi_device *spi = to_spi_device(dev);
67 struct rs5c348_plat_data *pdata = spi->dev.platform_data; 67 struct rs5c348_plat_data *pdata = dev_get_platdata(&spi->dev);
68 u8 txbuf[5+7], *txp; 68 u8 txbuf[5+7], *txp;
69 int ret; 69 int ret;
70 70
@@ -100,7 +100,7 @@ static int
100rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm) 100rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm)
101{ 101{
102 struct spi_device *spi = to_spi_device(dev); 102 struct spi_device *spi = to_spi_device(dev);
103 struct rs5c348_plat_data *pdata = spi->dev.platform_data; 103 struct rs5c348_plat_data *pdata = dev_get_platdata(&spi->dev);
104 u8 txbuf[5], rxbuf[7]; 104 u8 txbuf[5], rxbuf[7];
105 int ret; 105 int ret;
106 106
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
new file mode 100644
index 000000000000..b7fd02bc0a14
--- /dev/null
+++ b/drivers/rtc/rtc-s5m.c
@@ -0,0 +1,635 @@
1/*
2 * Copyright (c) 2013 Samsung Electronics Co., Ltd
3 * http://www.samsung.com
4 *
5 * Copyright (C) 2013 Google, Inc
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/module.h>
19#include <linux/i2c.h>
20#include <linux/slab.h>
21#include <linux/bcd.h>
22#include <linux/bitops.h>
23#include <linux/regmap.h>
24#include <linux/rtc.h>
25#include <linux/delay.h>
26#include <linux/platform_device.h>
27#include <linux/mfd/samsung/core.h>
28#include <linux/mfd/samsung/irq.h>
29#include <linux/mfd/samsung/rtc.h>
30
31struct s5m_rtc_info {
32 struct device *dev;
33 struct sec_pmic_dev *s5m87xx;
34 struct regmap *rtc;
35 struct rtc_device *rtc_dev;
36 int irq;
37 int device_type;
38 int rtc_24hr_mode;
39 bool wtsr_smpl;
40};
41
42static void s5m8767_data_to_tm(u8 *data, struct rtc_time *tm,
43 int rtc_24hr_mode)
44{
45 tm->tm_sec = data[RTC_SEC] & 0x7f;
46 tm->tm_min = data[RTC_MIN] & 0x7f;
47 if (rtc_24hr_mode) {
48 tm->tm_hour = data[RTC_HOUR] & 0x1f;
49 } else {
50 tm->tm_hour = data[RTC_HOUR] & 0x0f;
51 if (data[RTC_HOUR] & HOUR_PM_MASK)
52 tm->tm_hour += 12;
53 }
54
55 tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f);
56 tm->tm_mday = data[RTC_DATE] & 0x1f;
57 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
58 tm->tm_year = (data[RTC_YEAR1] & 0x7f) + 100;
59 tm->tm_yday = 0;
60 tm->tm_isdst = 0;
61}
62
63static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data)
64{
65 data[RTC_SEC] = tm->tm_sec;
66 data[RTC_MIN] = tm->tm_min;
67
68 if (tm->tm_hour >= 12)
69 data[RTC_HOUR] = tm->tm_hour | HOUR_PM_MASK;
70 else
71 data[RTC_HOUR] = tm->tm_hour & ~HOUR_PM_MASK;
72
73 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
74 data[RTC_DATE] = tm->tm_mday;
75 data[RTC_MONTH] = tm->tm_mon + 1;
76 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
77
78 if (tm->tm_year < 100) {
79 pr_err("s5m8767 RTC cannot handle the year %d.\n",
80 1900 + tm->tm_year);
81 return -EINVAL;
82 } else {
83 return 0;
84 }
85}
86
87static inline int s5m8767_rtc_set_time_reg(struct s5m_rtc_info *info)
88{
89 int ret;
90 unsigned int data;
91
92 ret = regmap_read(info->rtc, SEC_RTC_UDR_CON, &data);
93 if (ret < 0) {
94 dev_err(info->dev, "failed to read update reg(%d)\n", ret);
95 return ret;
96 }
97
98 data |= RTC_TIME_EN_MASK;
99 data |= RTC_UDR_MASK;
100
101 ret = regmap_write(info->rtc, SEC_RTC_UDR_CON, data);
102 if (ret < 0) {
103 dev_err(info->dev, "failed to write update reg(%d)\n", ret);
104 return ret;
105 }
106
107 do {
108 ret = regmap_read(info->rtc, SEC_RTC_UDR_CON, &data);
109 } while ((data & RTC_UDR_MASK) && !ret);
110
111 return ret;
112}
113
114static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info)
115{
116 int ret;
117 unsigned int data;
118
119 ret = regmap_read(info->rtc, SEC_RTC_UDR_CON, &data);
120 if (ret < 0) {
121 dev_err(info->dev, "%s: fail to read update reg(%d)\n",
122 __func__, ret);
123 return ret;
124 }
125
126 data &= ~RTC_TIME_EN_MASK;
127 data |= RTC_UDR_MASK;
128
129 ret = regmap_write(info->rtc, SEC_RTC_UDR_CON, data);
130 if (ret < 0) {
131 dev_err(info->dev, "%s: fail to write update reg(%d)\n",
132 __func__, ret);
133 return ret;
134 }
135
136 do {
137 ret = regmap_read(info->rtc, SEC_RTC_UDR_CON, &data);
138 } while ((data & RTC_UDR_MASK) && !ret);
139
140 return ret;
141}
142
143static void s5m8763_data_to_tm(u8 *data, struct rtc_time *tm)
144{
145 tm->tm_sec = bcd2bin(data[RTC_SEC]);
146 tm->tm_min = bcd2bin(data[RTC_MIN]);
147
148 if (data[RTC_HOUR] & HOUR_12) {
149 tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x1f);
150 if (data[RTC_HOUR] & HOUR_PM)
151 tm->tm_hour += 12;
152 } else {
153 tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
154 }
155
156 tm->tm_wday = data[RTC_WEEKDAY] & 0x07;
157 tm->tm_mday = bcd2bin(data[RTC_DATE]);
158 tm->tm_mon = bcd2bin(data[RTC_MONTH]);
159 tm->tm_year = bcd2bin(data[RTC_YEAR1]) + bcd2bin(data[RTC_YEAR2]) * 100;
160 tm->tm_year -= 1900;
161}
162
163static void s5m8763_tm_to_data(struct rtc_time *tm, u8 *data)
164{
165 data[RTC_SEC] = bin2bcd(tm->tm_sec);
166 data[RTC_MIN] = bin2bcd(tm->tm_min);
167 data[RTC_HOUR] = bin2bcd(tm->tm_hour);
168 data[RTC_WEEKDAY] = tm->tm_wday;
169 data[RTC_DATE] = bin2bcd(tm->tm_mday);
170 data[RTC_MONTH] = bin2bcd(tm->tm_mon);
171 data[RTC_YEAR1] = bin2bcd(tm->tm_year % 100);
172 data[RTC_YEAR2] = bin2bcd((tm->tm_year + 1900) / 100);
173}
174
175static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
176{
177 struct s5m_rtc_info *info = dev_get_drvdata(dev);
178 u8 data[8];
179 int ret;
180
181 ret = regmap_bulk_read(info->rtc, SEC_RTC_SEC, data, 8);
182 if (ret < 0)
183 return ret;
184
185 switch (info->device_type) {
186 case S5M8763X:
187 s5m8763_data_to_tm(data, tm);
188 break;
189
190 case S5M8767X:
191 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode);
192 break;
193
194 default:
195 return -EINVAL;
196 }
197
198 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
199 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
200 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
201
202 return rtc_valid_tm(tm);
203}
204
205static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)
206{
207 struct s5m_rtc_info *info = dev_get_drvdata(dev);
208 u8 data[8];
209 int ret = 0;
210
211 switch (info->device_type) {
212 case S5M8763X:
213 s5m8763_tm_to_data(tm, data);
214 break;
215 case S5M8767X:
216 ret = s5m8767_tm_to_data(tm, data);
217 break;
218 default:
219 return -EINVAL;
220 }
221
222 if (ret < 0)
223 return ret;
224
225 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
226 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
227 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
228
229 ret = regmap_raw_write(info->rtc, SEC_RTC_SEC, data, 8);
230 if (ret < 0)
231 return ret;
232
233 ret = s5m8767_rtc_set_time_reg(info);
234
235 return ret;
236}
237
238static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
239{
240 struct s5m_rtc_info *info = dev_get_drvdata(dev);
241 u8 data[8];
242 unsigned int val;
243 int ret, i;
244
245 ret = regmap_bulk_read(info->rtc, SEC_ALARM0_SEC, data, 8);
246 if (ret < 0)
247 return ret;
248
249 switch (info->device_type) {
250 case S5M8763X:
251 s5m8763_data_to_tm(data, &alrm->time);
252 ret = regmap_read(info->rtc, SEC_ALARM0_CONF, &val);
253 if (ret < 0)
254 return ret;
255
256 alrm->enabled = !!val;
257
258 ret = regmap_read(info->rtc, SEC_RTC_STATUS, &val);
259 if (ret < 0)
260 return ret;
261
262 break;
263
264 case S5M8767X:
265 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
266 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
267 1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
268 alrm->time.tm_mday, alrm->time.tm_hour,
269 alrm->time.tm_min, alrm->time.tm_sec,
270 alrm->time.tm_wday);
271
272 alrm->enabled = 0;
273 for (i = 0; i < 7; i++) {
274 if (data[i] & ALARM_ENABLE_MASK) {
275 alrm->enabled = 1;
276 break;
277 }
278 }
279
280 alrm->pending = 0;
281 ret = regmap_read(info->rtc, SEC_RTC_STATUS, &val);
282 if (ret < 0)
283 return ret;
284 break;
285
286 default:
287 return -EINVAL;
288 }
289
290 if (val & ALARM0_STATUS)
291 alrm->pending = 1;
292 else
293 alrm->pending = 0;
294
295 return 0;
296}
297
298static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)
299{
300 u8 data[8];
301 int ret, i;
302 struct rtc_time tm;
303
304 ret = regmap_bulk_read(info->rtc, SEC_ALARM0_SEC, data, 8);
305 if (ret < 0)
306 return ret;
307
308 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
309 dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
310 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
311 tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
312
313 switch (info->device_type) {
314 case S5M8763X:
315 ret = regmap_write(info->rtc, SEC_ALARM0_CONF, 0);
316 break;
317
318 case S5M8767X:
319 for (i = 0; i < 7; i++)
320 data[i] &= ~ALARM_ENABLE_MASK;
321
322 ret = regmap_raw_write(info->rtc, SEC_ALARM0_SEC, data, 8);
323 if (ret < 0)
324 return ret;
325
326 ret = s5m8767_rtc_set_alarm_reg(info);
327
328 break;
329
330 default:
331 return -EINVAL;
332 }
333
334 return ret;
335}
336
337static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)
338{
339 int ret;
340 u8 data[8];
341 u8 alarm0_conf;
342 struct rtc_time tm;
343
344 ret = regmap_bulk_read(info->rtc, SEC_ALARM0_SEC, data, 8);
345 if (ret < 0)
346 return ret;
347
348 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
349 dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
350 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
351 tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
352
353 switch (info->device_type) {
354 case S5M8763X:
355 alarm0_conf = 0x77;
356 ret = regmap_write(info->rtc, SEC_ALARM0_CONF, alarm0_conf);
357 break;
358
359 case S5M8767X:
360 data[RTC_SEC] |= ALARM_ENABLE_MASK;
361 data[RTC_MIN] |= ALARM_ENABLE_MASK;
362 data[RTC_HOUR] |= ALARM_ENABLE_MASK;
363 data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
364 if (data[RTC_DATE] & 0x1f)
365 data[RTC_DATE] |= ALARM_ENABLE_MASK;
366 if (data[RTC_MONTH] & 0xf)
367 data[RTC_MONTH] |= ALARM_ENABLE_MASK;
368 if (data[RTC_YEAR1] & 0x7f)
369 data[RTC_YEAR1] |= ALARM_ENABLE_MASK;
370
371 ret = regmap_raw_write(info->rtc, SEC_ALARM0_SEC, data, 8);
372 if (ret < 0)
373 return ret;
374 ret = s5m8767_rtc_set_alarm_reg(info);
375
376 break;
377
378 default:
379 return -EINVAL;
380 }
381
382 return ret;
383}
384
385static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
386{
387 struct s5m_rtc_info *info = dev_get_drvdata(dev);
388 u8 data[8];
389 int ret;
390
391 switch (info->device_type) {
392 case S5M8763X:
393 s5m8763_tm_to_data(&alrm->time, data);
394 break;
395
396 case S5M8767X:
397 s5m8767_tm_to_data(&alrm->time, data);
398 break;
399
400 default:
401 return -EINVAL;
402 }
403
404 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
405 1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
406 alrm->time.tm_mday, alrm->time.tm_hour, alrm->time.tm_min,
407 alrm->time.tm_sec, alrm->time.tm_wday);
408
409 ret = s5m_rtc_stop_alarm(info);
410 if (ret < 0)
411 return ret;
412
413 ret = regmap_raw_write(info->rtc, SEC_ALARM0_SEC, data, 8);
414 if (ret < 0)
415 return ret;
416
417 ret = s5m8767_rtc_set_alarm_reg(info);
418 if (ret < 0)
419 return ret;
420
421 if (alrm->enabled)
422 ret = s5m_rtc_start_alarm(info);
423
424 return ret;
425}
426
427static int s5m_rtc_alarm_irq_enable(struct device *dev,
428 unsigned int enabled)
429{
430 struct s5m_rtc_info *info = dev_get_drvdata(dev);
431
432 if (enabled)
433 return s5m_rtc_start_alarm(info);
434 else
435 return s5m_rtc_stop_alarm(info);
436}
437
438static irqreturn_t s5m_rtc_alarm_irq(int irq, void *data)
439{
440 struct s5m_rtc_info *info = data;
441
442 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
443
444 return IRQ_HANDLED;
445}
446
447static const struct rtc_class_ops s5m_rtc_ops = {
448 .read_time = s5m_rtc_read_time,
449 .set_time = s5m_rtc_set_time,
450 .read_alarm = s5m_rtc_read_alarm,
451 .set_alarm = s5m_rtc_set_alarm,
452 .alarm_irq_enable = s5m_rtc_alarm_irq_enable,
453};
454
455static void s5m_rtc_enable_wtsr(struct s5m_rtc_info *info, bool enable)
456{
457 int ret;
458 ret = regmap_update_bits(info->rtc, SEC_WTSR_SMPL_CNTL,
459 WTSR_ENABLE_MASK,
460 enable ? WTSR_ENABLE_MASK : 0);
461 if (ret < 0)
462 dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
463 __func__, ret);
464}
465
466static void s5m_rtc_enable_smpl(struct s5m_rtc_info *info, bool enable)
467{
468 int ret;
469 ret = regmap_update_bits(info->rtc, SEC_WTSR_SMPL_CNTL,
470 SMPL_ENABLE_MASK,
471 enable ? SMPL_ENABLE_MASK : 0);
472 if (ret < 0)
473 dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
474 __func__, ret);
475}
476
477static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info)
478{
479 u8 data[2];
480 unsigned int tp_read;
481 int ret;
482 struct rtc_time tm;
483
484 ret = regmap_read(info->rtc, SEC_RTC_UDR_CON, &tp_read);
485 if (ret < 0) {
486 dev_err(info->dev, "%s: fail to read control reg(%d)\n",
487 __func__, ret);
488 return ret;
489 }
490
491 /* Set RTC control register : Binary mode, 24hour mode */
492 data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
493 data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
494
495 info->rtc_24hr_mode = 1;
496 ret = regmap_raw_write(info->rtc, SEC_ALARM0_CONF, data, 2);
497 if (ret < 0) {
498 dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
499 __func__, ret);
500 return ret;
501 }
502
503 /* In first boot time, Set rtc time to 1/1/2012 00:00:00(SUN) */
504 if ((tp_read & RTC_TCON_MASK) == 0) {
505 dev_dbg(info->dev, "rtc init\n");
506 tm.tm_sec = 0;
507 tm.tm_min = 0;
508 tm.tm_hour = 0;
509 tm.tm_wday = 0;
510 tm.tm_mday = 1;
511 tm.tm_mon = 0;
512 tm.tm_year = 112;
513 tm.tm_yday = 0;
514 tm.tm_isdst = 0;
515 ret = s5m_rtc_set_time(info->dev, &tm);
516 }
517
518 ret = regmap_update_bits(info->rtc, SEC_RTC_UDR_CON,
519 RTC_TCON_MASK, tp_read | RTC_TCON_MASK);
520 if (ret < 0)
521 dev_err(info->dev, "%s: fail to update TCON reg(%d)\n",
522 __func__, ret);
523
524 return ret;
525}
526
527static int s5m_rtc_probe(struct platform_device *pdev)
528{
529 struct sec_pmic_dev *s5m87xx = dev_get_drvdata(pdev->dev.parent);
530 struct sec_platform_data *pdata = s5m87xx->pdata;
531 struct s5m_rtc_info *info;
532 int ret;
533
534 if (!pdata) {
535 dev_err(pdev->dev.parent, "Platform data not supplied\n");
536 return -ENODEV;
537 }
538
539 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
540 if (!info)
541 return -ENOMEM;
542
543 info->dev = &pdev->dev;
544 info->s5m87xx = s5m87xx;
545 info->rtc = s5m87xx->rtc;
546 info->device_type = s5m87xx->device_type;
547 info->wtsr_smpl = s5m87xx->wtsr_smpl;
548
549 switch (pdata->device_type) {
550 case S5M8763X:
551 info->irq = s5m87xx->irq_base + S5M8763_IRQ_ALARM0;
552 break;
553
554 case S5M8767X:
555 info->irq = s5m87xx->irq_base + S5M8767_IRQ_RTCA1;
556 break;
557
558 default:
559 ret = -EINVAL;
560 dev_err(&pdev->dev, "Unsupported device type: %d\n", ret);
561 return ret;
562 }
563
564 platform_set_drvdata(pdev, info);
565
566 ret = s5m8767_rtc_init_reg(info);
567
568 if (info->wtsr_smpl) {
569 s5m_rtc_enable_wtsr(info, true);
570 s5m_rtc_enable_smpl(info, true);
571 }
572
573 device_init_wakeup(&pdev->dev, 1);
574
575 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc",
576 &s5m_rtc_ops, THIS_MODULE);
577
578 if (IS_ERR(info->rtc_dev))
579 return PTR_ERR(info->rtc_dev);
580
581 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
582 s5m_rtc_alarm_irq, 0, "rtc-alarm0",
583 info);
584 if (ret < 0)
585 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
586 info->irq, ret);
587
588 return ret;
589}
590
591static void s5m_rtc_shutdown(struct platform_device *pdev)
592{
593 struct s5m_rtc_info *info = platform_get_drvdata(pdev);
594 int i;
595 unsigned int val = 0;
596 if (info->wtsr_smpl) {
597 for (i = 0; i < 3; i++) {
598 s5m_rtc_enable_wtsr(info, false);
599 regmap_read(info->rtc, SEC_WTSR_SMPL_CNTL, &val);
600 pr_debug("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val);
601 if (val & WTSR_ENABLE_MASK)
602 pr_emerg("%s: fail to disable WTSR\n",
603 __func__);
604 else {
605 pr_info("%s: success to disable WTSR\n",
606 __func__);
607 break;
608 }
609 }
610 }
611 /* Disable SMPL when power off */
612 s5m_rtc_enable_smpl(info, false);
613}
614
615static const struct platform_device_id s5m_rtc_id[] = {
616 { "s5m-rtc", 0 },
617};
618
619static struct platform_driver s5m_rtc_driver = {
620 .driver = {
621 .name = "s5m-rtc",
622 .owner = THIS_MODULE,
623 },
624 .probe = s5m_rtc_probe,
625 .shutdown = s5m_rtc_shutdown,
626 .id_table = s5m_rtc_id,
627};
628
629module_platform_driver(s5m_rtc_driver);
630
631/* Module information */
632MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
633MODULE_DESCRIPTION("Samsung S5M RTC driver");
634MODULE_LICENSE("GPL");
635MODULE_ALIAS("platform:s5m-rtc");
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 6d87e26355a3..d0d2b047658b 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -649,8 +649,9 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
649 clk_enable(rtc->clk); 649 clk_enable(rtc->clk);
650 650
651 rtc->capabilities = RTC_DEF_CAPABILITIES; 651 rtc->capabilities = RTC_DEF_CAPABILITIES;
652 if (pdev->dev.platform_data) { 652 if (dev_get_platdata(&pdev->dev)) {
653 struct sh_rtc_platform_info *pinfo = pdev->dev.platform_data; 653 struct sh_rtc_platform_info *pinfo =
654 dev_get_platdata(&pdev->dev);
654 655
655 /* 656 /*
656 * Some CPUs have special capabilities in addition to the 657 * Some CPUs have special capabilities in addition to the
diff --git a/drivers/rtc/rtc-sirfsoc.c b/drivers/rtc/rtc-sirfsoc.c
index 63460cf80f1b..3eb3642ae299 100644
--- a/drivers/rtc/rtc-sirfsoc.c
+++ b/drivers/rtc/rtc-sirfsoc.c
@@ -59,7 +59,7 @@ static int sirfsoc_rtc_read_alarm(struct device *dev,
59 unsigned long rtc_alarm, rtc_count; 59 unsigned long rtc_alarm, rtc_count;
60 struct sirfsoc_rtc_drv *rtcdrv; 60 struct sirfsoc_rtc_drv *rtcdrv;
61 61
62 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev); 62 rtcdrv = dev_get_drvdata(dev);
63 63
64 local_irq_disable(); 64 local_irq_disable();
65 65
@@ -94,7 +94,7 @@ static int sirfsoc_rtc_set_alarm(struct device *dev,
94{ 94{
95 unsigned long rtc_status_reg, rtc_alarm; 95 unsigned long rtc_status_reg, rtc_alarm;
96 struct sirfsoc_rtc_drv *rtcdrv; 96 struct sirfsoc_rtc_drv *rtcdrv;
97 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev); 97 rtcdrv = dev_get_drvdata(dev);
98 98
99 if (alrm->enabled) { 99 if (alrm->enabled) {
100 rtc_tm_to_time(&(alrm->time), &rtc_alarm); 100 rtc_tm_to_time(&(alrm->time), &rtc_alarm);
@@ -157,7 +157,7 @@ static int sirfsoc_rtc_read_time(struct device *dev,
157{ 157{
158 unsigned long tmp_rtc = 0; 158 unsigned long tmp_rtc = 0;
159 struct sirfsoc_rtc_drv *rtcdrv; 159 struct sirfsoc_rtc_drv *rtcdrv;
160 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev); 160 rtcdrv = dev_get_drvdata(dev);
161 /* 161 /*
162 * This patch is taken from WinCE - Need to validate this for 162 * This patch is taken from WinCE - Need to validate this for
163 * correctness. To work around sirfsoc RTC counter double sync logic 163 * correctness. To work around sirfsoc RTC counter double sync logic
@@ -178,7 +178,7 @@ static int sirfsoc_rtc_set_time(struct device *dev,
178{ 178{
179 unsigned long rtc_time; 179 unsigned long rtc_time;
180 struct sirfsoc_rtc_drv *rtcdrv; 180 struct sirfsoc_rtc_drv *rtcdrv;
181 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev); 181 rtcdrv = dev_get_drvdata(dev);
182 182
183 rtc_tm_to_time(tm, &rtc_time); 183 rtc_tm_to_time(tm, &rtc_time);
184 184
@@ -274,7 +274,7 @@ static int sirfsoc_rtc_probe(struct platform_device *pdev)
274 err = of_property_read_u32(np, "reg", &rtcdrv->rtc_base); 274 err = of_property_read_u32(np, "reg", &rtcdrv->rtc_base);
275 if (err) { 275 if (err) {
276 dev_err(&pdev->dev, "unable to find base address of rtc node in dtb\n"); 276 dev_err(&pdev->dev, "unable to find base address of rtc node in dtb\n");
277 goto error; 277 return err;
278 } 278 }
279 279
280 platform_set_drvdata(pdev, rtcdrv); 280 platform_set_drvdata(pdev, rtcdrv);
@@ -290,7 +290,7 @@ static int sirfsoc_rtc_probe(struct platform_device *pdev)
290 rtc_div = ((32768 / RTC_HZ) / 2) - 1; 290 rtc_div = ((32768 / RTC_HZ) / 2) - 1;
291 sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV); 291 sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
292 292
293 rtcdrv->rtc = rtc_device_register(pdev->name, &(pdev->dev), 293 rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
294 &sirfsoc_rtc_ops, THIS_MODULE); 294 &sirfsoc_rtc_ops, THIS_MODULE);
295 if (IS_ERR(rtcdrv->rtc)) { 295 if (IS_ERR(rtcdrv->rtc)) {
296 err = PTR_ERR(rtcdrv->rtc); 296 err = PTR_ERR(rtcdrv->rtc);
@@ -322,24 +322,15 @@ static int sirfsoc_rtc_probe(struct platform_device *pdev)
322 rtcdrv); 322 rtcdrv);
323 if (err) { 323 if (err) {
324 dev_err(&pdev->dev, "Unable to register for the SiRF SOC RTC IRQ\n"); 324 dev_err(&pdev->dev, "Unable to register for the SiRF SOC RTC IRQ\n");
325 goto error; 325 return err;
326 } 326 }
327 327
328 return 0; 328 return 0;
329
330error:
331 if (rtcdrv->rtc)
332 rtc_device_unregister(rtcdrv->rtc);
333
334 return err;
335} 329}
336 330
337static int sirfsoc_rtc_remove(struct platform_device *pdev) 331static int sirfsoc_rtc_remove(struct platform_device *pdev)
338{ 332{
339 struct sirfsoc_rtc_drv *rtcdrv = platform_get_drvdata(pdev);
340
341 device_init_wakeup(&pdev->dev, 0); 333 device_init_wakeup(&pdev->dev, 0);
342 rtc_device_unregister(rtcdrv->rtc);
343 334
344 return 0; 335 return 0;
345} 336}
@@ -373,7 +364,7 @@ static int sirfsoc_rtc_thaw(struct device *dev)
373{ 364{
374 u32 tmp; 365 u32 tmp;
375 struct sirfsoc_rtc_drv *rtcdrv; 366 struct sirfsoc_rtc_drv *rtcdrv;
376 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev); 367 rtcdrv = dev_get_drvdata(dev);
377 368
378 /* 369 /*
379 * if resume from snapshot and the rtc power is losed, 370 * if resume from snapshot and the rtc power is losed,
@@ -467,7 +458,7 @@ static struct platform_driver sirfsoc_rtc_driver = {
467#ifdef CONFIG_PM 458#ifdef CONFIG_PM
468 .pm = &sirfsoc_rtc_pm_ops, 459 .pm = &sirfsoc_rtc_pm_ops,
469#endif 460#endif
470 .of_match_table = of_match_ptr(sirfsoc_rtc_of_match), 461 .of_match_table = sirfsoc_rtc_of_match,
471 }, 462 },
472 .probe = sirfsoc_rtc_probe, 463 .probe = sirfsoc_rtc_probe,
473 .remove = sirfsoc_rtc_remove, 464 .remove = sirfsoc_rtc_remove,
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 316a342115b2..fa384fe28988 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -329,7 +329,7 @@ static struct platform_driver snvs_rtc_driver = {
329 .name = "snvs_rtc", 329 .name = "snvs_rtc",
330 .owner = THIS_MODULE, 330 .owner = THIS_MODULE,
331 .pm = &snvs_rtc_pm_ops, 331 .pm = &snvs_rtc_pm_ops,
332 .of_match_table = of_match_ptr(snvs_dt_ids), 332 .of_match_table = snvs_dt_ids,
333 }, 333 },
334 .probe = snvs_rtc_probe, 334 .probe = snvs_rtc_probe,
335}; 335};
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 26019531db15..ea96492357b0 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -343,7 +343,7 @@ static struct platform_driver stmp3xxx_rtcdrv = {
343 .name = "stmp3xxx-rtc", 343 .name = "stmp3xxx-rtc",
344 .owner = THIS_MODULE, 344 .owner = THIS_MODULE,
345 .pm = &stmp3xxx_rtc_pm_ops, 345 .pm = &stmp3xxx_rtc_pm_ops,
346 .of_match_table = of_match_ptr(rtc_dt_ids), 346 .of_match_table = rtc_dt_ids,
347 }, 347 },
348}; 348};
349 349
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
index a9caf043b0ce..7af00208d637 100644
--- a/drivers/rtc/rtc-tps65910.c
+++ b/drivers/rtc/rtc-tps65910.c
@@ -22,7 +22,6 @@
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/bcd.h> 23#include <linux/bcd.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
26#include <linux/interrupt.h> 25#include <linux/interrupt.h>
27#include <linux/mfd/tps65910.h> 26#include <linux/mfd/tps65910.h>
28 27
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index d07d89823020..25222cdccdc6 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -303,7 +303,7 @@ static const struct rtc_class_ops v3020_rtc_ops = {
303 303
304static int rtc_probe(struct platform_device *pdev) 304static int rtc_probe(struct platform_device *pdev)
305{ 305{
306 struct v3020_platform_data *pdata = pdev->dev.platform_data; 306 struct v3020_platform_data *pdata = dev_get_platdata(&pdev->dev);
307 struct v3020 *chip; 307 struct v3020 *chip;
308 int retval = -EBUSY; 308 int retval = -EBUSY;
309 int i; 309 int i;
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index 54e104e197e3..aabc22c587fb 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -20,6 +20,7 @@
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/io.h>
23#include <linux/ioport.h> 24#include <linux/ioport.h>
24#include <linux/interrupt.h> 25#include <linux/interrupt.h>
25#include <linux/module.h> 26#include <linux/module.h>
@@ -27,11 +28,10 @@
27#include <linux/rtc.h> 28#include <linux/rtc.h>
28#include <linux/spinlock.h> 29#include <linux/spinlock.h>
29#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/uaccess.h>
30#include <linux/log2.h> 32#include <linux/log2.h>
31 33
32#include <asm/div64.h> 34#include <asm/div64.h>
33#include <asm/io.h>
34#include <asm/uaccess.h>
35 35
36MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>"); 36MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
37MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 37MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
index c2d6331fc712..df2ef3eba7cd 100644
--- a/drivers/rtc/rtc-vt8500.c
+++ b/drivers/rtc/rtc-vt8500.c
@@ -228,7 +228,7 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
228 vt8500_rtc->irq_alarm = platform_get_irq(pdev, 0); 228 vt8500_rtc->irq_alarm = platform_get_irq(pdev, 0);
229 if (vt8500_rtc->irq_alarm < 0) { 229 if (vt8500_rtc->irq_alarm < 0) {
230 dev_err(&pdev->dev, "No alarm IRQ resource defined\n"); 230 dev_err(&pdev->dev, "No alarm IRQ resource defined\n");
231 return -ENXIO; 231 return vt8500_rtc->irq_alarm;
232 } 232 }
233 233
234 vt8500_rtc->res = devm_request_mem_region(&pdev->dev, 234 vt8500_rtc->res = devm_request_mem_region(&pdev->dev,
@@ -296,7 +296,7 @@ static struct platform_driver vt8500_rtc_driver = {
296 .driver = { 296 .driver = {
297 .name = "vt8500-rtc", 297 .name = "vt8500-rtc",
298 .owner = THIS_MODULE, 298 .owner = THIS_MODULE,
299 .of_match_table = of_match_ptr(wmt_dt_ids), 299 .of_match_table = wmt_dt_ids,
300 }, 300 },
301}; 301};
302 302
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_errno.h b/drivers/staging/lustre/lustre/include/lustre/lustre_errno.h
index 2870487dd286..35aefa2cdad1 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_errno.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_errno.h
@@ -165,7 +165,7 @@
165#define LUSTRE_EHOSTUNREACH 113 /* No route to host */ 165#define LUSTRE_EHOSTUNREACH 113 /* No route to host */
166#define LUSTRE_EALREADY 114 /* Operation already in progress */ 166#define LUSTRE_EALREADY 114 /* Operation already in progress */
167#define LUSTRE_EINPROGRESS 115 /* Operation now in progress */ 167#define LUSTRE_EINPROGRESS 115 /* Operation now in progress */
168#define LUSTRE_ESTALE 116 /* Stale NFS file handle */ 168#define LUSTRE_ESTALE 116 /* Stale file handle */
169#define LUSTRE_EUCLEAN 117 /* Structure needs cleaning */ 169#define LUSTRE_EUCLEAN 117 /* Structure needs cleaning */
170#define LUSTRE_ENOTNAM 118 /* Not a XENIX named type file */ 170#define LUSTRE_ENOTNAM 118 /* Not a XENIX named type file */
171#define LUSTRE_ENAVAIL 119 /* No XENIX semaphores available */ 171#define LUSTRE_ENAVAIL 119 /* No XENIX semaphores available */
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index f519da9034b7..96c4a19b1918 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -158,14 +158,12 @@ static int pruss_probe(struct platform_device *dev)
158 if (pdata->sram_pool) { 158 if (pdata->sram_pool) {
159 gdev->sram_pool = pdata->sram_pool; 159 gdev->sram_pool = pdata->sram_pool;
160 gdev->sram_vaddr = 160 gdev->sram_vaddr =
161 gen_pool_alloc(gdev->sram_pool, sram_pool_sz); 161 (unsigned long)gen_pool_dma_alloc(gdev->sram_pool,
162 sram_pool_sz, &gdev->sram_paddr);
162 if (!gdev->sram_vaddr) { 163 if (!gdev->sram_vaddr) {
163 dev_err(&dev->dev, "Could not allocate SRAM pool\n"); 164 dev_err(&dev->dev, "Could not allocate SRAM pool\n");
164 goto out_free; 165 goto out_free;
165 } 166 }
166 gdev->sram_paddr =
167 gen_pool_virt_to_phys(gdev->sram_pool,
168 gdev->sram_vaddr);
169 } 167 }
170 168
171 gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz, 169 gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz,
diff --git a/drivers/video/acornfb.c b/drivers/video/acornfb.c
index 7e8346ec9cdc..a305caea58ee 100644
--- a/drivers/video/acornfb.c
+++ b/drivers/video/acornfb.c
@@ -949,9 +949,7 @@ free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
949 * the page. 949 * the page.
950 */ 950 */
951 page = virt_to_page(virtual_start); 951 page = virt_to_page(virtual_start);
952 ClearPageReserved(page); 952 __free_reserved_page(page);
953 init_page_count(page);
954 free_page(virtual_start);
955 953
956 virtual_start += PAGE_SIZE; 954 virtual_start += PAGE_SIZE;
957 mb_freed += PAGE_SIZE / 1024; 955 mb_freed += PAGE_SIZE / 1024;
diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index 2cd63507ed74..7db5234462d0 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -196,7 +196,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
196static int pm860x_backlight_probe(struct platform_device *pdev) 196static int pm860x_backlight_probe(struct platform_device *pdev)
197{ 197{
198 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 198 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
199 struct pm860x_backlight_pdata *pdata = pdev->dev.platform_data; 199 struct pm860x_backlight_pdata *pdata = dev_get_platdata(&pdev->dev);
200 struct pm860x_backlight_data *data; 200 struct pm860x_backlight_data *data;
201 struct backlight_device *bl; 201 struct backlight_device *bl;
202 struct resource *res; 202 struct resource *res;
@@ -243,7 +243,7 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
243 memset(&props, 0, sizeof(struct backlight_properties)); 243 memset(&props, 0, sizeof(struct backlight_properties));
244 props.type = BACKLIGHT_RAW; 244 props.type = BACKLIGHT_RAW;
245 props.max_brightness = MAX_BRIGHTNESS; 245 props.max_brightness = MAX_BRIGHTNESS;
246 bl = backlight_device_register(name, &pdev->dev, data, 246 bl = devm_backlight_device_register(&pdev->dev, name, &pdev->dev, data,
247 &pm860x_backlight_ops, &props); 247 &pm860x_backlight_ops, &props);
248 if (IS_ERR(bl)) { 248 if (IS_ERR(bl)) {
249 dev_err(&pdev->dev, "failed to register backlight\n"); 249 dev_err(&pdev->dev, "failed to register backlight\n");
@@ -256,21 +256,10 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
256 /* read current backlight */ 256 /* read current backlight */
257 ret = pm860x_backlight_get_brightness(bl); 257 ret = pm860x_backlight_get_brightness(bl);
258 if (ret < 0) 258 if (ret < 0)
259 goto out_brt; 259 return ret;
260 260
261 backlight_update_status(bl); 261 backlight_update_status(bl);
262 return 0; 262 return 0;
263out_brt:
264 backlight_device_unregister(bl);
265 return ret;
266}
267
268static int pm860x_backlight_remove(struct platform_device *pdev)
269{
270 struct backlight_device *bl = platform_get_drvdata(pdev);
271
272 backlight_device_unregister(bl);
273 return 0;
274} 263}
275 264
276static struct platform_driver pm860x_backlight_driver = { 265static struct platform_driver pm860x_backlight_driver = {
@@ -279,7 +268,6 @@ static struct platform_driver pm860x_backlight_driver = {
279 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
280 }, 269 },
281 .probe = pm860x_backlight_probe, 270 .probe = pm860x_backlight_probe,
282 .remove = pm860x_backlight_remove,
283}; 271};
284 272
285module_platform_driver(pm860x_backlight_driver); 273module_platform_driver(pm860x_backlight_driver);
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index d4a7a351d67c..5a3eb2ecb525 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -368,12 +368,12 @@ config BACKLIGHT_AAT2870
368 If you have a AnalogicTech AAT2870 say Y to enable the 368 If you have a AnalogicTech AAT2870 say Y to enable the
369 backlight driver. 369 backlight driver.
370 370
371config BACKLIGHT_LM3630 371config BACKLIGHT_LM3630A
372 tristate "Backlight Driver for LM3630" 372 tristate "Backlight Driver for LM3630A"
373 depends on BACKLIGHT_CLASS_DEVICE && I2C 373 depends on BACKLIGHT_CLASS_DEVICE && I2C
374 select REGMAP_I2C 374 select REGMAP_I2C
375 help 375 help
376 This supports TI LM3630 Backlight Driver 376 This supports TI LM3630A Backlight Driver
377 377
378config BACKLIGHT_LM3639 378config BACKLIGHT_LM3639
379 tristate "Backlight Driver for LM3639" 379 tristate "Backlight Driver for LM3639"
@@ -388,8 +388,8 @@ config BACKLIGHT_LP855X
388 tristate "Backlight driver for TI LP855X" 388 tristate "Backlight driver for TI LP855X"
389 depends on BACKLIGHT_CLASS_DEVICE && I2C 389 depends on BACKLIGHT_CLASS_DEVICE && I2C
390 help 390 help
391 This supports TI LP8550, LP8551, LP8552, LP8553, LP8556 and LP8557 391 This supports TI LP8550, LP8551, LP8552, LP8553, LP8555, LP8556 and
392 backlight driver. 392 LP8557 backlight driver.
393 393
394config BACKLIGHT_LP8788 394config BACKLIGHT_LP8788
395 tristate "Backlight driver for TI LP8788 MFD" 395 tristate "Backlight driver for TI LP8788 MFD"
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 38e1babb1946..bb820024f346 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -37,7 +37,7 @@ obj-$(CONFIG_BACKLIGHT_GPIO) += gpio_backlight.o
37obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o 37obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
38obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o 38obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o
39obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o 39obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
40obj-$(CONFIG_BACKLIGHT_LM3630) += lm3630_bl.o 40obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o
41obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o 41obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
42obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o 42obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
43obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o 43obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
diff --git a/drivers/video/backlight/aat2870_bl.c b/drivers/video/backlight/aat2870_bl.c
index c6fc668d6236..ee0c0a982e4e 100644
--- a/drivers/video/backlight/aat2870_bl.c
+++ b/drivers/video/backlight/aat2870_bl.c
@@ -127,7 +127,7 @@ static const struct backlight_ops aat2870_bl_ops = {
127 127
128static int aat2870_bl_probe(struct platform_device *pdev) 128static int aat2870_bl_probe(struct platform_device *pdev)
129{ 129{
130 struct aat2870_bl_platform_data *pdata = pdev->dev.platform_data; 130 struct aat2870_bl_platform_data *pdata = dev_get_platdata(&pdev->dev);
131 struct aat2870_bl_driver_data *aat2870_bl; 131 struct aat2870_bl_driver_data *aat2870_bl;
132 struct backlight_device *bd; 132 struct backlight_device *bd;
133 struct backlight_properties props; 133 struct backlight_properties props;
@@ -158,8 +158,9 @@ static int aat2870_bl_probe(struct platform_device *pdev)
158 memset(&props, 0, sizeof(struct backlight_properties)); 158 memset(&props, 0, sizeof(struct backlight_properties));
159 159
160 props.type = BACKLIGHT_RAW; 160 props.type = BACKLIGHT_RAW;
161 bd = backlight_device_register("aat2870-backlight", &pdev->dev, 161 bd = devm_backlight_device_register(&pdev->dev, "aat2870-backlight",
162 aat2870_bl, &aat2870_bl_ops, &props); 162 &pdev->dev, aat2870_bl, &aat2870_bl_ops,
163 &props);
163 if (IS_ERR(bd)) { 164 if (IS_ERR(bd)) {
164 dev_err(&pdev->dev, 165 dev_err(&pdev->dev,
165 "Failed allocate memory for backlight device\n"); 166 "Failed allocate memory for backlight device\n");
@@ -194,13 +195,11 @@ static int aat2870_bl_probe(struct platform_device *pdev)
194 ret = aat2870_bl_update_status(bd); 195 ret = aat2870_bl_update_status(bd);
195 if (ret < 0) { 196 if (ret < 0) {
196 dev_err(&pdev->dev, "Failed to initialize\n"); 197 dev_err(&pdev->dev, "Failed to initialize\n");
197 goto out_bl_dev_unregister; 198 return ret;
198 } 199 }
199 200
200 return 0; 201 return 0;
201 202
202out_bl_dev_unregister:
203 backlight_device_unregister(bd);
204out: 203out:
205 return ret; 204 return ret;
206} 205}
@@ -214,8 +213,6 @@ static int aat2870_bl_remove(struct platform_device *pdev)
214 bd->props.brightness = 0; 213 bd->props.brightness = 0;
215 backlight_update_status(bd); 214 backlight_update_status(bd);
216 215
217 backlight_device_unregister(bd);
218
219 return 0; 216 return 0;
220} 217}
221 218
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index c84701b7ca6e..f37097a261a2 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -297,7 +297,7 @@ static int adp5520_bl_probe(struct platform_device *pdev)
297 return -ENOMEM; 297 return -ENOMEM;
298 298
299 data->master = pdev->dev.parent; 299 data->master = pdev->dev.parent;
300 data->pdata = pdev->dev.platform_data; 300 data->pdata = dev_get_platdata(&pdev->dev);
301 301
302 if (data->pdata == NULL) { 302 if (data->pdata == NULL) {
303 dev_err(&pdev->dev, "missing platform data\n"); 303 dev_err(&pdev->dev, "missing platform data\n");
@@ -312,8 +312,9 @@ static int adp5520_bl_probe(struct platform_device *pdev)
312 memset(&props, 0, sizeof(struct backlight_properties)); 312 memset(&props, 0, sizeof(struct backlight_properties));
313 props.type = BACKLIGHT_RAW; 313 props.type = BACKLIGHT_RAW;
314 props.max_brightness = ADP5020_MAX_BRIGHTNESS; 314 props.max_brightness = ADP5020_MAX_BRIGHTNESS;
315 bl = backlight_device_register(pdev->name, data->master, data, 315 bl = devm_backlight_device_register(&pdev->dev, pdev->name,
316 &adp5520_bl_ops, &props); 316 data->master, data, &adp5520_bl_ops,
317 &props);
317 if (IS_ERR(bl)) { 318 if (IS_ERR(bl)) {
318 dev_err(&pdev->dev, "failed to register backlight\n"); 319 dev_err(&pdev->dev, "failed to register backlight\n");
319 return PTR_ERR(bl); 320 return PTR_ERR(bl);
@@ -326,7 +327,7 @@ static int adp5520_bl_probe(struct platform_device *pdev)
326 327
327 if (ret) { 328 if (ret) {
328 dev_err(&pdev->dev, "failed to register sysfs\n"); 329 dev_err(&pdev->dev, "failed to register sysfs\n");
329 backlight_device_unregister(bl); 330 return ret;
330 } 331 }
331 332
332 platform_set_drvdata(pdev, bl); 333 platform_set_drvdata(pdev, bl);
@@ -347,8 +348,6 @@ static int adp5520_bl_remove(struct platform_device *pdev)
347 sysfs_remove_group(&bl->dev.kobj, 348 sysfs_remove_group(&bl->dev.kobj,
348 &adp5520_bl_attr_group); 349 &adp5520_bl_attr_group);
349 350
350 backlight_device_unregister(bl);
351
352 return 0; 351 return 0;
353} 352}
354 353
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
index 75b10f876127..9d656717d0f7 100644
--- a/drivers/video/backlight/adp8860_bl.c
+++ b/drivers/video/backlight/adp8860_bl.c
@@ -216,7 +216,7 @@ static int adp8860_led_setup(struct adp8860_led *led)
216static int adp8860_led_probe(struct i2c_client *client) 216static int adp8860_led_probe(struct i2c_client *client)
217{ 217{
218 struct adp8860_backlight_platform_data *pdata = 218 struct adp8860_backlight_platform_data *pdata =
219 client->dev.platform_data; 219 dev_get_platdata(&client->dev);
220 struct adp8860_bl *data = i2c_get_clientdata(client); 220 struct adp8860_bl *data = i2c_get_clientdata(client);
221 struct adp8860_led *led, *led_dat; 221 struct adp8860_led *led, *led_dat;
222 struct led_info *cur_led; 222 struct led_info *cur_led;
@@ -300,7 +300,7 @@ static int adp8860_led_probe(struct i2c_client *client)
300static int adp8860_led_remove(struct i2c_client *client) 300static int adp8860_led_remove(struct i2c_client *client)
301{ 301{
302 struct adp8860_backlight_platform_data *pdata = 302 struct adp8860_backlight_platform_data *pdata =
303 client->dev.platform_data; 303 dev_get_platdata(&client->dev);
304 struct adp8860_bl *data = i2c_get_clientdata(client); 304 struct adp8860_bl *data = i2c_get_clientdata(client);
305 int i; 305 int i;
306 306
@@ -658,7 +658,7 @@ static int adp8860_probe(struct i2c_client *client,
658 struct backlight_device *bl; 658 struct backlight_device *bl;
659 struct adp8860_bl *data; 659 struct adp8860_bl *data;
660 struct adp8860_backlight_platform_data *pdata = 660 struct adp8860_backlight_platform_data *pdata =
661 client->dev.platform_data; 661 dev_get_platdata(&client->dev);
662 struct backlight_properties props; 662 struct backlight_properties props;
663 uint8_t reg_val; 663 uint8_t reg_val;
664 int ret; 664 int ret;
@@ -711,8 +711,9 @@ static int adp8860_probe(struct i2c_client *client,
711 711
712 mutex_init(&data->lock); 712 mutex_init(&data->lock);
713 713
714 bl = backlight_device_register(dev_driver_string(&client->dev), 714 bl = devm_backlight_device_register(&client->dev,
715 &client->dev, data, &adp8860_bl_ops, &props); 715 dev_driver_string(&client->dev),
716 &client->dev, data, &adp8860_bl_ops, &props);
716 if (IS_ERR(bl)) { 717 if (IS_ERR(bl)) {
717 dev_err(&client->dev, "failed to register backlight\n"); 718 dev_err(&client->dev, "failed to register backlight\n");
718 return PTR_ERR(bl); 719 return PTR_ERR(bl);
@@ -728,7 +729,7 @@ static int adp8860_probe(struct i2c_client *client,
728 729
729 if (ret) { 730 if (ret) {
730 dev_err(&client->dev, "failed to register sysfs\n"); 731 dev_err(&client->dev, "failed to register sysfs\n");
731 goto out1; 732 return ret;
732 } 733 }
733 734
734 ret = adp8860_bl_setup(bl); 735 ret = adp8860_bl_setup(bl);
@@ -751,8 +752,6 @@ out:
751 if (data->en_ambl_sens) 752 if (data->en_ambl_sens)
752 sysfs_remove_group(&data->bl->dev.kobj, 753 sysfs_remove_group(&data->bl->dev.kobj,
753 &adp8860_bl_attr_group); 754 &adp8860_bl_attr_group);
754out1:
755 backlight_device_unregister(bl);
756 755
757 return ret; 756 return ret;
758} 757}
@@ -770,8 +769,6 @@ static int adp8860_remove(struct i2c_client *client)
770 sysfs_remove_group(&data->bl->dev.kobj, 769 sysfs_remove_group(&data->bl->dev.kobj,
771 &adp8860_bl_attr_group); 770 &adp8860_bl_attr_group);
772 771
773 backlight_device_unregister(data->bl);
774
775 return 0; 772 return 0;
776} 773}
777 774
diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
index 90049d7b5c60..63707205326b 100644
--- a/drivers/video/backlight/adp8870_bl.c
+++ b/drivers/video/backlight/adp8870_bl.c
@@ -238,7 +238,7 @@ static int adp8870_led_setup(struct adp8870_led *led)
238static int adp8870_led_probe(struct i2c_client *client) 238static int adp8870_led_probe(struct i2c_client *client)
239{ 239{
240 struct adp8870_backlight_platform_data *pdata = 240 struct adp8870_backlight_platform_data *pdata =
241 client->dev.platform_data; 241 dev_get_platdata(&client->dev);
242 struct adp8870_bl *data = i2c_get_clientdata(client); 242 struct adp8870_bl *data = i2c_get_clientdata(client);
243 struct adp8870_led *led, *led_dat; 243 struct adp8870_led *led, *led_dat;
244 struct led_info *cur_led; 244 struct led_info *cur_led;
@@ -325,7 +325,7 @@ static int adp8870_led_probe(struct i2c_client *client)
325static int adp8870_led_remove(struct i2c_client *client) 325static int adp8870_led_remove(struct i2c_client *client)
326{ 326{
327 struct adp8870_backlight_platform_data *pdata = 327 struct adp8870_backlight_platform_data *pdata =
328 client->dev.platform_data; 328 dev_get_platdata(&client->dev);
329 struct adp8870_bl *data = i2c_get_clientdata(client); 329 struct adp8870_bl *data = i2c_get_clientdata(client);
330 int i; 330 int i;
331 331
@@ -848,7 +848,7 @@ static int adp8870_probe(struct i2c_client *client,
848 struct backlight_device *bl; 848 struct backlight_device *bl;
849 struct adp8870_bl *data; 849 struct adp8870_bl *data;
850 struct adp8870_backlight_platform_data *pdata = 850 struct adp8870_backlight_platform_data *pdata =
851 client->dev.platform_data; 851 dev_get_platdata(&client->dev);
852 uint8_t reg_val; 852 uint8_t reg_val;
853 int ret; 853 int ret;
854 854
@@ -888,8 +888,9 @@ static int adp8870_probe(struct i2c_client *client,
888 memset(&props, 0, sizeof(props)); 888 memset(&props, 0, sizeof(props));
889 props.type = BACKLIGHT_RAW; 889 props.type = BACKLIGHT_RAW;
890 props.max_brightness = props.brightness = ADP8870_MAX_BRIGHTNESS; 890 props.max_brightness = props.brightness = ADP8870_MAX_BRIGHTNESS;
891 bl = backlight_device_register(dev_driver_string(&client->dev), 891 bl = devm_backlight_device_register(&client->dev,
892 &client->dev, data, &adp8870_bl_ops, &props); 892 dev_driver_string(&client->dev),
893 &client->dev, data, &adp8870_bl_ops, &props);
893 if (IS_ERR(bl)) { 894 if (IS_ERR(bl)) {
894 dev_err(&client->dev, "failed to register backlight\n"); 895 dev_err(&client->dev, "failed to register backlight\n");
895 return PTR_ERR(bl); 896 return PTR_ERR(bl);
@@ -902,7 +903,7 @@ static int adp8870_probe(struct i2c_client *client,
902 &adp8870_bl_attr_group); 903 &adp8870_bl_attr_group);
903 if (ret) { 904 if (ret) {
904 dev_err(&client->dev, "failed to register sysfs\n"); 905 dev_err(&client->dev, "failed to register sysfs\n");
905 goto out1; 906 return ret;
906 } 907 }
907 } 908 }
908 909
@@ -925,8 +926,6 @@ out:
925 if (data->pdata->en_ambl_sens) 926 if (data->pdata->en_ambl_sens)
926 sysfs_remove_group(&data->bl->dev.kobj, 927 sysfs_remove_group(&data->bl->dev.kobj,
927 &adp8870_bl_attr_group); 928 &adp8870_bl_attr_group);
928out1:
929 backlight_device_unregister(bl);
930 929
931 return ret; 930 return ret;
932} 931}
@@ -944,8 +943,6 @@ static int adp8870_remove(struct i2c_client *client)
944 sysfs_remove_group(&data->bl->dev.kobj, 943 sysfs_remove_group(&data->bl->dev.kobj,
945 &adp8870_bl_attr_group); 944 &adp8870_bl_attr_group);
946 945
947 backlight_device_unregister(data->bl);
948
949 return 0; 946 return 0;
950} 947}
951 948
diff --git a/drivers/video/backlight/ams369fg06.c b/drivers/video/backlight/ams369fg06.c
index 319fef6cb422..d8952c4aa689 100644
--- a/drivers/video/backlight/ams369fg06.c
+++ b/drivers/video/backlight/ams369fg06.c
@@ -471,14 +471,14 @@ static int ams369fg06_probe(struct spi_device *spi)
471 lcd->spi = spi; 471 lcd->spi = spi;
472 lcd->dev = &spi->dev; 472 lcd->dev = &spi->dev;
473 473
474 lcd->lcd_pd = spi->dev.platform_data; 474 lcd->lcd_pd = dev_get_platdata(&spi->dev);
475 if (!lcd->lcd_pd) { 475 if (!lcd->lcd_pd) {
476 dev_err(&spi->dev, "platform data is NULL\n"); 476 dev_err(&spi->dev, "platform data is NULL\n");
477 return -EINVAL; 477 return -EINVAL;
478 } 478 }
479 479
480 ld = lcd_device_register("ams369fg06", &spi->dev, lcd, 480 ld = devm_lcd_device_register(&spi->dev, "ams369fg06", &spi->dev, lcd,
481 &ams369fg06_lcd_ops); 481 &ams369fg06_lcd_ops);
482 if (IS_ERR(ld)) 482 if (IS_ERR(ld))
483 return PTR_ERR(ld); 483 return PTR_ERR(ld);
484 484
@@ -488,12 +488,11 @@ static int ams369fg06_probe(struct spi_device *spi)
488 props.type = BACKLIGHT_RAW; 488 props.type = BACKLIGHT_RAW;
489 props.max_brightness = MAX_BRIGHTNESS; 489 props.max_brightness = MAX_BRIGHTNESS;
490 490
491 bd = backlight_device_register("ams369fg06-bl", &spi->dev, lcd, 491 bd = devm_backlight_device_register(&spi->dev, "ams369fg06-bl",
492 &ams369fg06_backlight_ops, &props); 492 &spi->dev, lcd,
493 if (IS_ERR(bd)) { 493 &ams369fg06_backlight_ops, &props);
494 ret = PTR_ERR(bd); 494 if (IS_ERR(bd))
495 goto out_lcd_unregister; 495 return PTR_ERR(bd);
496 }
497 496
498 bd->props.brightness = DEFAULT_BRIGHTNESS; 497 bd->props.brightness = DEFAULT_BRIGHTNESS;
499 lcd->bd = bd; 498 lcd->bd = bd;
@@ -516,10 +515,6 @@ static int ams369fg06_probe(struct spi_device *spi)
516 dev_info(&spi->dev, "ams369fg06 panel driver has been probed.\n"); 515 dev_info(&spi->dev, "ams369fg06 panel driver has been probed.\n");
517 516
518 return 0; 517 return 0;
519
520out_lcd_unregister:
521 lcd_device_unregister(ld);
522 return ret;
523} 518}
524 519
525static int ams369fg06_remove(struct spi_device *spi) 520static int ams369fg06_remove(struct spi_device *spi)
@@ -527,9 +522,6 @@ static int ams369fg06_remove(struct spi_device *spi)
527 struct ams369fg06 *lcd = spi_get_drvdata(spi); 522 struct ams369fg06 *lcd = spi_get_drvdata(spi);
528 523
529 ams369fg06_power(lcd, FB_BLANK_POWERDOWN); 524 ams369fg06_power(lcd, FB_BLANK_POWERDOWN);
530 backlight_device_unregister(lcd->bd);
531 lcd_device_unregister(lcd->ld);
532
533 return 0; 525 return 0;
534} 526}
535 527
diff --git a/drivers/video/backlight/as3711_bl.c b/drivers/video/backlight/as3711_bl.c
index 123887cd76bd..bb1fc45b7549 100644
--- a/drivers/video/backlight/as3711_bl.c
+++ b/drivers/video/backlight/as3711_bl.c
@@ -240,7 +240,8 @@ static int as3711_bl_register(struct platform_device *pdev,
240 /* max tuning I = 31uA for voltage- and 38250uA for current-feedback */ 240 /* max tuning I = 31uA for voltage- and 38250uA for current-feedback */
241 props.max_brightness = max_brightness; 241 props.max_brightness = max_brightness;
242 242
243 bl = backlight_device_register(su->type == AS3711_BL_SU1 ? 243 bl = devm_backlight_device_register(&pdev->dev,
244 su->type == AS3711_BL_SU1 ?
244 "as3711-su1" : "as3711-su2", 245 "as3711-su1" : "as3711-su2",
245 &pdev->dev, su, 246 &pdev->dev, su,
246 &as3711_bl_ops, &props); 247 &as3711_bl_ops, &props);
@@ -432,8 +433,7 @@ static int as3711_backlight_probe(struct platform_device *pdev)
432 case AS3711_SU2_LX_SD4: 433 case AS3711_SU2_LX_SD4:
433 break; 434 break;
434 default: 435 default:
435 ret = -EINVAL; 436 return -EINVAL;
436 goto esu2;
437 } 437 }
438 438
439 switch (pdata->su2_feedback) { 439 switch (pdata->su2_feedback) {
@@ -447,8 +447,7 @@ static int as3711_backlight_probe(struct platform_device *pdev)
447 max_brightness = min(pdata->su2_max_uA / 150, 255); 447 max_brightness = min(pdata->su2_max_uA / 150, 255);
448 break; 448 break;
449 default: 449 default:
450 ret = -EINVAL; 450 return -EINVAL;
451 goto esu2;
452 } 451 }
453 452
454 ret = as3711_bl_init_su2(supply); 453 ret = as3711_bl_init_su2(supply);
@@ -457,26 +456,12 @@ static int as3711_backlight_probe(struct platform_device *pdev)
457 456
458 ret = as3711_bl_register(pdev, max_brightness, su); 457 ret = as3711_bl_register(pdev, max_brightness, su);
459 if (ret < 0) 458 if (ret < 0)
460 goto esu2; 459 return ret;
461 } 460 }
462 461
463 platform_set_drvdata(pdev, supply); 462 platform_set_drvdata(pdev, supply);
464 463
465 return 0; 464 return 0;
466
467esu2:
468 backlight_device_unregister(supply->su1.bl);
469 return ret;
470}
471
472static int as3711_backlight_remove(struct platform_device *pdev)
473{
474 struct as3711_bl_supply *supply = platform_get_drvdata(pdev);
475
476 backlight_device_unregister(supply->su1.bl);
477 backlight_device_unregister(supply->su2.bl);
478
479 return 0;
480} 465}
481 466
482static struct platform_driver as3711_backlight_driver = { 467static struct platform_driver as3711_backlight_driver = {
@@ -485,7 +470,6 @@ static struct platform_driver as3711_backlight_driver = {
485 .owner = THIS_MODULE, 470 .owner = THIS_MODULE,
486 }, 471 },
487 .probe = as3711_backlight_probe, 472 .probe = as3711_backlight_probe,
488 .remove = as3711_backlight_remove,
489}; 473};
490 474
491module_platform_driver(as3711_backlight_driver); 475module_platform_driver(as3711_backlight_driver);
diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index f7447f7004fb..261b1a4ec3d8 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -12,7 +12,6 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/fb.h> 14#include <linux/fb.h>
15#include <linux/clk.h>
16#include <linux/gpio.h> 15#include <linux/gpio.h>
17#include <linux/backlight.h> 16#include <linux/backlight.h>
18#include <linux/atmel_pwm.h> 17#include <linux/atmel_pwm.h>
@@ -27,6 +26,14 @@ struct atmel_pwm_bl {
27 int gpio_on; 26 int gpio_on;
28}; 27};
29 28
29static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
30{
31 if (!gpio_is_valid(pwmbl->gpio_on))
32 return;
33
34 gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
35}
36
30static int atmel_pwm_bl_set_intensity(struct backlight_device *bd) 37static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
31{ 38{
32 struct atmel_pwm_bl *pwmbl = bl_get_data(bd); 39 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
@@ -49,19 +56,13 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
49 pwm_duty = pwmbl->pdata->pwm_duty_min; 56 pwm_duty = pwmbl->pdata->pwm_duty_min;
50 57
51 if (!intensity) { 58 if (!intensity) {
52 if (pwmbl->gpio_on != -1) { 59 atmel_pwm_bl_set_gpio_on(pwmbl, 0);
53 gpio_set_value(pwmbl->gpio_on,
54 0 ^ pwmbl->pdata->on_active_low);
55 }
56 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty); 60 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
57 pwm_channel_disable(&pwmbl->pwmc); 61 pwm_channel_disable(&pwmbl->pwmc);
58 } else { 62 } else {
59 pwm_channel_enable(&pwmbl->pwmc); 63 pwm_channel_enable(&pwmbl->pwmc);
60 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty); 64 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
61 if (pwmbl->gpio_on != -1) { 65 atmel_pwm_bl_set_gpio_on(pwmbl, 1);
62 gpio_set_value(pwmbl->gpio_on,
63 1 ^ pwmbl->pdata->on_active_low);
64 }
65 } 66 }
66 67
67 return 0; 68 return 0;
@@ -70,17 +71,16 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
70static int atmel_pwm_bl_get_intensity(struct backlight_device *bd) 71static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
71{ 72{
72 struct atmel_pwm_bl *pwmbl = bl_get_data(bd); 73 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
73 u8 intensity; 74 u32 cdty;
75 u32 intensity;
74 76
75 if (pwmbl->pdata->pwm_active_low) { 77 cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
76 intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) - 78 if (pwmbl->pdata->pwm_active_low)
77 pwmbl->pdata->pwm_duty_min; 79 intensity = cdty - pwmbl->pdata->pwm_duty_min;
78 } else { 80 else
79 intensity = pwmbl->pdata->pwm_duty_max - 81 intensity = pwmbl->pdata->pwm_duty_max - cdty;
80 pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
81 }
82 82
83 return intensity; 83 return intensity & 0xffff;
84} 84}
85 85
86static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl) 86static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
@@ -124,46 +124,40 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
124 const struct atmel_pwm_bl_platform_data *pdata; 124 const struct atmel_pwm_bl_platform_data *pdata;
125 struct backlight_device *bldev; 125 struct backlight_device *bldev;
126 struct atmel_pwm_bl *pwmbl; 126 struct atmel_pwm_bl *pwmbl;
127 unsigned long flags;
127 int retval; 128 int retval;
128 129
130 pdata = dev_get_platdata(&pdev->dev);
131 if (!pdata)
132 return -ENODEV;
133
134 if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
135 pdata->pwm_duty_min > pdata->pwm_duty_max ||
136 pdata->pwm_frequency == 0)
137 return -EINVAL;
138
129 pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl), 139 pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
130 GFP_KERNEL); 140 GFP_KERNEL);
131 if (!pwmbl) 141 if (!pwmbl)
132 return -ENOMEM; 142 return -ENOMEM;
133 143
134 pwmbl->pdev = pdev; 144 pwmbl->pdev = pdev;
135
136 pdata = pdev->dev.platform_data;
137 if (!pdata) {
138 retval = -ENODEV;
139 goto err_free_mem;
140 }
141
142 if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
143 pdata->pwm_duty_min > pdata->pwm_duty_max ||
144 pdata->pwm_frequency == 0) {
145 retval = -EINVAL;
146 goto err_free_mem;
147 }
148
149 pwmbl->pdata = pdata; 145 pwmbl->pdata = pdata;
150 pwmbl->gpio_on = pdata->gpio_on; 146 pwmbl->gpio_on = pdata->gpio_on;
151 147
152 retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc); 148 retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
153 if (retval) 149 if (retval)
154 goto err_free_mem; 150 return retval;
155
156 if (pwmbl->gpio_on != -1) {
157 retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
158 "gpio_atmel_pwm_bl");
159 if (retval) {
160 pwmbl->gpio_on = -1;
161 goto err_free_pwm;
162 }
163 151
152 if (gpio_is_valid(pwmbl->gpio_on)) {
164 /* Turn display off by default. */ 153 /* Turn display off by default. */
165 retval = gpio_direction_output(pwmbl->gpio_on, 154 if (pdata->on_active_low)
166 0 ^ pdata->on_active_low); 155 flags = GPIOF_OUT_INIT_HIGH;
156 else
157 flags = GPIOF_OUT_INIT_LOW;
158
159 retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
160 flags, "gpio_atmel_pwm_bl");
167 if (retval) 161 if (retval)
168 goto err_free_pwm; 162 goto err_free_pwm;
169 } 163 }
@@ -171,8 +165,9 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
171 memset(&props, 0, sizeof(struct backlight_properties)); 165 memset(&props, 0, sizeof(struct backlight_properties));
172 props.type = BACKLIGHT_RAW; 166 props.type = BACKLIGHT_RAW;
173 props.max_brightness = pdata->pwm_duty_max - pdata->pwm_duty_min; 167 props.max_brightness = pdata->pwm_duty_max - pdata->pwm_duty_min;
174 bldev = backlight_device_register("atmel-pwm-bl", &pdev->dev, pwmbl, 168 bldev = devm_backlight_device_register(&pdev->dev, "atmel-pwm-bl",
175 &atmel_pwm_bl_ops, &props); 169 &pdev->dev, pwmbl, &atmel_pwm_bl_ops,
170 &props);
176 if (IS_ERR(bldev)) { 171 if (IS_ERR(bldev)) {
177 retval = PTR_ERR(bldev); 172 retval = PTR_ERR(bldev);
178 goto err_free_pwm; 173 goto err_free_pwm;
@@ -188,17 +183,15 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
188 183
189 retval = atmel_pwm_bl_init_pwm(pwmbl); 184 retval = atmel_pwm_bl_init_pwm(pwmbl);
190 if (retval) 185 if (retval)
191 goto err_free_bl_dev; 186 goto err_free_pwm;
192 187
193 atmel_pwm_bl_set_intensity(bldev); 188 atmel_pwm_bl_set_intensity(bldev);
194 189
195 return 0; 190 return 0;
196 191
197err_free_bl_dev:
198 backlight_device_unregister(bldev);
199err_free_pwm: 192err_free_pwm:
200 pwm_channel_free(&pwmbl->pwmc); 193 pwm_channel_free(&pwmbl->pwmc);
201err_free_mem: 194
202 return retval; 195 return retval;
203} 196}
204 197
@@ -206,11 +199,9 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
206{ 199{
207 struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev); 200 struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
208 201
209 if (pwmbl->gpio_on != -1) 202 atmel_pwm_bl_set_gpio_on(pwmbl, 0);
210 gpio_set_value(pwmbl->gpio_on, 0);
211 pwm_channel_disable(&pwmbl->pwmc); 203 pwm_channel_disable(&pwmbl->pwmc);
212 pwm_channel_free(&pwmbl->pwmc); 204 pwm_channel_free(&pwmbl->pwmc);
213 backlight_device_unregister(pwmbl->bldev);
214 205
215 return 0; 206 return 0;
216} 207}
@@ -229,3 +220,4 @@ module_platform_driver(atmel_pwm_bl_driver);
229MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>"); 220MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
230MODULE_DESCRIPTION("Atmel PWM backlight driver"); 221MODULE_DESCRIPTION("Atmel PWM backlight driver");
231MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
223MODULE_ALIAS("platform:atmel-pwm-bl");
diff --git a/drivers/video/backlight/bd6107.c b/drivers/video/backlight/bd6107.c
index 15e3294b29fe..16dd9bc625bd 100644
--- a/drivers/video/backlight/bd6107.c
+++ b/drivers/video/backlight/bd6107.c
@@ -128,7 +128,7 @@ static const struct backlight_ops bd6107_backlight_ops = {
128static int bd6107_probe(struct i2c_client *client, 128static int bd6107_probe(struct i2c_client *client,
129 const struct i2c_device_id *id) 129 const struct i2c_device_id *id)
130{ 130{
131 struct bd6107_platform_data *pdata = client->dev.platform_data; 131 struct bd6107_platform_data *pdata = dev_get_platdata(&client->dev);
132 struct backlight_device *backlight; 132 struct backlight_device *backlight;
133 struct backlight_properties props; 133 struct backlight_properties props;
134 struct bd6107 *bd; 134 struct bd6107 *bd;
@@ -166,7 +166,8 @@ static int bd6107_probe(struct i2c_client *client,
166 props.brightness = clamp_t(unsigned int, pdata->def_value, 0, 166 props.brightness = clamp_t(unsigned int, pdata->def_value, 0,
167 props.max_brightness); 167 props.max_brightness);
168 168
169 backlight = backlight_device_register(dev_name(&client->dev), 169 backlight = devm_backlight_device_register(&client->dev,
170 dev_name(&client->dev),
170 &bd->client->dev, bd, 171 &bd->client->dev, bd,
171 &bd6107_backlight_ops, &props); 172 &bd6107_backlight_ops, &props);
172 if (IS_ERR(backlight)) { 173 if (IS_ERR(backlight)) {
@@ -186,7 +187,6 @@ static int bd6107_remove(struct i2c_client *client)
186 187
187 backlight->props.brightness = 0; 188 backlight->props.brightness = 0;
188 backlight_update_status(backlight); 189 backlight_update_status(backlight);
189 backlight_device_unregister(backlight);
190 190
191 return 0; 191 return 0;
192} 192}
diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
index c97867a717a7..db8db5fa6583 100644
--- a/drivers/video/backlight/corgi_lcd.c
+++ b/drivers/video/backlight/corgi_lcd.c
@@ -533,7 +533,7 @@ static int setup_gpio_backlight(struct corgi_lcd *lcd,
533static int corgi_lcd_probe(struct spi_device *spi) 533static int corgi_lcd_probe(struct spi_device *spi)
534{ 534{
535 struct backlight_properties props; 535 struct backlight_properties props;
536 struct corgi_lcd_platform_data *pdata = spi->dev.platform_data; 536 struct corgi_lcd_platform_data *pdata = dev_get_platdata(&spi->dev);
537 struct corgi_lcd *lcd; 537 struct corgi_lcd *lcd;
538 int ret = 0; 538 int ret = 0;
539 539
@@ -550,8 +550,8 @@ static int corgi_lcd_probe(struct spi_device *spi)
550 550
551 lcd->spi_dev = spi; 551 lcd->spi_dev = spi;
552 552
553 lcd->lcd_dev = lcd_device_register("corgi_lcd", &spi->dev, 553 lcd->lcd_dev = devm_lcd_device_register(&spi->dev, "corgi_lcd",
554 lcd, &corgi_lcd_ops); 554 &spi->dev, lcd, &corgi_lcd_ops);
555 if (IS_ERR(lcd->lcd_dev)) 555 if (IS_ERR(lcd->lcd_dev))
556 return PTR_ERR(lcd->lcd_dev); 556 return PTR_ERR(lcd->lcd_dev);
557 557
@@ -561,18 +561,18 @@ static int corgi_lcd_probe(struct spi_device *spi)
561 memset(&props, 0, sizeof(struct backlight_properties)); 561 memset(&props, 0, sizeof(struct backlight_properties));
562 props.type = BACKLIGHT_RAW; 562 props.type = BACKLIGHT_RAW;
563 props.max_brightness = pdata->max_intensity; 563 props.max_brightness = pdata->max_intensity;
564 lcd->bl_dev = backlight_device_register("corgi_bl", &spi->dev, lcd, 564 lcd->bl_dev = devm_backlight_device_register(&spi->dev, "corgi_bl",
565 &corgi_bl_ops, &props); 565 &spi->dev, lcd, &corgi_bl_ops,
566 if (IS_ERR(lcd->bl_dev)) { 566 &props);
567 ret = PTR_ERR(lcd->bl_dev); 567 if (IS_ERR(lcd->bl_dev))
568 goto err_unregister_lcd; 568 return PTR_ERR(lcd->bl_dev);
569 } 569
570 lcd->bl_dev->props.brightness = pdata->default_intensity; 570 lcd->bl_dev->props.brightness = pdata->default_intensity;
571 lcd->bl_dev->props.power = FB_BLANK_UNBLANK; 571 lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
572 572
573 ret = setup_gpio_backlight(lcd, pdata); 573 ret = setup_gpio_backlight(lcd, pdata);
574 if (ret) 574 if (ret)
575 goto err_unregister_bl; 575 return ret;
576 576
577 lcd->kick_battery = pdata->kick_battery; 577 lcd->kick_battery = pdata->kick_battery;
578 578
@@ -583,12 +583,6 @@ static int corgi_lcd_probe(struct spi_device *spi)
583 lcd->limit_mask = pdata->limit_mask; 583 lcd->limit_mask = pdata->limit_mask;
584 the_corgi_lcd = lcd; 584 the_corgi_lcd = lcd;
585 return 0; 585 return 0;
586
587err_unregister_bl:
588 backlight_device_unregister(lcd->bl_dev);
589err_unregister_lcd:
590 lcd_device_unregister(lcd->lcd_dev);
591 return ret;
592} 586}
593 587
594static int corgi_lcd_remove(struct spi_device *spi) 588static int corgi_lcd_remove(struct spi_device *spi)
@@ -598,11 +592,7 @@ static int corgi_lcd_remove(struct spi_device *spi)
598 lcd->bl_dev->props.power = FB_BLANK_UNBLANK; 592 lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
599 lcd->bl_dev->props.brightness = 0; 593 lcd->bl_dev->props.brightness = 0;
600 backlight_update_status(lcd->bl_dev); 594 backlight_update_status(lcd->bl_dev);
601 backlight_device_unregister(lcd->bl_dev);
602
603 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN); 595 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN);
604 lcd_device_unregister(lcd->lcd_dev);
605
606 return 0; 596 return 0;
607} 597}
608 598
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
index 37bae801e23b..f3fed9ef745f 100644
--- a/drivers/video/backlight/cr_bllcd.c
+++ b/drivers/video/backlight/cr_bllcd.c
@@ -195,16 +195,17 @@ static int cr_backlight_probe(struct platform_device *pdev)
195 195
196 memset(&props, 0, sizeof(struct backlight_properties)); 196 memset(&props, 0, sizeof(struct backlight_properties));
197 props.type = BACKLIGHT_RAW; 197 props.type = BACKLIGHT_RAW;
198 bdp = backlight_device_register("cr-backlight", &pdev->dev, NULL, 198 bdp = devm_backlight_device_register(&pdev->dev, "cr-backlight",
199 &cr_backlight_ops, &props); 199 &pdev->dev, NULL, &cr_backlight_ops,
200 &props);
200 if (IS_ERR(bdp)) { 201 if (IS_ERR(bdp)) {
201 pci_dev_put(lpc_dev); 202 pci_dev_put(lpc_dev);
202 return PTR_ERR(bdp); 203 return PTR_ERR(bdp);
203 } 204 }
204 205
205 ldp = lcd_device_register("cr-lcd", &pdev->dev, NULL, &cr_lcd_ops); 206 ldp = devm_lcd_device_register(&pdev->dev, "cr-lcd", &pdev->dev, NULL,
207 &cr_lcd_ops);
206 if (IS_ERR(ldp)) { 208 if (IS_ERR(ldp)) {
207 backlight_device_unregister(bdp);
208 pci_dev_put(lpc_dev); 209 pci_dev_put(lpc_dev);
209 return PTR_ERR(ldp); 210 return PTR_ERR(ldp);
210 } 211 }
@@ -215,8 +216,6 @@ static int cr_backlight_probe(struct platform_device *pdev)
215 216
216 crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL); 217 crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL);
217 if (!crp) { 218 if (!crp) {
218 lcd_device_unregister(ldp);
219 backlight_device_unregister(bdp);
220 pci_dev_put(lpc_dev); 219 pci_dev_put(lpc_dev);
221 return -ENOMEM; 220 return -ENOMEM;
222 } 221 }
@@ -241,8 +240,6 @@ static int cr_backlight_remove(struct platform_device *pdev)
241 crp->cr_backlight_device->props.max_brightness = 0; 240 crp->cr_backlight_device->props.max_brightness = 0;
242 cr_backlight_set_intensity(crp->cr_backlight_device); 241 cr_backlight_set_intensity(crp->cr_backlight_device);
243 cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN); 242 cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN);
244 backlight_device_unregister(crp->cr_backlight_device);
245 lcd_device_unregister(crp->cr_lcd_device);
246 pci_dev_put(lpc_dev); 243 pci_dev_put(lpc_dev);
247 244
248 return 0; 245 return 0;
diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
index 67cadd30e273..12c5d840c590 100644
--- a/drivers/video/backlight/da903x_bl.c
+++ b/drivers/video/backlight/da903x_bl.c
@@ -109,7 +109,7 @@ static const struct backlight_ops da903x_backlight_ops = {
109 109
110static int da903x_backlight_probe(struct platform_device *pdev) 110static int da903x_backlight_probe(struct platform_device *pdev)
111{ 111{
112 struct da9034_backlight_pdata *pdata = pdev->dev.platform_data; 112 struct da9034_backlight_pdata *pdata = dev_get_platdata(&pdev->dev);
113 struct da903x_backlight_data *data; 113 struct da903x_backlight_data *data;
114 struct backlight_device *bl; 114 struct backlight_device *bl;
115 struct backlight_properties props; 115 struct backlight_properties props;
@@ -144,8 +144,9 @@ static int da903x_backlight_probe(struct platform_device *pdev)
144 memset(&props, 0, sizeof(props)); 144 memset(&props, 0, sizeof(props));
145 props.type = BACKLIGHT_RAW; 145 props.type = BACKLIGHT_RAW;
146 props.max_brightness = max_brightness; 146 props.max_brightness = max_brightness;
147 bl = backlight_device_register(pdev->name, data->da903x_dev, data, 147 bl = devm_backlight_device_register(&pdev->dev, pdev->name,
148 &da903x_backlight_ops, &props); 148 data->da903x_dev, data,
149 &da903x_backlight_ops, &props);
149 if (IS_ERR(bl)) { 150 if (IS_ERR(bl)) {
150 dev_err(&pdev->dev, "failed to register backlight\n"); 151 dev_err(&pdev->dev, "failed to register backlight\n");
151 return PTR_ERR(bl); 152 return PTR_ERR(bl);
@@ -158,21 +159,12 @@ static int da903x_backlight_probe(struct platform_device *pdev)
158 return 0; 159 return 0;
159} 160}
160 161
161static int da903x_backlight_remove(struct platform_device *pdev)
162{
163 struct backlight_device *bl = platform_get_drvdata(pdev);
164
165 backlight_device_unregister(bl);
166 return 0;
167}
168
169static struct platform_driver da903x_backlight_driver = { 162static struct platform_driver da903x_backlight_driver = {
170 .driver = { 163 .driver = {
171 .name = "da903x-backlight", 164 .name = "da903x-backlight",
172 .owner = THIS_MODULE, 165 .owner = THIS_MODULE,
173 }, 166 },
174 .probe = da903x_backlight_probe, 167 .probe = da903x_backlight_probe,
175 .remove = da903x_backlight_remove,
176}; 168};
177 169
178module_platform_driver(da903x_backlight_driver); 170module_platform_driver(da903x_backlight_driver);
diff --git a/drivers/video/backlight/da9052_bl.c b/drivers/video/backlight/da9052_bl.c
index 842da5a3ac4f..20d55becaa74 100644
--- a/drivers/video/backlight/da9052_bl.c
+++ b/drivers/video/backlight/da9052_bl.c
@@ -125,8 +125,9 @@ static int da9052_backlight_probe(struct platform_device *pdev)
125 props.type = BACKLIGHT_RAW; 125 props.type = BACKLIGHT_RAW;
126 props.max_brightness = DA9052_MAX_BRIGHTNESS; 126 props.max_brightness = DA9052_MAX_BRIGHTNESS;
127 127
128 bl = backlight_device_register(pdev->name, wleds->da9052->dev, wleds, 128 bl = devm_backlight_device_register(&pdev->dev, pdev->name,
129 &da9052_backlight_ops, &props); 129 wleds->da9052->dev, wleds,
130 &da9052_backlight_ops, &props);
130 if (IS_ERR(bl)) { 131 if (IS_ERR(bl)) {
131 dev_err(&pdev->dev, "Failed to register backlight\n"); 132 dev_err(&pdev->dev, "Failed to register backlight\n");
132 return PTR_ERR(bl); 133 return PTR_ERR(bl);
@@ -147,7 +148,6 @@ static int da9052_backlight_remove(struct platform_device *pdev)
147 wleds->brightness = 0; 148 wleds->brightness = 0;
148 wleds->state = DA9052_WLEDS_OFF; 149 wleds->state = DA9052_WLEDS_OFF;
149 da9052_adjust_wled_brightness(wleds); 150 da9052_adjust_wled_brightness(wleds);
150 backlight_device_unregister(bl);
151 151
152 return 0; 152 return 0;
153} 153}
diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c
index 018368ba4124..0d1f633c6480 100644
--- a/drivers/video/backlight/ep93xx_bl.c
+++ b/drivers/video/backlight/ep93xx_bl.c
@@ -92,8 +92,8 @@ static int ep93xxbl_probe(struct platform_device *dev)
92 memset(&props, 0, sizeof(struct backlight_properties)); 92 memset(&props, 0, sizeof(struct backlight_properties));
93 props.type = BACKLIGHT_RAW; 93 props.type = BACKLIGHT_RAW;
94 props.max_brightness = EP93XX_MAX_BRIGHT; 94 props.max_brightness = EP93XX_MAX_BRIGHT;
95 bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl, 95 bl = devm_backlight_device_register(&dev->dev, dev->name, &dev->dev,
96 &ep93xxbl_ops, &props); 96 ep93xxbl, &ep93xxbl_ops, &props);
97 if (IS_ERR(bl)) 97 if (IS_ERR(bl))
98 return PTR_ERR(bl); 98 return PTR_ERR(bl);
99 99
@@ -106,14 +106,6 @@ static int ep93xxbl_probe(struct platform_device *dev)
106 return 0; 106 return 0;
107} 107}
108 108
109static int ep93xxbl_remove(struct platform_device *dev)
110{
111 struct backlight_device *bl = platform_get_drvdata(dev);
112
113 backlight_device_unregister(bl);
114 return 0;
115}
116
117#ifdef CONFIG_PM_SLEEP 109#ifdef CONFIG_PM_SLEEP
118static int ep93xxbl_suspend(struct device *dev) 110static int ep93xxbl_suspend(struct device *dev)
119{ 111{
@@ -140,7 +132,6 @@ static struct platform_driver ep93xxbl_driver = {
140 .pm = &ep93xxbl_pm_ops, 132 .pm = &ep93xxbl_pm_ops,
141 }, 133 },
142 .probe = ep93xxbl_probe, 134 .probe = ep93xxbl_probe,
143 .remove = ep93xxbl_remove,
144}; 135};
145 136
146module_platform_driver(ep93xxbl_driver); 137module_platform_driver(ep93xxbl_driver);
diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
index 19e393b41438..5d8d65200db7 100644
--- a/drivers/video/backlight/generic_bl.c
+++ b/drivers/video/backlight/generic_bl.c
@@ -79,7 +79,7 @@ static const struct backlight_ops genericbl_ops = {
79static int genericbl_probe(struct platform_device *pdev) 79static int genericbl_probe(struct platform_device *pdev)
80{ 80{
81 struct backlight_properties props; 81 struct backlight_properties props;
82 struct generic_bl_info *machinfo = pdev->dev.platform_data; 82 struct generic_bl_info *machinfo = dev_get_platdata(&pdev->dev);
83 const char *name = "generic-bl"; 83 const char *name = "generic-bl";
84 struct backlight_device *bd; 84 struct backlight_device *bd;
85 85
@@ -93,8 +93,8 @@ static int genericbl_probe(struct platform_device *pdev)
93 memset(&props, 0, sizeof(struct backlight_properties)); 93 memset(&props, 0, sizeof(struct backlight_properties));
94 props.type = BACKLIGHT_RAW; 94 props.type = BACKLIGHT_RAW;
95 props.max_brightness = machinfo->max_intensity; 95 props.max_brightness = machinfo->max_intensity;
96 bd = backlight_device_register(name, &pdev->dev, NULL, &genericbl_ops, 96 bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev,
97 &props); 97 NULL, &genericbl_ops, &props);
98 if (IS_ERR(bd)) 98 if (IS_ERR(bd))
99 return PTR_ERR(bd); 99 return PTR_ERR(bd);
100 100
@@ -118,8 +118,6 @@ static int genericbl_remove(struct platform_device *pdev)
118 bd->props.brightness = 0; 118 bd->props.brightness = 0;
119 backlight_update_status(bd); 119 backlight_update_status(bd);
120 120
121 backlight_device_unregister(bd);
122
123 dev_info(&pdev->dev, "Generic Backlight Driver Unloaded\n"); 121 dev_info(&pdev->dev, "Generic Backlight Driver Unloaded\n");
124 return 0; 122 return 0;
125} 123}
diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c
index 5fa217f9f445..81fb12770c2a 100644
--- a/drivers/video/backlight/gpio_backlight.c
+++ b/drivers/video/backlight/gpio_backlight.c
@@ -62,7 +62,8 @@ static const struct backlight_ops gpio_backlight_ops = {
62 62
63static int gpio_backlight_probe(struct platform_device *pdev) 63static int gpio_backlight_probe(struct platform_device *pdev)
64{ 64{
65 struct gpio_backlight_platform_data *pdata = pdev->dev.platform_data; 65 struct gpio_backlight_platform_data *pdata =
66 dev_get_platdata(&pdev->dev);
66 struct backlight_properties props; 67 struct backlight_properties props;
67 struct backlight_device *bl; 68 struct backlight_device *bl;
68 struct gpio_backlight *gbl; 69 struct gpio_backlight *gbl;
@@ -94,8 +95,9 @@ static int gpio_backlight_probe(struct platform_device *pdev)
94 memset(&props, 0, sizeof(props)); 95 memset(&props, 0, sizeof(props));
95 props.type = BACKLIGHT_RAW; 96 props.type = BACKLIGHT_RAW;
96 props.max_brightness = 1; 97 props.max_brightness = 1;
97 bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, gbl, 98 bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev),
98 &gpio_backlight_ops, &props); 99 &pdev->dev, gbl, &gpio_backlight_ops,
100 &props);
99 if (IS_ERR(bl)) { 101 if (IS_ERR(bl)) {
100 dev_err(&pdev->dev, "failed to register backlight\n"); 102 dev_err(&pdev->dev, "failed to register backlight\n");
101 return PTR_ERR(bl); 103 return PTR_ERR(bl);
@@ -108,21 +110,12 @@ static int gpio_backlight_probe(struct platform_device *pdev)
108 return 0; 110 return 0;
109} 111}
110 112
111static int gpio_backlight_remove(struct platform_device *pdev)
112{
113 struct backlight_device *bl = platform_get_drvdata(pdev);
114
115 backlight_device_unregister(bl);
116 return 0;
117}
118
119static struct platform_driver gpio_backlight_driver = { 113static struct platform_driver gpio_backlight_driver = {
120 .driver = { 114 .driver = {
121 .name = "gpio-backlight", 115 .name = "gpio-backlight",
122 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
123 }, 117 },
124 .probe = gpio_backlight_probe, 118 .probe = gpio_backlight_probe,
125 .remove = gpio_backlight_remove,
126}; 119};
127 120
128module_platform_driver(gpio_backlight_driver); 121module_platform_driver(gpio_backlight_driver);
diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c
index c7af8c45ab8a..985e854e244b 100644
--- a/drivers/video/backlight/hx8357.c
+++ b/drivers/video/backlight/hx8357.c
@@ -648,7 +648,8 @@ static int hx8357_probe(struct spi_device *spi)
648 lcd->use_im_pins = 0; 648 lcd->use_im_pins = 0;
649 } 649 }
650 650
651 lcdev = lcd_device_register("mxsfb", &spi->dev, lcd, &hx8357_ops); 651 lcdev = devm_lcd_device_register(&spi->dev, "mxsfb", &spi->dev, lcd,
652 &hx8357_ops);
652 if (IS_ERR(lcdev)) { 653 if (IS_ERR(lcdev)) {
653 ret = PTR_ERR(lcdev); 654 ret = PTR_ERR(lcdev);
654 return ret; 655 return ret;
@@ -660,32 +661,19 @@ static int hx8357_probe(struct spi_device *spi)
660 ret = ((int (*)(struct lcd_device *))match->data)(lcdev); 661 ret = ((int (*)(struct lcd_device *))match->data)(lcdev);
661 if (ret) { 662 if (ret) {
662 dev_err(&spi->dev, "Couldn't initialize panel\n"); 663 dev_err(&spi->dev, "Couldn't initialize panel\n");
663 goto init_error; 664 return ret;
664 } 665 }
665 666
666 dev_info(&spi->dev, "Panel probed\n"); 667 dev_info(&spi->dev, "Panel probed\n");
667 668
668 return 0; 669 return 0;
669
670init_error:
671 lcd_device_unregister(lcdev);
672 return ret;
673}
674
675static int hx8357_remove(struct spi_device *spi)
676{
677 struct lcd_device *lcdev = spi_get_drvdata(spi);
678
679 lcd_device_unregister(lcdev);
680 return 0;
681} 670}
682 671
683static struct spi_driver hx8357_driver = { 672static struct spi_driver hx8357_driver = {
684 .probe = hx8357_probe, 673 .probe = hx8357_probe,
685 .remove = hx8357_remove,
686 .driver = { 674 .driver = {
687 .name = "hx8357", 675 .name = "hx8357",
688 .of_match_table = of_match_ptr(hx8357_dt_ids), 676 .of_match_table = hx8357_dt_ids,
689 }, 677 },
690}; 678};
691 679
diff --git a/drivers/video/backlight/ili922x.c b/drivers/video/backlight/ili922x.c
index d9f65c2d9b01..73464e4b4c74 100644
--- a/drivers/video/backlight/ili922x.c
+++ b/drivers/video/backlight/ili922x.c
@@ -513,8 +513,8 @@ static int ili922x_probe(struct spi_device *spi)
513 513
514 ili->power = FB_BLANK_POWERDOWN; 514 ili->power = FB_BLANK_POWERDOWN;
515 515
516 lcd = lcd_device_register("ili922xlcd", &spi->dev, ili, 516 lcd = devm_lcd_device_register(&spi->dev, "ili922xlcd", &spi->dev, ili,
517 &ili922x_ops); 517 &ili922x_ops);
518 if (IS_ERR(lcd)) { 518 if (IS_ERR(lcd)) {
519 dev_err(&spi->dev, "cannot register LCD\n"); 519 dev_err(&spi->dev, "cannot register LCD\n");
520 return PTR_ERR(lcd); 520 return PTR_ERR(lcd);
@@ -530,10 +530,7 @@ static int ili922x_probe(struct spi_device *spi)
530 530
531static int ili922x_remove(struct spi_device *spi) 531static int ili922x_remove(struct spi_device *spi)
532{ 532{
533 struct ili922x *ili = spi_get_drvdata(spi);
534
535 ili922x_poweroff(spi); 533 ili922x_poweroff(spi);
536 lcd_device_unregister(ili->ld);
537 return 0; 534 return 0;
538} 535}
539 536
diff --git a/drivers/video/backlight/ili9320.c b/drivers/video/backlight/ili9320.c
index f8be90c5dedc..e2b8b40a9bd9 100644
--- a/drivers/video/backlight/ili9320.c
+++ b/drivers/video/backlight/ili9320.c
@@ -198,7 +198,7 @@ static void ili9320_setup_spi(struct ili9320 *ili,
198int ili9320_probe_spi(struct spi_device *spi, 198int ili9320_probe_spi(struct spi_device *spi,
199 struct ili9320_client *client) 199 struct ili9320_client *client)
200{ 200{
201 struct ili9320_platdata *cfg = spi->dev.platform_data; 201 struct ili9320_platdata *cfg = dev_get_platdata(&spi->dev);
202 struct device *dev = &spi->dev; 202 struct device *dev = &spi->dev;
203 struct ili9320 *ili; 203 struct ili9320 *ili;
204 struct lcd_device *lcd; 204 struct lcd_device *lcd;
@@ -235,7 +235,8 @@ int ili9320_probe_spi(struct spi_device *spi,
235 235
236 ili9320_setup_spi(ili, spi); 236 ili9320_setup_spi(ili, spi);
237 237
238 lcd = lcd_device_register("ili9320", dev, ili, &ili9320_ops); 238 lcd = devm_lcd_device_register(&spi->dev, "ili9320", dev, ili,
239 &ili9320_ops);
239 if (IS_ERR(lcd)) { 240 if (IS_ERR(lcd)) {
240 dev_err(dev, "failed to register lcd device\n"); 241 dev_err(dev, "failed to register lcd device\n");
241 return PTR_ERR(lcd); 242 return PTR_ERR(lcd);
@@ -248,24 +249,16 @@ int ili9320_probe_spi(struct spi_device *spi,
248 ret = ili9320_power(ili, FB_BLANK_UNBLANK); 249 ret = ili9320_power(ili, FB_BLANK_UNBLANK);
249 if (ret != 0) { 250 if (ret != 0) {
250 dev_err(dev, "failed to set lcd power state\n"); 251 dev_err(dev, "failed to set lcd power state\n");
251 goto err_unregister; 252 return ret;
252 } 253 }
253 254
254 return 0; 255 return 0;
255
256 err_unregister:
257 lcd_device_unregister(lcd);
258
259 return ret;
260} 256}
261EXPORT_SYMBOL_GPL(ili9320_probe_spi); 257EXPORT_SYMBOL_GPL(ili9320_probe_spi);
262 258
263int ili9320_remove(struct ili9320 *ili) 259int ili9320_remove(struct ili9320 *ili)
264{ 260{
265 ili9320_power(ili, FB_BLANK_POWERDOWN); 261 ili9320_power(ili, FB_BLANK_POWERDOWN);
266
267 lcd_device_unregister(ili->lcd);
268
269 return 0; 262 return 0;
270} 263}
271EXPORT_SYMBOL_GPL(ili9320_remove); 264EXPORT_SYMBOL_GPL(ili9320_remove);
diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
index bca6ccc74dfb..7592cc25c963 100644
--- a/drivers/video/backlight/kb3886_bl.c
+++ b/drivers/video/backlight/kb3886_bl.c
@@ -141,7 +141,7 @@ static const struct backlight_ops kb3886bl_ops = {
141static int kb3886bl_probe(struct platform_device *pdev) 141static int kb3886bl_probe(struct platform_device *pdev)
142{ 142{
143 struct backlight_properties props; 143 struct backlight_properties props;
144 struct kb3886bl_machinfo *machinfo = pdev->dev.platform_data; 144 struct kb3886bl_machinfo *machinfo = dev_get_platdata(&pdev->dev);
145 145
146 bl_machinfo = machinfo; 146 bl_machinfo = machinfo;
147 if (!machinfo->limit_mask) 147 if (!machinfo->limit_mask)
@@ -150,10 +150,10 @@ static int kb3886bl_probe(struct platform_device *pdev)
150 memset(&props, 0, sizeof(struct backlight_properties)); 150 memset(&props, 0, sizeof(struct backlight_properties));
151 props.type = BACKLIGHT_RAW; 151 props.type = BACKLIGHT_RAW;
152 props.max_brightness = machinfo->max_intensity; 152 props.max_brightness = machinfo->max_intensity;
153 kb3886_backlight_device = backlight_device_register("kb3886-bl", 153 kb3886_backlight_device = devm_backlight_device_register(&pdev->dev,
154 &pdev->dev, NULL, 154 "kb3886-bl", &pdev->dev,
155 &kb3886bl_ops, 155 NULL, &kb3886bl_ops,
156 &props); 156 &props);
157 if (IS_ERR(kb3886_backlight_device)) 157 if (IS_ERR(kb3886_backlight_device))
158 return PTR_ERR(kb3886_backlight_device); 158 return PTR_ERR(kb3886_backlight_device);
159 159
@@ -166,18 +166,8 @@ static int kb3886bl_probe(struct platform_device *pdev)
166 return 0; 166 return 0;
167} 167}
168 168
169static int kb3886bl_remove(struct platform_device *pdev)
170{
171 struct backlight_device *bd = platform_get_drvdata(pdev);
172
173 backlight_device_unregister(bd);
174
175 return 0;
176}
177
178static struct platform_driver kb3886bl_driver = { 169static struct platform_driver kb3886bl_driver = {
179 .probe = kb3886bl_probe, 170 .probe = kb3886bl_probe,
180 .remove = kb3886bl_remove,
181 .driver = { 171 .driver = {
182 .name = "kb3886-bl", 172 .name = "kb3886-bl",
183 .pm = &kb3886bl_pm_ops, 173 .pm = &kb3886bl_pm_ops,
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c
index a35a38c709cf..923eae2f85f8 100644
--- a/drivers/video/backlight/l4f00242t03.c
+++ b/drivers/video/backlight/l4f00242t03.c
@@ -48,7 +48,7 @@ static void l4f00242t03_reset(unsigned int gpio)
48 48
49static void l4f00242t03_lcd_init(struct spi_device *spi) 49static void l4f00242t03_lcd_init(struct spi_device *spi)
50{ 50{
51 struct l4f00242t03_pdata *pdata = spi->dev.platform_data; 51 struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
52 struct l4f00242t03_priv *priv = spi_get_drvdata(spi); 52 struct l4f00242t03_priv *priv = spi_get_drvdata(spi);
53 const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) }; 53 const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) };
54 int ret; 54 int ret;
@@ -88,7 +88,7 @@ static void l4f00242t03_lcd_init(struct spi_device *spi)
88 88
89static void l4f00242t03_lcd_powerdown(struct spi_device *spi) 89static void l4f00242t03_lcd_powerdown(struct spi_device *spi)
90{ 90{
91 struct l4f00242t03_pdata *pdata = spi->dev.platform_data; 91 struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
92 struct l4f00242t03_priv *priv = spi_get_drvdata(spi); 92 struct l4f00242t03_priv *priv = spi_get_drvdata(spi);
93 93
94 dev_dbg(&spi->dev, "Powering down LCD\n"); 94 dev_dbg(&spi->dev, "Powering down LCD\n");
@@ -171,7 +171,7 @@ static struct lcd_ops l4f_ops = {
171static int l4f00242t03_probe(struct spi_device *spi) 171static int l4f00242t03_probe(struct spi_device *spi)
172{ 172{
173 struct l4f00242t03_priv *priv; 173 struct l4f00242t03_priv *priv;
174 struct l4f00242t03_pdata *pdata = spi->dev.platform_data; 174 struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
175 int ret; 175 int ret;
176 176
177 if (pdata == NULL) { 177 if (pdata == NULL) {
diff --git a/drivers/video/backlight/ld9040.c b/drivers/video/backlight/ld9040.c
index 1e0a3093ce50..506a6c236039 100644
--- a/drivers/video/backlight/ld9040.c
+++ b/drivers/video/backlight/ld9040.c
@@ -702,7 +702,7 @@ static int ld9040_probe(struct spi_device *spi)
702 lcd->spi = spi; 702 lcd->spi = spi;
703 lcd->dev = &spi->dev; 703 lcd->dev = &spi->dev;
704 704
705 lcd->lcd_pd = spi->dev.platform_data; 705 lcd->lcd_pd = dev_get_platdata(&spi->dev);
706 if (!lcd->lcd_pd) { 706 if (!lcd->lcd_pd) {
707 dev_err(&spi->dev, "platform data is NULL.\n"); 707 dev_err(&spi->dev, "platform data is NULL.\n");
708 return -EINVAL; 708 return -EINVAL;
@@ -716,7 +716,8 @@ static int ld9040_probe(struct spi_device *spi)
716 return ret; 716 return ret;
717 } 717 }
718 718
719 ld = lcd_device_register("ld9040", &spi->dev, lcd, &ld9040_lcd_ops); 719 ld = devm_lcd_device_register(&spi->dev, "ld9040", &spi->dev, lcd,
720 &ld9040_lcd_ops);
720 if (IS_ERR(ld)) 721 if (IS_ERR(ld))
721 return PTR_ERR(ld); 722 return PTR_ERR(ld);
722 723
@@ -726,12 +727,10 @@ static int ld9040_probe(struct spi_device *spi)
726 props.type = BACKLIGHT_RAW; 727 props.type = BACKLIGHT_RAW;
727 props.max_brightness = MAX_BRIGHTNESS; 728 props.max_brightness = MAX_BRIGHTNESS;
728 729
729 bd = backlight_device_register("ld9040-bl", &spi->dev, 730 bd = devm_backlight_device_register(&spi->dev, "ld9040-bl", &spi->dev,
730 lcd, &ld9040_backlight_ops, &props); 731 lcd, &ld9040_backlight_ops, &props);
731 if (IS_ERR(bd)) { 732 if (IS_ERR(bd))
732 ret = PTR_ERR(bd); 733 return PTR_ERR(bd);
733 goto out_unregister_lcd;
734 }
735 734
736 bd->props.brightness = MAX_BRIGHTNESS; 735 bd->props.brightness = MAX_BRIGHTNESS;
737 lcd->bd = bd; 736 lcd->bd = bd;
@@ -757,11 +756,6 @@ static int ld9040_probe(struct spi_device *spi)
757 756
758 dev_info(&spi->dev, "ld9040 panel driver has been probed.\n"); 757 dev_info(&spi->dev, "ld9040 panel driver has been probed.\n");
759 return 0; 758 return 0;
760
761out_unregister_lcd:
762 lcd_device_unregister(lcd->ld);
763
764 return ret;
765} 759}
766 760
767static int ld9040_remove(struct spi_device *spi) 761static int ld9040_remove(struct spi_device *spi)
@@ -769,9 +763,6 @@ static int ld9040_remove(struct spi_device *spi)
769 struct ld9040 *lcd = spi_get_drvdata(spi); 763 struct ld9040 *lcd = spi_get_drvdata(spi);
770 764
771 ld9040_power(lcd, FB_BLANK_POWERDOWN); 765 ld9040_power(lcd, FB_BLANK_POWERDOWN);
772 backlight_device_unregister(lcd->bd);
773 lcd_device_unregister(lcd->ld);
774
775 return 0; 766 return 0;
776} 767}
777 768
diff --git a/drivers/video/backlight/ld9040_gamma.h b/drivers/video/backlight/ld9040_gamma.h
index 038d9c86ec03..c5e586d97385 100644
--- a/drivers/video/backlight/ld9040_gamma.h
+++ b/drivers/video/backlight/ld9040_gamma.h
@@ -169,7 +169,9 @@ static const unsigned int ld9040_22_50[] = {
169 169
170struct ld9040_gamma { 170struct ld9040_gamma {
171 unsigned int *gamma_22_table[MAX_GAMMA_LEVEL]; 171 unsigned int *gamma_22_table[MAX_GAMMA_LEVEL];
172} gamma_table = { 172};
173
174static struct ld9040_gamma gamma_table = {
173 .gamma_22_table[0] = (unsigned int *)&ld9040_22_50, 175 .gamma_22_table[0] = (unsigned int *)&ld9040_22_50,
174 .gamma_22_table[1] = (unsigned int *)&ld9040_22_70, 176 .gamma_22_table[1] = (unsigned int *)&ld9040_22_70,
175 .gamma_22_table[2] = (unsigned int *)&ld9040_22_80, 177 .gamma_22_table[2] = (unsigned int *)&ld9040_22_80,
diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c
index 1d1dbfb789e3..187d1c283c1d 100644
--- a/drivers/video/backlight/lm3533_bl.c
+++ b/drivers/video/backlight/lm3533_bl.c
@@ -284,7 +284,7 @@ static int lm3533_bl_probe(struct platform_device *pdev)
284 if (!lm3533) 284 if (!lm3533)
285 return -EINVAL; 285 return -EINVAL;
286 286
287 pdata = pdev->dev.platform_data; 287 pdata = dev_get_platdata(&pdev->dev);
288 if (!pdata) { 288 if (!pdata) {
289 dev_err(&pdev->dev, "no platform data\n"); 289 dev_err(&pdev->dev, "no platform data\n");
290 return -EINVAL; 290 return -EINVAL;
@@ -313,8 +313,9 @@ static int lm3533_bl_probe(struct platform_device *pdev)
313 props.type = BACKLIGHT_RAW; 313 props.type = BACKLIGHT_RAW;
314 props.max_brightness = LM3533_BL_MAX_BRIGHTNESS; 314 props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
315 props.brightness = pdata->default_brightness; 315 props.brightness = pdata->default_brightness;
316 bd = backlight_device_register(pdata->name, pdev->dev.parent, bl, 316 bd = devm_backlight_device_register(&pdev->dev, pdata->name,
317 &lm3533_bl_ops, &props); 317 pdev->dev.parent, bl, &lm3533_bl_ops,
318 &props);
318 if (IS_ERR(bd)) { 319 if (IS_ERR(bd)) {
319 dev_err(&pdev->dev, "failed to register backlight device\n"); 320 dev_err(&pdev->dev, "failed to register backlight device\n");
320 return PTR_ERR(bd); 321 return PTR_ERR(bd);
@@ -328,7 +329,7 @@ static int lm3533_bl_probe(struct platform_device *pdev)
328 ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group); 329 ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
329 if (ret < 0) { 330 if (ret < 0) {
330 dev_err(&pdev->dev, "failed to create sysfs attributes\n"); 331 dev_err(&pdev->dev, "failed to create sysfs attributes\n");
331 goto err_unregister; 332 return ret;
332 } 333 }
333 334
334 backlight_update_status(bd); 335 backlight_update_status(bd);
@@ -345,8 +346,6 @@ static int lm3533_bl_probe(struct platform_device *pdev)
345 346
346err_sysfs_remove: 347err_sysfs_remove:
347 sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group); 348 sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
348err_unregister:
349 backlight_device_unregister(bd);
350 349
351 return ret; 350 return ret;
352} 351}
@@ -363,7 +362,6 @@ static int lm3533_bl_remove(struct platform_device *pdev)
363 362
364 lm3533_ctrlbank_disable(&bl->cb); 363 lm3533_ctrlbank_disable(&bl->cb);
365 sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group); 364 sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
366 backlight_device_unregister(bd);
367 365
368 return 0; 366 return 0;
369} 367}
diff --git a/drivers/video/backlight/lm3630_bl.c b/drivers/video/backlight/lm3630_bl.c
deleted file mode 100644
index 76a62e978fc3..000000000000
--- a/drivers/video/backlight/lm3630_bl.c
+++ /dev/null
@@ -1,475 +0,0 @@
1/*
2* Simple driver for Texas Instruments LM3630 Backlight driver chip
3* Copyright (C) 2012 Texas Instruments
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 2 as
7* published by the Free Software Foundation.
8*
9*/
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/i2c.h>
13#include <linux/backlight.h>
14#include <linux/err.h>
15#include <linux/delay.h>
16#include <linux/uaccess.h>
17#include <linux/interrupt.h>
18#include <linux/regmap.h>
19#include <linux/platform_data/lm3630_bl.h>
20
21#define REG_CTRL 0x00
22#define REG_CONFIG 0x01
23#define REG_BRT_A 0x03
24#define REG_BRT_B 0x04
25#define REG_INT_STATUS 0x09
26#define REG_INT_EN 0x0A
27#define REG_FAULT 0x0B
28#define REG_PWM_OUTLOW 0x12
29#define REG_PWM_OUTHIGH 0x13
30#define REG_MAX 0x1F
31
32#define INT_DEBOUNCE_MSEC 10
33
34enum lm3630_leds {
35 BLED_ALL = 0,
36 BLED_1,
37 BLED_2
38};
39
40static const char * const bled_name[] = {
41 [BLED_ALL] = "lm3630_bled", /*Bank1 controls all string */
42 [BLED_1] = "lm3630_bled1", /*Bank1 controls bled1 */
43 [BLED_2] = "lm3630_bled2", /*Bank1 or 2 controls bled2 */
44};
45
46struct lm3630_chip_data {
47 struct device *dev;
48 struct delayed_work work;
49 int irq;
50 struct workqueue_struct *irqthread;
51 struct lm3630_platform_data *pdata;
52 struct backlight_device *bled1;
53 struct backlight_device *bled2;
54 struct regmap *regmap;
55};
56
57/* initialize chip */
58static int lm3630_chip_init(struct lm3630_chip_data *pchip)
59{
60 int ret;
61 unsigned int reg_val;
62 struct lm3630_platform_data *pdata = pchip->pdata;
63
64 /*pwm control */
65 reg_val = ((pdata->pwm_active & 0x01) << 2) | (pdata->pwm_ctrl & 0x03);
66 ret = regmap_update_bits(pchip->regmap, REG_CONFIG, 0x07, reg_val);
67 if (ret < 0)
68 goto out;
69
70 /* bank control */
71 reg_val = ((pdata->bank_b_ctrl & 0x01) << 1) |
72 (pdata->bank_a_ctrl & 0x07);
73 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x07, reg_val);
74 if (ret < 0)
75 goto out;
76
77 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
78 if (ret < 0)
79 goto out;
80
81 /* set initial brightness */
82 if (pdata->bank_a_ctrl != BANK_A_CTRL_DISABLE) {
83 ret = regmap_write(pchip->regmap,
84 REG_BRT_A, pdata->init_brt_led1);
85 if (ret < 0)
86 goto out;
87 }
88
89 if (pdata->bank_b_ctrl != BANK_B_CTRL_DISABLE) {
90 ret = regmap_write(pchip->regmap,
91 REG_BRT_B, pdata->init_brt_led2);
92 if (ret < 0)
93 goto out;
94 }
95 return ret;
96
97out:
98 dev_err(pchip->dev, "i2c failed to access register\n");
99 return ret;
100}
101
102/* interrupt handling */
103static void lm3630_delayed_func(struct work_struct *work)
104{
105 int ret;
106 unsigned int reg_val;
107 struct lm3630_chip_data *pchip;
108
109 pchip = container_of(work, struct lm3630_chip_data, work.work);
110
111 ret = regmap_read(pchip->regmap, REG_INT_STATUS, &reg_val);
112 if (ret < 0) {
113 dev_err(pchip->dev,
114 "i2c failed to access REG_INT_STATUS Register\n");
115 return;
116 }
117
118 dev_info(pchip->dev, "REG_INT_STATUS Register is 0x%x\n", reg_val);
119}
120
121static irqreturn_t lm3630_isr_func(int irq, void *chip)
122{
123 int ret;
124 struct lm3630_chip_data *pchip = chip;
125 unsigned long delay = msecs_to_jiffies(INT_DEBOUNCE_MSEC);
126
127 queue_delayed_work(pchip->irqthread, &pchip->work, delay);
128
129 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
130 if (ret < 0)
131 goto out;
132
133 return IRQ_HANDLED;
134out:
135 dev_err(pchip->dev, "i2c failed to access register\n");
136 return IRQ_HANDLED;
137}
138
139static int lm3630_intr_config(struct lm3630_chip_data *pchip)
140{
141 INIT_DELAYED_WORK(&pchip->work, lm3630_delayed_func);
142 pchip->irqthread = create_singlethread_workqueue("lm3630-irqthd");
143 if (!pchip->irqthread) {
144 dev_err(pchip->dev, "create irq thread fail...\n");
145 return -1;
146 }
147 if (request_threaded_irq
148 (pchip->irq, NULL, lm3630_isr_func,
149 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "lm3630_irq", pchip)) {
150 dev_err(pchip->dev, "request threaded irq fail..\n");
151 return -1;
152 }
153 return 0;
154}
155
156static bool
157set_intensity(struct backlight_device *bl, struct lm3630_chip_data *pchip)
158{
159 if (!pchip->pdata->pwm_set_intensity)
160 return false;
161 pchip->pdata->pwm_set_intensity(bl->props.brightness - 1,
162 pchip->pdata->pwm_period);
163 return true;
164}
165
166/* update and get brightness */
167static int lm3630_bank_a_update_status(struct backlight_device *bl)
168{
169 int ret;
170 struct lm3630_chip_data *pchip = bl_get_data(bl);
171 enum lm3630_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
172
173 /* brightness 0 means disable */
174 if (!bl->props.brightness) {
175 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x04, 0x00);
176 if (ret < 0)
177 goto out;
178 return bl->props.brightness;
179 }
180
181 /* pwm control */
182 if (pwm_ctrl == PWM_CTRL_BANK_A || pwm_ctrl == PWM_CTRL_BANK_ALL) {
183 if (!set_intensity(bl, pchip))
184 dev_err(pchip->dev, "No pwm control func. in plat-data\n");
185 } else {
186
187 /* i2c control */
188 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
189 if (ret < 0)
190 goto out;
191 mdelay(1);
192 ret = regmap_write(pchip->regmap,
193 REG_BRT_A, bl->props.brightness - 1);
194 if (ret < 0)
195 goto out;
196 }
197 return bl->props.brightness;
198out:
199 dev_err(pchip->dev, "i2c failed to access REG_CTRL\n");
200 return bl->props.brightness;
201}
202
203static int lm3630_bank_a_get_brightness(struct backlight_device *bl)
204{
205 unsigned int reg_val;
206 int brightness, ret;
207 struct lm3630_chip_data *pchip = bl_get_data(bl);
208 enum lm3630_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
209
210 if (pwm_ctrl == PWM_CTRL_BANK_A || pwm_ctrl == PWM_CTRL_BANK_ALL) {
211 ret = regmap_read(pchip->regmap, REG_PWM_OUTHIGH, &reg_val);
212 if (ret < 0)
213 goto out;
214 brightness = reg_val & 0x01;
215 ret = regmap_read(pchip->regmap, REG_PWM_OUTLOW, &reg_val);
216 if (ret < 0)
217 goto out;
218 brightness = ((brightness << 8) | reg_val) + 1;
219 } else {
220 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
221 if (ret < 0)
222 goto out;
223 mdelay(1);
224 ret = regmap_read(pchip->regmap, REG_BRT_A, &reg_val);
225 if (ret < 0)
226 goto out;
227 brightness = reg_val + 1;
228 }
229 bl->props.brightness = brightness;
230 return bl->props.brightness;
231out:
232 dev_err(pchip->dev, "i2c failed to access register\n");
233 return 0;
234}
235
236static const struct backlight_ops lm3630_bank_a_ops = {
237 .options = BL_CORE_SUSPENDRESUME,
238 .update_status = lm3630_bank_a_update_status,
239 .get_brightness = lm3630_bank_a_get_brightness,
240};
241
242static int lm3630_bank_b_update_status(struct backlight_device *bl)
243{
244 int ret;
245 struct lm3630_chip_data *pchip = bl_get_data(bl);
246 enum lm3630_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
247
248 if (pwm_ctrl == PWM_CTRL_BANK_B || pwm_ctrl == PWM_CTRL_BANK_ALL) {
249 if (!set_intensity(bl, pchip))
250 dev_err(pchip->dev,
251 "no pwm control func. in plat-data\n");
252 } else {
253 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
254 if (ret < 0)
255 goto out;
256 mdelay(1);
257 ret = regmap_write(pchip->regmap,
258 REG_BRT_B, bl->props.brightness - 1);
259 }
260 return bl->props.brightness;
261out:
262 dev_err(pchip->dev, "i2c failed to access register\n");
263 return bl->props.brightness;
264}
265
266static int lm3630_bank_b_get_brightness(struct backlight_device *bl)
267{
268 unsigned int reg_val;
269 int brightness, ret;
270 struct lm3630_chip_data *pchip = bl_get_data(bl);
271 enum lm3630_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
272
273 if (pwm_ctrl == PWM_CTRL_BANK_B || pwm_ctrl == PWM_CTRL_BANK_ALL) {
274 ret = regmap_read(pchip->regmap, REG_PWM_OUTHIGH, &reg_val);
275 if (ret < 0)
276 goto out;
277 brightness = reg_val & 0x01;
278 ret = regmap_read(pchip->regmap, REG_PWM_OUTLOW, &reg_val);
279 if (ret < 0)
280 goto out;
281 brightness = ((brightness << 8) | reg_val) + 1;
282 } else {
283 ret = regmap_update_bits(pchip->regmap, REG_CTRL, 0x80, 0x00);
284 if (ret < 0)
285 goto out;
286 mdelay(1);
287 ret = regmap_read(pchip->regmap, REG_BRT_B, &reg_val);
288 if (ret < 0)
289 goto out;
290 brightness = reg_val + 1;
291 }
292 bl->props.brightness = brightness;
293
294 return bl->props.brightness;
295out:
296 dev_err(pchip->dev, "i2c failed to access register\n");
297 return bl->props.brightness;
298}
299
300static const struct backlight_ops lm3630_bank_b_ops = {
301 .options = BL_CORE_SUSPENDRESUME,
302 .update_status = lm3630_bank_b_update_status,
303 .get_brightness = lm3630_bank_b_get_brightness,
304};
305
306static int lm3630_backlight_register(struct lm3630_chip_data *pchip,
307 enum lm3630_leds ledno)
308{
309 const char *name = bled_name[ledno];
310 struct backlight_properties props;
311 struct lm3630_platform_data *pdata = pchip->pdata;
312
313 props.type = BACKLIGHT_RAW;
314 switch (ledno) {
315 case BLED_1:
316 case BLED_ALL:
317 props.brightness = pdata->init_brt_led1;
318 props.max_brightness = pdata->max_brt_led1;
319 pchip->bled1 =
320 backlight_device_register(name, pchip->dev, pchip,
321 &lm3630_bank_a_ops, &props);
322 if (IS_ERR(pchip->bled1))
323 return PTR_ERR(pchip->bled1);
324 break;
325 case BLED_2:
326 props.brightness = pdata->init_brt_led2;
327 props.max_brightness = pdata->max_brt_led2;
328 pchip->bled2 =
329 backlight_device_register(name, pchip->dev, pchip,
330 &lm3630_bank_b_ops, &props);
331 if (IS_ERR(pchip->bled2))
332 return PTR_ERR(pchip->bled2);
333 break;
334 }
335 return 0;
336}
337
338static void lm3630_backlight_unregister(struct lm3630_chip_data *pchip)
339{
340 if (pchip->bled1)
341 backlight_device_unregister(pchip->bled1);
342 if (pchip->bled2)
343 backlight_device_unregister(pchip->bled2);
344}
345
346static const struct regmap_config lm3630_regmap = {
347 .reg_bits = 8,
348 .val_bits = 8,
349 .max_register = REG_MAX,
350};
351
352static int lm3630_probe(struct i2c_client *client,
353 const struct i2c_device_id *id)
354{
355 struct lm3630_platform_data *pdata = client->dev.platform_data;
356 struct lm3630_chip_data *pchip;
357 int ret;
358
359 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
360 dev_err(&client->dev, "fail : i2c functionality check...\n");
361 return -EOPNOTSUPP;
362 }
363
364 if (pdata == NULL) {
365 dev_err(&client->dev, "fail : no platform data.\n");
366 return -ENODATA;
367 }
368
369 pchip = devm_kzalloc(&client->dev, sizeof(struct lm3630_chip_data),
370 GFP_KERNEL);
371 if (!pchip)
372 return -ENOMEM;
373 pchip->pdata = pdata;
374 pchip->dev = &client->dev;
375
376 pchip->regmap = devm_regmap_init_i2c(client, &lm3630_regmap);
377 if (IS_ERR(pchip->regmap)) {
378 ret = PTR_ERR(pchip->regmap);
379 dev_err(&client->dev, "fail : allocate register map: %d\n",
380 ret);
381 return ret;
382 }
383 i2c_set_clientdata(client, pchip);
384
385 /* chip initialize */
386 ret = lm3630_chip_init(pchip);
387 if (ret < 0) {
388 dev_err(&client->dev, "fail : init chip\n");
389 goto err_chip_init;
390 }
391
392 switch (pdata->bank_a_ctrl) {
393 case BANK_A_CTRL_ALL:
394 ret = lm3630_backlight_register(pchip, BLED_ALL);
395 pdata->bank_b_ctrl = BANK_B_CTRL_DISABLE;
396 break;
397 case BANK_A_CTRL_LED1:
398 ret = lm3630_backlight_register(pchip, BLED_1);
399 break;
400 case BANK_A_CTRL_LED2:
401 ret = lm3630_backlight_register(pchip, BLED_2);
402 pdata->bank_b_ctrl = BANK_B_CTRL_DISABLE;
403 break;
404 default:
405 break;
406 }
407
408 if (ret < 0)
409 goto err_bl_reg;
410
411 if (pdata->bank_b_ctrl && pchip->bled2 == NULL) {
412 ret = lm3630_backlight_register(pchip, BLED_2);
413 if (ret < 0)
414 goto err_bl_reg;
415 }
416
417 /* interrupt enable : irq 0 is not allowed for lm3630 */
418 pchip->irq = client->irq;
419 if (pchip->irq)
420 lm3630_intr_config(pchip);
421
422 dev_info(&client->dev, "LM3630 backlight register OK.\n");
423 return 0;
424
425err_bl_reg:
426 dev_err(&client->dev, "fail : backlight register.\n");
427 lm3630_backlight_unregister(pchip);
428err_chip_init:
429 return ret;
430}
431
432static int lm3630_remove(struct i2c_client *client)
433{
434 int ret;
435 struct lm3630_chip_data *pchip = i2c_get_clientdata(client);
436
437 ret = regmap_write(pchip->regmap, REG_BRT_A, 0);
438 if (ret < 0)
439 dev_err(pchip->dev, "i2c failed to access register\n");
440
441 ret = regmap_write(pchip->regmap, REG_BRT_B, 0);
442 if (ret < 0)
443 dev_err(pchip->dev, "i2c failed to access register\n");
444
445 lm3630_backlight_unregister(pchip);
446 if (pchip->irq) {
447 free_irq(pchip->irq, pchip);
448 flush_workqueue(pchip->irqthread);
449 destroy_workqueue(pchip->irqthread);
450 }
451 return 0;
452}
453
454static const struct i2c_device_id lm3630_id[] = {
455 {LM3630_NAME, 0},
456 {}
457};
458
459MODULE_DEVICE_TABLE(i2c, lm3630_id);
460
461static struct i2c_driver lm3630_i2c_driver = {
462 .driver = {
463 .name = LM3630_NAME,
464 },
465 .probe = lm3630_probe,
466 .remove = lm3630_remove,
467 .id_table = lm3630_id,
468};
469
470module_i2c_driver(lm3630_i2c_driver);
471
472MODULE_DESCRIPTION("Texas Instruments Backlight driver for LM3630");
473MODULE_AUTHOR("G.Shark Jeong <gshark.jeong@gmail.com>");
474MODULE_AUTHOR("Daniel Jeong <daniel.jeong@ti.com>");
475MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
new file mode 100644
index 000000000000..35fe4825a454
--- /dev/null
+++ b/drivers/video/backlight/lm3630a_bl.c
@@ -0,0 +1,483 @@
1/*
2* Simple driver for Texas Instruments LM3630A Backlight driver chip
3* Copyright (C) 2012 Texas Instruments
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 2 as
7* published by the Free Software Foundation.
8*
9*/
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/i2c.h>
13#include <linux/backlight.h>
14#include <linux/err.h>
15#include <linux/delay.h>
16#include <linux/uaccess.h>
17#include <linux/interrupt.h>
18#include <linux/regmap.h>
19#include <linux/pwm.h>
20#include <linux/platform_data/lm3630a_bl.h>
21
22#define REG_CTRL 0x00
23#define REG_BOOST 0x02
24#define REG_CONFIG 0x01
25#define REG_BRT_A 0x03
26#define REG_BRT_B 0x04
27#define REG_I_A 0x05
28#define REG_I_B 0x06
29#define REG_INT_STATUS 0x09
30#define REG_INT_EN 0x0A
31#define REG_FAULT 0x0B
32#define REG_PWM_OUTLOW 0x12
33#define REG_PWM_OUTHIGH 0x13
34#define REG_MAX 0x1F
35
36#define INT_DEBOUNCE_MSEC 10
37struct lm3630a_chip {
38 struct device *dev;
39 struct delayed_work work;
40
41 int irq;
42 struct workqueue_struct *irqthread;
43 struct lm3630a_platform_data *pdata;
44 struct backlight_device *bleda;
45 struct backlight_device *bledb;
46 struct regmap *regmap;
47 struct pwm_device *pwmd;
48};
49
50/* i2c access */
51static int lm3630a_read(struct lm3630a_chip *pchip, unsigned int reg)
52{
53 int rval;
54 unsigned int reg_val;
55
56 rval = regmap_read(pchip->regmap, reg, &reg_val);
57 if (rval < 0)
58 return rval;
59 return reg_val & 0xFF;
60}
61
62static int lm3630a_write(struct lm3630a_chip *pchip,
63 unsigned int reg, unsigned int data)
64{
65 return regmap_write(pchip->regmap, reg, data);
66}
67
68static int lm3630a_update(struct lm3630a_chip *pchip,
69 unsigned int reg, unsigned int mask,
70 unsigned int data)
71{
72 return regmap_update_bits(pchip->regmap, reg, mask, data);
73}
74
75/* initialize chip */
76static int lm3630a_chip_init(struct lm3630a_chip *pchip)
77{
78 int rval;
79 struct lm3630a_platform_data *pdata = pchip->pdata;
80
81 usleep_range(1000, 2000);
82 /* set Filter Strength Register */
83 rval = lm3630a_write(pchip, 0x50, 0x03);
84 /* set Cofig. register */
85 rval |= lm3630a_update(pchip, REG_CONFIG, 0x07, pdata->pwm_ctrl);
86 /* set boost control */
87 rval |= lm3630a_write(pchip, REG_BOOST, 0x38);
88 /* set current A */
89 rval |= lm3630a_update(pchip, REG_I_A, 0x1F, 0x1F);
90 /* set current B */
91 rval |= lm3630a_write(pchip, REG_I_B, 0x1F);
92 /* set control */
93 rval |= lm3630a_update(pchip, REG_CTRL, 0x14, pdata->leda_ctrl);
94 rval |= lm3630a_update(pchip, REG_CTRL, 0x0B, pdata->ledb_ctrl);
95 usleep_range(1000, 2000);
96 /* set brightness A and B */
97 rval |= lm3630a_write(pchip, REG_BRT_A, pdata->leda_init_brt);
98 rval |= lm3630a_write(pchip, REG_BRT_B, pdata->ledb_init_brt);
99
100 if (rval < 0)
101 dev_err(pchip->dev, "i2c failed to access register\n");
102 return rval;
103}
104
105/* interrupt handling */
106static void lm3630a_delayed_func(struct work_struct *work)
107{
108 int rval;
109 struct lm3630a_chip *pchip;
110
111 pchip = container_of(work, struct lm3630a_chip, work.work);
112
113 rval = lm3630a_read(pchip, REG_INT_STATUS);
114 if (rval < 0) {
115 dev_err(pchip->dev,
116 "i2c failed to access REG_INT_STATUS Register\n");
117 return;
118 }
119
120 dev_info(pchip->dev, "REG_INT_STATUS Register is 0x%x\n", rval);
121}
122
123static irqreturn_t lm3630a_isr_func(int irq, void *chip)
124{
125 int rval;
126 struct lm3630a_chip *pchip = chip;
127 unsigned long delay = msecs_to_jiffies(INT_DEBOUNCE_MSEC);
128
129 queue_delayed_work(pchip->irqthread, &pchip->work, delay);
130
131 rval = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
132 if (rval < 0) {
133 dev_err(pchip->dev, "i2c failed to access register\n");
134 return IRQ_NONE;
135 }
136 return IRQ_HANDLED;
137}
138
139static int lm3630a_intr_config(struct lm3630a_chip *pchip)
140{
141 int rval;
142
143 rval = lm3630a_write(pchip, REG_INT_EN, 0x87);
144 if (rval < 0)
145 return rval;
146
147 INIT_DELAYED_WORK(&pchip->work, lm3630a_delayed_func);
148 pchip->irqthread = create_singlethread_workqueue("lm3630a-irqthd");
149 if (!pchip->irqthread) {
150 dev_err(pchip->dev, "create irq thread fail\n");
151 return -ENOMEM;
152 }
153 if (request_threaded_irq
154 (pchip->irq, NULL, lm3630a_isr_func,
155 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "lm3630a_irq", pchip)) {
156 dev_err(pchip->dev, "request threaded irq fail\n");
157 destroy_workqueue(pchip->irqthread);
158 return -ENOMEM;
159 }
160 return rval;
161}
162
163static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max)
164{
165 unsigned int period = pwm_get_period(pchip->pwmd);
166 unsigned int duty = br * period / br_max;
167
168 pwm_config(pchip->pwmd, duty, period);
169 if (duty)
170 pwm_enable(pchip->pwmd);
171 else
172 pwm_disable(pchip->pwmd);
173}
174
175/* update and get brightness */
176static int lm3630a_bank_a_update_status(struct backlight_device *bl)
177{
178 int ret;
179 struct lm3630a_chip *pchip = bl_get_data(bl);
180 enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
181
182 /* pwm control */
183 if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) {
184 lm3630a_pwm_ctrl(pchip, bl->props.brightness,
185 bl->props.max_brightness);
186 return bl->props.brightness;
187 }
188
189 /* disable sleep */
190 ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
191 if (ret < 0)
192 goto out_i2c_err;
193 usleep_range(1000, 2000);
194 /* minimum brightness is 0x04 */
195 ret = lm3630a_write(pchip, REG_BRT_A, bl->props.brightness);
196 if (bl->props.brightness < 0x4)
197 ret |= lm3630a_update(pchip, REG_CTRL, LM3630A_LEDA_ENABLE, 0);
198 else
199 ret |= lm3630a_update(pchip, REG_CTRL,
200 LM3630A_LEDA_ENABLE, LM3630A_LEDA_ENABLE);
201 if (ret < 0)
202 goto out_i2c_err;
203 return bl->props.brightness;
204
205out_i2c_err:
206 dev_err(pchip->dev, "i2c failed to access\n");
207 return bl->props.brightness;
208}
209
210static int lm3630a_bank_a_get_brightness(struct backlight_device *bl)
211{
212 int brightness, rval;
213 struct lm3630a_chip *pchip = bl_get_data(bl);
214 enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
215
216 if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) {
217 rval = lm3630a_read(pchip, REG_PWM_OUTHIGH);
218 if (rval < 0)
219 goto out_i2c_err;
220 brightness = (rval & 0x01) << 8;
221 rval = lm3630a_read(pchip, REG_PWM_OUTLOW);
222 if (rval < 0)
223 goto out_i2c_err;
224 brightness |= rval;
225 goto out;
226 }
227
228 /* disable sleep */
229 rval = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
230 if (rval < 0)
231 goto out_i2c_err;
232 usleep_range(1000, 2000);
233 rval = lm3630a_read(pchip, REG_BRT_A);
234 if (rval < 0)
235 goto out_i2c_err;
236 brightness = rval;
237
238out:
239 bl->props.brightness = brightness;
240 return bl->props.brightness;
241out_i2c_err:
242 dev_err(pchip->dev, "i2c failed to access register\n");
243 return 0;
244}
245
246static const struct backlight_ops lm3630a_bank_a_ops = {
247 .options = BL_CORE_SUSPENDRESUME,
248 .update_status = lm3630a_bank_a_update_status,
249 .get_brightness = lm3630a_bank_a_get_brightness,
250};
251
252/* update and get brightness */
253static int lm3630a_bank_b_update_status(struct backlight_device *bl)
254{
255 int ret;
256 struct lm3630a_chip *pchip = bl_get_data(bl);
257 enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
258
259 /* pwm control */
260 if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0) {
261 lm3630a_pwm_ctrl(pchip, bl->props.brightness,
262 bl->props.max_brightness);
263 return bl->props.brightness;
264 }
265
266 /* disable sleep */
267 ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
268 if (ret < 0)
269 goto out_i2c_err;
270 usleep_range(1000, 2000);
271 /* minimum brightness is 0x04 */
272 ret = lm3630a_write(pchip, REG_BRT_B, bl->props.brightness);
273 if (bl->props.brightness < 0x4)
274 ret |= lm3630a_update(pchip, REG_CTRL, LM3630A_LEDB_ENABLE, 0);
275 else
276 ret |= lm3630a_update(pchip, REG_CTRL,
277 LM3630A_LEDB_ENABLE, LM3630A_LEDB_ENABLE);
278 if (ret < 0)
279 goto out_i2c_err;
280 return bl->props.brightness;
281
282out_i2c_err:
283 dev_err(pchip->dev, "i2c failed to access REG_CTRL\n");
284 return bl->props.brightness;
285}
286
287static int lm3630a_bank_b_get_brightness(struct backlight_device *bl)
288{
289 int brightness, rval;
290 struct lm3630a_chip *pchip = bl_get_data(bl);
291 enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
292
293 if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0) {
294 rval = lm3630a_read(pchip, REG_PWM_OUTHIGH);
295 if (rval < 0)
296 goto out_i2c_err;
297 brightness = (rval & 0x01) << 8;
298 rval = lm3630a_read(pchip, REG_PWM_OUTLOW);
299 if (rval < 0)
300 goto out_i2c_err;
301 brightness |= rval;
302 goto out;
303 }
304
305 /* disable sleep */
306 rval = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
307 if (rval < 0)
308 goto out_i2c_err;
309 usleep_range(1000, 2000);
310 rval = lm3630a_read(pchip, REG_BRT_B);
311 if (rval < 0)
312 goto out_i2c_err;
313 brightness = rval;
314
315out:
316 bl->props.brightness = brightness;
317 return bl->props.brightness;
318out_i2c_err:
319 dev_err(pchip->dev, "i2c failed to access register\n");
320 return 0;
321}
322
323static const struct backlight_ops lm3630a_bank_b_ops = {
324 .options = BL_CORE_SUSPENDRESUME,
325 .update_status = lm3630a_bank_b_update_status,
326 .get_brightness = lm3630a_bank_b_get_brightness,
327};
328
329static int lm3630a_backlight_register(struct lm3630a_chip *pchip)
330{
331 struct backlight_properties props;
332 struct lm3630a_platform_data *pdata = pchip->pdata;
333
334 props.type = BACKLIGHT_RAW;
335 if (pdata->leda_ctrl != LM3630A_LEDA_DISABLE) {
336 props.brightness = pdata->leda_init_brt;
337 props.max_brightness = pdata->leda_max_brt;
338 pchip->bleda =
339 devm_backlight_device_register(pchip->dev, "lm3630a_leda",
340 pchip->dev, pchip,
341 &lm3630a_bank_a_ops, &props);
342 if (IS_ERR(pchip->bleda))
343 return PTR_ERR(pchip->bleda);
344 }
345
346 if ((pdata->ledb_ctrl != LM3630A_LEDB_DISABLE) &&
347 (pdata->ledb_ctrl != LM3630A_LEDB_ON_A)) {
348 props.brightness = pdata->ledb_init_brt;
349 props.max_brightness = pdata->ledb_max_brt;
350 pchip->bledb =
351 devm_backlight_device_register(pchip->dev, "lm3630a_ledb",
352 pchip->dev, pchip,
353 &lm3630a_bank_b_ops, &props);
354 if (IS_ERR(pchip->bledb))
355 return PTR_ERR(pchip->bledb);
356 }
357 return 0;
358}
359
360static const struct regmap_config lm3630a_regmap = {
361 .reg_bits = 8,
362 .val_bits = 8,
363 .max_register = REG_MAX,
364};
365
366static int lm3630a_probe(struct i2c_client *client,
367 const struct i2c_device_id *id)
368{
369 struct lm3630a_platform_data *pdata = dev_get_platdata(&client->dev);
370 struct lm3630a_chip *pchip;
371 int rval;
372
373 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
374 dev_err(&client->dev, "fail : i2c functionality check\n");
375 return -EOPNOTSUPP;
376 }
377
378 pchip = devm_kzalloc(&client->dev, sizeof(struct lm3630a_chip),
379 GFP_KERNEL);
380 if (!pchip)
381 return -ENOMEM;
382 pchip->dev = &client->dev;
383
384 pchip->regmap = devm_regmap_init_i2c(client, &lm3630a_regmap);
385 if (IS_ERR(pchip->regmap)) {
386 rval = PTR_ERR(pchip->regmap);
387 dev_err(&client->dev, "fail : allocate reg. map: %d\n", rval);
388 return rval;
389 }
390
391 i2c_set_clientdata(client, pchip);
392 if (pdata == NULL) {
393 pdata = devm_kzalloc(pchip->dev,
394 sizeof(struct lm3630a_platform_data),
395 GFP_KERNEL);
396 if (pdata == NULL)
397 return -ENOMEM;
398 /* default values */
399 pdata->leda_ctrl = LM3630A_LEDA_ENABLE;
400 pdata->ledb_ctrl = LM3630A_LEDB_ENABLE;
401 pdata->leda_max_brt = LM3630A_MAX_BRIGHTNESS;
402 pdata->ledb_max_brt = LM3630A_MAX_BRIGHTNESS;
403 pdata->leda_init_brt = LM3630A_MAX_BRIGHTNESS;
404 pdata->ledb_init_brt = LM3630A_MAX_BRIGHTNESS;
405 }
406 pchip->pdata = pdata;
407
408 /* chip initialize */
409 rval = lm3630a_chip_init(pchip);
410 if (rval < 0) {
411 dev_err(&client->dev, "fail : init chip\n");
412 return rval;
413 }
414 /* backlight register */
415 rval = lm3630a_backlight_register(pchip);
416 if (rval < 0) {
417 dev_err(&client->dev, "fail : backlight register.\n");
418 return rval;
419 }
420 /* pwm */
421 if (pdata->pwm_ctrl != LM3630A_PWM_DISABLE) {
422 pchip->pwmd = devm_pwm_get(pchip->dev, "lm3630a-pwm");
423 if (IS_ERR(pchip->pwmd)) {
424 dev_err(&client->dev, "fail : get pwm device\n");
425 return PTR_ERR(pchip->pwmd);
426 }
427 }
428 pchip->pwmd->period = pdata->pwm_period;
429
430 /* interrupt enable : irq 0 is not allowed */
431 pchip->irq = client->irq;
432 if (pchip->irq) {
433 rval = lm3630a_intr_config(pchip);
434 if (rval < 0)
435 return rval;
436 }
437 dev_info(&client->dev, "LM3630A backlight register OK.\n");
438 return 0;
439}
440
441static int lm3630a_remove(struct i2c_client *client)
442{
443 int rval;
444 struct lm3630a_chip *pchip = i2c_get_clientdata(client);
445
446 rval = lm3630a_write(pchip, REG_BRT_A, 0);
447 if (rval < 0)
448 dev_err(pchip->dev, "i2c failed to access register\n");
449
450 rval = lm3630a_write(pchip, REG_BRT_B, 0);
451 if (rval < 0)
452 dev_err(pchip->dev, "i2c failed to access register\n");
453
454 if (pchip->irq) {
455 free_irq(pchip->irq, pchip);
456 flush_workqueue(pchip->irqthread);
457 destroy_workqueue(pchip->irqthread);
458 }
459 return 0;
460}
461
462static const struct i2c_device_id lm3630a_id[] = {
463 {LM3630A_NAME, 0},
464 {}
465};
466
467MODULE_DEVICE_TABLE(i2c, lm3630a_id);
468
469static struct i2c_driver lm3630a_i2c_driver = {
470 .driver = {
471 .name = LM3630A_NAME,
472 },
473 .probe = lm3630a_probe,
474 .remove = lm3630a_remove,
475 .id_table = lm3630a_id,
476};
477
478module_i2c_driver(lm3630a_i2c_driver);
479
480MODULE_DESCRIPTION("Texas Instruments Backlight driver for LM3630A");
481MODULE_AUTHOR("Daniel Jeong <gshark.jeong@gmail.com>");
482MODULE_AUTHOR("LDD MLP <ldd-mlp@list.ti.com>");
483MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/backlight/lm3639_bl.c b/drivers/video/backlight/lm3639_bl.c
index 053964da8dd3..6fd60adf922e 100644
--- a/drivers/video/backlight/lm3639_bl.c
+++ b/drivers/video/backlight/lm3639_bl.c
@@ -76,10 +76,13 @@ static int lm3639_chip_init(struct lm3639_chip_data *pchip)
76 goto out; 76 goto out;
77 77
78 /* output pins config. */ 78 /* output pins config. */
79 if (!pdata->init_brt_led) 79 if (!pdata->init_brt_led) {
80 reg_val = pdata->fled_pins | pdata->bled_pins; 80 reg_val = pdata->fled_pins;
81 else 81 reg_val |= pdata->bled_pins;
82 reg_val = pdata->fled_pins | pdata->bled_pins | 0x01; 82 } else {
83 reg_val = pdata->fled_pins;
84 reg_val |= pdata->bled_pins | 0x01;
85 }
83 86
84 ret = regmap_update_bits(pchip->regmap, REG_ENABLE, 0x79, reg_val); 87 ret = regmap_update_bits(pchip->regmap, REG_ENABLE, 0x79, reg_val);
85 if (ret < 0) 88 if (ret < 0)
@@ -304,7 +307,7 @@ static int lm3639_probe(struct i2c_client *client,
304{ 307{
305 int ret; 308 int ret;
306 struct lm3639_chip_data *pchip; 309 struct lm3639_chip_data *pchip;
307 struct lm3639_platform_data *pdata = client->dev.platform_data; 310 struct lm3639_platform_data *pdata = dev_get_platdata(&client->dev);
308 struct backlight_properties props; 311 struct backlight_properties props;
309 312
310 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 313 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
diff --git a/drivers/video/backlight/lms283gf05.c b/drivers/video/backlight/lms283gf05.c
index 4eec47261cd3..de8832504f68 100644
--- a/drivers/video/backlight/lms283gf05.c
+++ b/drivers/video/backlight/lms283gf05.c
@@ -128,7 +128,7 @@ static int lms283gf05_power_set(struct lcd_device *ld, int power)
128{ 128{
129 struct lms283gf05_state *st = lcd_get_data(ld); 129 struct lms283gf05_state *st = lcd_get_data(ld);
130 struct spi_device *spi = st->spi; 130 struct spi_device *spi = st->spi;
131 struct lms283gf05_pdata *pdata = spi->dev.platform_data; 131 struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev);
132 132
133 if (power <= FB_BLANK_NORMAL) { 133 if (power <= FB_BLANK_NORMAL) {
134 if (pdata) 134 if (pdata)
@@ -153,7 +153,7 @@ static struct lcd_ops lms_ops = {
153static int lms283gf05_probe(struct spi_device *spi) 153static int lms283gf05_probe(struct spi_device *spi)
154{ 154{
155 struct lms283gf05_state *st; 155 struct lms283gf05_state *st;
156 struct lms283gf05_pdata *pdata = spi->dev.platform_data; 156 struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev);
157 struct lcd_device *ld; 157 struct lcd_device *ld;
158 int ret = 0; 158 int ret = 0;
159 159
@@ -173,7 +173,8 @@ static int lms283gf05_probe(struct spi_device *spi)
173 return -ENOMEM; 173 return -ENOMEM;
174 } 174 }
175 175
176 ld = lcd_device_register("lms283gf05", &spi->dev, st, &lms_ops); 176 ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st,
177 &lms_ops);
177 if (IS_ERR(ld)) 178 if (IS_ERR(ld))
178 return PTR_ERR(ld); 179 return PTR_ERR(ld);
179 180
@@ -190,22 +191,12 @@ static int lms283gf05_probe(struct spi_device *spi)
190 return 0; 191 return 0;
191} 192}
192 193
193static int lms283gf05_remove(struct spi_device *spi)
194{
195 struct lms283gf05_state *st = spi_get_drvdata(spi);
196
197 lcd_device_unregister(st->ld);
198
199 return 0;
200}
201
202static struct spi_driver lms283gf05_driver = { 194static struct spi_driver lms283gf05_driver = {
203 .driver = { 195 .driver = {
204 .name = "lms283gf05", 196 .name = "lms283gf05",
205 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
206 }, 198 },
207 .probe = lms283gf05_probe, 199 .probe = lms283gf05_probe,
208 .remove = lms283gf05_remove,
209}; 200};
210 201
211module_spi_driver(lms283gf05_driver); 202module_spi_driver(lms283gf05_driver);
diff --git a/drivers/video/backlight/lms501kf03.c b/drivers/video/backlight/lms501kf03.c
index cf01b9ac8131..77258b7b04be 100644
--- a/drivers/video/backlight/lms501kf03.c
+++ b/drivers/video/backlight/lms501kf03.c
@@ -344,14 +344,14 @@ static int lms501kf03_probe(struct spi_device *spi)
344 lcd->spi = spi; 344 lcd->spi = spi;
345 lcd->dev = &spi->dev; 345 lcd->dev = &spi->dev;
346 346
347 lcd->lcd_pd = spi->dev.platform_data; 347 lcd->lcd_pd = dev_get_platdata(&spi->dev);
348 if (!lcd->lcd_pd) { 348 if (!lcd->lcd_pd) {
349 dev_err(&spi->dev, "platform data is NULL\n"); 349 dev_err(&spi->dev, "platform data is NULL\n");
350 return -EINVAL; 350 return -EINVAL;
351 } 351 }
352 352
353 ld = lcd_device_register("lms501kf03", &spi->dev, lcd, 353 ld = devm_lcd_device_register(&spi->dev, "lms501kf03", &spi->dev, lcd,
354 &lms501kf03_lcd_ops); 354 &lms501kf03_lcd_ops);
355 if (IS_ERR(ld)) 355 if (IS_ERR(ld))
356 return PTR_ERR(ld); 356 return PTR_ERR(ld);
357 357
@@ -382,8 +382,6 @@ static int lms501kf03_remove(struct spi_device *spi)
382 struct lms501kf03 *lcd = spi_get_drvdata(spi); 382 struct lms501kf03 *lcd = spi_get_drvdata(spi);
383 383
384 lms501kf03_power(lcd, FB_BLANK_POWERDOWN); 384 lms501kf03_power(lcd, FB_BLANK_POWERDOWN);
385 lcd_device_unregister(lcd->ld);
386
387 return 0; 385 return 0;
388} 386}
389 387
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index c0b41f13bd4a..cae80d555e84 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -26,13 +26,15 @@
26#define LP8556_EPROM_START 0xA0 26#define LP8556_EPROM_START 0xA0
27#define LP8556_EPROM_END 0xAF 27#define LP8556_EPROM_END 0xAF
28 28
29/* LP8557 Registers */ 29/* LP8555/7 Registers */
30#define LP8557_BL_CMD 0x00 30#define LP8557_BL_CMD 0x00
31#define LP8557_BL_MASK 0x01 31#define LP8557_BL_MASK 0x01
32#define LP8557_BL_ON 0x01 32#define LP8557_BL_ON 0x01
33#define LP8557_BL_OFF 0x00 33#define LP8557_BL_OFF 0x00
34#define LP8557_BRIGHTNESS_CTRL 0x04 34#define LP8557_BRIGHTNESS_CTRL 0x04
35#define LP8557_CONFIG 0x10 35#define LP8557_CONFIG 0x10
36#define LP8555_EPROM_START 0x10
37#define LP8555_EPROM_END 0x7A
36#define LP8557_EPROM_START 0x10 38#define LP8557_EPROM_START 0x10
37#define LP8557_EPROM_END 0x1E 39#define LP8557_EPROM_END 0x1E
38 40
@@ -111,6 +113,10 @@ static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr)
111 start = LP8556_EPROM_START; 113 start = LP8556_EPROM_START;
112 end = LP8556_EPROM_END; 114 end = LP8556_EPROM_END;
113 break; 115 break;
116 case LP8555:
117 start = LP8555_EPROM_START;
118 end = LP8555_EPROM_END;
119 break;
114 case LP8557: 120 case LP8557:
115 start = LP8557_EPROM_START; 121 start = LP8557_EPROM_START;
116 end = LP8557_EPROM_END; 122 end = LP8557_EPROM_END;
@@ -165,9 +171,14 @@ static int lp855x_configure(struct lp855x *lp)
165 struct lp855x_platform_data *pd = lp->pdata; 171 struct lp855x_platform_data *pd = lp->pdata;
166 172
167 switch (lp->chip_id) { 173 switch (lp->chip_id) {
168 case LP8550 ... LP8556: 174 case LP8550:
175 case LP8551:
176 case LP8552:
177 case LP8553:
178 case LP8556:
169 lp->cfg = &lp855x_dev_cfg; 179 lp->cfg = &lp855x_dev_cfg;
170 break; 180 break;
181 case LP8555:
171 case LP8557: 182 case LP8557:
172 lp->cfg = &lp8557_dev_cfg; 183 lp->cfg = &lp8557_dev_cfg;
173 break; 184 break;
@@ -289,7 +300,7 @@ static int lp855x_backlight_register(struct lp855x *lp)
289 300
290 props.brightness = pdata->initial_brightness; 301 props.brightness = pdata->initial_brightness;
291 302
292 bl = backlight_device_register(name, lp->dev, lp, 303 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp,
293 &lp855x_bl_ops, &props); 304 &lp855x_bl_ops, &props);
294 if (IS_ERR(bl)) 305 if (IS_ERR(bl))
295 return PTR_ERR(bl); 306 return PTR_ERR(bl);
@@ -299,12 +310,6 @@ static int lp855x_backlight_register(struct lp855x *lp)
299 return 0; 310 return 0;
300} 311}
301 312
302static void lp855x_backlight_unregister(struct lp855x *lp)
303{
304 if (lp->bl)
305 backlight_device_unregister(lp->bl);
306}
307
308static ssize_t lp855x_get_chip_id(struct device *dev, 313static ssize_t lp855x_get_chip_id(struct device *dev,
309 struct device_attribute *attr, char *buf) 314 struct device_attribute *attr, char *buf)
310{ 315{
@@ -394,7 +399,7 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node)
394static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) 399static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
395{ 400{
396 struct lp855x *lp; 401 struct lp855x *lp;
397 struct lp855x_platform_data *pdata = cl->dev.platform_data; 402 struct lp855x_platform_data *pdata = dev_get_platdata(&cl->dev);
398 struct device_node *node = cl->dev.of_node; 403 struct device_node *node = cl->dev.of_node;
399 int ret; 404 int ret;
400 405
@@ -403,7 +408,7 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
403 if (ret < 0) 408 if (ret < 0)
404 return ret; 409 return ret;
405 410
406 pdata = cl->dev.platform_data; 411 pdata = dev_get_platdata(&cl->dev);
407 } 412 }
408 413
409 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 414 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
@@ -428,29 +433,24 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
428 ret = lp855x_configure(lp); 433 ret = lp855x_configure(lp);
429 if (ret) { 434 if (ret) {
430 dev_err(lp->dev, "device config err: %d", ret); 435 dev_err(lp->dev, "device config err: %d", ret);
431 goto err_dev; 436 return ret;
432 } 437 }
433 438
434 ret = lp855x_backlight_register(lp); 439 ret = lp855x_backlight_register(lp);
435 if (ret) { 440 if (ret) {
436 dev_err(lp->dev, 441 dev_err(lp->dev,
437 "failed to register backlight. err: %d\n", ret); 442 "failed to register backlight. err: %d\n", ret);
438 goto err_dev; 443 return ret;
439 } 444 }
440 445
441 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group); 446 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group);
442 if (ret) { 447 if (ret) {
443 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret); 448 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret);
444 goto err_sysfs; 449 return ret;
445 } 450 }
446 451
447 backlight_update_status(lp->bl); 452 backlight_update_status(lp->bl);
448 return 0; 453 return 0;
449
450err_sysfs:
451 lp855x_backlight_unregister(lp);
452err_dev:
453 return ret;
454} 454}
455 455
456static int lp855x_remove(struct i2c_client *cl) 456static int lp855x_remove(struct i2c_client *cl)
@@ -460,7 +460,6 @@ static int lp855x_remove(struct i2c_client *cl)
460 lp->bl->props.brightness = 0; 460 lp->bl->props.brightness = 0;
461 backlight_update_status(lp->bl); 461 backlight_update_status(lp->bl);
462 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); 462 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group);
463 lp855x_backlight_unregister(lp);
464 463
465 return 0; 464 return 0;
466} 465}
@@ -470,6 +469,7 @@ static const struct of_device_id lp855x_dt_ids[] = {
470 { .compatible = "ti,lp8551", }, 469 { .compatible = "ti,lp8551", },
471 { .compatible = "ti,lp8552", }, 470 { .compatible = "ti,lp8552", },
472 { .compatible = "ti,lp8553", }, 471 { .compatible = "ti,lp8553", },
472 { .compatible = "ti,lp8555", },
473 { .compatible = "ti,lp8556", }, 473 { .compatible = "ti,lp8556", },
474 { .compatible = "ti,lp8557", }, 474 { .compatible = "ti,lp8557", },
475 { } 475 { }
@@ -481,6 +481,7 @@ static const struct i2c_device_id lp855x_ids[] = {
481 {"lp8551", LP8551}, 481 {"lp8551", LP8551},
482 {"lp8552", LP8552}, 482 {"lp8552", LP8552},
483 {"lp8553", LP8553}, 483 {"lp8553", LP8553},
484 {"lp8555", LP8555},
484 {"lp8556", LP8556}, 485 {"lp8556", LP8556},
485 {"lp8557", LP8557}, 486 {"lp8557", LP8557},
486 { } 487 { }
diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c
index 980855ec9bb1..e49905d495dc 100644
--- a/drivers/video/backlight/lp8788_bl.c
+++ b/drivers/video/backlight/lp8788_bl.c
@@ -52,7 +52,7 @@ struct lp8788_bl {
52 struct pwm_device *pwm; 52 struct pwm_device *pwm;
53}; 53};
54 54
55struct lp8788_bl_config default_bl_config = { 55static struct lp8788_bl_config default_bl_config = {
56 .bl_mode = LP8788_BL_REGISTER_ONLY, 56 .bl_mode = LP8788_BL_REGISTER_ONLY,
57 .dim_mode = LP8788_DIM_EXPONENTIAL, 57 .dim_mode = LP8788_DIM_EXPONENTIAL,
58 .full_scale = LP8788_FULLSCALE_1900uA, 58 .full_scale = LP8788_FULLSCALE_1900uA,
diff --git a/drivers/video/backlight/ltv350qv.c b/drivers/video/backlight/ltv350qv.c
index ed1b39268131..383f550e165e 100644
--- a/drivers/video/backlight/ltv350qv.c
+++ b/drivers/video/backlight/ltv350qv.c
@@ -242,7 +242,8 @@ static int ltv350qv_probe(struct spi_device *spi)
242 if (!lcd->buffer) 242 if (!lcd->buffer)
243 return -ENOMEM; 243 return -ENOMEM;
244 244
245 ld = lcd_device_register("ltv350qv", &spi->dev, lcd, &ltv_ops); 245 ld = devm_lcd_device_register(&spi->dev, "ltv350qv", &spi->dev, lcd,
246 &ltv_ops);
246 if (IS_ERR(ld)) 247 if (IS_ERR(ld))
247 return PTR_ERR(ld); 248 return PTR_ERR(ld);
248 249
@@ -250,15 +251,11 @@ static int ltv350qv_probe(struct spi_device *spi)
250 251
251 ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK); 252 ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
252 if (ret) 253 if (ret)
253 goto out_unregister; 254 return ret;
254 255
255 spi_set_drvdata(spi, lcd); 256 spi_set_drvdata(spi, lcd);
256 257
257 return 0; 258 return 0;
258
259out_unregister:
260 lcd_device_unregister(ld);
261 return ret;
262} 259}
263 260
264static int ltv350qv_remove(struct spi_device *spi) 261static int ltv350qv_remove(struct spi_device *spi)
@@ -266,8 +263,6 @@ static int ltv350qv_remove(struct spi_device *spi)
266 struct ltv350qv *lcd = spi_get_drvdata(spi); 263 struct ltv350qv *lcd = spi_get_drvdata(spi);
267 264
268 ltv350qv_power(lcd, FB_BLANK_POWERDOWN); 265 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
269 lcd_device_unregister(lcd->ld);
270
271 return 0; 266 return 0;
272} 267}
273 268
diff --git a/drivers/video/backlight/lv5207lp.c b/drivers/video/backlight/lv5207lp.c
index 498fd73d59b9..1802b2d1357d 100644
--- a/drivers/video/backlight/lv5207lp.c
+++ b/drivers/video/backlight/lv5207lp.c
@@ -93,7 +93,7 @@ static const struct backlight_ops lv5207lp_backlight_ops = {
93static int lv5207lp_probe(struct i2c_client *client, 93static int lv5207lp_probe(struct i2c_client *client,
94 const struct i2c_device_id *id) 94 const struct i2c_device_id *id)
95{ 95{
96 struct lv5207lp_platform_data *pdata = client->dev.platform_data; 96 struct lv5207lp_platform_data *pdata = dev_get_platdata(&client->dev);
97 struct backlight_device *backlight; 97 struct backlight_device *backlight;
98 struct backlight_properties props; 98 struct backlight_properties props;
99 struct lv5207lp *lv; 99 struct lv5207lp *lv;
@@ -124,9 +124,9 @@ static int lv5207lp_probe(struct i2c_client *client,
124 props.brightness = clamp_t(unsigned int, pdata->def_value, 0, 124 props.brightness = clamp_t(unsigned int, pdata->def_value, 0,
125 props.max_brightness); 125 props.max_brightness);
126 126
127 backlight = backlight_device_register(dev_name(&client->dev), 127 backlight = devm_backlight_device_register(&client->dev,
128 &lv->client->dev, lv, 128 dev_name(&client->dev), &lv->client->dev,
129 &lv5207lp_backlight_ops, &props); 129 lv, &lv5207lp_backlight_ops, &props);
130 if (IS_ERR(backlight)) { 130 if (IS_ERR(backlight)) {
131 dev_err(&client->dev, "failed to register backlight\n"); 131 dev_err(&client->dev, "failed to register backlight\n");
132 return PTR_ERR(backlight); 132 return PTR_ERR(backlight);
@@ -144,7 +144,6 @@ static int lv5207lp_remove(struct i2c_client *client)
144 144
145 backlight->props.brightness = 0; 145 backlight->props.brightness = 0;
146 backlight_update_status(backlight); 146 backlight_update_status(backlight);
147 backlight_device_unregister(backlight);
148 147
149 return 0; 148 return 0;
150} 149}
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c
index 886e797f75f9..66fa08c920d2 100644
--- a/drivers/video/backlight/max8925_bl.c
+++ b/drivers/video/backlight/max8925_bl.c
@@ -163,7 +163,8 @@ static int max8925_backlight_probe(struct platform_device *pdev)
163 memset(&props, 0, sizeof(struct backlight_properties)); 163 memset(&props, 0, sizeof(struct backlight_properties));
164 props.type = BACKLIGHT_RAW; 164 props.type = BACKLIGHT_RAW;
165 props.max_brightness = MAX_BRIGHTNESS; 165 props.max_brightness = MAX_BRIGHTNESS;
166 bl = backlight_device_register("max8925-backlight", &pdev->dev, data, 166 bl = devm_backlight_device_register(&pdev->dev, "max8925-backlight",
167 &pdev->dev, data,
167 &max8925_backlight_ops, &props); 168 &max8925_backlight_ops, &props);
168 if (IS_ERR(bl)) { 169 if (IS_ERR(bl)) {
169 dev_err(&pdev->dev, "failed to register backlight\n"); 170 dev_err(&pdev->dev, "failed to register backlight\n");
@@ -188,20 +189,9 @@ static int max8925_backlight_probe(struct platform_device *pdev)
188 } 189 }
189 ret = max8925_set_bits(chip->i2c, data->reg_mode_cntl, 0xfe, value); 190 ret = max8925_set_bits(chip->i2c, data->reg_mode_cntl, 0xfe, value);
190 if (ret < 0) 191 if (ret < 0)
191 goto out_brt; 192 return ret;
192 backlight_update_status(bl); 193 backlight_update_status(bl);
193 return 0; 194 return 0;
194out_brt:
195 backlight_device_unregister(bl);
196 return ret;
197}
198
199static int max8925_backlight_remove(struct platform_device *pdev)
200{
201 struct backlight_device *bl = platform_get_drvdata(pdev);
202
203 backlight_device_unregister(bl);
204 return 0;
205} 195}
206 196
207static struct platform_driver max8925_backlight_driver = { 197static struct platform_driver max8925_backlight_driver = {
@@ -210,7 +200,6 @@ static struct platform_driver max8925_backlight_driver = {
210 .owner = THIS_MODULE, 200 .owner = THIS_MODULE,
211 }, 201 },
212 .probe = max8925_backlight_probe, 202 .probe = max8925_backlight_probe,
213 .remove = max8925_backlight_remove,
214}; 203};
215 204
216module_platform_driver(max8925_backlight_driver); 205module_platform_driver(max8925_backlight_driver);
diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
index 812e22e35cab..ac11a4650c19 100644
--- a/drivers/video/backlight/omap1_bl.c
+++ b/drivers/video/backlight/omap1_bl.c
@@ -133,7 +133,7 @@ static int omapbl_probe(struct platform_device *pdev)
133 struct backlight_properties props; 133 struct backlight_properties props;
134 struct backlight_device *dev; 134 struct backlight_device *dev;
135 struct omap_backlight *bl; 135 struct omap_backlight *bl;
136 struct omap_backlight_config *pdata = pdev->dev.platform_data; 136 struct omap_backlight_config *pdata = dev_get_platdata(&pdev->dev);
137 137
138 if (!pdata) 138 if (!pdata)
139 return -ENXIO; 139 return -ENXIO;
diff --git a/drivers/video/backlight/pandora_bl.c b/drivers/video/backlight/pandora_bl.c
index 633b0a22fd64..2098c5d6efb9 100644
--- a/drivers/video/backlight/pandora_bl.c
+++ b/drivers/video/backlight/pandora_bl.c
@@ -120,8 +120,8 @@ static int pandora_backlight_probe(struct platform_device *pdev)
120 memset(&props, 0, sizeof(props)); 120 memset(&props, 0, sizeof(props));
121 props.max_brightness = MAX_USER_VALUE; 121 props.max_brightness = MAX_USER_VALUE;
122 props.type = BACKLIGHT_RAW; 122 props.type = BACKLIGHT_RAW;
123 bl = backlight_device_register(pdev->name, &pdev->dev, 123 bl = devm_backlight_device_register(&pdev->dev, pdev->name, &pdev->dev,
124 NULL, &pandora_backlight_ops, &props); 124 NULL, &pandora_backlight_ops, &props);
125 if (IS_ERR(bl)) { 125 if (IS_ERR(bl)) {
126 dev_err(&pdev->dev, "failed to register backlight\n"); 126 dev_err(&pdev->dev, "failed to register backlight\n");
127 return PTR_ERR(bl); 127 return PTR_ERR(bl);
@@ -145,20 +145,12 @@ static int pandora_backlight_probe(struct platform_device *pdev)
145 return 0; 145 return 0;
146} 146}
147 147
148static int pandora_backlight_remove(struct platform_device *pdev)
149{
150 struct backlight_device *bl = platform_get_drvdata(pdev);
151 backlight_device_unregister(bl);
152 return 0;
153}
154
155static struct platform_driver pandora_backlight_driver = { 148static struct platform_driver pandora_backlight_driver = {
156 .driver = { 149 .driver = {
157 .name = "pandora-backlight", 150 .name = "pandora-backlight",
158 .owner = THIS_MODULE, 151 .owner = THIS_MODULE,
159 }, 152 },
160 .probe = pandora_backlight_probe, 153 .probe = pandora_backlight_probe,
161 .remove = pandora_backlight_remove,
162}; 154};
163 155
164module_platform_driver(pandora_backlight_driver); 156module_platform_driver(pandora_backlight_driver);
diff --git a/drivers/video/backlight/pcf50633-backlight.c b/drivers/video/backlight/pcf50633-backlight.c
index 6ed76be18f19..b95d3b0aaffe 100644
--- a/drivers/video/backlight/pcf50633-backlight.c
+++ b/drivers/video/backlight/pcf50633-backlight.c
@@ -103,7 +103,7 @@ static int pcf50633_bl_probe(struct platform_device *pdev)
103{ 103{
104 struct pcf50633_bl *pcf_bl; 104 struct pcf50633_bl *pcf_bl;
105 struct device *parent = pdev->dev.parent; 105 struct device *parent = pdev->dev.parent;
106 struct pcf50633_platform_data *pcf50633_data = parent->platform_data; 106 struct pcf50633_platform_data *pcf50633_data = dev_get_platdata(parent);
107 struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data; 107 struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data;
108 struct backlight_properties bl_props; 108 struct backlight_properties bl_props;
109 109
@@ -126,7 +126,8 @@ static int pcf50633_bl_probe(struct platform_device *pdev)
126 126
127 pcf_bl->pcf = dev_to_pcf50633(pdev->dev.parent); 127 pcf_bl->pcf = dev_to_pcf50633(pdev->dev.parent);
128 128
129 pcf_bl->bl = backlight_device_register(pdev->name, &pdev->dev, pcf_bl, 129 pcf_bl->bl = devm_backlight_device_register(&pdev->dev, pdev->name,
130 &pdev->dev, pcf_bl,
130 &pcf50633_bl_ops, &bl_props); 131 &pcf50633_bl_ops, &bl_props);
131 132
132 if (IS_ERR(pcf_bl->bl)) 133 if (IS_ERR(pcf_bl->bl))
@@ -147,18 +148,8 @@ static int pcf50633_bl_probe(struct platform_device *pdev)
147 return 0; 148 return 0;
148} 149}
149 150
150static int pcf50633_bl_remove(struct platform_device *pdev)
151{
152 struct pcf50633_bl *pcf_bl = platform_get_drvdata(pdev);
153
154 backlight_device_unregister(pcf_bl->bl);
155
156 return 0;
157}
158
159static struct platform_driver pcf50633_bl_driver = { 151static struct platform_driver pcf50633_bl_driver = {
160 .probe = pcf50633_bl_probe, 152 .probe = pcf50633_bl_probe,
161 .remove = pcf50633_bl_remove,
162 .driver = { 153 .driver = {
163 .name = "pcf50633-backlight", 154 .name = "pcf50633-backlight",
164 }, 155 },
diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
index 056836706708..d01884d4f1bf 100644
--- a/drivers/video/backlight/platform_lcd.c
+++ b/drivers/video/backlight/platform_lcd.c
@@ -80,7 +80,7 @@ static int platform_lcd_probe(struct platform_device *pdev)
80 struct device *dev = &pdev->dev; 80 struct device *dev = &pdev->dev;
81 int err; 81 int err;
82 82
83 pdata = pdev->dev.platform_data; 83 pdata = dev_get_platdata(&pdev->dev);
84 if (!pdata) { 84 if (!pdata) {
85 dev_err(dev, "no platform data supplied\n"); 85 dev_err(dev, "no platform data supplied\n");
86 return -EINVAL; 86 return -EINVAL;
@@ -101,30 +101,17 @@ static int platform_lcd_probe(struct platform_device *pdev)
101 101
102 plcd->us = dev; 102 plcd->us = dev;
103 plcd->pdata = pdata; 103 plcd->pdata = pdata;
104 plcd->lcd = lcd_device_register(dev_name(dev), dev, 104 plcd->lcd = devm_lcd_device_register(&pdev->dev, dev_name(dev), dev,
105 plcd, &platform_lcd_ops); 105 plcd, &platform_lcd_ops);
106 if (IS_ERR(plcd->lcd)) { 106 if (IS_ERR(plcd->lcd)) {
107 dev_err(dev, "cannot register lcd device\n"); 107 dev_err(dev, "cannot register lcd device\n");
108 err = PTR_ERR(plcd->lcd); 108 return PTR_ERR(plcd->lcd);
109 goto err;
110 } 109 }
111 110
112 platform_set_drvdata(pdev, plcd); 111 platform_set_drvdata(pdev, plcd);
113 platform_lcd_set_power(plcd->lcd, FB_BLANK_NORMAL); 112 platform_lcd_set_power(plcd->lcd, FB_BLANK_NORMAL);
114 113
115 return 0; 114 return 0;
116
117 err:
118 return err;
119}
120
121static int platform_lcd_remove(struct platform_device *pdev)
122{
123 struct platform_lcd *plcd = platform_get_drvdata(pdev);
124
125 lcd_device_unregister(plcd->lcd);
126
127 return 0;
128} 115}
129 116
130#ifdef CONFIG_PM_SLEEP 117#ifdef CONFIG_PM_SLEEP
@@ -168,7 +155,6 @@ static struct platform_driver platform_lcd_driver = {
168 .of_match_table = of_match_ptr(platform_lcd_of_match), 155 .of_match_table = of_match_ptr(platform_lcd_of_match),
169 }, 156 },
170 .probe = platform_lcd_probe, 157 .probe = platform_lcd_probe,
171 .remove = platform_lcd_remove,
172}; 158};
173 159
174module_platform_driver(platform_lcd_driver); 160module_platform_driver(platform_lcd_driver);
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 1fea627394d7..36db5d98dd2f 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -163,7 +163,7 @@ static int pwm_backlight_parse_dt(struct device *dev,
163 163
164static int pwm_backlight_probe(struct platform_device *pdev) 164static int pwm_backlight_probe(struct platform_device *pdev)
165{ 165{
166 struct platform_pwm_backlight_data *data = pdev->dev.platform_data; 166 struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev);
167 struct platform_pwm_backlight_data defdata; 167 struct platform_pwm_backlight_data defdata;
168 struct backlight_properties props; 168 struct backlight_properties props;
169 struct backlight_device *bl; 169 struct backlight_device *bl;
diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
index b37bb1854bf4..510a1bcf76f1 100644
--- a/drivers/video/backlight/s6e63m0.c
+++ b/drivers/video/backlight/s6e63m0.c
@@ -735,13 +735,14 @@ static int s6e63m0_probe(struct spi_device *spi)
735 lcd->spi = spi; 735 lcd->spi = spi;
736 lcd->dev = &spi->dev; 736 lcd->dev = &spi->dev;
737 737
738 lcd->lcd_pd = spi->dev.platform_data; 738 lcd->lcd_pd = dev_get_platdata(&spi->dev);
739 if (!lcd->lcd_pd) { 739 if (!lcd->lcd_pd) {
740 dev_err(&spi->dev, "platform data is NULL.\n"); 740 dev_err(&spi->dev, "platform data is NULL.\n");
741 return -EINVAL; 741 return -EINVAL;
742 } 742 }
743 743
744 ld = lcd_device_register("s6e63m0", &spi->dev, lcd, &s6e63m0_lcd_ops); 744 ld = devm_lcd_device_register(&spi->dev, "s6e63m0", &spi->dev, lcd,
745 &s6e63m0_lcd_ops);
745 if (IS_ERR(ld)) 746 if (IS_ERR(ld))
746 return PTR_ERR(ld); 747 return PTR_ERR(ld);
747 748
@@ -751,12 +752,11 @@ static int s6e63m0_probe(struct spi_device *spi)
751 props.type = BACKLIGHT_RAW; 752 props.type = BACKLIGHT_RAW;
752 props.max_brightness = MAX_BRIGHTNESS; 753 props.max_brightness = MAX_BRIGHTNESS;
753 754
754 bd = backlight_device_register("s6e63m0bl-bl", &spi->dev, lcd, 755 bd = devm_backlight_device_register(&spi->dev, "s6e63m0bl-bl",
755 &s6e63m0_backlight_ops, &props); 756 &spi->dev, lcd, &s6e63m0_backlight_ops,
756 if (IS_ERR(bd)) { 757 &props);
757 ret = PTR_ERR(bd); 758 if (IS_ERR(bd))
758 goto out_lcd_unregister; 759 return PTR_ERR(bd);
759 }
760 760
761 bd->props.brightness = MAX_BRIGHTNESS; 761 bd->props.brightness = MAX_BRIGHTNESS;
762 lcd->bd = bd; 762 lcd->bd = bd;
@@ -798,10 +798,6 @@ static int s6e63m0_probe(struct spi_device *spi)
798 dev_info(&spi->dev, "s6e63m0 panel driver has been probed.\n"); 798 dev_info(&spi->dev, "s6e63m0 panel driver has been probed.\n");
799 799
800 return 0; 800 return 0;
801
802out_lcd_unregister:
803 lcd_device_unregister(ld);
804 return ret;
805} 801}
806 802
807static int s6e63m0_remove(struct spi_device *spi) 803static int s6e63m0_remove(struct spi_device *spi)
@@ -811,8 +807,6 @@ static int s6e63m0_remove(struct spi_device *spi)
811 s6e63m0_power(lcd, FB_BLANK_POWERDOWN); 807 s6e63m0_power(lcd, FB_BLANK_POWERDOWN);
812 device_remove_file(&spi->dev, &dev_attr_gamma_table); 808 device_remove_file(&spi->dev, &dev_attr_gamma_table);
813 device_remove_file(&spi->dev, &dev_attr_gamma_mode); 809 device_remove_file(&spi->dev, &dev_attr_gamma_mode);
814 backlight_device_unregister(lcd->bd);
815 lcd_device_unregister(lcd->ld);
816 810
817 return 0; 811 return 0;
818} 812}
diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c
index 18cdf466d50a..908016fc5829 100644
--- a/drivers/video/backlight/tdo24m.c
+++ b/drivers/video/backlight/tdo24m.c
@@ -338,7 +338,7 @@ static int tdo24m_probe(struct spi_device *spi)
338 enum tdo24m_model model; 338 enum tdo24m_model model;
339 int err; 339 int err;
340 340
341 pdata = spi->dev.platform_data; 341 pdata = dev_get_platdata(&spi->dev);
342 if (pdata) 342 if (pdata)
343 model = pdata->model; 343 model = pdata->model;
344 else 344 else
@@ -385,21 +385,17 @@ static int tdo24m_probe(struct spi_device *spi)
385 return -EINVAL; 385 return -EINVAL;
386 } 386 }
387 387
388 lcd->lcd_dev = lcd_device_register("tdo24m", &spi->dev, 388 lcd->lcd_dev = devm_lcd_device_register(&spi->dev, "tdo24m", &spi->dev,
389 lcd, &tdo24m_ops); 389 lcd, &tdo24m_ops);
390 if (IS_ERR(lcd->lcd_dev)) 390 if (IS_ERR(lcd->lcd_dev))
391 return PTR_ERR(lcd->lcd_dev); 391 return PTR_ERR(lcd->lcd_dev);
392 392
393 spi_set_drvdata(spi, lcd); 393 spi_set_drvdata(spi, lcd);
394 err = tdo24m_power(lcd, FB_BLANK_UNBLANK); 394 err = tdo24m_power(lcd, FB_BLANK_UNBLANK);
395 if (err) 395 if (err)
396 goto out_unregister; 396 return err;
397 397
398 return 0; 398 return 0;
399
400out_unregister:
401 lcd_device_unregister(lcd->lcd_dev);
402 return err;
403} 399}
404 400
405static int tdo24m_remove(struct spi_device *spi) 401static int tdo24m_remove(struct spi_device *spi)
@@ -407,8 +403,6 @@ static int tdo24m_remove(struct spi_device *spi)
407 struct tdo24m *lcd = spi_get_drvdata(spi); 403 struct tdo24m *lcd = spi_get_drvdata(spi);
408 404
409 tdo24m_power(lcd, FB_BLANK_POWERDOWN); 405 tdo24m_power(lcd, FB_BLANK_POWERDOWN);
410 lcd_device_unregister(lcd->lcd_dev);
411
412 return 0; 406 return 0;
413} 407}
414 408
diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
index 9df66ac68b34..b8db9338cacd 100644
--- a/drivers/video/backlight/tosa_bl.c
+++ b/drivers/video/backlight/tosa_bl.c
@@ -38,7 +38,7 @@ struct tosa_bl_data {
38 38
39static void tosa_bl_set_backlight(struct tosa_bl_data *data, int brightness) 39static void tosa_bl_set_backlight(struct tosa_bl_data *data, int brightness)
40{ 40{
41 struct spi_device *spi = data->i2c->dev.platform_data; 41 struct spi_device *spi = dev_get_platdata(&data->i2c->dev);
42 42
43 i2c_smbus_write_byte_data(data->i2c, DAC_CH1, data->comadj); 43 i2c_smbus_write_byte_data(data->i2c, DAC_CH1, data->comadj);
44 44
diff --git a/drivers/video/backlight/tps65217_bl.c b/drivers/video/backlight/tps65217_bl.c
index 05782312aeb3..cbba37e6836e 100644
--- a/drivers/video/backlight/tps65217_bl.c
+++ b/drivers/video/backlight/tps65217_bl.c
@@ -287,12 +287,11 @@ static int tps65217_bl_probe(struct platform_device *pdev)
287 if (IS_ERR(pdata)) 287 if (IS_ERR(pdata))
288 return PTR_ERR(pdata); 288 return PTR_ERR(pdata);
289 } else { 289 } else {
290 if (!pdev->dev.platform_data) { 290 pdata = dev_get_platdata(&pdev->dev);
291 if (!pdata) {
291 dev_err(&pdev->dev, "no platform data provided\n"); 292 dev_err(&pdev->dev, "no platform data provided\n");
292 return -EINVAL; 293 return -EINVAL;
293 } 294 }
294
295 pdata = pdev->dev.platform_data;
296 } 295 }
297 296
298 tps65217_bl = devm_kzalloc(&pdev->dev, sizeof(*tps65217_bl), 297 tps65217_bl = devm_kzalloc(&pdev->dev, sizeof(*tps65217_bl),
@@ -314,7 +313,7 @@ static int tps65217_bl_probe(struct platform_device *pdev)
314 bl_props.type = BACKLIGHT_RAW; 313 bl_props.type = BACKLIGHT_RAW;
315 bl_props.max_brightness = 100; 314 bl_props.max_brightness = 100;
316 315
317 tps65217_bl->bl = backlight_device_register(pdev->name, 316 tps65217_bl->bl = devm_backlight_device_register(&pdev->dev, pdev->name,
318 tps65217_bl->dev, tps65217_bl, 317 tps65217_bl->dev, tps65217_bl,
319 &tps65217_bl_ops, &bl_props); 318 &tps65217_bl_ops, &bl_props);
320 if (IS_ERR(tps65217_bl->bl)) { 319 if (IS_ERR(tps65217_bl->bl)) {
@@ -330,18 +329,8 @@ static int tps65217_bl_probe(struct platform_device *pdev)
330 return 0; 329 return 0;
331} 330}
332 331
333static int tps65217_bl_remove(struct platform_device *pdev)
334{
335 struct tps65217_bl *tps65217_bl = platform_get_drvdata(pdev);
336
337 backlight_device_unregister(tps65217_bl->bl);
338
339 return 0;
340}
341
342static struct platform_driver tps65217_bl_driver = { 332static struct platform_driver tps65217_bl_driver = {
343 .probe = tps65217_bl_probe, 333 .probe = tps65217_bl_probe,
344 .remove = tps65217_bl_remove,
345 .driver = { 334 .driver = {
346 .owner = THIS_MODULE, 335 .owner = THIS_MODULE,
347 .name = "tps65217-bl", 336 .name = "tps65217-bl",
diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
index 9e5517a3a52b..8b9455e93069 100644
--- a/drivers/video/backlight/wm831x_bl.c
+++ b/drivers/video/backlight/wm831x_bl.c
@@ -123,7 +123,7 @@ static const struct backlight_ops wm831x_backlight_ops = {
123static int wm831x_backlight_probe(struct platform_device *pdev) 123static int wm831x_backlight_probe(struct platform_device *pdev)
124{ 124{
125 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 125 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
126 struct wm831x_pdata *wm831x_pdata; 126 struct wm831x_pdata *wm831x_pdata = dev_get_platdata(pdev->dev.parent);
127 struct wm831x_backlight_pdata *pdata; 127 struct wm831x_backlight_pdata *pdata;
128 struct wm831x_backlight_data *data; 128 struct wm831x_backlight_data *data;
129 struct backlight_device *bl; 129 struct backlight_device *bl;
@@ -131,12 +131,10 @@ static int wm831x_backlight_probe(struct platform_device *pdev)
131 int ret, i, max_isel, isink_reg, dcdc_cfg; 131 int ret, i, max_isel, isink_reg, dcdc_cfg;
132 132
133 /* We need platform data */ 133 /* We need platform data */
134 if (pdev->dev.parent->platform_data) { 134 if (wm831x_pdata)
135 wm831x_pdata = pdev->dev.parent->platform_data;
136 pdata = wm831x_pdata->backlight; 135 pdata = wm831x_pdata->backlight;
137 } else { 136 else
138 pdata = NULL; 137 pdata = NULL;
139 }
140 138
141 if (!pdata) { 139 if (!pdata) {
142 dev_err(&pdev->dev, "No platform data supplied\n"); 140 dev_err(&pdev->dev, "No platform data supplied\n");
@@ -197,8 +195,8 @@ static int wm831x_backlight_probe(struct platform_device *pdev)
197 memset(&props, 0, sizeof(props)); 195 memset(&props, 0, sizeof(props));
198 props.type = BACKLIGHT_RAW; 196 props.type = BACKLIGHT_RAW;
199 props.max_brightness = max_isel; 197 props.max_brightness = max_isel;
200 bl = backlight_device_register("wm831x", &pdev->dev, data, 198 bl = devm_backlight_device_register(&pdev->dev, "wm831x", &pdev->dev,
201 &wm831x_backlight_ops, &props); 199 data, &wm831x_backlight_ops, &props);
202 if (IS_ERR(bl)) { 200 if (IS_ERR(bl)) {
203 dev_err(&pdev->dev, "failed to register backlight\n"); 201 dev_err(&pdev->dev, "failed to register backlight\n");
204 return PTR_ERR(bl); 202 return PTR_ERR(bl);
@@ -216,21 +214,12 @@ static int wm831x_backlight_probe(struct platform_device *pdev)
216 return 0; 214 return 0;
217} 215}
218 216
219static int wm831x_backlight_remove(struct platform_device *pdev)
220{
221 struct backlight_device *bl = platform_get_drvdata(pdev);
222
223 backlight_device_unregister(bl);
224 return 0;
225}
226
227static struct platform_driver wm831x_backlight_driver = { 217static struct platform_driver wm831x_backlight_driver = {
228 .driver = { 218 .driver = {
229 .name = "wm831x-backlight", 219 .name = "wm831x-backlight",
230 .owner = THIS_MODULE, 220 .owner = THIS_MODULE,
231 }, 221 },
232 .probe = wm831x_backlight_probe, 222 .probe = wm831x_backlight_probe,
233 .remove = wm831x_backlight_remove,
234}; 223};
235 224
236module_platform_driver(wm831x_backlight_driver); 225module_platform_driver(wm831x_backlight_driver);
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index 41613f92a723..02df3b1381d2 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -255,17 +255,17 @@ static int ds1wm_find_divisor(int gclk)
255static void ds1wm_up(struct ds1wm_data *ds1wm_data) 255static void ds1wm_up(struct ds1wm_data *ds1wm_data)
256{ 256{
257 int divisor; 257 int divisor;
258 struct ds1wm_driver_data *plat = ds1wm_data->pdev->dev.platform_data; 258 struct device *dev = &ds1wm_data->pdev->dev;
259 struct ds1wm_driver_data *plat = dev_get_platdata(dev);
259 260
260 if (ds1wm_data->cell->enable) 261 if (ds1wm_data->cell->enable)
261 ds1wm_data->cell->enable(ds1wm_data->pdev); 262 ds1wm_data->cell->enable(ds1wm_data->pdev);
262 263
263 divisor = ds1wm_find_divisor(plat->clock_rate); 264 divisor = ds1wm_find_divisor(plat->clock_rate);
264 dev_dbg(&ds1wm_data->pdev->dev, 265 dev_dbg(dev, "found divisor 0x%x for clock %d\n",
265 "found divisor 0x%x for clock %d\n", divisor, plat->clock_rate); 266 divisor, plat->clock_rate);
266 if (divisor == 0) { 267 if (divisor == 0) {
267 dev_err(&ds1wm_data->pdev->dev, 268 dev_err(dev, "no suitable divisor for %dHz clock\n",
268 "no suitable divisor for %dHz clock\n",
269 plat->clock_rate); 269 plat->clock_rate);
270 return; 270 return;
271 } 271 }
@@ -481,7 +481,7 @@ static int ds1wm_probe(struct platform_device *pdev)
481 ds1wm_data->cell = mfd_get_cell(pdev); 481 ds1wm_data->cell = mfd_get_cell(pdev);
482 if (!ds1wm_data->cell) 482 if (!ds1wm_data->cell)
483 return -ENODEV; 483 return -ENODEV;
484 plat = pdev->dev.platform_data; 484 plat = dev_get_platdata(&pdev->dev);
485 if (!plat) 485 if (!plat)
486 return -ENODEV; 486 return -ENODEV;
487 487
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index fa932c2f7d97..66efa96c4603 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -709,7 +709,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
709 709
710 sl->owner = THIS_MODULE; 710 sl->owner = THIS_MODULE;
711 sl->master = dev; 711 sl->master = dev;
712 set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); 712 set_bit(W1_SLAVE_ACTIVE, &sl->flags);
713 713
714 memset(&msg, 0, sizeof(msg)); 714 memset(&msg, 0, sizeof(msg));
715 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num)); 715 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num));
@@ -866,7 +866,7 @@ void w1_slave_found(struct w1_master *dev, u64 rn)
866 866
867 sl = w1_slave_search_device(dev, tmp); 867 sl = w1_slave_search_device(dev, tmp);
868 if (sl) { 868 if (sl) {
869 set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); 869 set_bit(W1_SLAVE_ACTIVE, &sl->flags);
870 } else { 870 } else {
871 if (rn && tmp->crc == w1_calc_crc8((u8 *)&rn_le, 7)) 871 if (rn && tmp->crc == w1_calc_crc8((u8 *)&rn_le, 7))
872 w1_attach_slave_device(dev, tmp); 872 w1_attach_slave_device(dev, tmp);
@@ -984,14 +984,14 @@ void w1_search_process_cb(struct w1_master *dev, u8 search_type,
984 struct w1_slave *sl, *sln; 984 struct w1_slave *sl, *sln;
985 985
986 list_for_each_entry(sl, &dev->slist, w1_slave_entry) 986 list_for_each_entry(sl, &dev->slist, w1_slave_entry)
987 clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); 987 clear_bit(W1_SLAVE_ACTIVE, &sl->flags);
988 988
989 w1_search_devices(dev, search_type, cb); 989 w1_search_devices(dev, search_type, cb);
990 990
991 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 991 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
992 if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) 992 if (!test_bit(W1_SLAVE_ACTIVE, &sl->flags) && !--sl->ttl)
993 w1_slave_detach(sl); 993 w1_slave_detach(sl);
994 else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) 994 else if (test_bit(W1_SLAVE_ACTIVE, &sl->flags))
995 sl->ttl = dev->slave_ttl; 995 sl->ttl = dev->slave_ttl;
996 } 996 }
997 997
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 45908e56c2f8..ca8081a101d6 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -67,8 +67,8 @@ struct w1_slave
67 struct w1_reg_num reg_num; 67 struct w1_reg_num reg_num;
68 atomic_t refcnt; 68 atomic_t refcnt;
69 u8 rom[9]; 69 u8 rom[9];
70 u32 flags;
71 int ttl; 70 int ttl;
71 unsigned long flags;
72 72
73 struct w1_master *master; 73 struct w1_master *master;
74 struct w1_family *family; 74 struct w1_family *family;
diff --git a/fs/cramfs/Kconfig b/fs/cramfs/Kconfig
index cd06466f365e..11b29d491b7c 100644
--- a/fs/cramfs/Kconfig
+++ b/fs/cramfs/Kconfig
@@ -1,5 +1,5 @@
1config CRAMFS 1config CRAMFS
2 tristate "Compressed ROM file system support (cramfs)" 2 tristate "Compressed ROM file system support (cramfs) (OBSOLETE)"
3 depends on BLOCK 3 depends on BLOCK
4 select ZLIB_INFLATE 4 select ZLIB_INFLATE
5 help 5 help
@@ -16,4 +16,7 @@ config CRAMFS
16 cramfs. Note that the root file system (the one containing the 16 cramfs. Note that the root file system (the one containing the
17 directory /) cannot be compiled as a module. 17 directory /) cannot be compiled as a module.
18 18
19 This filesystem is obsoleted by SquashFS, which is much better
20 in terms of performance and features.
21
19 If unsure, say N. 22 If unsure, say N.
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index c7c83ff0f752..9c0444cccbe1 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -566,8 +566,7 @@ void debugfs_remove_recursive(struct dentry *dentry)
566 mutex_lock(&parent->d_inode->i_mutex); 566 mutex_lock(&parent->d_inode->i_mutex);
567 567
568 if (child != dentry) { 568 if (child != dentry) {
569 next = list_entry(child->d_u.d_child.next, struct dentry, 569 next = list_next_entry(child, d_u.d_child);
570 d_u.d_child);
571 goto up; 570 goto up;
572 } 571 }
573 572
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 073d30b9d1ac..a726b9f29cb7 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -498,6 +498,7 @@ static void devpts_kill_sb(struct super_block *sb)
498{ 498{
499 struct pts_fs_info *fsi = DEVPTS_SB(sb); 499 struct pts_fs_info *fsi = DEVPTS_SB(sb);
500 500
501 ida_destroy(&fsi->allocated_ptys);
501 kfree(fsi); 502 kfree(fsi);
502 kill_litter_super(sb); 503 kill_litter_super(sb);
503} 504}
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 983e3960abff..79b65c3b9e87 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -41,6 +41,7 @@
41#include <linux/proc_fs.h> 41#include <linux/proc_fs.h>
42#include <linux/seq_file.h> 42#include <linux/seq_file.h>
43#include <linux/compat.h> 43#include <linux/compat.h>
44#include <linux/rculist.h>
44 45
45/* 46/*
46 * LOCKING: 47 * LOCKING:
@@ -133,8 +134,12 @@ struct nested_calls {
133 * of these on a server and we do not want this to take another cache line. 134 * of these on a server and we do not want this to take another cache line.
134 */ 135 */
135struct epitem { 136struct epitem {
136 /* RB tree node used to link this structure to the eventpoll RB tree */ 137 union {
137 struct rb_node rbn; 138 /* RB tree node links this structure to the eventpoll RB tree */
139 struct rb_node rbn;
140 /* Used to free the struct epitem */
141 struct rcu_head rcu;
142 };
138 143
139 /* List header used to link this structure to the eventpoll ready list */ 144 /* List header used to link this structure to the eventpoll ready list */
140 struct list_head rdllink; 145 struct list_head rdllink;
@@ -580,14 +585,14 @@ static inline void ep_pm_stay_awake_rcu(struct epitem *epi)
580 * @sproc: Pointer to the scan callback. 585 * @sproc: Pointer to the scan callback.
581 * @priv: Private opaque data passed to the @sproc callback. 586 * @priv: Private opaque data passed to the @sproc callback.
582 * @depth: The current depth of recursive f_op->poll calls. 587 * @depth: The current depth of recursive f_op->poll calls.
588 * @ep_locked: caller already holds ep->mtx
583 * 589 *
584 * Returns: The same integer error code returned by the @sproc callback. 590 * Returns: The same integer error code returned by the @sproc callback.
585 */ 591 */
586static int ep_scan_ready_list(struct eventpoll *ep, 592static int ep_scan_ready_list(struct eventpoll *ep,
587 int (*sproc)(struct eventpoll *, 593 int (*sproc)(struct eventpoll *,
588 struct list_head *, void *), 594 struct list_head *, void *),
589 void *priv, 595 void *priv, int depth, bool ep_locked)
590 int depth)
591{ 596{
592 int error, pwake = 0; 597 int error, pwake = 0;
593 unsigned long flags; 598 unsigned long flags;
@@ -598,7 +603,9 @@ static int ep_scan_ready_list(struct eventpoll *ep,
598 * We need to lock this because we could be hit by 603 * We need to lock this because we could be hit by
599 * eventpoll_release_file() and epoll_ctl(). 604 * eventpoll_release_file() and epoll_ctl().
600 */ 605 */
601 mutex_lock_nested(&ep->mtx, depth); 606
607 if (!ep_locked)
608 mutex_lock_nested(&ep->mtx, depth);
602 609
603 /* 610 /*
604 * Steal the ready list, and re-init the original one to the 611 * Steal the ready list, and re-init the original one to the
@@ -662,7 +669,8 @@ static int ep_scan_ready_list(struct eventpoll *ep,
662 } 669 }
663 spin_unlock_irqrestore(&ep->lock, flags); 670 spin_unlock_irqrestore(&ep->lock, flags);
664 671
665 mutex_unlock(&ep->mtx); 672 if (!ep_locked)
673 mutex_unlock(&ep->mtx);
666 674
667 /* We have to call this outside the lock */ 675 /* We have to call this outside the lock */
668 if (pwake) 676 if (pwake)
@@ -671,6 +679,12 @@ static int ep_scan_ready_list(struct eventpoll *ep,
671 return error; 679 return error;
672} 680}
673 681
682static void epi_rcu_free(struct rcu_head *head)
683{
684 struct epitem *epi = container_of(head, struct epitem, rcu);
685 kmem_cache_free(epi_cache, epi);
686}
687
674/* 688/*
675 * Removes a "struct epitem" from the eventpoll RB tree and deallocates 689 * Removes a "struct epitem" from the eventpoll RB tree and deallocates
676 * all the associated resources. Must be called with "mtx" held. 690 * all the associated resources. Must be called with "mtx" held.
@@ -692,8 +706,7 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
692 706
693 /* Remove the current item from the list of epoll hooks */ 707 /* Remove the current item from the list of epoll hooks */
694 spin_lock(&file->f_lock); 708 spin_lock(&file->f_lock);
695 if (ep_is_linked(&epi->fllink)) 709 list_del_rcu(&epi->fllink);
696 list_del_init(&epi->fllink);
697 spin_unlock(&file->f_lock); 710 spin_unlock(&file->f_lock);
698 711
699 rb_erase(&epi->rbn, &ep->rbr); 712 rb_erase(&epi->rbn, &ep->rbr);
@@ -704,9 +717,14 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
704 spin_unlock_irqrestore(&ep->lock, flags); 717 spin_unlock_irqrestore(&ep->lock, flags);
705 718
706 wakeup_source_unregister(ep_wakeup_source(epi)); 719 wakeup_source_unregister(ep_wakeup_source(epi));
707 720 /*
708 /* At this point it is safe to free the eventpoll item */ 721 * At this point it is safe to free the eventpoll item. Use the union
709 kmem_cache_free(epi_cache, epi); 722 * field epi->rcu, since we are trying to minimize the size of
723 * 'struct epitem'. The 'rbn' field is no longer in use. Protected by
724 * ep->mtx. The rcu read side, reverse_path_check_proc(), does not make
725 * use of the rbn field.
726 */
727 call_rcu(&epi->rcu, epi_rcu_free);
710 728
711 atomic_long_dec(&ep->user->epoll_watches); 729 atomic_long_dec(&ep->user->epoll_watches);
712 730
@@ -807,15 +825,34 @@ static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
807 return 0; 825 return 0;
808} 826}
809 827
828static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead,
829 poll_table *pt);
830
831struct readyevents_arg {
832 struct eventpoll *ep;
833 bool locked;
834};
835
810static int ep_poll_readyevents_proc(void *priv, void *cookie, int call_nests) 836static int ep_poll_readyevents_proc(void *priv, void *cookie, int call_nests)
811{ 837{
812 return ep_scan_ready_list(priv, ep_read_events_proc, NULL, call_nests + 1); 838 struct readyevents_arg *arg = priv;
839
840 return ep_scan_ready_list(arg->ep, ep_read_events_proc, NULL,
841 call_nests + 1, arg->locked);
813} 842}
814 843
815static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait) 844static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
816{ 845{
817 int pollflags; 846 int pollflags;
818 struct eventpoll *ep = file->private_data; 847 struct eventpoll *ep = file->private_data;
848 struct readyevents_arg arg;
849
850 /*
851 * During ep_insert() we already hold the ep->mtx for the tfile.
852 * Prevent re-aquisition.
853 */
854 arg.locked = wait && (wait->_qproc == ep_ptable_queue_proc);
855 arg.ep = ep;
819 856
820 /* Insert inside our poll wait queue */ 857 /* Insert inside our poll wait queue */
821 poll_wait(file, &ep->poll_wait, wait); 858 poll_wait(file, &ep->poll_wait, wait);
@@ -827,7 +864,7 @@ static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
827 * could re-enter here. 864 * could re-enter here.
828 */ 865 */
829 pollflags = ep_call_nested(&poll_readywalk_ncalls, EP_MAX_NESTS, 866 pollflags = ep_call_nested(&poll_readywalk_ncalls, EP_MAX_NESTS,
830 ep_poll_readyevents_proc, ep, ep, current); 867 ep_poll_readyevents_proc, &arg, ep, current);
831 868
832 return pollflags != -1 ? pollflags : 0; 869 return pollflags != -1 ? pollflags : 0;
833} 870}
@@ -872,7 +909,6 @@ static const struct file_operations eventpoll_fops = {
872 */ 909 */
873void eventpoll_release_file(struct file *file) 910void eventpoll_release_file(struct file *file)
874{ 911{
875 struct list_head *lsthead = &file->f_ep_links;
876 struct eventpoll *ep; 912 struct eventpoll *ep;
877 struct epitem *epi; 913 struct epitem *epi;
878 914
@@ -890,17 +926,12 @@ void eventpoll_release_file(struct file *file)
890 * Besides, ep_remove() acquires the lock, so we can't hold it here. 926 * Besides, ep_remove() acquires the lock, so we can't hold it here.
891 */ 927 */
892 mutex_lock(&epmutex); 928 mutex_lock(&epmutex);
893 929 list_for_each_entry_rcu(epi, &file->f_ep_links, fllink) {
894 while (!list_empty(lsthead)) {
895 epi = list_first_entry(lsthead, struct epitem, fllink);
896
897 ep = epi->ep; 930 ep = epi->ep;
898 list_del_init(&epi->fllink);
899 mutex_lock_nested(&ep->mtx, 0); 931 mutex_lock_nested(&ep->mtx, 0);
900 ep_remove(ep, epi); 932 ep_remove(ep, epi);
901 mutex_unlock(&ep->mtx); 933 mutex_unlock(&ep->mtx);
902 } 934 }
903
904 mutex_unlock(&epmutex); 935 mutex_unlock(&epmutex);
905} 936}
906 937
@@ -1138,7 +1169,9 @@ static int reverse_path_check_proc(void *priv, void *cookie, int call_nests)
1138 struct file *child_file; 1169 struct file *child_file;
1139 struct epitem *epi; 1170 struct epitem *epi;
1140 1171
1141 list_for_each_entry(epi, &file->f_ep_links, fllink) { 1172 /* CTL_DEL can remove links here, but that can't increase our count */
1173 rcu_read_lock();
1174 list_for_each_entry_rcu(epi, &file->f_ep_links, fllink) {
1142 child_file = epi->ep->file; 1175 child_file = epi->ep->file;
1143 if (is_file_epoll(child_file)) { 1176 if (is_file_epoll(child_file)) {
1144 if (list_empty(&child_file->f_ep_links)) { 1177 if (list_empty(&child_file->f_ep_links)) {
@@ -1160,6 +1193,7 @@ static int reverse_path_check_proc(void *priv, void *cookie, int call_nests)
1160 "file is not an ep!\n"); 1193 "file is not an ep!\n");
1161 } 1194 }
1162 } 1195 }
1196 rcu_read_unlock();
1163 return error; 1197 return error;
1164} 1198}
1165 1199
@@ -1231,7 +1265,7 @@ static noinline void ep_destroy_wakeup_source(struct epitem *epi)
1231 * Must be called with "mtx" held. 1265 * Must be called with "mtx" held.
1232 */ 1266 */
1233static int ep_insert(struct eventpoll *ep, struct epoll_event *event, 1267static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
1234 struct file *tfile, int fd) 1268 struct file *tfile, int fd, int full_check)
1235{ 1269{
1236 int error, revents, pwake = 0; 1270 int error, revents, pwake = 0;
1237 unsigned long flags; 1271 unsigned long flags;
@@ -1286,7 +1320,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
1286 1320
1287 /* Add the current item to the list of active epoll hook for this file */ 1321 /* Add the current item to the list of active epoll hook for this file */
1288 spin_lock(&tfile->f_lock); 1322 spin_lock(&tfile->f_lock);
1289 list_add_tail(&epi->fllink, &tfile->f_ep_links); 1323 list_add_tail_rcu(&epi->fllink, &tfile->f_ep_links);
1290 spin_unlock(&tfile->f_lock); 1324 spin_unlock(&tfile->f_lock);
1291 1325
1292 /* 1326 /*
@@ -1297,7 +1331,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
1297 1331
1298 /* now check if we've created too many backpaths */ 1332 /* now check if we've created too many backpaths */
1299 error = -EINVAL; 1333 error = -EINVAL;
1300 if (reverse_path_check()) 1334 if (full_check && reverse_path_check())
1301 goto error_remove_epi; 1335 goto error_remove_epi;
1302 1336
1303 /* We have to drop the new item inside our item list to keep track of it */ 1337 /* We have to drop the new item inside our item list to keep track of it */
@@ -1327,8 +1361,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
1327 1361
1328error_remove_epi: 1362error_remove_epi:
1329 spin_lock(&tfile->f_lock); 1363 spin_lock(&tfile->f_lock);
1330 if (ep_is_linked(&epi->fllink)) 1364 list_del_rcu(&epi->fllink);
1331 list_del_init(&epi->fllink);
1332 spin_unlock(&tfile->f_lock); 1365 spin_unlock(&tfile->f_lock);
1333 1366
1334 rb_erase(&epi->rbn, &ep->rbr); 1367 rb_erase(&epi->rbn, &ep->rbr);
@@ -1521,7 +1554,7 @@ static int ep_send_events(struct eventpoll *ep,
1521 esed.maxevents = maxevents; 1554 esed.maxevents = maxevents;
1522 esed.events = events; 1555 esed.events = events;
1523 1556
1524 return ep_scan_ready_list(ep, ep_send_events_proc, &esed, 0); 1557 return ep_scan_ready_list(ep, ep_send_events_proc, &esed, 0, false);
1525} 1558}
1526 1559
1527static inline struct timespec ep_set_mstimeout(long ms) 1560static inline struct timespec ep_set_mstimeout(long ms)
@@ -1791,11 +1824,12 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1791 struct epoll_event __user *, event) 1824 struct epoll_event __user *, event)
1792{ 1825{
1793 int error; 1826 int error;
1794 int did_lock_epmutex = 0; 1827 int full_check = 0;
1795 struct fd f, tf; 1828 struct fd f, tf;
1796 struct eventpoll *ep; 1829 struct eventpoll *ep;
1797 struct epitem *epi; 1830 struct epitem *epi;
1798 struct epoll_event epds; 1831 struct epoll_event epds;
1832 struct eventpoll *tep = NULL;
1799 1833
1800 error = -EFAULT; 1834 error = -EFAULT;
1801 if (ep_op_has_event(op) && 1835 if (ep_op_has_event(op) &&
@@ -1844,26 +1878,40 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1844 * and hang them on the tfile_check_list, so we can check that we 1878 * and hang them on the tfile_check_list, so we can check that we
1845 * haven't created too many possible wakeup paths. 1879 * haven't created too many possible wakeup paths.
1846 * 1880 *
1847 * We need to hold the epmutex across both ep_insert and ep_remove 1881 * We do not need to take the global 'epumutex' on EPOLL_CTL_ADD when
1848 * b/c we want to make sure we are looking at a coherent view of 1882 * the epoll file descriptor is attaching directly to a wakeup source,
1849 * epoll network. 1883 * unless the epoll file descriptor is nested. The purpose of taking the
1884 * 'epmutex' on add is to prevent complex toplogies such as loops and
1885 * deep wakeup paths from forming in parallel through multiple
1886 * EPOLL_CTL_ADD operations.
1850 */ 1887 */
1851 if (op == EPOLL_CTL_ADD || op == EPOLL_CTL_DEL) { 1888 mutex_lock_nested(&ep->mtx, 0);
1852 mutex_lock(&epmutex);
1853 did_lock_epmutex = 1;
1854 }
1855 if (op == EPOLL_CTL_ADD) { 1889 if (op == EPOLL_CTL_ADD) {
1856 if (is_file_epoll(tf.file)) { 1890 if (!list_empty(&f.file->f_ep_links) ||
1857 error = -ELOOP; 1891 is_file_epoll(tf.file)) {
1858 if (ep_loop_check(ep, tf.file) != 0) { 1892 full_check = 1;
1859 clear_tfile_check_list(); 1893 mutex_unlock(&ep->mtx);
1860 goto error_tgt_fput; 1894 mutex_lock(&epmutex);
1895 if (is_file_epoll(tf.file)) {
1896 error = -ELOOP;
1897 if (ep_loop_check(ep, tf.file) != 0) {
1898 clear_tfile_check_list();
1899 goto error_tgt_fput;
1900 }
1901 } else
1902 list_add(&tf.file->f_tfile_llink,
1903 &tfile_check_list);
1904 mutex_lock_nested(&ep->mtx, 0);
1905 if (is_file_epoll(tf.file)) {
1906 tep = tf.file->private_data;
1907 mutex_lock_nested(&tep->mtx, 1);
1861 } 1908 }
1862 } else 1909 }
1863 list_add(&tf.file->f_tfile_llink, &tfile_check_list); 1910 }
1911 if (op == EPOLL_CTL_DEL && is_file_epoll(tf.file)) {
1912 tep = tf.file->private_data;
1913 mutex_lock_nested(&tep->mtx, 1);
1864 } 1914 }
1865
1866 mutex_lock_nested(&ep->mtx, 0);
1867 1915
1868 /* 1916 /*
1869 * Try to lookup the file inside our RB tree, Since we grabbed "mtx" 1917 * Try to lookup the file inside our RB tree, Since we grabbed "mtx"
@@ -1877,10 +1925,11 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1877 case EPOLL_CTL_ADD: 1925 case EPOLL_CTL_ADD:
1878 if (!epi) { 1926 if (!epi) {
1879 epds.events |= POLLERR | POLLHUP; 1927 epds.events |= POLLERR | POLLHUP;
1880 error = ep_insert(ep, &epds, tf.file, fd); 1928 error = ep_insert(ep, &epds, tf.file, fd, full_check);
1881 } else 1929 } else
1882 error = -EEXIST; 1930 error = -EEXIST;
1883 clear_tfile_check_list(); 1931 if (full_check)
1932 clear_tfile_check_list();
1884 break; 1933 break;
1885 case EPOLL_CTL_DEL: 1934 case EPOLL_CTL_DEL:
1886 if (epi) 1935 if (epi)
@@ -1896,10 +1945,12 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1896 error = -ENOENT; 1945 error = -ENOENT;
1897 break; 1946 break;
1898 } 1947 }
1948 if (tep != NULL)
1949 mutex_unlock(&tep->mtx);
1899 mutex_unlock(&ep->mtx); 1950 mutex_unlock(&ep->mtx);
1900 1951
1901error_tgt_fput: 1952error_tgt_fput:
1902 if (did_lock_epmutex) 1953 if (full_check)
1903 mutex_unlock(&epmutex); 1954 mutex_unlock(&epmutex);
1904 1955
1905 fdput(tf); 1956 fdput(tf);
diff --git a/fs/exec.c b/fs/exec.c
index be4c81c7251c..977319fd77f3 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1664,6 +1664,12 @@ int __get_dumpable(unsigned long mm_flags)
1664 return (ret > SUID_DUMP_USER) ? SUID_DUMP_ROOT : ret; 1664 return (ret > SUID_DUMP_USER) ? SUID_DUMP_ROOT : ret;
1665} 1665}
1666 1666
1667/*
1668 * This returns the actual value of the suid_dumpable flag. For things
1669 * that are using this for checking for privilege transitions, it must
1670 * test against SUID_DUMP_USER rather than treating it as a boolean
1671 * value.
1672 */
1667int get_dumpable(struct mm_struct *mm) 1673int get_dumpable(struct mm_struct *mm)
1668{ 1674{
1669 return __get_dumpable(mm->flags); 1675 return __get_dumpable(mm->flags);
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 09c11329a17c..1f4a10ece2f1 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -40,13 +40,18 @@
40struct wb_writeback_work { 40struct wb_writeback_work {
41 long nr_pages; 41 long nr_pages;
42 struct super_block *sb; 42 struct super_block *sb;
43 unsigned long *older_than_this; 43 /*
44 * Write only inodes dirtied before this time. Don't forget to set
45 * older_than_this_is_set when you set this.
46 */
47 unsigned long older_than_this;
44 enum writeback_sync_modes sync_mode; 48 enum writeback_sync_modes sync_mode;
45 unsigned int tagged_writepages:1; 49 unsigned int tagged_writepages:1;
46 unsigned int for_kupdate:1; 50 unsigned int for_kupdate:1;
47 unsigned int range_cyclic:1; 51 unsigned int range_cyclic:1;
48 unsigned int for_background:1; 52 unsigned int for_background:1;
49 unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ 53 unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
54 unsigned int older_than_this_is_set:1;
50 enum wb_reason reason; /* why was writeback initiated? */ 55 enum wb_reason reason; /* why was writeback initiated? */
51 56
52 struct list_head list; /* pending work list */ 57 struct list_head list; /* pending work list */
@@ -247,10 +252,10 @@ static int move_expired_inodes(struct list_head *delaying_queue,
247 int do_sb_sort = 0; 252 int do_sb_sort = 0;
248 int moved = 0; 253 int moved = 0;
249 254
255 WARN_ON_ONCE(!work->older_than_this_is_set);
250 while (!list_empty(delaying_queue)) { 256 while (!list_empty(delaying_queue)) {
251 inode = wb_inode(delaying_queue->prev); 257 inode = wb_inode(delaying_queue->prev);
252 if (work->older_than_this && 258 if (inode_dirtied_after(inode, work->older_than_this))
253 inode_dirtied_after(inode, *work->older_than_this))
254 break; 259 break;
255 list_move(&inode->i_wb_list, &tmp); 260 list_move(&inode->i_wb_list, &tmp);
256 moved++; 261 moved++;
@@ -734,6 +739,8 @@ static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
734 .sync_mode = WB_SYNC_NONE, 739 .sync_mode = WB_SYNC_NONE,
735 .range_cyclic = 1, 740 .range_cyclic = 1,
736 .reason = reason, 741 .reason = reason,
742 .older_than_this = jiffies,
743 .older_than_this_is_set = 1,
737 }; 744 };
738 745
739 spin_lock(&wb->list_lock); 746 spin_lock(&wb->list_lock);
@@ -792,12 +799,13 @@ static long wb_writeback(struct bdi_writeback *wb,
792{ 799{
793 unsigned long wb_start = jiffies; 800 unsigned long wb_start = jiffies;
794 long nr_pages = work->nr_pages; 801 long nr_pages = work->nr_pages;
795 unsigned long oldest_jif;
796 struct inode *inode; 802 struct inode *inode;
797 long progress; 803 long progress;
798 804
799 oldest_jif = jiffies; 805 if (!work->older_than_this_is_set) {
800 work->older_than_this = &oldest_jif; 806 work->older_than_this = jiffies;
807 work->older_than_this_is_set = 1;
808 }
801 809
802 spin_lock(&wb->list_lock); 810 spin_lock(&wb->list_lock);
803 for (;;) { 811 for (;;) {
@@ -831,10 +839,10 @@ static long wb_writeback(struct bdi_writeback *wb,
831 * safe. 839 * safe.
832 */ 840 */
833 if (work->for_kupdate) { 841 if (work->for_kupdate) {
834 oldest_jif = jiffies - 842 work->older_than_this = jiffies -
835 msecs_to_jiffies(dirty_expire_interval * 10); 843 msecs_to_jiffies(dirty_expire_interval * 10);
836 } else if (work->for_background) 844 } else if (work->for_background)
837 oldest_jif = jiffies; 845 work->older_than_this = jiffies;
838 846
839 trace_writeback_start(wb->bdi, work); 847 trace_writeback_start(wb->bdi, work);
840 if (list_empty(&wb->b_io)) 848 if (list_empty(&wb->b_io))
@@ -1346,18 +1354,21 @@ EXPORT_SYMBOL(try_to_writeback_inodes_sb);
1346 1354
1347/** 1355/**
1348 * sync_inodes_sb - sync sb inode pages 1356 * sync_inodes_sb - sync sb inode pages
1349 * @sb: the superblock 1357 * @sb: the superblock
1358 * @older_than_this: timestamp
1350 * 1359 *
1351 * This function writes and waits on any dirty inode belonging to this 1360 * This function writes and waits on any dirty inode belonging to this
1352 * super_block. 1361 * superblock that has been dirtied before given timestamp.
1353 */ 1362 */
1354void sync_inodes_sb(struct super_block *sb) 1363void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this)
1355{ 1364{
1356 DECLARE_COMPLETION_ONSTACK(done); 1365 DECLARE_COMPLETION_ONSTACK(done);
1357 struct wb_writeback_work work = { 1366 struct wb_writeback_work work = {
1358 .sb = sb, 1367 .sb = sb,
1359 .sync_mode = WB_SYNC_ALL, 1368 .sync_mode = WB_SYNC_ALL,
1360 .nr_pages = LONG_MAX, 1369 .nr_pages = LONG_MAX,
1370 .older_than_this = older_than_this,
1371 .older_than_this_is_set = 1,
1361 .range_cyclic = 0, 1372 .range_cyclic = 0,
1362 .done = &done, 1373 .done = &done,
1363 .reason = WB_REASON_SYNC, 1374 .reason = WB_REASON_SYNC,
diff --git a/fs/hfs/btree.h b/fs/hfs/btree.h
index 2a1d712f85dc..f6bd266d70b5 100644
--- a/fs/hfs/btree.h
+++ b/fs/hfs/btree.h
@@ -153,11 +153,6 @@ struct hfs_btree_header_rec {
153 u32 reserved3[16]; 153 u32 reserved3[16];
154} __packed; 154} __packed;
155 155
156#define HFS_NODE_INDEX 0x00 /* An internal (index) node */
157#define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
158#define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
159#define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
160
161#define BTREE_ATTR_BADCLOSE 0x00000001 /* b-tree not closed properly. not 156#define BTREE_ATTR_BADCLOSE 0x00000001 /* b-tree not closed properly. not
162 used by hfsplus. */ 157 used by hfsplus. */
163#define HFS_TREE_BIGKEYS 0x00000002 /* key length is u16 instead of u8. 158#define HFS_TREE_BIGKEYS 0x00000002 /* key length is u16 instead of u8.
diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
index 0c6540c91167..0fcec8b2a90b 100644
--- a/fs/hfsplus/btree.c
+++ b/fs/hfsplus/btree.c
@@ -15,6 +15,118 @@
15#include "hfsplus_fs.h" 15#include "hfsplus_fs.h"
16#include "hfsplus_raw.h" 16#include "hfsplus_raw.h"
17 17
18/*
19 * Initial source code of clump size calculation is gotten
20 * from http://opensource.apple.com/tarballs/diskdev_cmds/
21 */
22#define CLUMP_ENTRIES 15
23
24static short clumptbl[CLUMP_ENTRIES * 3] = {
25/*
26 * Volume Attributes Catalog Extents
27 * Size Clump (MB) Clump (MB) Clump (MB)
28 */
29 /* 1GB */ 4, 4, 4,
30 /* 2GB */ 6, 6, 4,
31 /* 4GB */ 8, 8, 4,
32 /* 8GB */ 11, 11, 5,
33 /*
34 * For volumes 16GB and larger, we want to make sure that a full OS
35 * install won't require fragmentation of the Catalog or Attributes
36 * B-trees. We do this by making the clump sizes sufficiently large,
37 * and by leaving a gap after the B-trees for them to grow into.
38 *
39 * For SnowLeopard 10A298, a FullNetInstall with all packages selected
40 * results in:
41 * Catalog B-tree Header
42 * nodeSize: 8192
43 * totalNodes: 31616
44 * freeNodes: 1978
45 * (used = 231.55 MB)
46 * Attributes B-tree Header
47 * nodeSize: 8192
48 * totalNodes: 63232
49 * freeNodes: 958
50 * (used = 486.52 MB)
51 *
52 * We also want Time Machine backup volumes to have a sufficiently
53 * large clump size to reduce fragmentation.
54 *
55 * The series of numbers for Catalog and Attribute form a geometric
56 * series. For Catalog (16GB to 512GB), each term is 8**(1/5) times
57 * the previous term. For Attributes (16GB to 512GB), each term is
58 * 4**(1/5) times the previous term. For 1TB to 16TB, each term is
59 * 2**(1/5) times the previous term.
60 */
61 /* 16GB */ 64, 32, 5,
62 /* 32GB */ 84, 49, 6,
63 /* 64GB */ 111, 74, 7,
64 /* 128GB */ 147, 111, 8,
65 /* 256GB */ 194, 169, 9,
66 /* 512GB */ 256, 256, 11,
67 /* 1TB */ 294, 294, 14,
68 /* 2TB */ 338, 338, 16,
69 /* 4TB */ 388, 388, 20,
70 /* 8TB */ 446, 446, 25,
71 /* 16TB */ 512, 512, 32
72};
73
74u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size,
75 u64 sectors, int file_id)
76{
77 u32 mod = max(node_size, block_size);
78 u32 clump_size;
79 int column;
80 int i;
81
82 /* Figure out which column of the above table to use for this file. */
83 switch (file_id) {
84 case HFSPLUS_ATTR_CNID:
85 column = 0;
86 break;
87 case HFSPLUS_CAT_CNID:
88 column = 1;
89 break;
90 default:
91 column = 2;
92 break;
93 }
94
95 /*
96 * The default clump size is 0.8% of the volume size. And
97 * it must also be a multiple of the node and block size.
98 */
99 if (sectors < 0x200000) {
100 clump_size = sectors << 2; /* 0.8 % */
101 if (clump_size < (8 * node_size))
102 clump_size = 8 * node_size;
103 } else {
104 /* turn exponent into table index... */
105 for (i = 0, sectors = sectors >> 22;
106 sectors && (i < CLUMP_ENTRIES - 1);
107 ++i, sectors = sectors >> 1) {
108 /* empty body */
109 }
110
111 clump_size = clumptbl[column + (i) * 3] * 1024 * 1024;
112 }
113
114 /*
115 * Round the clump size to a multiple of node and block size.
116 * NOTE: This rounds down.
117 */
118 clump_size /= mod;
119 clump_size *= mod;
120
121 /*
122 * Rounding down could have rounded down to 0 if the block size was
123 * greater than the clump size. If so, just use one block or node.
124 */
125 if (clump_size == 0)
126 clump_size = mod;
127
128 return clump_size;
129}
18 130
19/* Get a reference to a B*Tree and do some initial checks */ 131/* Get a reference to a B*Tree and do some initial checks */
20struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) 132struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 2b9cd01696e2..08846425b67f 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -127,6 +127,14 @@ struct hfs_bnode {
127#define HFS_BNODE_DELETED 4 127#define HFS_BNODE_DELETED 4
128 128
129/* 129/*
130 * Attributes file states
131 */
132#define HFSPLUS_EMPTY_ATTR_TREE 0
133#define HFSPLUS_CREATING_ATTR_TREE 1
134#define HFSPLUS_VALID_ATTR_TREE 2
135#define HFSPLUS_FAILED_ATTR_TREE 3
136
137/*
130 * HFS+ superblock info (built from Volume Header on disk) 138 * HFS+ superblock info (built from Volume Header on disk)
131 */ 139 */
132 140
@@ -141,6 +149,7 @@ struct hfsplus_sb_info {
141 struct hfs_btree *ext_tree; 149 struct hfs_btree *ext_tree;
142 struct hfs_btree *cat_tree; 150 struct hfs_btree *cat_tree;
143 struct hfs_btree *attr_tree; 151 struct hfs_btree *attr_tree;
152 atomic_t attr_tree_state;
144 struct inode *alloc_file; 153 struct inode *alloc_file;
145 struct inode *hidden_dir; 154 struct inode *hidden_dir;
146 struct nls_table *nls; 155 struct nls_table *nls;
@@ -380,6 +389,7 @@ int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
380int hfsplus_block_free(struct super_block *, u32, u32); 389int hfsplus_block_free(struct super_block *, u32, u32);
381 390
382/* btree.c */ 391/* btree.c */
392u32 hfsplus_calc_btree_clump_size(u32, u32, u64, int);
383struct hfs_btree *hfs_btree_open(struct super_block *, u32); 393struct hfs_btree *hfs_btree_open(struct super_block *, u32);
384void hfs_btree_close(struct hfs_btree *); 394void hfs_btree_close(struct hfs_btree *);
385int hfs_btree_write(struct hfs_btree *); 395int hfs_btree_write(struct hfs_btree *);
diff --git a/fs/hfsplus/hfsplus_raw.h b/fs/hfsplus/hfsplus_raw.h
index 452ede01b036..8ffb3a8ffe75 100644
--- a/fs/hfsplus/hfsplus_raw.h
+++ b/fs/hfsplus/hfsplus_raw.h
@@ -156,10 +156,10 @@ struct hfs_bnode_desc {
156} __packed; 156} __packed;
157 157
158/* HFS+ BTree node types */ 158/* HFS+ BTree node types */
159#define HFS_NODE_INDEX 0x00 159#define HFS_NODE_INDEX 0x00 /* An internal (index) node */
160#define HFS_NODE_HEADER 0x01 160#define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
161#define HFS_NODE_MAP 0x02 161#define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
162#define HFS_NODE_LEAF 0xFF 162#define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
163 163
164/* HFS+ BTree header */ 164/* HFS+ BTree header */
165struct hfs_btree_header_rec { 165struct hfs_btree_header_rec {
@@ -187,6 +187,9 @@ struct hfs_btree_header_rec {
187/* HFS+ BTree misc info */ 187/* HFS+ BTree misc info */
188#define HFSPLUS_TREE_HEAD 0 188#define HFSPLUS_TREE_HEAD 0
189#define HFSPLUS_NODE_MXSZ 32768 189#define HFSPLUS_NODE_MXSZ 32768
190#define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
191#define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
192#define HFSPLUS_BTREE_HDR_USER_BYTES 128
190 193
191/* Some special File ID numbers (stolen from hfs.h) */ 194/* Some special File ID numbers (stolen from hfs.h) */
192#define HFSPLUS_POR_CNID 1 /* Parent Of the Root */ 195#define HFSPLUS_POR_CNID 1 /* Parent Of the Root */
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 4c4d142cf890..80875aa640ef 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -474,12 +474,14 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
474 pr_err("failed to load catalog file\n"); 474 pr_err("failed to load catalog file\n");
475 goto out_close_ext_tree; 475 goto out_close_ext_tree;
476 } 476 }
477 atomic_set(&sbi->attr_tree_state, HFSPLUS_EMPTY_ATTR_TREE);
477 if (vhdr->attr_file.total_blocks != 0) { 478 if (vhdr->attr_file.total_blocks != 0) {
478 sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID); 479 sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
479 if (!sbi->attr_tree) { 480 if (!sbi->attr_tree) {
480 pr_err("failed to load attributes file\n"); 481 pr_err("failed to load attributes file\n");
481 goto out_close_cat_tree; 482 goto out_close_cat_tree;
482 } 483 }
484 atomic_set(&sbi->attr_tree_state, HFSPLUS_VALID_ATTR_TREE);
483 } 485 }
484 sb->s_xattr = hfsplus_xattr_handlers; 486 sb->s_xattr = hfsplus_xattr_handlers;
485 487
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index bd8471fb9a6a..efc85b1377cc 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -127,6 +127,208 @@ static int can_set_xattr(struct inode *inode, const char *name,
127 return 0; 127 return 0;
128} 128}
129 129
130static void hfsplus_init_header_node(struct inode *attr_file,
131 u32 clump_size,
132 char *buf, size_t node_size)
133{
134 struct hfs_bnode_desc *desc;
135 struct hfs_btree_header_rec *head;
136 u16 offset;
137 __be16 *rec_offsets;
138 u32 hdr_node_map_rec_bits;
139 char *bmp;
140 u32 used_nodes;
141 u32 used_bmp_bytes;
142
143 hfs_dbg(ATTR_MOD, "init_hdr_attr_file: clump %u, node_size %zu\n",
144 clump_size, node_size);
145
146 /* The end of the node contains list of record offsets */
147 rec_offsets = (__be16 *)(buf + node_size);
148
149 desc = (struct hfs_bnode_desc *)buf;
150 desc->type = HFS_NODE_HEADER;
151 desc->num_recs = cpu_to_be16(HFSPLUS_BTREE_HDR_NODE_RECS_COUNT);
152 offset = sizeof(struct hfs_bnode_desc);
153 *--rec_offsets = cpu_to_be16(offset);
154
155 head = (struct hfs_btree_header_rec *)(buf + offset);
156 head->node_size = cpu_to_be16(node_size);
157 head->node_count = cpu_to_be32(i_size_read(attr_file) / node_size);
158 head->free_nodes = cpu_to_be32(be32_to_cpu(head->node_count) - 1);
159 head->clump_size = cpu_to_be32(clump_size);
160 head->attributes |= cpu_to_be32(HFS_TREE_BIGKEYS | HFS_TREE_VARIDXKEYS);
161 head->max_key_len = cpu_to_be16(HFSPLUS_ATTR_KEYLEN - sizeof(u16));
162 offset += sizeof(struct hfs_btree_header_rec);
163 *--rec_offsets = cpu_to_be16(offset);
164 offset += HFSPLUS_BTREE_HDR_USER_BYTES;
165 *--rec_offsets = cpu_to_be16(offset);
166
167 hdr_node_map_rec_bits = 8 * (node_size - offset - (4 * sizeof(u16)));
168 if (be32_to_cpu(head->node_count) > hdr_node_map_rec_bits) {
169 u32 map_node_bits;
170 u32 map_nodes;
171
172 desc->next = cpu_to_be32(be32_to_cpu(head->leaf_tail) + 1);
173 map_node_bits = 8 * (node_size - sizeof(struct hfs_bnode_desc) -
174 (2 * sizeof(u16)) - 2);
175 map_nodes = (be32_to_cpu(head->node_count) -
176 hdr_node_map_rec_bits +
177 (map_node_bits - 1)) / map_node_bits;
178 be32_add_cpu(&head->free_nodes, 0 - map_nodes);
179 }
180
181 bmp = buf + offset;
182 used_nodes =
183 be32_to_cpu(head->node_count) - be32_to_cpu(head->free_nodes);
184 used_bmp_bytes = used_nodes / 8;
185 if (used_bmp_bytes) {
186 memset(bmp, 0xFF, used_bmp_bytes);
187 bmp += used_bmp_bytes;
188 used_nodes %= 8;
189 }
190 *bmp = ~(0xFF >> used_nodes);
191 offset += hdr_node_map_rec_bits / 8;
192 *--rec_offsets = cpu_to_be16(offset);
193}
194
195static int hfsplus_create_attributes_file(struct super_block *sb)
196{
197 int err = 0;
198 struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
199 struct inode *attr_file;
200 struct hfsplus_inode_info *hip;
201 u32 clump_size;
202 u16 node_size = HFSPLUS_ATTR_TREE_NODE_SIZE;
203 char *buf;
204 int index, written;
205 struct address_space *mapping;
206 struct page *page;
207 int old_state = HFSPLUS_EMPTY_ATTR_TREE;
208
209 hfs_dbg(ATTR_MOD, "create_attr_file: ino %d\n", HFSPLUS_ATTR_CNID);
210
211check_attr_tree_state_again:
212 switch (atomic_read(&sbi->attr_tree_state)) {
213 case HFSPLUS_EMPTY_ATTR_TREE:
214 if (old_state != atomic_cmpxchg(&sbi->attr_tree_state,
215 old_state,
216 HFSPLUS_CREATING_ATTR_TREE))
217 goto check_attr_tree_state_again;
218 break;
219 case HFSPLUS_CREATING_ATTR_TREE:
220 /*
221 * This state means that another thread is in process
222 * of AttributesFile creation. Theoretically, it is
223 * possible to be here. But really __setxattr() method
224 * first of all calls hfs_find_init() for lookup in
225 * B-tree of CatalogFile. This method locks mutex of
226 * CatalogFile's B-tree. As a result, if some thread
227 * is inside AttributedFile creation operation then
228 * another threads will be waiting unlocking of
229 * CatalogFile's B-tree's mutex. However, if code will
230 * change then we will return error code (-EAGAIN) from
231 * here. Really, it means that first try to set of xattr
232 * fails with error but second attempt will have success.
233 */
234 return -EAGAIN;
235 case HFSPLUS_VALID_ATTR_TREE:
236 return 0;
237 case HFSPLUS_FAILED_ATTR_TREE:
238 return -EOPNOTSUPP;
239 default:
240 BUG();
241 }
242
243 attr_file = hfsplus_iget(sb, HFSPLUS_ATTR_CNID);
244 if (IS_ERR(attr_file)) {
245 pr_err("failed to load attributes file\n");
246 return PTR_ERR(attr_file);
247 }
248
249 BUG_ON(i_size_read(attr_file) != 0);
250
251 hip = HFSPLUS_I(attr_file);
252
253 clump_size = hfsplus_calc_btree_clump_size(sb->s_blocksize,
254 node_size,
255 sbi->sect_count,
256 HFSPLUS_ATTR_CNID);
257
258 mutex_lock(&hip->extents_lock);
259 hip->clump_blocks = clump_size >> sbi->alloc_blksz_shift;
260 mutex_unlock(&hip->extents_lock);
261
262 if (sbi->free_blocks <= (hip->clump_blocks << 1)) {
263 err = -ENOSPC;
264 goto end_attr_file_creation;
265 }
266
267 while (hip->alloc_blocks < hip->clump_blocks) {
268 err = hfsplus_file_extend(attr_file);
269 if (unlikely(err)) {
270 pr_err("failed to extend attributes file\n");
271 goto end_attr_file_creation;
272 }
273 hip->phys_size = attr_file->i_size =
274 (loff_t)hip->alloc_blocks << sbi->alloc_blksz_shift;
275 hip->fs_blocks = hip->alloc_blocks << sbi->fs_shift;
276 inode_set_bytes(attr_file, attr_file->i_size);
277 }
278
279 buf = kzalloc(node_size, GFP_NOFS);
280 if (!buf) {
281 pr_err("failed to allocate memory for header node\n");
282 err = -ENOMEM;
283 goto end_attr_file_creation;
284 }
285
286 hfsplus_init_header_node(attr_file, clump_size, buf, node_size);
287
288 mapping = attr_file->i_mapping;
289
290 index = 0;
291 written = 0;
292 for (; written < node_size; index++, written += PAGE_CACHE_SIZE) {
293 void *kaddr;
294
295 page = read_mapping_page(mapping, index, NULL);
296 if (IS_ERR(page)) {
297 err = PTR_ERR(page);
298 goto failed_header_node_init;
299 }
300
301 kaddr = kmap_atomic(page);
302 memcpy(kaddr, buf + written,
303 min_t(size_t, PAGE_CACHE_SIZE, node_size - written));
304 kunmap_atomic(kaddr);
305
306 set_page_dirty(page);
307 page_cache_release(page);
308 }
309
310 hfsplus_mark_inode_dirty(attr_file, HFSPLUS_I_ATTR_DIRTY);
311
312 sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
313 if (!sbi->attr_tree)
314 pr_err("failed to load attributes file\n");
315
316failed_header_node_init:
317 kfree(buf);
318
319end_attr_file_creation:
320 iput(attr_file);
321
322 if (!err)
323 atomic_set(&sbi->attr_tree_state, HFSPLUS_VALID_ATTR_TREE);
324 else if (err == -ENOSPC)
325 atomic_set(&sbi->attr_tree_state, HFSPLUS_EMPTY_ATTR_TREE);
326 else
327 atomic_set(&sbi->attr_tree_state, HFSPLUS_FAILED_ATTR_TREE);
328
329 return err;
330}
331
130int __hfsplus_setxattr(struct inode *inode, const char *name, 332int __hfsplus_setxattr(struct inode *inode, const char *name,
131 const void *value, size_t size, int flags) 333 const void *value, size_t size, int flags)
132{ 334{
@@ -211,8 +413,9 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
211 } 413 }
212 414
213 if (!HFSPLUS_SB(inode->i_sb)->attr_tree) { 415 if (!HFSPLUS_SB(inode->i_sb)->attr_tree) {
214 err = -EOPNOTSUPP; 416 err = hfsplus_create_attributes_file(inode->i_sb);
215 goto end_setxattr; 417 if (unlikely(err))
418 goto end_setxattr;
216 } 419 }
217 420
218 if (hfsplus_attr_exists(inode, name)) { 421 if (hfsplus_attr_exists(inode, name)) {
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 17e6bdde96c5..dc7411fe185d 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -1025,7 +1025,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
1025 for(i = count; i < (num_got + count); i++) { 1025 for(i = count; i < (num_got + count); i++) {
1026 bhs[i] = sb_getblk(osb->sb, first_blkno); 1026 bhs[i] = sb_getblk(osb->sb, first_blkno);
1027 if (bhs[i] == NULL) { 1027 if (bhs[i] == NULL) {
1028 status = -EIO; 1028 status = -ENOMEM;
1029 mlog_errno(status); 1029 mlog_errno(status);
1030 goto bail; 1030 goto bail;
1031 } 1031 }
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index f37d3c0e2053..aeb44e879c51 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -80,6 +80,7 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
80 80
81 if ((u64)iblock >= ocfs2_clusters_to_blocks(inode->i_sb, 81 if ((u64)iblock >= ocfs2_clusters_to_blocks(inode->i_sb,
82 le32_to_cpu(fe->i_clusters))) { 82 le32_to_cpu(fe->i_clusters))) {
83 err = -ENOMEM;
83 mlog(ML_ERROR, "block offset is outside the allocated size: " 84 mlog(ML_ERROR, "block offset is outside the allocated size: "
84 "%llu\n", (unsigned long long)iblock); 85 "%llu\n", (unsigned long long)iblock);
85 goto bail; 86 goto bail;
@@ -92,6 +93,7 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
92 iblock; 93 iblock;
93 buffer_cache_bh = sb_getblk(osb->sb, blkno); 94 buffer_cache_bh = sb_getblk(osb->sb, blkno);
94 if (!buffer_cache_bh) { 95 if (!buffer_cache_bh) {
96 err = -ENOMEM;
95 mlog(ML_ERROR, "couldn't getblock for symlink!\n"); 97 mlog(ML_ERROR, "couldn't getblock for symlink!\n");
96 goto bail; 98 goto bail;
97 } 99 }
@@ -592,26 +594,11 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
592 ocfs2_rw_unlock(inode, level); 594 ocfs2_rw_unlock(inode, level);
593} 595}
594 596
595/*
596 * ocfs2_invalidatepage() and ocfs2_releasepage() are shamelessly stolen
597 * from ext3. PageChecked() bits have been removed as OCFS2 does not
598 * do journalled data.
599 */
600static void ocfs2_invalidatepage(struct page *page, unsigned int offset,
601 unsigned int length)
602{
603 journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal;
604
605 jbd2_journal_invalidatepage(journal, page, offset, length);
606}
607
608static int ocfs2_releasepage(struct page *page, gfp_t wait) 597static int ocfs2_releasepage(struct page *page, gfp_t wait)
609{ 598{
610 journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal;
611
612 if (!page_has_buffers(page)) 599 if (!page_has_buffers(page))
613 return 0; 600 return 0;
614 return jbd2_journal_try_to_free_buffers(journal, page, wait); 601 return try_to_free_buffers(page);
615} 602}
616 603
617static ssize_t ocfs2_direct_IO(int rw, 604static ssize_t ocfs2_direct_IO(int rw,
@@ -1802,8 +1789,7 @@ try_again:
1802 data_ac->ac_resv = &OCFS2_I(inode)->ip_la_data_resv; 1789 data_ac->ac_resv = &OCFS2_I(inode)->ip_la_data_resv;
1803 1790
1804 credits = ocfs2_calc_extend_credits(inode->i_sb, 1791 credits = ocfs2_calc_extend_credits(inode->i_sb,
1805 &di->id2.i_list, 1792 &di->id2.i_list);
1806 clusters_to_alloc);
1807 1793
1808 } 1794 }
1809 1795
@@ -1897,10 +1883,14 @@ out_commit:
1897out: 1883out:
1898 ocfs2_free_write_ctxt(wc); 1884 ocfs2_free_write_ctxt(wc);
1899 1885
1900 if (data_ac) 1886 if (data_ac) {
1901 ocfs2_free_alloc_context(data_ac); 1887 ocfs2_free_alloc_context(data_ac);
1902 if (meta_ac) 1888 data_ac = NULL;
1889 }
1890 if (meta_ac) {
1903 ocfs2_free_alloc_context(meta_ac); 1891 ocfs2_free_alloc_context(meta_ac);
1892 meta_ac = NULL;
1893 }
1904 1894
1905 if (ret == -ENOSPC && try_free) { 1895 if (ret == -ENOSPC && try_free) {
1906 /* 1896 /*
@@ -2087,7 +2077,7 @@ const struct address_space_operations ocfs2_aops = {
2087 .write_end = ocfs2_write_end, 2077 .write_end = ocfs2_write_end,
2088 .bmap = ocfs2_bmap, 2078 .bmap = ocfs2_bmap,
2089 .direct_IO = ocfs2_direct_IO, 2079 .direct_IO = ocfs2_direct_IO,
2090 .invalidatepage = ocfs2_invalidatepage, 2080 .invalidatepage = block_invalidatepage,
2091 .releasepage = ocfs2_releasepage, 2081 .releasepage = ocfs2_releasepage,
2092 .migratepage = buffer_migrate_page, 2082 .migratepage = buffer_migrate_page,
2093 .is_partially_uptodate = block_is_partially_uptodate, 2083 .is_partially_uptodate = block_is_partially_uptodate,
diff --git a/fs/ocfs2/buffer_head_io.c b/fs/ocfs2/buffer_head_io.c
index 5d18ad10c27f..5b704c63a103 100644
--- a/fs/ocfs2/buffer_head_io.c
+++ b/fs/ocfs2/buffer_head_io.c
@@ -115,7 +115,7 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
115 if (bhs[i] == NULL) { 115 if (bhs[i] == NULL) {
116 bhs[i] = sb_getblk(osb->sb, block++); 116 bhs[i] = sb_getblk(osb->sb, block++);
117 if (bhs[i] == NULL) { 117 if (bhs[i] == NULL) {
118 status = -EIO; 118 status = -ENOMEM;
119 mlog_errno(status); 119 mlog_errno(status);
120 goto bail; 120 goto bail;
121 } 121 }
@@ -214,7 +214,7 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
214 bhs[i] = sb_getblk(sb, block++); 214 bhs[i] = sb_getblk(sb, block++);
215 if (bhs[i] == NULL) { 215 if (bhs[i] == NULL) {
216 ocfs2_metadata_cache_io_unlock(ci); 216 ocfs2_metadata_cache_io_unlock(ci);
217 status = -EIO; 217 status = -ENOMEM;
218 mlog_errno(status); 218 mlog_errno(status);
219 goto bail; 219 goto bail;
220 } 220 }
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 363f0dcc924f..73920ffda05b 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -35,6 +35,7 @@
35#include <linux/time.h> 35#include <linux/time.h>
36#include <linux/debugfs.h> 36#include <linux/debugfs.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/bitmap.h>
38 39
39#include "heartbeat.h" 40#include "heartbeat.h"
40#include "tcp.h" 41#include "tcp.h"
@@ -282,15 +283,6 @@ struct o2hb_bio_wait_ctxt {
282 int wc_error; 283 int wc_error;
283}; 284};
284 285
285static int o2hb_pop_count(void *map, int count)
286{
287 int i = -1, pop = 0;
288
289 while ((i = find_next_bit(map, count, i + 1)) < count)
290 pop++;
291 return pop;
292}
293
294static void o2hb_write_timeout(struct work_struct *work) 286static void o2hb_write_timeout(struct work_struct *work)
295{ 287{
296 int failed, quorum; 288 int failed, quorum;
@@ -307,9 +299,9 @@ static void o2hb_write_timeout(struct work_struct *work)
307 spin_lock_irqsave(&o2hb_live_lock, flags); 299 spin_lock_irqsave(&o2hb_live_lock, flags);
308 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap)) 300 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
309 set_bit(reg->hr_region_num, o2hb_failed_region_bitmap); 301 set_bit(reg->hr_region_num, o2hb_failed_region_bitmap);
310 failed = o2hb_pop_count(&o2hb_failed_region_bitmap, 302 failed = bitmap_weight(o2hb_failed_region_bitmap,
311 O2NM_MAX_REGIONS); 303 O2NM_MAX_REGIONS);
312 quorum = o2hb_pop_count(&o2hb_quorum_region_bitmap, 304 quorum = bitmap_weight(o2hb_quorum_region_bitmap,
313 O2NM_MAX_REGIONS); 305 O2NM_MAX_REGIONS);
314 spin_unlock_irqrestore(&o2hb_live_lock, flags); 306 spin_unlock_irqrestore(&o2hb_live_lock, flags);
315 307
@@ -765,7 +757,7 @@ static void o2hb_set_quorum_device(struct o2hb_region *reg)
765 * If global heartbeat active, unpin all regions if the 757 * If global heartbeat active, unpin all regions if the
766 * region count > CUT_OFF 758 * region count > CUT_OFF
767 */ 759 */
768 if (o2hb_pop_count(&o2hb_quorum_region_bitmap, 760 if (bitmap_weight(o2hb_quorum_region_bitmap,
769 O2NM_MAX_REGIONS) > O2HB_PIN_CUT_OFF) 761 O2NM_MAX_REGIONS) > O2HB_PIN_CUT_OFF)
770 o2hb_region_unpin(NULL); 762 o2hb_region_unpin(NULL);
771unlock: 763unlock:
@@ -954,23 +946,9 @@ out:
954 return changed; 946 return changed;
955} 947}
956 948
957/* This could be faster if we just implmented a find_last_bit, but I 949static int o2hb_highest_node(unsigned long *nodes, int numbits)
958 * don't think the circumstances warrant it. */
959static int o2hb_highest_node(unsigned long *nodes,
960 int numbits)
961{ 950{
962 int highest, node; 951 return find_last_bit(nodes, numbits);
963
964 highest = numbits;
965 node = -1;
966 while ((node = find_next_bit(nodes, numbits, node + 1)) != -1) {
967 if (node >= numbits)
968 break;
969
970 highest = node;
971 }
972
973 return highest;
974} 952}
975 953
976static int o2hb_do_disk_heartbeat(struct o2hb_region *reg) 954static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)
@@ -1829,7 +1807,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1829 live_threshold = O2HB_LIVE_THRESHOLD; 1807 live_threshold = O2HB_LIVE_THRESHOLD;
1830 if (o2hb_global_heartbeat_active()) { 1808 if (o2hb_global_heartbeat_active()) {
1831 spin_lock(&o2hb_live_lock); 1809 spin_lock(&o2hb_live_lock);
1832 if (o2hb_pop_count(&o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1) 1810 if (bitmap_weight(o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1)
1833 live_threshold <<= 1; 1811 live_threshold <<= 1;
1834 spin_unlock(&o2hb_live_lock); 1812 spin_unlock(&o2hb_live_lock);
1835 } 1813 }
@@ -2180,7 +2158,7 @@ static void o2hb_heartbeat_group_drop_item(struct config_group *group,
2180 if (!o2hb_dependent_users) 2158 if (!o2hb_dependent_users)
2181 goto unlock; 2159 goto unlock;
2182 2160
2183 if (o2hb_pop_count(&o2hb_quorum_region_bitmap, 2161 if (bitmap_weight(o2hb_quorum_region_bitmap,
2184 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2162 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
2185 o2hb_region_pin(NULL); 2163 o2hb_region_pin(NULL);
2186 2164
@@ -2480,7 +2458,7 @@ static int o2hb_region_inc_user(const char *region_uuid)
2480 if (o2hb_dependent_users > 1) 2458 if (o2hb_dependent_users > 1)
2481 goto unlock; 2459 goto unlock;
2482 2460
2483 if (o2hb_pop_count(&o2hb_quorum_region_bitmap, 2461 if (bitmap_weight(o2hb_quorum_region_bitmap,
2484 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2462 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
2485 ret = o2hb_region_pin(NULL); 2463 ret = o2hb_region_pin(NULL);
2486 2464
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h
index baa2b9ef7eef..2260fb9e6508 100644
--- a/fs/ocfs2/cluster/masklog.h
+++ b/fs/ocfs2/cluster/masklog.h
@@ -199,7 +199,8 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits;
199#define mlog_errno(st) do { \ 199#define mlog_errno(st) do { \
200 int _st = (st); \ 200 int _st = (st); \
201 if (_st != -ERESTARTSYS && _st != -EINTR && \ 201 if (_st != -ERESTARTSYS && _st != -EINTR && \
202 _st != AOP_TRUNCATED_PAGE && _st != -ENOSPC) \ 202 _st != AOP_TRUNCATED_PAGE && _st != -ENOSPC && \
203 _st != -EDQUOT) \
203 mlog(ML_ERROR, "status = %lld\n", (long long)_st); \ 204 mlog(ML_ERROR, "status = %lld\n", (long long)_st); \
204} while (0) 205} while (0)
205 206
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 30544ce8e9f7..91a7e85ac8fd 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -2349,7 +2349,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
2349 2349
2350 dx_root_bh = sb_getblk(osb->sb, dr_blkno); 2350 dx_root_bh = sb_getblk(osb->sb, dr_blkno);
2351 if (dx_root_bh == NULL) { 2351 if (dx_root_bh == NULL) {
2352 ret = -EIO; 2352 ret = -ENOMEM;
2353 goto out; 2353 goto out;
2354 } 2354 }
2355 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh); 2355 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh);
@@ -2422,7 +2422,7 @@ static int ocfs2_dx_dir_format_cluster(struct ocfs2_super *osb,
2422 for (i = 0; i < num_dx_leaves; i++) { 2422 for (i = 0; i < num_dx_leaves; i++) {
2423 bh = sb_getblk(osb->sb, start_blk + i); 2423 bh = sb_getblk(osb->sb, start_blk + i);
2424 if (bh == NULL) { 2424 if (bh == NULL) {
2425 ret = -EIO; 2425 ret = -ENOMEM;
2426 goto out; 2426 goto out;
2427 } 2427 }
2428 dx_leaves[i] = bh; 2428 dx_leaves[i] = bh;
@@ -2929,7 +2929,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
2929 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); 2929 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
2930 dirdata_bh = sb_getblk(sb, blkno); 2930 dirdata_bh = sb_getblk(sb, blkno);
2931 if (!dirdata_bh) { 2931 if (!dirdata_bh) {
2932 ret = -EIO; 2932 ret = -ENOMEM;
2933 mlog_errno(ret); 2933 mlog_errno(ret);
2934 goto out_commit; 2934 goto out_commit;
2935 } 2935 }
@@ -3159,7 +3159,7 @@ static int ocfs2_do_extend_dir(struct super_block *sb,
3159 3159
3160 *new_bh = sb_getblk(sb, p_blkno); 3160 *new_bh = sb_getblk(sb, p_blkno);
3161 if (!*new_bh) { 3161 if (!*new_bh) {
3162 status = -EIO; 3162 status = -ENOMEM;
3163 mlog_errno(status); 3163 mlog_errno(status);
3164 goto bail; 3164 goto bail;
3165 } 3165 }
@@ -3284,7 +3284,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
3284 if (ocfs2_dir_resv_allowed(osb)) 3284 if (ocfs2_dir_resv_allowed(osb))
3285 data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv; 3285 data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv;
3286 3286
3287 credits = ocfs2_calc_extend_credits(sb, el, 1); 3287 credits = ocfs2_calc_extend_credits(sb, el);
3288 } else { 3288 } else {
3289 spin_unlock(&OCFS2_I(dir)->ip_lock); 3289 spin_unlock(&OCFS2_I(dir)->ip_lock);
3290 credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS; 3290 credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
@@ -3716,7 +3716,7 @@ static int ocfs2_dx_dir_rebalance_credits(struct ocfs2_super *osb,
3716{ 3716{
3717 int credits = ocfs2_clusters_to_blocks(osb->sb, 2); 3717 int credits = ocfs2_clusters_to_blocks(osb->sb, 2);
3718 3718
3719 credits += ocfs2_calc_extend_credits(osb->sb, &dx_root->dr_list, 1); 3719 credits += ocfs2_calc_extend_credits(osb->sb, &dx_root->dr_list);
3720 credits += ocfs2_quota_trans_credits(osb->sb); 3720 credits += ocfs2_quota_trans_credits(osb->sb);
3721 return credits; 3721 return credits;
3722} 3722}
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
index cf0f103963b1..af3f7aa73e13 100644
--- a/fs/ocfs2/dlm/dlmmaster.c
+++ b/fs/ocfs2/dlm/dlmmaster.c
@@ -1885,8 +1885,10 @@ ok:
1885 * up nodes that this node contacted */ 1885 * up nodes that this node contacted */
1886 while ((nn = find_next_bit (mle->response_map, O2NM_MAX_NODES, 1886 while ((nn = find_next_bit (mle->response_map, O2NM_MAX_NODES,
1887 nn+1)) < O2NM_MAX_NODES) { 1887 nn+1)) < O2NM_MAX_NODES) {
1888 if (nn != dlm->node_num && nn != assert->node_idx) 1888 if (nn != dlm->node_num && nn != assert->node_idx) {
1889 master_request = 1; 1889 master_request = 1;
1890 break;
1891 }
1890 } 1892 }
1891 } 1893 }
1892 mle->master = assert->node_idx; 1894 mle->master = assert->node_idx;
@@ -2354,6 +2356,10 @@ static int dlm_is_lockres_migrateable(struct dlm_ctxt *dlm,
2354 2356
2355 assert_spin_locked(&res->spinlock); 2357 assert_spin_locked(&res->spinlock);
2356 2358
2359 /* delay migration when the lockres is in MIGRATING state */
2360 if (res->state & DLM_LOCK_RES_MIGRATING)
2361 return 0;
2362
2357 if (res->owner != dlm->node_num) 2363 if (res->owner != dlm->node_num)
2358 return 0; 2364 return 0;
2359 2365
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c
index 0b5adca1b178..7035af09cc03 100644
--- a/fs/ocfs2/dlm/dlmrecovery.c
+++ b/fs/ocfs2/dlm/dlmrecovery.c
@@ -1886,6 +1886,13 @@ static int dlm_process_recovery_data(struct dlm_ctxt *dlm,
1886 if (ml->type == LKM_NLMODE) 1886 if (ml->type == LKM_NLMODE)
1887 goto skip_lvb; 1887 goto skip_lvb;
1888 1888
1889 /*
1890 * If the lock is in the blocked list it can't have a valid lvb,
1891 * so skip it
1892 */
1893 if (ml->list == DLM_BLOCKED_LIST)
1894 goto skip_lvb;
1895
1889 if (!dlm_lvb_is_empty(mres->lvb)) { 1896 if (!dlm_lvb_is_empty(mres->lvb)) {
1890 if (lksb->flags & DLM_LKSB_PUT_LVB) { 1897 if (lksb->flags & DLM_LKSB_PUT_LVB) {
1891 /* other node was trying to update 1898 /* other node was trying to update
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index d71903c6068b..6fff128cad16 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -580,7 +580,7 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
580 int did_quota = 0; 580 int did_quota = 0;
581 581
582 /* 582 /*
583 * This function only exists for file systems which don't 583 * Unwritten extent only exists for file systems which
584 * support holes. 584 * support holes.
585 */ 585 */
586 BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb)); 586 BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb));
@@ -603,8 +603,7 @@ restart_all:
603 goto leave; 603 goto leave;
604 } 604 }
605 605
606 credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list, 606 credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list);
607 clusters_to_add);
608 handle = ocfs2_start_trans(osb, credits); 607 handle = ocfs2_start_trans(osb, credits);
609 if (IS_ERR(handle)) { 608 if (IS_ERR(handle)) {
610 status = PTR_ERR(handle); 609 status = PTR_ERR(handle);
diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h
index 0b479bab3671..9ff4e8cf9d97 100644
--- a/fs/ocfs2/journal.h
+++ b/fs/ocfs2/journal.h
@@ -524,8 +524,7 @@ static inline int ocfs2_calc_dxi_expand_credits(struct super_block *sb)
524 * the result may be wrong. 524 * the result may be wrong.
525 */ 525 */
526static inline int ocfs2_calc_extend_credits(struct super_block *sb, 526static inline int ocfs2_calc_extend_credits(struct super_block *sb,
527 struct ocfs2_extent_list *root_el, 527 struct ocfs2_extent_list *root_el)
528 u32 bits_wanted)
529{ 528{
530 int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks; 529 int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks;
531 530
diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
index 3d3f3c83065c..631a98213474 100644
--- a/fs/ocfs2/move_extents.c
+++ b/fs/ocfs2/move_extents.c
@@ -201,8 +201,7 @@ static int ocfs2_lock_allocators_move_extents(struct inode *inode,
201 } 201 }
202 } 202 }
203 203
204 *credits += ocfs2_calc_extend_credits(osb->sb, et->et_root_el, 204 *credits += ocfs2_calc_extend_credits(osb->sb, et->et_root_el);
205 clusters_to_move + 2);
206 205
207 mlog(0, "reserve metadata_blocks: %d, data_clusters: %u, credits: %d\n", 206 mlog(0, "reserve metadata_blocks: %d, data_clusters: %u, credits: %d\n",
208 extra_blocks, clusters_to_move, *credits); 207 extra_blocks, clusters_to_move, *credits);
@@ -1067,8 +1066,10 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
1067 if (status) 1066 if (status)
1068 return status; 1067 return status;
1069 1068
1070 if ((!S_ISREG(inode->i_mode)) || !(filp->f_mode & FMODE_WRITE)) 1069 if ((!S_ISREG(inode->i_mode)) || !(filp->f_mode & FMODE_WRITE)) {
1070 status = -EPERM;
1071 goto out_drop; 1071 goto out_drop;
1072 }
1072 1073
1073 if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) { 1074 if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) {
1074 status = -EPERM; 1075 status = -EPERM;
@@ -1090,8 +1091,10 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
1090 goto out_free; 1091 goto out_free;
1091 } 1092 }
1092 1093
1093 if (range.me_start > i_size_read(inode)) 1094 if (range.me_start > i_size_read(inode)) {
1095 status = -EINVAL;
1094 goto out_free; 1096 goto out_free;
1097 }
1095 1098
1096 if (range.me_start + range.me_len > i_size_read(inode)) 1099 if (range.me_start + range.me_len > i_size_read(inode))
1097 range.me_len = i_size_read(inode) - range.me_start; 1100 range.me_len = i_size_read(inode) - range.me_start;
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index be3f8676a438..4f791f6d27d0 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -489,7 +489,7 @@ static int __ocfs2_mknod_locked(struct inode *dir,
489 489
490 *new_fe_bh = sb_getblk(osb->sb, fe_blkno); 490 *new_fe_bh = sb_getblk(osb->sb, fe_blkno);
491 if (!*new_fe_bh) { 491 if (!*new_fe_bh) {
492 status = -EIO; 492 status = -ENOMEM;
493 mlog_errno(status); 493 mlog_errno(status);
494 goto leave; 494 goto leave;
495 } 495 }
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index bf4dfc14bb2c..55767e1ba724 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -612,6 +612,11 @@ static int ocfs2_create_refcount_tree(struct inode *inode,
612 } 612 }
613 613
614 new_bh = sb_getblk(inode->i_sb, first_blkno); 614 new_bh = sb_getblk(inode->i_sb, first_blkno);
615 if (!new_bh) {
616 ret = -ENOMEM;
617 mlog_errno(ret);
618 goto out_commit;
619 }
615 ocfs2_set_new_buffer_uptodate(&new_tree->rf_ci, new_bh); 620 ocfs2_set_new_buffer_uptodate(&new_tree->rf_ci, new_bh);
616 621
617 ret = ocfs2_journal_access_rb(handle, &new_tree->rf_ci, new_bh, 622 ret = ocfs2_journal_access_rb(handle, &new_tree->rf_ci, new_bh,
@@ -1310,7 +1315,7 @@ static int ocfs2_expand_inline_ref_root(handle_t *handle,
1310 1315
1311 new_bh = sb_getblk(sb, blkno); 1316 new_bh = sb_getblk(sb, blkno);
1312 if (new_bh == NULL) { 1317 if (new_bh == NULL) {
1313 ret = -EIO; 1318 ret = -ENOMEM;
1314 mlog_errno(ret); 1319 mlog_errno(ret);
1315 goto out; 1320 goto out;
1316 } 1321 }
@@ -1561,7 +1566,7 @@ static int ocfs2_new_leaf_refcount_block(handle_t *handle,
1561 1566
1562 new_bh = sb_getblk(sb, blkno); 1567 new_bh = sb_getblk(sb, blkno);
1563 if (new_bh == NULL) { 1568 if (new_bh == NULL) {
1564 ret = -EIO; 1569 ret = -ENOMEM;
1565 mlog_errno(ret); 1570 mlog_errno(ret);
1566 goto out; 1571 goto out;
1567 } 1572 }
@@ -2502,8 +2507,7 @@ static int ocfs2_calc_refcount_meta_credits(struct super_block *sb,
2502 ocfs2_init_refcount_extent_tree(&et, ci, ref_root_bh); 2507 ocfs2_init_refcount_extent_tree(&et, ci, ref_root_bh);
2503 *meta_add += ocfs2_extend_meta_needed(et.et_root_el); 2508 *meta_add += ocfs2_extend_meta_needed(et.et_root_el);
2504 *credits += ocfs2_calc_extend_credits(sb, 2509 *credits += ocfs2_calc_extend_credits(sb,
2505 et.et_root_el, 2510 et.et_root_el);
2506 ref_blocks);
2507 } else { 2511 } else {
2508 *credits += OCFS2_EXPAND_REFCOUNT_TREE_CREDITS; 2512 *credits += OCFS2_EXPAND_REFCOUNT_TREE_CREDITS;
2509 *meta_add += 1; 2513 *meta_add += 1;
@@ -2874,8 +2878,7 @@ static int ocfs2_lock_refcount_allocators(struct super_block *sb,
2874 meta_add = 2878 meta_add =
2875 ocfs2_extend_meta_needed(et->et_root_el); 2879 ocfs2_extend_meta_needed(et->et_root_el);
2876 2880
2877 *credits += ocfs2_calc_extend_credits(sb, et->et_root_el, 2881 *credits += ocfs2_calc_extend_credits(sb, et->et_root_el);
2878 num_clusters + 2);
2879 2882
2880 ret = ocfs2_calc_refcount_meta_credits(sb, ref_ci, ref_root_bh, 2883 ret = ocfs2_calc_refcount_meta_credits(sb, ref_ci, ref_root_bh,
2881 p_cluster, num_clusters, 2884 p_cluster, num_clusters,
@@ -3031,7 +3034,7 @@ int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
3031 for (i = 0; i < blocks; i++, old_block++, new_block++) { 3034 for (i = 0; i < blocks; i++, old_block++, new_block++) {
3032 new_bh = sb_getblk(osb->sb, new_block); 3035 new_bh = sb_getblk(osb->sb, new_block);
3033 if (new_bh == NULL) { 3036 if (new_bh == NULL) {
3034 ret = -EIO; 3037 ret = -ENOMEM;
3035 mlog_errno(ret); 3038 mlog_errno(ret);
3036 break; 3039 break;
3037 } 3040 }
@@ -3625,8 +3628,7 @@ int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
3625 3628
3626 ocfs2_init_refcount_extent_tree(&et, ref_ci, ref_root_bh); 3629 ocfs2_init_refcount_extent_tree(&et, ref_ci, ref_root_bh);
3627 *credits += ocfs2_calc_extend_credits(inode->i_sb, 3630 *credits += ocfs2_calc_extend_credits(inode->i_sb,
3628 et.et_root_el, 3631 et.et_root_el);
3629 ref_blocks);
3630 } 3632 }
3631 3633
3632out: 3634out:
diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c
index ec55add7604a..822ebc10f281 100644
--- a/fs/ocfs2/resize.c
+++ b/fs/ocfs2/resize.c
@@ -469,6 +469,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
469 struct ocfs2_chain_list *cl; 469 struct ocfs2_chain_list *cl;
470 struct ocfs2_chain_rec *cr; 470 struct ocfs2_chain_rec *cr;
471 u16 cl_bpc; 471 u16 cl_bpc;
472 u64 bg_ptr;
472 473
473 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 474 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
474 return -EROFS; 475 return -EROFS;
@@ -513,7 +514,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
513 ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh); 514 ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
514 if (ret) { 515 if (ret) {
515 mlog_errno(ret); 516 mlog_errno(ret);
516 goto out_unlock; 517 goto out_free_group_bh;
517 } 518 }
518 519
519 trace_ocfs2_group_add((unsigned long long)input->group, 520 trace_ocfs2_group_add((unsigned long long)input->group,
@@ -523,7 +524,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
523 if (IS_ERR(handle)) { 524 if (IS_ERR(handle)) {
524 mlog_errno(PTR_ERR(handle)); 525 mlog_errno(PTR_ERR(handle));
525 ret = -EINVAL; 526 ret = -EINVAL;
526 goto out_unlock; 527 goto out_free_group_bh;
527 } 528 }
528 529
529 cl_bpc = le16_to_cpu(fe->id2.i_chain.cl_bpc); 530 cl_bpc = le16_to_cpu(fe->id2.i_chain.cl_bpc);
@@ -538,12 +539,14 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
538 } 539 }
539 540
540 group = (struct ocfs2_group_desc *)group_bh->b_data; 541 group = (struct ocfs2_group_desc *)group_bh->b_data;
542 bg_ptr = le64_to_cpu(group->bg_next_group);
541 group->bg_next_group = cr->c_blkno; 543 group->bg_next_group = cr->c_blkno;
542 ocfs2_journal_dirty(handle, group_bh); 544 ocfs2_journal_dirty(handle, group_bh);
543 545
544 ret = ocfs2_journal_access_di(handle, INODE_CACHE(main_bm_inode), 546 ret = ocfs2_journal_access_di(handle, INODE_CACHE(main_bm_inode),
545 main_bm_bh, OCFS2_JOURNAL_ACCESS_WRITE); 547 main_bm_bh, OCFS2_JOURNAL_ACCESS_WRITE);
546 if (ret < 0) { 548 if (ret < 0) {
549 group->bg_next_group = cpu_to_le64(bg_ptr);
547 mlog_errno(ret); 550 mlog_errno(ret);
548 goto out_commit; 551 goto out_commit;
549 } 552 }
@@ -574,8 +577,11 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
574 577
575out_commit: 578out_commit:
576 ocfs2_commit_trans(osb, handle); 579 ocfs2_commit_trans(osb, handle);
577out_unlock: 580
581out_free_group_bh:
578 brelse(group_bh); 582 brelse(group_bh);
583
584out_unlock:
579 brelse(main_bm_bh); 585 brelse(main_bm_bh);
580 586
581 ocfs2_inode_unlock(main_bm_inode, 1); 587 ocfs2_inode_unlock(main_bm_inode, 1);
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c
index 39abf89697ed..cb7ec0b63ddc 100644
--- a/fs/ocfs2/stackglue.c
+++ b/fs/ocfs2/stackglue.c
@@ -643,7 +643,7 @@ error:
643 643
644#define FS_OCFS2_NM 1 644#define FS_OCFS2_NM 1
645 645
646static ctl_table ocfs2_nm_table[] = { 646static struct ctl_table ocfs2_nm_table[] = {
647 { 647 {
648 .procname = "hb_ctl_path", 648 .procname = "hb_ctl_path",
649 .data = ocfs2_hb_ctl_path, 649 .data = ocfs2_hb_ctl_path,
@@ -654,7 +654,7 @@ static ctl_table ocfs2_nm_table[] = {
654 { } 654 { }
655}; 655};
656 656
657static ctl_table ocfs2_mod_table[] = { 657static struct ctl_table ocfs2_mod_table[] = {
658 { 658 {
659 .procname = "nm", 659 .procname = "nm",
660 .data = NULL, 660 .data = NULL,
@@ -665,7 +665,7 @@ static ctl_table ocfs2_mod_table[] = {
665 { } 665 { }
666}; 666};
667 667
668static ctl_table ocfs2_kern_table[] = { 668static struct ctl_table ocfs2_kern_table[] = {
669 { 669 {
670 .procname = "ocfs2", 670 .procname = "ocfs2",
671 .data = NULL, 671 .data = NULL,
@@ -676,7 +676,7 @@ static ctl_table ocfs2_kern_table[] = {
676 { } 676 { }
677}; 677};
678 678
679static ctl_table ocfs2_root_table[] = { 679static struct ctl_table ocfs2_root_table[] = {
680 { 680 {
681 .procname = "fs", 681 .procname = "fs",
682 .data = NULL, 682 .data = NULL,
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 5397c07ce608..2c91452c4047 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -481,7 +481,7 @@ ocfs2_block_group_alloc_contig(struct ocfs2_super *osb, handle_t *handle,
481 481
482 bg_bh = sb_getblk(osb->sb, bg_blkno); 482 bg_bh = sb_getblk(osb->sb, bg_blkno);
483 if (!bg_bh) { 483 if (!bg_bh) {
484 status = -EIO; 484 status = -ENOMEM;
485 mlog_errno(status); 485 mlog_errno(status);
486 goto bail; 486 goto bail;
487 } 487 }
@@ -661,7 +661,7 @@ ocfs2_block_group_alloc_discontig(handle_t *handle,
661 661
662 bg_bh = sb_getblk(osb->sb, bg_blkno); 662 bg_bh = sb_getblk(osb->sb, bg_blkno);
663 if (!bg_bh) { 663 if (!bg_bh) {
664 status = -EIO; 664 status = -ENOMEM;
665 mlog_errno(status); 665 mlog_errno(status);
666 goto bail; 666 goto bail;
667 } 667 }
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index d4e81e4a9b04..c41492957aa5 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -1848,8 +1848,8 @@ static int ocfs2_get_sector(struct super_block *sb,
1848 1848
1849 *bh = sb_getblk(sb, block); 1849 *bh = sb_getblk(sb, block);
1850 if (!*bh) { 1850 if (!*bh) {
1851 mlog_errno(-EIO); 1851 mlog_errno(-ENOMEM);
1852 return -EIO; 1852 return -ENOMEM;
1853 } 1853 }
1854 lock_buffer(*bh); 1854 lock_buffer(*bh);
1855 if (!buffer_dirty(*bh)) 1855 if (!buffer_dirty(*bh))
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 6ce0686eab72..f0a1326d9bba 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -377,7 +377,7 @@ static int ocfs2_init_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
377 bucket->bu_bhs[i] = sb_getblk(bucket->bu_inode->i_sb, 377 bucket->bu_bhs[i] = sb_getblk(bucket->bu_inode->i_sb,
378 xb_blkno + i); 378 xb_blkno + i);
379 if (!bucket->bu_bhs[i]) { 379 if (!bucket->bu_bhs[i]) {
380 rc = -EIO; 380 rc = -ENOMEM;
381 mlog_errno(rc); 381 mlog_errno(rc);
382 break; 382 break;
383 } 383 }
@@ -754,8 +754,7 @@ static int ocfs2_xattr_extend_allocation(struct inode *inode,
754 BUG_ON(why == RESTART_META); 754 BUG_ON(why == RESTART_META);
755 755
756 credits = ocfs2_calc_extend_credits(inode->i_sb, 756 credits = ocfs2_calc_extend_credits(inode->i_sb,
757 &vb->vb_xv->xr_list, 757 &vb->vb_xv->xr_list);
758 clusters_to_add);
759 status = ocfs2_extend_trans(handle, credits); 758 status = ocfs2_extend_trans(handle, credits);
760 if (status < 0) { 759 if (status < 0) {
761 status = -ENOMEM; 760 status = -ENOMEM;
@@ -2865,6 +2864,12 @@ static int ocfs2_create_xattr_block(struct inode *inode,
2865 } 2864 }
2866 2865
2867 new_bh = sb_getblk(inode->i_sb, first_blkno); 2866 new_bh = sb_getblk(inode->i_sb, first_blkno);
2867 if (!new_bh) {
2868 ret = -ENOMEM;
2869 mlog_errno(ret);
2870 goto end;
2871 }
2872
2868 ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh); 2873 ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);
2869 2874
2870 ret = ocfs2_journal_access_xb(ctxt->handle, INODE_CACHE(inode), 2875 ret = ocfs2_journal_access_xb(ctxt->handle, INODE_CACHE(inode),
@@ -3040,8 +3045,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode,
3040 if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { 3045 if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
3041 clusters_add += new_clusters; 3046 clusters_add += new_clusters;
3042 credits += ocfs2_calc_extend_credits(inode->i_sb, 3047 credits += ocfs2_calc_extend_credits(inode->i_sb,
3043 &def_xv.xv.xr_list, 3048 &def_xv.xv.xr_list);
3044 new_clusters);
3045 } 3049 }
3046 3050
3047 goto meta_guess; 3051 goto meta_guess;
@@ -3106,8 +3110,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode,
3106 if (!ocfs2_xattr_is_local(xe)) 3110 if (!ocfs2_xattr_is_local(xe))
3107 credits += ocfs2_calc_extend_credits( 3111 credits += ocfs2_calc_extend_credits(
3108 inode->i_sb, 3112 inode->i_sb,
3109 &def_xv.xv.xr_list, 3113 &def_xv.xv.xr_list);
3110 new_clusters);
3111 goto out; 3114 goto out;
3112 } 3115 }
3113 } 3116 }
@@ -3132,9 +3135,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode,
3132 meta_add += ocfs2_extend_meta_needed(&xv->xr_list); 3135 meta_add += ocfs2_extend_meta_needed(&xv->xr_list);
3133 clusters_add += new_clusters - old_clusters; 3136 clusters_add += new_clusters - old_clusters;
3134 credits += ocfs2_calc_extend_credits(inode->i_sb, 3137 credits += ocfs2_calc_extend_credits(inode->i_sb,
3135 &xv->xr_list, 3138 &xv->xr_list);
3136 new_clusters -
3137 old_clusters);
3138 if (value_size >= OCFS2_XATTR_ROOT_SIZE) 3139 if (value_size >= OCFS2_XATTR_ROOT_SIZE)
3139 goto out; 3140 goto out;
3140 } 3141 }
@@ -3180,7 +3181,7 @@ meta_guess:
3180 &xb->xb_attrs.xb_root.xt_list; 3181 &xb->xb_attrs.xb_root.xt_list;
3181 meta_add += ocfs2_extend_meta_needed(el); 3182 meta_add += ocfs2_extend_meta_needed(el);
3182 credits += ocfs2_calc_extend_credits(inode->i_sb, 3183 credits += ocfs2_calc_extend_credits(inode->i_sb,
3183 el, 1); 3184 el);
3184 } else 3185 } else
3185 credits += OCFS2_SUBALLOC_ALLOC + 1; 3186 credits += OCFS2_SUBALLOC_ALLOC + 1;
3186 3187
@@ -6216,8 +6217,7 @@ static int ocfs2_value_metas_in_xattr_header(struct super_block *sb,
6216 le16_to_cpu(xv->xr_list.l_next_free_rec); 6217 le16_to_cpu(xv->xr_list.l_next_free_rec);
6217 6218
6218 *credits += ocfs2_calc_extend_credits(sb, 6219 *credits += ocfs2_calc_extend_credits(sb,
6219 &def_xv.xv.xr_list, 6220 &def_xv.xv.xr_list);
6220 le32_to_cpu(xv->xr_clusters));
6221 6221
6222 /* 6222 /*
6223 * If the value is a tree with depth > 1, We don't go deep 6223 * If the value is a tree with depth > 1, We don't go deep
@@ -6782,7 +6782,7 @@ static int ocfs2_lock_reflink_xattr_rec_allocators(
6782 metas.num_metas += ocfs2_extend_meta_needed(xt_et->et_root_el); 6782 metas.num_metas += ocfs2_extend_meta_needed(xt_et->et_root_el);
6783 6783
6784 *credits += ocfs2_calc_extend_credits(osb->sb, 6784 *credits += ocfs2_calc_extend_credits(osb->sb,
6785 xt_et->et_root_el, len); 6785 xt_et->et_root_el);
6786 6786
6787 if (metas.num_metas) { 6787 if (metas.num_metas) {
6788 ret = ocfs2_reserve_new_metadata_blocks(osb, metas.num_metas, 6788 ret = ocfs2_reserve_new_metadata_blocks(osb, metas.num_metas,
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 15af6222f8a4..2183fcf41d59 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -31,6 +31,10 @@ config PROC_FS
31config PROC_KCORE 31config PROC_KCORE
32 bool "/proc/kcore support" if !ARM 32 bool "/proc/kcore support" if !ARM
33 depends on PROC_FS && MMU 33 depends on PROC_FS && MMU
34 help
35 Provides a virtual ELF core file of the live kernel. This can
36 be read with gdb and other ELF tools. No modifications can be
37 made using this mechanism.
34 38
35config PROC_VMCORE 39config PROC_VMCORE
36 bool "/proc/vmcore support" 40 bool "/proc/vmcore support"
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 8eaa1ba793fc..28955d4b7218 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -285,19 +285,23 @@ static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma)
285 return rv; 285 return rv;
286} 286}
287 287
288static unsigned long proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags) 288static unsigned long
289proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr,
290 unsigned long len, unsigned long pgoff,
291 unsigned long flags)
289{ 292{
290 struct proc_dir_entry *pde = PDE(file_inode(file)); 293 struct proc_dir_entry *pde = PDE(file_inode(file));
291 unsigned long rv = -EIO; 294 unsigned long rv = -EIO;
292 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) = NULL; 295 unsigned long (*get_area)(struct file *, unsigned long, unsigned long,
296 unsigned long, unsigned long) = NULL;
293 if (use_pde(pde)) { 297 if (use_pde(pde)) {
294#ifdef CONFIG_MMU 298#ifdef CONFIG_MMU
295 get_unmapped_area = current->mm->get_unmapped_area; 299 get_area = current->mm->get_unmapped_area;
296#endif 300#endif
297 if (pde->proc_fops->get_unmapped_area) 301 if (pde->proc_fops->get_unmapped_area)
298 get_unmapped_area = pde->proc_fops->get_unmapped_area; 302 get_area = pde->proc_fops->get_unmapped_area;
299 if (get_unmapped_area) 303 if (get_area)
300 rv = get_unmapped_area(file, orig_addr, len, pgoff, flags); 304 rv = get_area(file, orig_addr, len, pgoff, flags);
301 unuse_pde(pde); 305 unuse_pde(pde);
302 } 306 }
303 return rv; 307 return rv;
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 06ea155e1a59..5ed0e52d6aa0 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -255,8 +255,7 @@ static int kcore_update_ram(void)
255 end_pfn = 0; 255 end_pfn = 0;
256 for_each_node_state(nid, N_MEMORY) { 256 for_each_node_state(nid, N_MEMORY) {
257 unsigned long node_end; 257 unsigned long node_end;
258 node_end = NODE_DATA(nid)->node_start_pfn + 258 node_end = node_end_pfn(nid);
259 NODE_DATA(nid)->node_spanned_pages;
260 if (end_pfn < node_end) 259 if (end_pfn < node_end)
261 end_pfn = node_end; 260 end_pfn = node_end;
262 } 261 }
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 59d85d608898..c805d5b69ba1 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -24,7 +24,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
24{ 24{
25 struct sysinfo i; 25 struct sysinfo i;
26 unsigned long committed; 26 unsigned long committed;
27 unsigned long allowed;
28 struct vmalloc_info vmi; 27 struct vmalloc_info vmi;
29 long cached; 28 long cached;
30 unsigned long pages[NR_LRU_LISTS]; 29 unsigned long pages[NR_LRU_LISTS];
@@ -37,8 +36,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
37 si_meminfo(&i); 36 si_meminfo(&i);
38 si_swapinfo(&i); 37 si_swapinfo(&i);
39 committed = percpu_counter_read_positive(&vm_committed_as); 38 committed = percpu_counter_read_positive(&vm_committed_as);
40 allowed = ((totalram_pages - hugetlb_total_pages())
41 * sysctl_overcommit_ratio / 100) + total_swap_pages;
42 39
43 cached = global_page_state(NR_FILE_PAGES) - 40 cached = global_page_state(NR_FILE_PAGES) -
44 total_swapcache_pages() - i.bufferram; 41 total_swapcache_pages() - i.bufferram;
@@ -147,7 +144,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
147 K(global_page_state(NR_UNSTABLE_NFS)), 144 K(global_page_state(NR_UNSTABLE_NFS)),
148 K(global_page_state(NR_BOUNCE)), 145 K(global_page_state(NR_BOUNCE)),
149 K(global_page_state(NR_WRITEBACK_TEMP)), 146 K(global_page_state(NR_WRITEBACK_TEMP)),
150 K(allowed), 147 K(vm_commit_limit()),
151 K(committed), 148 K(committed),
152 (unsigned long)VMALLOC_TOTAL >> 10, 149 (unsigned long)VMALLOC_TOTAL >> 10,
153 vmi.used >> 10, 150 vmi.used >> 10,
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 390bdab01c3c..abbe825d20ff 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -561,6 +561,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
561 [ilog2(VM_NONLINEAR)] = "nl", 561 [ilog2(VM_NONLINEAR)] = "nl",
562 [ilog2(VM_ARCH_1)] = "ar", 562 [ilog2(VM_ARCH_1)] = "ar",
563 [ilog2(VM_DONTDUMP)] = "dd", 563 [ilog2(VM_DONTDUMP)] = "dd",
564#ifdef CONFIG_MEM_SOFT_DIRTY
565 [ilog2(VM_SOFTDIRTY)] = "sd",
566#endif
564 [ilog2(VM_MIXEDMAP)] = "mm", 567 [ilog2(VM_MIXEDMAP)] = "mm",
565 [ilog2(VM_HUGEPAGE)] = "hg", 568 [ilog2(VM_HUGEPAGE)] = "hg",
566 [ilog2(VM_NOHUGEPAGE)] = "nh", 569 [ilog2(VM_NOHUGEPAGE)] = "nh",
@@ -1387,8 +1390,8 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1387 struct mm_struct *mm = vma->vm_mm; 1390 struct mm_struct *mm = vma->vm_mm;
1388 struct mm_walk walk = {}; 1391 struct mm_walk walk = {};
1389 struct mempolicy *pol; 1392 struct mempolicy *pol;
1390 int n; 1393 char buffer[64];
1391 char buffer[50]; 1394 int nid;
1392 1395
1393 if (!mm) 1396 if (!mm)
1394 return 0; 1397 return 0;
@@ -1404,10 +1407,8 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1404 walk.mm = mm; 1407 walk.mm = mm;
1405 1408
1406 pol = get_vma_policy(task, vma, vma->vm_start); 1409 pol = get_vma_policy(task, vma, vma->vm_start);
1407 n = mpol_to_str(buffer, sizeof(buffer), pol); 1410 mpol_to_str(buffer, sizeof(buffer), pol);
1408 mpol_cond_put(pol); 1411 mpol_cond_put(pol);
1409 if (n < 0)
1410 return n;
1411 1412
1412 seq_printf(m, "%08lx %s", vma->vm_start, buffer); 1413 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
1413 1414
@@ -1460,9 +1461,9 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1460 if (md->writeback) 1461 if (md->writeback)
1461 seq_printf(m, " writeback=%lu", md->writeback); 1462 seq_printf(m, " writeback=%lu", md->writeback);
1462 1463
1463 for_each_node_state(n, N_MEMORY) 1464 for_each_node_state(nid, N_MEMORY)
1464 if (md->node[n]) 1465 if (md->node[nid])
1465 seq_printf(m, " N%d=%lu", n, md->node[n]); 1466 seq_printf(m, " N%d=%lu", nid, md->node[nid]);
1466out: 1467out:
1467 seq_putc(m, '\n'); 1468 seq_putc(m, '\n');
1468 1469
diff --git a/fs/sync.c b/fs/sync.c
index 6c0ca3b75758..f15537452231 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -27,10 +27,11 @@
27 * wait == 1 case since in that case write_inode() functions do 27 * wait == 1 case since in that case write_inode() functions do
28 * sync_dirty_buffer() and thus effectively write one block at a time. 28 * sync_dirty_buffer() and thus effectively write one block at a time.
29 */ 29 */
30static int __sync_filesystem(struct super_block *sb, int wait) 30static int __sync_filesystem(struct super_block *sb, int wait,
31 unsigned long start)
31{ 32{
32 if (wait) 33 if (wait)
33 sync_inodes_sb(sb); 34 sync_inodes_sb(sb, start);
34 else 35 else
35 writeback_inodes_sb(sb, WB_REASON_SYNC); 36 writeback_inodes_sb(sb, WB_REASON_SYNC);
36 37
@@ -47,6 +48,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
47int sync_filesystem(struct super_block *sb) 48int sync_filesystem(struct super_block *sb)
48{ 49{
49 int ret; 50 int ret;
51 unsigned long start = jiffies;
50 52
51 /* 53 /*
52 * We need to be protected against the filesystem going from 54 * We need to be protected against the filesystem going from
@@ -60,17 +62,17 @@ int sync_filesystem(struct super_block *sb)
60 if (sb->s_flags & MS_RDONLY) 62 if (sb->s_flags & MS_RDONLY)
61 return 0; 63 return 0;
62 64
63 ret = __sync_filesystem(sb, 0); 65 ret = __sync_filesystem(sb, 0, start);
64 if (ret < 0) 66 if (ret < 0)
65 return ret; 67 return ret;
66 return __sync_filesystem(sb, 1); 68 return __sync_filesystem(sb, 1, start);
67} 69}
68EXPORT_SYMBOL_GPL(sync_filesystem); 70EXPORT_SYMBOL_GPL(sync_filesystem);
69 71
70static void sync_inodes_one_sb(struct super_block *sb, void *arg) 72static void sync_inodes_one_sb(struct super_block *sb, void *arg)
71{ 73{
72 if (!(sb->s_flags & MS_RDONLY)) 74 if (!(sb->s_flags & MS_RDONLY))
73 sync_inodes_sb(sb); 75 sync_inodes_sb(sb, *((unsigned long *)arg));
74} 76}
75 77
76static void sync_fs_one_sb(struct super_block *sb, void *arg) 78static void sync_fs_one_sb(struct super_block *sb, void *arg)
@@ -102,9 +104,10 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
102SYSCALL_DEFINE0(sync) 104SYSCALL_DEFINE0(sync)
103{ 105{
104 int nowait = 0, wait = 1; 106 int nowait = 0, wait = 1;
107 unsigned long start = jiffies;
105 108
106 wakeup_flusher_threads(0, WB_REASON_SYNC); 109 wakeup_flusher_threads(0, WB_REASON_SYNC);
107 iterate_supers(sync_inodes_one_sb, NULL); 110 iterate_supers(sync_inodes_one_sb, &start);
108 iterate_supers(sync_fs_one_sb, &nowait); 111 iterate_supers(sync_fs_one_sb, &nowait);
109 iterate_supers(sync_fs_one_sb, &wait); 112 iterate_supers(sync_fs_one_sb, &wait);
110 iterate_bdevs(fdatawrite_one_bdev, NULL); 113 iterate_bdevs(fdatawrite_one_bdev, NULL);
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 15188cc99449..8968f5036fa1 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -918,7 +918,7 @@ xfs_flush_inodes(
918 struct super_block *sb = mp->m_super; 918 struct super_block *sb = mp->m_super;
919 919
920 if (down_read_trylock(&sb->s_umount)) { 920 if (down_read_trylock(&sb->s_umount)) {
921 sync_inodes_sb(sb); 921 sync_inodes_sb(sb, jiffies);
922 up_read(&sb->s_umount); 922 up_read(&sb->s_umount);
923 } 923 }
924} 924}
diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h
index 71c778033f57..998d4d544f18 100644
--- a/include/asm-generic/bitops/find.h
+++ b/include/asm-generic/bitops/find.h
@@ -7,6 +7,9 @@
7 * @addr: The address to base the search on 7 * @addr: The address to base the search on
8 * @offset: The bitnumber to start searching at 8 * @offset: The bitnumber to start searching at
9 * @size: The bitmap size in bits 9 * @size: The bitmap size in bits
10 *
11 * Returns the bit number for the next set bit
12 * If no bits are set, returns @size.
10 */ 13 */
11extern unsigned long find_next_bit(const unsigned long *addr, unsigned long 14extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
12 size, unsigned long offset); 15 size, unsigned long offset);
@@ -18,6 +21,9 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
18 * @addr: The address to base the search on 21 * @addr: The address to base the search on
19 * @offset: The bitnumber to start searching at 22 * @offset: The bitnumber to start searching at
20 * @size: The bitmap size in bits 23 * @size: The bitmap size in bits
24 *
25 * Returns the bit number of the next zero bit
26 * If no bits are zero, returns @size.
21 */ 27 */
22extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned 28extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
23 long size, unsigned long offset); 29 long size, unsigned long offset);
@@ -28,9 +34,10 @@ extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
28/** 34/**
29 * find_first_bit - find the first set bit in a memory region 35 * find_first_bit - find the first set bit in a memory region
30 * @addr: The address to start the search at 36 * @addr: The address to start the search at
31 * @size: The maximum size to search 37 * @size: The maximum number of bits to search
32 * 38 *
33 * Returns the bit number of the first set bit. 39 * Returns the bit number of the first set bit.
40 * If no bits are set, returns @size.
34 */ 41 */
35extern unsigned long find_first_bit(const unsigned long *addr, 42extern unsigned long find_first_bit(const unsigned long *addr,
36 unsigned long size); 43 unsigned long size);
@@ -38,9 +45,10 @@ extern unsigned long find_first_bit(const unsigned long *addr,
38/** 45/**
39 * find_first_zero_bit - find the first cleared bit in a memory region 46 * find_first_zero_bit - find the first cleared bit in a memory region
40 * @addr: The address to start the search at 47 * @addr: The address to start the search at
41 * @size: The maximum size to search 48 * @size: The maximum number of bits to search
42 * 49 *
43 * Returns the bit number of the first cleared bit. 50 * Returns the bit number of the first cleared bit.
51 * If no bits are zero, returns @size.
44 */ 52 */
45extern unsigned long find_first_zero_bit(const unsigned long *addr, 53extern unsigned long find_first_zero_bit(const unsigned long *addr,
46 unsigned long size); 54 unsigned long size);
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 790d3305a5a7..fd8bf3219ef7 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -100,9 +100,6 @@ extern void setup_new_exec(struct linux_binprm * bprm);
100extern void would_dump(struct linux_binprm *, struct file *); 100extern void would_dump(struct linux_binprm *, struct file *);
101 101
102extern int suid_dumpable; 102extern int suid_dumpable;
103#define SUID_DUMP_DISABLE 0 /* No setuid dumping */
104#define SUID_DUMP_USER 1 /* Dump as user of process */
105#define SUID_DUMP_ROOT 2 /* Dump as root */
106 103
107/* Stack area protections */ 104/* Stack area protections */
108#define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */ 105#define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 78cdf51ff5ba..eb8a49d75ab3 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -41,14 +41,14 @@
41 COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__) 41 COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
42 42
43#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ 43#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
44 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ 44 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
45 __attribute__((alias(__stringify(compat_SyS##name)))); \
45 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ 46 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
46 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\ 47 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
47 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\ 48 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
48 { \ 49 { \
49 return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ 50 return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
50 } \ 51 } \
51 SYSCALL_ALIAS(compat_sys##name, compat_SyS##name); \
52 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) 52 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
53 53
54#ifndef compat_user_stack_pointer 54#ifndef compat_user_stack_pointer
diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
index f8d41cb1cbe0..1eda33d7cb10 100644
--- a/include/linux/genalloc.h
+++ b/include/linux/genalloc.h
@@ -94,6 +94,8 @@ static inline int gen_pool_add(struct gen_pool *pool, unsigned long addr,
94} 94}
95extern void gen_pool_destroy(struct gen_pool *); 95extern void gen_pool_destroy(struct gen_pool *);
96extern unsigned long gen_pool_alloc(struct gen_pool *, size_t); 96extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
97extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size,
98 dma_addr_t *dma);
97extern void gen_pool_free(struct gen_pool *, unsigned long, size_t); 99extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
98extern void gen_pool_for_each_chunk(struct gen_pool *, 100extern void gen_pool_for_each_chunk(struct gen_pool *,
99 void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *); 101 void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
diff --git a/include/linux/init.h b/include/linux/init.h
index f1c27a71d03c..8e68a64bfe00 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -26,8 +26,8 @@
26 * extern int initialize_foobar_device(int, int, int) __init; 26 * extern int initialize_foobar_device(int, int, int) __init;
27 * 27 *
28 * For initialized data: 28 * For initialized data:
29 * You should insert __initdata between the variable name and equal 29 * You should insert __initdata or __initconst between the variable name
30 * sign followed by value, e.g.: 30 * and equal sign followed by value, e.g.:
31 * 31 *
32 * static int init_variable __initdata = 0; 32 * static int init_variable __initdata = 0;
33 * static const char linux_logo[] __initconst = { 0x32, 0x36, ... }; 33 * static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
@@ -35,8 +35,6 @@
35 * Don't forget to initialize data not at file scope, i.e. within a function, 35 * Don't forget to initialize data not at file scope, i.e. within a function,
36 * as gcc otherwise puts the data into the bss section and not into the init 36 * as gcc otherwise puts the data into the bss section and not into the init
37 * section. 37 * section.
38 *
39 * Also note, that this data cannot be "const".
40 */ 38 */
41 39
42/* These are for everybody (although not all archs will actually 40/* These are for everybody (although not all archs will actually
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index a5079072da66..cf08540d6204 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -132,14 +132,14 @@ static __always_inline void jump_label_init(void)
132 132
133static __always_inline bool static_key_false(struct static_key *key) 133static __always_inline bool static_key_false(struct static_key *key)
134{ 134{
135 if (unlikely(atomic_read(&key->enabled)) > 0) 135 if (unlikely(atomic_read(&key->enabled) > 0))
136 return true; 136 return true;
137 return false; 137 return false;
138} 138}
139 139
140static __always_inline bool static_key_true(struct static_key *key) 140static __always_inline bool static_key_true(struct static_key *key)
141{ 141{
142 if (likely(atomic_read(&key->enabled)) > 0) 142 if (likely(atomic_read(&key->enabled) > 0))
143 return true; 143 return true;
144 return false; 144 return false;
145} 145}
diff --git a/include/linux/kernel-page-flags.h b/include/linux/kernel-page-flags.h
index 546eb6a76934..f65ce09784f1 100644
--- a/include/linux/kernel-page-flags.h
+++ b/include/linux/kernel-page-flags.h
@@ -15,5 +15,6 @@
15#define KPF_OWNER_PRIVATE 37 15#define KPF_OWNER_PRIVATE 37
16#define KPF_ARCH 38 16#define KPF_ARCH 38
17#define KPF_UNCACHED 39 17#define KPF_UNCACHED 39
18#define KPF_SOFTDIRTY 40
18 19
19#endif /* LINUX_KERNEL_PAGE_FLAGS_H */ 20#endif /* LINUX_KERNEL_PAGE_FLAGS_H */
diff --git a/include/linux/list.h b/include/linux/list.h
index f4d8a2f12a33..ef9594171062 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -362,6 +362,17 @@ static inline void list_splice_tail_init(struct list_head *list,
362 list_entry((ptr)->next, type, member) 362 list_entry((ptr)->next, type, member)
363 363
364/** 364/**
365 * list_last_entry - get the last element from a list
366 * @ptr: the list head to take the element from.
367 * @type: the type of the struct this is embedded in.
368 * @member: the name of the list_struct within the struct.
369 *
370 * Note, that list is expected to be not empty.
371 */
372#define list_last_entry(ptr, type, member) \
373 list_entry((ptr)->prev, type, member)
374
375/**
365 * list_first_entry_or_null - get the first element from a list 376 * list_first_entry_or_null - get the first element from a list
366 * @ptr: the list head to take the element from. 377 * @ptr: the list head to take the element from.
367 * @type: the type of the struct this is embedded in. 378 * @type: the type of the struct this is embedded in.
@@ -373,6 +384,22 @@ static inline void list_splice_tail_init(struct list_head *list,
373 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) 384 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
374 385
375/** 386/**
387 * list_next_entry - get the next element in list
388 * @pos: the type * to cursor
389 * @member: the name of the list_struct within the struct.
390 */
391#define list_next_entry(pos, member) \
392 list_entry((pos)->member.next, typeof(*(pos)), member)
393
394/**
395 * list_prev_entry - get the prev element in list
396 * @pos: the type * to cursor
397 * @member: the name of the list_struct within the struct.
398 */
399#define list_prev_entry(pos, member) \
400 list_entry((pos)->member.prev, typeof(*(pos)), member)
401
402/**
376 * list_for_each - iterate over a list 403 * list_for_each - iterate over a list
377 * @pos: the &struct list_head to use as a loop cursor. 404 * @pos: the &struct list_head to use as a loop cursor.
378 * @head: the head for your list. 405 * @head: the head for your list.
@@ -416,9 +443,9 @@ static inline void list_splice_tail_init(struct list_head *list,
416 * @member: the name of the list_struct within the struct. 443 * @member: the name of the list_struct within the struct.
417 */ 444 */
418#define list_for_each_entry(pos, head, member) \ 445#define list_for_each_entry(pos, head, member) \
419 for (pos = list_entry((head)->next, typeof(*pos), member); \ 446 for (pos = list_first_entry(head, typeof(*pos), member); \
420 &pos->member != (head); \ 447 &pos->member != (head); \
421 pos = list_entry(pos->member.next, typeof(*pos), member)) 448 pos = list_next_entry(pos, member))
422 449
423/** 450/**
424 * list_for_each_entry_reverse - iterate backwards over list of given type. 451 * list_for_each_entry_reverse - iterate backwards over list of given type.
@@ -427,9 +454,9 @@ static inline void list_splice_tail_init(struct list_head *list,
427 * @member: the name of the list_struct within the struct. 454 * @member: the name of the list_struct within the struct.
428 */ 455 */
429#define list_for_each_entry_reverse(pos, head, member) \ 456#define list_for_each_entry_reverse(pos, head, member) \
430 for (pos = list_entry((head)->prev, typeof(*pos), member); \ 457 for (pos = list_last_entry(head, typeof(*pos), member); \
431 &pos->member != (head); \ 458 &pos->member != (head); \
432 pos = list_entry(pos->member.prev, typeof(*pos), member)) 459 pos = list_prev_entry(pos, member))
433 460
434/** 461/**
435 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() 462 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
@@ -452,9 +479,9 @@ static inline void list_splice_tail_init(struct list_head *list,
452 * the current position. 479 * the current position.
453 */ 480 */
454#define list_for_each_entry_continue(pos, head, member) \ 481#define list_for_each_entry_continue(pos, head, member) \
455 for (pos = list_entry(pos->member.next, typeof(*pos), member); \ 482 for (pos = list_next_entry(pos, member); \
456 &pos->member != (head); \ 483 &pos->member != (head); \
457 pos = list_entry(pos->member.next, typeof(*pos), member)) 484 pos = list_next_entry(pos, member))
458 485
459/** 486/**
460 * list_for_each_entry_continue_reverse - iterate backwards from the given point 487 * list_for_each_entry_continue_reverse - iterate backwards from the given point
@@ -466,9 +493,9 @@ static inline void list_splice_tail_init(struct list_head *list,
466 * the current position. 493 * the current position.
467 */ 494 */
468#define list_for_each_entry_continue_reverse(pos, head, member) \ 495#define list_for_each_entry_continue_reverse(pos, head, member) \
469 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ 496 for (pos = list_prev_entry(pos, member); \
470 &pos->member != (head); \ 497 &pos->member != (head); \
471 pos = list_entry(pos->member.prev, typeof(*pos), member)) 498 pos = list_prev_entry(pos, member))
472 499
473/** 500/**
474 * list_for_each_entry_from - iterate over list of given type from the current point 501 * list_for_each_entry_from - iterate over list of given type from the current point
@@ -479,8 +506,8 @@ static inline void list_splice_tail_init(struct list_head *list,
479 * Iterate over list of given type, continuing from current position. 506 * Iterate over list of given type, continuing from current position.
480 */ 507 */
481#define list_for_each_entry_from(pos, head, member) \ 508#define list_for_each_entry_from(pos, head, member) \
482 for (; &pos->member != (head); \ 509 for (; &pos->member != (head); \
483 pos = list_entry(pos->member.next, typeof(*pos), member)) 510 pos = list_next_entry(pos, member))
484 511
485/** 512/**
486 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 513 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@@ -490,10 +517,10 @@ static inline void list_splice_tail_init(struct list_head *list,
490 * @member: the name of the list_struct within the struct. 517 * @member: the name of the list_struct within the struct.
491 */ 518 */
492#define list_for_each_entry_safe(pos, n, head, member) \ 519#define list_for_each_entry_safe(pos, n, head, member) \
493 for (pos = list_entry((head)->next, typeof(*pos), member), \ 520 for (pos = list_first_entry(head, typeof(*pos), member), \
494 n = list_entry(pos->member.next, typeof(*pos), member); \ 521 n = list_next_entry(pos, member); \
495 &pos->member != (head); \ 522 &pos->member != (head); \
496 pos = n, n = list_entry(n->member.next, typeof(*n), member)) 523 pos = n, n = list_next_entry(n, member))
497 524
498/** 525/**
499 * list_for_each_entry_safe_continue - continue list iteration safe against removal 526 * list_for_each_entry_safe_continue - continue list iteration safe against removal
@@ -506,10 +533,10 @@ static inline void list_splice_tail_init(struct list_head *list,
506 * safe against removal of list entry. 533 * safe against removal of list entry.
507 */ 534 */
508#define list_for_each_entry_safe_continue(pos, n, head, member) \ 535#define list_for_each_entry_safe_continue(pos, n, head, member) \
509 for (pos = list_entry(pos->member.next, typeof(*pos), member), \ 536 for (pos = list_next_entry(pos, member), \
510 n = list_entry(pos->member.next, typeof(*pos), member); \ 537 n = list_next_entry(pos, member); \
511 &pos->member != (head); \ 538 &pos->member != (head); \
512 pos = n, n = list_entry(n->member.next, typeof(*n), member)) 539 pos = n, n = list_next_entry(n, member))
513 540
514/** 541/**
515 * list_for_each_entry_safe_from - iterate over list from current point safe against removal 542 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
@@ -522,9 +549,9 @@ static inline void list_splice_tail_init(struct list_head *list,
522 * removal of list entry. 549 * removal of list entry.
523 */ 550 */
524#define list_for_each_entry_safe_from(pos, n, head, member) \ 551#define list_for_each_entry_safe_from(pos, n, head, member) \
525 for (n = list_entry(pos->member.next, typeof(*pos), member); \ 552 for (n = list_next_entry(pos, member); \
526 &pos->member != (head); \ 553 &pos->member != (head); \
527 pos = n, n = list_entry(n->member.next, typeof(*n), member)) 554 pos = n, n = list_next_entry(n, member))
528 555
529/** 556/**
530 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal 557 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
@@ -537,10 +564,10 @@ static inline void list_splice_tail_init(struct list_head *list,
537 * of list entry. 564 * of list entry.
538 */ 565 */
539#define list_for_each_entry_safe_reverse(pos, n, head, member) \ 566#define list_for_each_entry_safe_reverse(pos, n, head, member) \
540 for (pos = list_entry((head)->prev, typeof(*pos), member), \ 567 for (pos = list_last_entry(head, typeof(*pos), member), \
541 n = list_entry(pos->member.prev, typeof(*pos), member); \ 568 n = list_prev_entry(pos, member); \
542 &pos->member != (head); \ 569 &pos->member != (head); \
543 pos = n, n = list_entry(n->member.prev, typeof(*n), member)) 570 pos = n, n = list_prev_entry(n, member))
544 571
545/** 572/**
546 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop 573 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
@@ -555,7 +582,7 @@ static inline void list_splice_tail_init(struct list_head *list,
555 * completing the current iteration of the loop body. 582 * completing the current iteration of the loop body.
556 */ 583 */
557#define list_safe_reset_next(pos, n, member) \ 584#define list_safe_reset_next(pos, n, member) \
558 n = list_entry(pos->member.next, typeof(*pos), member) 585 n = list_next_entry(pos, member)
559 586
560/* 587/*
561 * Double linked lists with a single pointer list head. 588 * Double linked lists with a single pointer list head.
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 31e95acddb4d..77c60e52939d 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -35,6 +35,7 @@ struct memblock_type {
35}; 35};
36 36
37struct memblock { 37struct memblock {
38 bool bottom_up; /* is bottom up direction? */
38 phys_addr_t current_limit; 39 phys_addr_t current_limit;
39 struct memblock_type memory; 40 struct memblock_type memory;
40 struct memblock_type reserved; 41 struct memblock_type reserved;
@@ -148,6 +149,29 @@ phys_addr_t memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid)
148 149
149phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align); 150phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align);
150 151
152#ifdef CONFIG_MOVABLE_NODE
153/*
154 * Set the allocation direction to bottom-up or top-down.
155 */
156static inline void memblock_set_bottom_up(bool enable)
157{
158 memblock.bottom_up = enable;
159}
160
161/*
162 * Check if the allocation direction is bottom-up or not.
163 * if this is true, that said, memblock will allocate memory
164 * in bottom-up direction.
165 */
166static inline bool memblock_bottom_up(void)
167{
168 return memblock.bottom_up;
169}
170#else
171static inline void memblock_set_bottom_up(bool enable) {}
172static inline bool memblock_bottom_up(void) { return false; }
173#endif
174
151/* Flags for memblock_alloc_base() amd __memblock_alloc_base() */ 175/* Flags for memblock_alloc_base() amd __memblock_alloc_base() */
152#define MEMBLOCK_ALLOC_ANYWHERE (~(phys_addr_t)0) 176#define MEMBLOCK_ALLOC_ANYWHERE (~(phys_addr_t)0)
153#define MEMBLOCK_ALLOC_ACCESSIBLE 0 177#define MEMBLOCK_ALLOC_ACCESSIBLE 0
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index dd38e62b84d2..4ca3d951fe91 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -94,6 +94,8 @@ extern void __online_page_set_limits(struct page *page);
94extern void __online_page_increment_counters(struct page *page); 94extern void __online_page_increment_counters(struct page *page);
95extern void __online_page_free(struct page *page); 95extern void __online_page_free(struct page *page);
96 96
97extern int try_online_node(int nid);
98
97#ifdef CONFIG_MEMORY_HOTREMOVE 99#ifdef CONFIG_MEMORY_HOTREMOVE
98extern bool is_pageblock_removable_nolock(struct page *page); 100extern bool is_pageblock_removable_nolock(struct page *page);
99extern int arch_remove_memory(u64 start, u64 size); 101extern int arch_remove_memory(u64 start, u64 size);
@@ -225,6 +227,11 @@ static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
225{ 227{
226} 228}
227 229
230static inline int try_online_node(int nid)
231{
232 return 0;
233}
234
228static inline void lock_memory_hotplug(void) {} 235static inline void lock_memory_hotplug(void) {}
229static inline void unlock_memory_hotplug(void) {} 236static inline void unlock_memory_hotplug(void) {}
230 237
@@ -256,14 +263,12 @@ static inline void remove_memory(int nid, u64 start, u64 size) {}
256 263
257extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, 264extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
258 void *arg, int (*func)(struct memory_block *, void *)); 265 void *arg, int (*func)(struct memory_block *, void *));
259extern int mem_online_node(int nid);
260extern int add_memory(int nid, u64 start, u64 size); 266extern int add_memory(int nid, u64 start, u64 size);
261extern int arch_add_memory(int nid, u64 start, u64 size); 267extern int arch_add_memory(int nid, u64 start, u64 size);
262extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); 268extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
263extern bool is_memblock_offlined(struct memory_block *mem); 269extern bool is_memblock_offlined(struct memory_block *mem);
264extern void remove_memory(int nid, u64 start, u64 size); 270extern void remove_memory(int nid, u64 start, u64 size);
265extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, 271extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn);
266 int nr_pages);
267extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); 272extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
268extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, 273extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
269 unsigned long pnum); 274 unsigned long pnum);
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index ea4d2495c646..9fe426b30a41 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -169,7 +169,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
169extern int mpol_parse_str(char *str, struct mempolicy **mpol); 169extern int mpol_parse_str(char *str, struct mempolicy **mpol);
170#endif 170#endif
171 171
172extern int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol); 172extern void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol);
173 173
174/* Check if a vma is migratable */ 174/* Check if a vma is migratable */
175static inline int vma_migratable(struct vm_area_struct *vma) 175static inline int vma_migratable(struct vm_area_struct *vma)
@@ -307,9 +307,8 @@ static inline int mpol_parse_str(char *str, struct mempolicy **mpol)
307} 307}
308#endif 308#endif
309 309
310static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) 310static inline void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
311{ 311{
312 return 0;
313} 312}
314 313
315static inline int mpol_misplaced(struct page *page, struct vm_area_struct *vma, 314static inline int mpol_misplaced(struct page *page, struct vm_area_struct *vma,
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 378ae8a04c6a..2d0c9071bcfb 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -51,6 +51,7 @@ struct sec_pmic_dev {
51 int ono; 51 int ono;
52 int type; 52 int type;
53 bool wakeup; 53 bool wakeup;
54 bool wtsr_smpl;
54}; 55};
55 56
56int sec_irq_init(struct sec_pmic_dev *sec_pmic); 57int sec_irq_init(struct sec_pmic_dev *sec_pmic);
diff --git a/include/linux/mfd/samsung/rtc.h b/include/linux/mfd/samsung/rtc.h
index 71597e20cddb..94b7cd6d8891 100644
--- a/include/linux/mfd/samsung/rtc.h
+++ b/include/linux/mfd/samsung/rtc.h
@@ -62,6 +62,11 @@ enum sec_rtc_reg {
62/* RTC Update Register1 */ 62/* RTC Update Register1 */
63#define RTC_UDR_SHIFT 0 63#define RTC_UDR_SHIFT 0
64#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT) 64#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)
65#define RTC_TCON_SHIFT 1
66#define RTC_TCON_MASK (1 << RTC_TCON_SHIFT)
67#define RTC_TIME_EN_SHIFT 3
68#define RTC_TIME_EN_MASK (1 << RTC_TIME_EN_SHIFT)
69
65/* RTC Hour register */ 70/* RTC Hour register */
66#define HOUR_PM_SHIFT 6 71#define HOUR_PM_SHIFT 6
67#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT) 72#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT)
@@ -69,6 +74,12 @@ enum sec_rtc_reg {
69#define ALARM_ENABLE_SHIFT 7 74#define ALARM_ENABLE_SHIFT 7
70#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT) 75#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT)
71 76
77#define SMPL_ENABLE_SHIFT 7
78#define SMPL_ENABLE_MASK (1 << SMPL_ENABLE_SHIFT)
79
80#define WTSR_ENABLE_SHIFT 6
81#define WTSR_ENABLE_MASK (1 << WTSR_ENABLE_SHIFT)
82
72enum { 83enum {
73 RTC_SEC = 0, 84 RTC_SEC = 0,
74 RTC_MIN, 85 RTC_MIN,
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8aa4006b9636..42a35d94b82c 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -50,6 +50,10 @@ extern int sysctl_legacy_va_layout;
50#include <asm/pgtable.h> 50#include <asm/pgtable.h>
51#include <asm/processor.h> 51#include <asm/processor.h>
52 52
53#ifndef __pa_symbol
54#define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
55#endif
56
53extern unsigned long sysctl_user_reserve_kbytes; 57extern unsigned long sysctl_user_reserve_kbytes;
54extern unsigned long sysctl_admin_reserve_kbytes; 58extern unsigned long sysctl_admin_reserve_kbytes;
55 59
diff --git a/include/linux/mman.h b/include/linux/mman.h
index 92dc257251e4..7f7f8dae4b1d 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -87,4 +87,6 @@ calc_vm_flag_bits(unsigned long flags)
87 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) | 87 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
88 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ); 88 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
89} 89}
90
91unsigned long vm_commit_limit(void);
90#endif /* _LINUX_MMAN_H */ 92#endif /* _LINUX_MMAN_H */
diff --git a/include/linux/msg.h b/include/linux/msg.h
index 391af8d11cce..e21f9d44307f 100644
--- a/include/linux/msg.h
+++ b/include/linux/msg.h
@@ -6,9 +6,9 @@
6 6
7/* one msg_msg structure for each message */ 7/* one msg_msg structure for each message */
8struct msg_msg { 8struct msg_msg {
9 struct list_head m_list; 9 struct list_head m_list;
10 long m_type; 10 long m_type;
11 int m_ts; /* message text size */ 11 size_t m_ts; /* message text size */
12 struct msg_msgseg* next; 12 struct msg_msgseg* next;
13 void *security; 13 void *security;
14 /* the actual message follows immediately */ 14 /* the actual message follows immediately */
diff --git a/include/linux/oom.h b/include/linux/oom.h
index da60007075b5..4cd62677feb9 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -82,6 +82,11 @@ static inline void oom_killer_enable(void)
82 oom_killer_disabled = false; 82 oom_killer_disabled = false;
83} 83}
84 84
85static inline bool oom_gfp_allowed(gfp_t gfp_mask)
86{
87 return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY);
88}
89
85extern struct task_struct *find_lock_task_mm(struct task_struct *p); 90extern struct task_struct *find_lock_task_mm(struct task_struct *p);
86 91
87/* sysctls */ 92/* sysctls */
diff --git a/include/linux/platform_data/lm3630_bl.h b/include/linux/platform_data/lm3630_bl.h
deleted file mode 100644
index 9176dd3f2d63..000000000000
--- a/include/linux/platform_data/lm3630_bl.h
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2* Simple driver for Texas Instruments LM3630 LED Flash driver chip
3* Copyright (C) 2012 Texas Instruments
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 2 as
7* published by the Free Software Foundation.
8*
9*/
10
11#ifndef __LINUX_LM3630_H
12#define __LINUX_LM3630_H
13
14#define LM3630_NAME "lm3630_bl"
15
16enum lm3630_pwm_ctrl {
17 PWM_CTRL_DISABLE = 0,
18 PWM_CTRL_BANK_A,
19 PWM_CTRL_BANK_B,
20 PWM_CTRL_BANK_ALL,
21};
22
23enum lm3630_pwm_active {
24 PWM_ACTIVE_HIGH = 0,
25 PWM_ACTIVE_LOW,
26};
27
28enum lm3630_bank_a_ctrl {
29 BANK_A_CTRL_DISABLE = 0x0,
30 BANK_A_CTRL_LED1 = 0x4,
31 BANK_A_CTRL_LED2 = 0x1,
32 BANK_A_CTRL_ALL = 0x5,
33};
34
35enum lm3630_bank_b_ctrl {
36 BANK_B_CTRL_DISABLE = 0,
37 BANK_B_CTRL_LED2,
38};
39
40struct lm3630_platform_data {
41
42 /* maximum brightness */
43 int max_brt_led1;
44 int max_brt_led2;
45
46 /* initial on brightness */
47 int init_brt_led1;
48 int init_brt_led2;
49 enum lm3630_pwm_ctrl pwm_ctrl;
50 enum lm3630_pwm_active pwm_active;
51 enum lm3630_bank_a_ctrl bank_a_ctrl;
52 enum lm3630_bank_b_ctrl bank_b_ctrl;
53 unsigned int pwm_period;
54 void (*pwm_set_intensity) (int brightness, int max_brightness);
55};
56
57#endif /* __LINUX_LM3630_H */
diff --git a/include/linux/platform_data/lm3630a_bl.h b/include/linux/platform_data/lm3630a_bl.h
new file mode 100644
index 000000000000..7538e38e270b
--- /dev/null
+++ b/include/linux/platform_data/lm3630a_bl.h
@@ -0,0 +1,65 @@
1/*
2* Simple driver for Texas Instruments LM3630A LED Flash driver chip
3* Copyright (C) 2012 Texas Instruments
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 2 as
7* published by the Free Software Foundation.
8*
9*/
10
11#ifndef __LINUX_LM3630A_H
12#define __LINUX_LM3630A_H
13
14#define LM3630A_NAME "lm3630a_bl"
15
16enum lm3630a_pwm_ctrl {
17 LM3630A_PWM_DISABLE = 0x00,
18 LM3630A_PWM_BANK_A,
19 LM3630A_PWM_BANK_B,
20 LM3630A_PWM_BANK_ALL,
21 LM3630A_PWM_BANK_A_ACT_LOW = 0x05,
22 LM3630A_PWM_BANK_B_ACT_LOW,
23 LM3630A_PWM_BANK_ALL_ACT_LOW,
24};
25
26enum lm3630a_leda_ctrl {
27 LM3630A_LEDA_DISABLE = 0x00,
28 LM3630A_LEDA_ENABLE = 0x04,
29 LM3630A_LEDA_ENABLE_LINEAR = 0x14,
30};
31
32enum lm3630a_ledb_ctrl {
33 LM3630A_LEDB_DISABLE = 0x00,
34 LM3630A_LEDB_ON_A = 0x01,
35 LM3630A_LEDB_ENABLE = 0x02,
36 LM3630A_LEDB_ENABLE_LINEAR = 0x0A,
37};
38
39#define LM3630A_MAX_BRIGHTNESS 255
40/*
41 *@leda_init_brt : led a init brightness. 4~255
42 *@leda_max_brt : led a max brightness. 4~255
43 *@leda_ctrl : led a disable, enable linear, enable exponential
44 *@ledb_init_brt : led b init brightness. 4~255
45 *@ledb_max_brt : led b max brightness. 4~255
46 *@ledb_ctrl : led b disable, enable linear, enable exponential
47 *@pwm_period : pwm period
48 *@pwm_ctrl : pwm disable, bank a or b, active high or low
49 */
50struct lm3630a_platform_data {
51
52 /* led a config. */
53 int leda_init_brt;
54 int leda_max_brt;
55 enum lm3630a_leda_ctrl leda_ctrl;
56 /* led b config. */
57 int ledb_init_brt;
58 int ledb_max_brt;
59 enum lm3630a_ledb_ctrl ledb_ctrl;
60 /* pwm config. */
61 unsigned int pwm_period;
62 enum lm3630a_pwm_ctrl pwm_ctrl;
63};
64
65#endif /* __LINUX_LM3630A_H */
diff --git a/include/linux/platform_data/lp855x.h b/include/linux/platform_data/lp855x.h
index ea3200527dd3..1b2ba24e4e03 100644
--- a/include/linux/platform_data/lp855x.h
+++ b/include/linux/platform_data/lp855x.h
@@ -40,6 +40,17 @@
40#define LP8553_PWM_CONFIG LP8550_PWM_CONFIG 40#define LP8553_PWM_CONFIG LP8550_PWM_CONFIG
41#define LP8553_I2C_CONFIG LP8550_I2C_CONFIG 41#define LP8553_I2C_CONFIG LP8550_I2C_CONFIG
42 42
43/* CONFIG register - LP8555 */
44#define LP8555_PWM_STANDBY BIT(7)
45#define LP8555_PWM_FILTER BIT(6)
46#define LP8555_RELOAD_EPROM BIT(3) /* use it if EPROMs should be reset
47 when the backlight turns on */
48#define LP8555_OFF_OPENLEDS BIT(2)
49#define LP8555_PWM_CONFIG LP8555_PWM_ONLY
50#define LP8555_I2C_CONFIG LP8555_I2C_ONLY
51#define LP8555_COMB1_CONFIG LP8555_COMBINED1
52#define LP8555_COMB2_CONFIG LP8555_COMBINED2
53
43/* DEVICE CONTROL register - LP8556 */ 54/* DEVICE CONTROL register - LP8556 */
44#define LP8556_PWM_CONFIG (LP8556_PWM_ONLY << BRT_MODE_SHFT) 55#define LP8556_PWM_CONFIG (LP8556_PWM_ONLY << BRT_MODE_SHFT)
45#define LP8556_COMB1_CONFIG (LP8556_COMBINED1 << BRT_MODE_SHFT) 56#define LP8556_COMB1_CONFIG (LP8556_COMBINED1 << BRT_MODE_SHFT)
@@ -65,6 +76,7 @@ enum lp855x_chip_id {
65 LP8551, 76 LP8551,
66 LP8552, 77 LP8552,
67 LP8553, 78 LP8553,
79 LP8555,
68 LP8556, 80 LP8556,
69 LP8557, 81 LP8557,
70}; 82};
@@ -89,6 +101,13 @@ enum lp8553_brighntess_source {
89 LP8553_I2C_ONLY = LP8550_I2C_ONLY, 101 LP8553_I2C_ONLY = LP8550_I2C_ONLY,
90}; 102};
91 103
104enum lp8555_brightness_source {
105 LP8555_PWM_ONLY,
106 LP8555_I2C_ONLY,
107 LP8555_COMBINED1, /* Brightness register with shaped PWM */
108 LP8555_COMBINED2, /* PWM with shaped brightness register */
109};
110
92enum lp8556_brightness_source { 111enum lp8556_brightness_source {
93 LP8556_PWM_ONLY, 112 LP8556_PWM_ONLY,
94 LP8556_COMBINED1, /* pwm + i2c before the shaper block */ 113 LP8556_COMBINED1, /* pwm + i2c before the shaper block */
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index aa870a4ddf54..57e75ae9910f 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -85,6 +85,11 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
85 *rb_link = node; 85 *rb_link = node;
86} 86}
87 87
88#define rb_entry_safe(ptr, type, member) \
89 ({ typeof(ptr) ____ptr = (ptr); \
90 ____ptr ? rb_entry(____ptr, type, member) : NULL; \
91 })
92
88/** 93/**
89 * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of 94 * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of
90 * given type safe against removal of rb_node entry 95 * given type safe against removal of rb_node entry
@@ -95,12 +100,9 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
95 * @field: the name of the rb_node field within 'type'. 100 * @field: the name of the rb_node field within 'type'.
96 */ 101 */
97#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ 102#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \
98 for (pos = rb_entry(rb_first_postorder(root), typeof(*pos), field),\ 103 for (pos = rb_entry_safe(rb_first_postorder(root), typeof(*pos), field); \
99 n = rb_entry(rb_next_postorder(&pos->field), \ 104 pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \
100 typeof(*pos), field); \ 105 typeof(*pos), field); 1; }); \
101 &pos->field; \ 106 pos = n)
102 pos = n, \
103 n = rb_entry(rb_next_postorder(&pos->field), \
104 typeof(*pos), field))
105 107
106#endif /* _LINUX_RBTREE_H */ 108#endif /* _LINUX_RBTREE_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 045b0d227846..f7efc8604652 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -323,6 +323,10 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
323extern void set_dumpable(struct mm_struct *mm, int value); 323extern void set_dumpable(struct mm_struct *mm, int value);
324extern int get_dumpable(struct mm_struct *mm); 324extern int get_dumpable(struct mm_struct *mm);
325 325
326#define SUID_DUMP_DISABLE 0 /* No setuid dumping */
327#define SUID_DUMP_USER 1 /* Dump as user of process */
328#define SUID_DUMP_ROOT 2 /* Dump as root */
329
326/* mm flags */ 330/* mm flags */
327/* dumpable bits */ 331/* dumpable bits */
328#define MMF_DUMPABLE 0 /* core dump is permitted */ 332#define MMF_DUMPABLE 0 /* core dump is permitted */
@@ -1062,15 +1066,6 @@ struct task_struct {
1062 struct hlist_head preempt_notifiers; 1066 struct hlist_head preempt_notifiers;
1063#endif 1067#endif
1064 1068
1065 /*
1066 * fpu_counter contains the number of consecutive context switches
1067 * that the FPU is used. If this is over a threshold, the lazy fpu
1068 * saving becomes unlazy to save the trap. This is an unsigned char
1069 * so that after 256 times the counter wraps and the behavior turns
1070 * lazy again; this to deal with bursty apps that only use FPU for
1071 * a short time
1072 */
1073 unsigned char fpu_counter;
1074#ifdef CONFIG_BLK_DEV_IO_TRACE 1069#ifdef CONFIG_BLK_DEV_IO_TRACE
1075 unsigned int btrace_seq; 1070 unsigned int btrace_seq;
1076#endif 1071#endif
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 7fac04e7ff6e..c27f846f6b71 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -184,7 +184,8 @@ extern struct trace_event_functions exit_syscall_print_funcs;
184 184
185#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__) 185#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
186#define __SYSCALL_DEFINEx(x, name, ...) \ 186#define __SYSCALL_DEFINEx(x, name, ...) \
187 asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ 187 asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
188 __attribute__((alias(__stringify(SyS##name)))); \
188 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ 189 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
189 asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ 190 asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
190 asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ 191 asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
@@ -194,7 +195,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;
194 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ 195 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \
195 return ret; \ 196 return ret; \
196 } \ 197 } \
197 SYSCALL_ALIAS(sys##name, SyS##name); \
198 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) 198 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
199 199
200asmlinkage long sys_time(time_t __user *tloc); 200asmlinkage long sys_time(time_t __user *tloc);
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 1855f0a22add..c557c6d096de 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -39,6 +39,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
39 PAGEOUTRUN, ALLOCSTALL, PGROTATED, 39 PAGEOUTRUN, ALLOCSTALL, PGROTATED,
40#ifdef CONFIG_NUMA_BALANCING 40#ifdef CONFIG_NUMA_BALANCING
41 NUMA_PTE_UPDATES, 41 NUMA_PTE_UPDATES,
42 NUMA_HUGE_PTE_UPDATES,
42 NUMA_HINT_FAULTS, 43 NUMA_HINT_FAULTS,
43 NUMA_HINT_FAULTS_LOCAL, 44 NUMA_HINT_FAULTS_LOCAL,
44 NUMA_PAGE_MIGRATE, 45 NUMA_PAGE_MIGRATE,
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index 021b8a319b9e..fc0e4320aa6d 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -97,7 +97,7 @@ void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
97int try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason); 97int try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason);
98int try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr, 98int try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
99 enum wb_reason reason); 99 enum wb_reason reason);
100void sync_inodes_sb(struct super_block *); 100void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this);
101void wakeup_flusher_threads(long nr_pages, enum wb_reason reason); 101void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
102void inode_wait_for_writeback(struct inode *inode); 102void inode_wait_for_writeback(struct inode *inode);
103 103
diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h
index d0c613476620..aece1346ceb7 100644
--- a/include/trace/events/kmem.h
+++ b/include/trace/events/kmem.h
@@ -267,14 +267,12 @@ DEFINE_EVENT_PRINT(mm_page, mm_page_pcpu_drain,
267TRACE_EVENT(mm_page_alloc_extfrag, 267TRACE_EVENT(mm_page_alloc_extfrag,
268 268
269 TP_PROTO(struct page *page, 269 TP_PROTO(struct page *page,
270 int alloc_order, int fallback_order, 270 int alloc_order, int fallback_order,
271 int alloc_migratetype, int fallback_migratetype, 271 int alloc_migratetype, int fallback_migratetype, int new_migratetype),
272 int change_ownership),
273 272
274 TP_ARGS(page, 273 TP_ARGS(page,
275 alloc_order, fallback_order, 274 alloc_order, fallback_order,
276 alloc_migratetype, fallback_migratetype, 275 alloc_migratetype, fallback_migratetype, new_migratetype),
277 change_ownership),
278 276
279 TP_STRUCT__entry( 277 TP_STRUCT__entry(
280 __field( struct page *, page ) 278 __field( struct page *, page )
@@ -291,7 +289,7 @@ TRACE_EVENT(mm_page_alloc_extfrag,
291 __entry->fallback_order = fallback_order; 289 __entry->fallback_order = fallback_order;
292 __entry->alloc_migratetype = alloc_migratetype; 290 __entry->alloc_migratetype = alloc_migratetype;
293 __entry->fallback_migratetype = fallback_migratetype; 291 __entry->fallback_migratetype = fallback_migratetype;
294 __entry->change_ownership = change_ownership; 292 __entry->change_ownership = (new_migratetype == alloc_migratetype);
295 ), 293 ),
296 294
297 TP_printk("page=%p pfn=%lu alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d", 295 TP_printk("page=%p pfn=%lu alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d",
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index 464ea82e10db..c7bbbe794e65 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -287,11 +287,11 @@ TRACE_EVENT(writeback_queue_io,
287 __field(int, reason) 287 __field(int, reason)
288 ), 288 ),
289 TP_fast_assign( 289 TP_fast_assign(
290 unsigned long *older_than_this = work->older_than_this; 290 unsigned long older_than_this = work->older_than_this;
291 strncpy(__entry->name, dev_name(wb->bdi->dev), 32); 291 strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
292 __entry->older = older_than_this ? *older_than_this : 0; 292 __entry->older = older_than_this;
293 __entry->age = older_than_this ? 293 __entry->age = older_than_this ?
294 (jiffies - *older_than_this) * 1000 / HZ : -1; 294 (jiffies - older_than_this) * 1000 / HZ : -1;
295 __entry->moved = moved; 295 __entry->moved = moved;
296 __entry->reason = work->reason; 296 __entry->reason = work->reason;
297 ), 297 ),
diff --git a/include/uapi/asm-generic/errno.h b/include/uapi/asm-generic/errno.h
index a1331ce50445..1e1ea6e6e7a5 100644
--- a/include/uapi/asm-generic/errno.h
+++ b/include/uapi/asm-generic/errno.h
@@ -86,7 +86,7 @@
86#define EHOSTUNREACH 113 /* No route to host */ 86#define EHOSTUNREACH 113 /* No route to host */
87#define EALREADY 114 /* Operation already in progress */ 87#define EALREADY 114 /* Operation already in progress */
88#define EINPROGRESS 115 /* Operation now in progress */ 88#define EINPROGRESS 115 /* Operation now in progress */
89#define ESTALE 116 /* Stale NFS file handle */ 89#define ESTALE 116 /* Stale file handle */
90#define EUCLEAN 117 /* Structure needs cleaning */ 90#define EUCLEAN 117 /* Structure needs cleaning */
91#define ENOTNAM 118 /* Not a XENIX named type file */ 91#define ENOTNAM 118 /* Not a XENIX named type file */
92#define ENAVAIL 119 /* No XENIX semaphores available */ 92#define ENAVAIL 119 /* No XENIX semaphores available */
diff --git a/init/Kconfig b/init/Kconfig
index bc8911fab28e..5496f307988e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -118,7 +118,6 @@ config HAVE_KERNEL_LZ4
118choice 118choice
119 prompt "Kernel compression mode" 119 prompt "Kernel compression mode"
120 default KERNEL_GZIP 120 default KERNEL_GZIP
121 depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
122 help 121 help
123 The linux kernel is a kind of self-extracting executable. 122 The linux kernel is a kind of self-extracting executable.
124 Several compression algorithms are available, which differ 123 Several compression algorithms are available, which differ
@@ -137,6 +136,13 @@ choice
137 136
138 If in doubt, select 'gzip' 137 If in doubt, select 'gzip'
139 138
139config KERNEL_UNCOMPRESSED
140 bool "No compression"
141 help
142 No compression at all. The kernel is huge but the compression and
143 decompression times are zero.
144 This is usually not what you want.
145
140config KERNEL_GZIP 146config KERNEL_GZIP
141 bool "Gzip" 147 bool "Gzip"
142 depends on HAVE_KERNEL_GZIP 148 depends on HAVE_KERNEL_GZIP
diff --git a/init/do_mounts.c b/init/do_mounts.c
index a51cddc2ff8c..8e5addc45874 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -197,6 +197,8 @@ done:
197 * is a zero-filled hex representation of the 1-based partition number. 197 * is a zero-filled hex representation of the 1-based partition number.
198 * 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to 198 * 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
199 * a partition with a known unique id. 199 * a partition with a known unique id.
200 * 8) <major>:<minor> major and minor number of the device separated by
201 * a colon.
200 * 202 *
201 * If name doesn't have fall into the categories above, we return (0,0). 203 * If name doesn't have fall into the categories above, we return (0,0).
202 * block_class is used to check if something is a disk name. If the disk 204 * block_class is used to check if something is a disk name. If the disk
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 6be2879cca66..7c098ac9068a 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -57,6 +57,11 @@ static int __init crd_load(int in_fd, int out_fd, decompress_fn deco);
57 * cramfs 57 * cramfs
58 * squashfs 58 * squashfs
59 * gzip 59 * gzip
60 * bzip2
61 * lzma
62 * xz
63 * lzo
64 * lz4
60 */ 65 */
61static int __init 66static int __init
62identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) 67identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
@@ -342,6 +347,13 @@ static int __init crd_load(int in_fd, int out_fd, decompress_fn deco)
342 int result; 347 int result;
343 crd_infd = in_fd; 348 crd_infd = in_fd;
344 crd_outfd = out_fd; 349 crd_outfd = out_fd;
350
351 if (!deco) {
352 pr_emerg("Invalid ramdisk decompression routine. "
353 "Select appropriate config option.\n");
354 panic("Could not decompress initial ramdisk image.");
355 }
356
345 result = deco(NULL, 0, compr_fill, compr_flush, NULL, NULL, error); 357 result = deco(NULL, 0, compr_fill, compr_flush, NULL, NULL, error);
346 if (decompress_error) 358 if (decompress_error)
347 result = 1; 359 result = 1;
diff --git a/init/main.c b/init/main.c
index 379090fadac9..67ee8ef0a669 100644
--- a/init/main.c
+++ b/init/main.c
@@ -124,7 +124,6 @@ EXPORT_SYMBOL(system_state);
124extern void time_init(void); 124extern void time_init(void);
125/* Default late time init is NULL. archs can override this later. */ 125/* Default late time init is NULL. archs can override this later. */
126void (*__initdata late_time_init)(void); 126void (*__initdata late_time_init)(void);
127extern void softirq_init(void);
128 127
129/* Untouched command line saved by arch-specific code. */ 128/* Untouched command line saved by arch-specific code. */
130char __initdata boot_command_line[COMMAND_LINE_SIZE]; 129char __initdata boot_command_line[COMMAND_LINE_SIZE];
@@ -811,10 +810,26 @@ static int run_init_process(const char *init_filename)
811 (const char __user *const __user *)envp_init); 810 (const char __user *const __user *)envp_init);
812} 811}
813 812
813static int try_to_run_init_process(const char *init_filename)
814{
815 int ret;
816
817 ret = run_init_process(init_filename);
818
819 if (ret && ret != -ENOENT) {
820 pr_err("Starting init: %s exists but couldn't execute it (error %d)\n",
821 init_filename, ret);
822 }
823
824 return ret;
825}
826
814static noinline void __init kernel_init_freeable(void); 827static noinline void __init kernel_init_freeable(void);
815 828
816static int __ref kernel_init(void *unused) 829static int __ref kernel_init(void *unused)
817{ 830{
831 int ret;
832
818 kernel_init_freeable(); 833 kernel_init_freeable();
819 /* need to finish all async __init code before freeing the memory */ 834 /* need to finish all async __init code before freeing the memory */
820 async_synchronize_full(); 835 async_synchronize_full();
@@ -826,9 +841,11 @@ static int __ref kernel_init(void *unused)
826 flush_delayed_fput(); 841 flush_delayed_fput();
827 842
828 if (ramdisk_execute_command) { 843 if (ramdisk_execute_command) {
829 if (!run_init_process(ramdisk_execute_command)) 844 ret = run_init_process(ramdisk_execute_command);
845 if (!ret)
830 return 0; 846 return 0;
831 pr_err("Failed to execute %s\n", ramdisk_execute_command); 847 pr_err("Failed to execute %s (error %d)\n",
848 ramdisk_execute_command, ret);
832 } 849 }
833 850
834 /* 851 /*
@@ -838,18 +855,19 @@ static int __ref kernel_init(void *unused)
838 * trying to recover a really broken machine. 855 * trying to recover a really broken machine.
839 */ 856 */
840 if (execute_command) { 857 if (execute_command) {
841 if (!run_init_process(execute_command)) 858 ret = run_init_process(execute_command);
859 if (!ret)
842 return 0; 860 return 0;
843 pr_err("Failed to execute %s. Attempting defaults...\n", 861 pr_err("Failed to execute %s (error %d). Attempting defaults...\n",
844 execute_command); 862 execute_command, ret);
845 } 863 }
846 if (!run_init_process("/sbin/init") || 864 if (!try_to_run_init_process("/sbin/init") ||
847 !run_init_process("/etc/init") || 865 !try_to_run_init_process("/etc/init") ||
848 !run_init_process("/bin/init") || 866 !try_to_run_init_process("/bin/init") ||
849 !run_init_process("/bin/sh")) 867 !try_to_run_init_process("/bin/sh"))
850 return 0; 868 return 0;
851 869
852 panic("No init found. Try passing init= option to kernel. " 870 panic("No working init found. Try passing init= option to kernel. "
853 "See Linux Documentation/init.txt for guidance."); 871 "See Linux Documentation/init.txt for guidance.");
854} 872}
855 873
diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index 491e71f2a1b8..7e7095974d54 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -41,15 +41,15 @@ struct msg_msgseg {
41 /* the next part of the message follows immediately */ 41 /* the next part of the message follows immediately */
42}; 42};
43 43
44#define DATALEN_MSG (int)(PAGE_SIZE-sizeof(struct msg_msg)) 44#define DATALEN_MSG ((size_t)PAGE_SIZE-sizeof(struct msg_msg))
45#define DATALEN_SEG (int)(PAGE_SIZE-sizeof(struct msg_msgseg)) 45#define DATALEN_SEG ((size_t)PAGE_SIZE-sizeof(struct msg_msgseg))
46 46
47 47
48static struct msg_msg *alloc_msg(int len) 48static struct msg_msg *alloc_msg(size_t len)
49{ 49{
50 struct msg_msg *msg; 50 struct msg_msg *msg;
51 struct msg_msgseg **pseg; 51 struct msg_msgseg **pseg;
52 int alen; 52 size_t alen;
53 53
54 alen = min(len, DATALEN_MSG); 54 alen = min(len, DATALEN_MSG);
55 msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL); 55 msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL);
@@ -80,12 +80,12 @@ out_err:
80 return NULL; 80 return NULL;
81} 81}
82 82
83struct msg_msg *load_msg(const void __user *src, int len) 83struct msg_msg *load_msg(const void __user *src, size_t len)
84{ 84{
85 struct msg_msg *msg; 85 struct msg_msg *msg;
86 struct msg_msgseg *seg; 86 struct msg_msgseg *seg;
87 int err = -EFAULT; 87 int err = -EFAULT;
88 int alen; 88 size_t alen;
89 89
90 msg = alloc_msg(len); 90 msg = alloc_msg(len);
91 if (msg == NULL) 91 if (msg == NULL)
@@ -117,8 +117,8 @@ out_err:
117struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst) 117struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
118{ 118{
119 struct msg_msgseg *dst_pseg, *src_pseg; 119 struct msg_msgseg *dst_pseg, *src_pseg;
120 int len = src->m_ts; 120 size_t len = src->m_ts;
121 int alen; 121 size_t alen;
122 122
123 BUG_ON(dst == NULL); 123 BUG_ON(dst == NULL);
124 if (src->m_ts > dst->m_ts) 124 if (src->m_ts > dst->m_ts)
@@ -147,9 +147,9 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
147 return ERR_PTR(-ENOSYS); 147 return ERR_PTR(-ENOSYS);
148} 148}
149#endif 149#endif
150int store_msg(void __user *dest, struct msg_msg *msg, int len) 150int store_msg(void __user *dest, struct msg_msg *msg, size_t len)
151{ 151{
152 int alen; 152 size_t alen;
153 struct msg_msgseg *seg; 153 struct msg_msgseg *seg;
154 154
155 alen = min(len, DATALEN_MSG); 155 alen = min(len, DATALEN_MSG);
diff --git a/ipc/util.c b/ipc/util.c
index 7684f41bce76..3ae17a4ace5b 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -90,10 +90,8 @@ static int ipc_memory_callback(struct notifier_block *self,
90 * In order not to keep the lock on the hotplug memory chain 90 * In order not to keep the lock on the hotplug memory chain
91 * for too long, queue a work item that will, when waken up, 91 * for too long, queue a work item that will, when waken up,
92 * activate the ipcns notification chain. 92 * activate the ipcns notification chain.
93 * No need to keep several ipc work items on the queue.
94 */ 93 */
95 if (!work_pending(&ipc_memory_wq)) 94 schedule_work(&ipc_memory_wq);
96 schedule_work(&ipc_memory_wq);
97 break; 95 break;
98 case MEM_GOING_ONLINE: 96 case MEM_GOING_ONLINE:
99 case MEM_GOING_OFFLINE: 97 case MEM_GOING_OFFLINE:
diff --git a/ipc/util.h b/ipc/util.h
index f2f5036f2eed..59d78aa94987 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -148,9 +148,9 @@ int ipc_parse_version (int *cmd);
148#endif 148#endif
149 149
150extern void free_msg(struct msg_msg *msg); 150extern void free_msg(struct msg_msg *msg);
151extern struct msg_msg *load_msg(const void __user *src, int len); 151extern struct msg_msg *load_msg(const void __user *src, size_t len);
152extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst); 152extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst);
153extern int store_msg(void __user *dest, struct msg_msg *msg, int len); 153extern int store_msg(void __user *dest, struct msg_msg *msg, size_t len);
154 154
155extern void recompute_msgmni(struct ipc_namespace *); 155extern void recompute_msgmni(struct ipc_namespace *);
156 156
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 63aa50d7ce1e..973d034acf84 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -437,11 +437,6 @@ int cpu_up(unsigned int cpu)
437{ 437{
438 int err = 0; 438 int err = 0;
439 439
440#ifdef CONFIG_MEMORY_HOTPLUG
441 int nid;
442 pg_data_t *pgdat;
443#endif
444
445 if (!cpu_possible(cpu)) { 440 if (!cpu_possible(cpu)) {
446 printk(KERN_ERR "can't online cpu %d because it is not " 441 printk(KERN_ERR "can't online cpu %d because it is not "
447 "configured as may-hotadd at boot time\n", cpu); 442 "configured as may-hotadd at boot time\n", cpu);
@@ -452,27 +447,9 @@ int cpu_up(unsigned int cpu)
452 return -EINVAL; 447 return -EINVAL;
453 } 448 }
454 449
455#ifdef CONFIG_MEMORY_HOTPLUG 450 err = try_online_node(cpu_to_node(cpu));
456 nid = cpu_to_node(cpu); 451 if (err)
457 if (!node_online(nid)) { 452 return err;
458 err = mem_online_node(nid);
459 if (err)
460 return err;
461 }
462
463 pgdat = NODE_DATA(nid);
464 if (!pgdat) {
465 printk(KERN_ERR
466 "Can't online cpu %d due to NULL pgdat\n", cpu);
467 return -ENOMEM;
468 }
469
470 if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
471 mutex_lock(&zonelists_mutex);
472 build_all_zonelists(NULL, NULL);
473 mutex_unlock(&zonelists_mutex);
474 }
475#endif
476 453
477 cpu_maps_update_begin(); 454 cpu_maps_update_begin();
478 455
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index d473988c1d0b..54996b71e66d 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -108,12 +108,6 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
108 struct timespec ts; 108 struct timespec ts;
109 cputime_t utime, stime, stimescaled, utimescaled; 109 cputime_t utime, stime, stimescaled, utimescaled;
110 110
111 /* Though tsk->delays accessed later, early exit avoids
112 * unnecessary returning of other data
113 */
114 if (!tsk->delays)
115 goto done;
116
117 tmp = (s64)d->cpu_run_real_total; 111 tmp = (s64)d->cpu_run_real_total;
118 task_cputime(tsk, &utime, &stime); 112 task_cputime(tsk, &utime, &stime);
119 cputime_to_timespec(utime + stime, &ts); 113 cputime_to_timespec(utime + stime, &ts);
@@ -158,7 +152,6 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
158 d->freepages_count += tsk->delays->freepages_count; 152 d->freepages_count += tsk->delays->freepages_count;
159 spin_unlock_irqrestore(&tsk->delays->lock, flags); 153 spin_unlock_irqrestore(&tsk->delays->lock, flags);
160 154
161done:
162 return 0; 155 return 0;
163} 156}
164 157
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8c875ef6e120..d724e7757cd1 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2234,9 +2234,6 @@ static void __perf_event_sync_stat(struct perf_event *event,
2234 perf_event_update_userpage(next_event); 2234 perf_event_update_userpage(next_event);
2235} 2235}
2236 2236
2237#define list_next_entry(pos, member) \
2238 list_entry(pos->member.next, typeof(*pos), member)
2239
2240static void perf_event_sync_stat(struct perf_event_context *ctx, 2237static void perf_event_sync_stat(struct perf_event_context *ctx,
2241 struct perf_event_context *next_ctx) 2238 struct perf_event_context *next_ctx)
2242{ 2239{
diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig
index d4da55d1fb65..d04ce8ac4399 100644
--- a/kernel/gcov/Kconfig
+++ b/kernel/gcov/Kconfig
@@ -46,4 +46,34 @@ config GCOV_PROFILE_ALL
46 larger and run slower. Also be sure to exclude files from profiling 46 larger and run slower. Also be sure to exclude files from profiling
47 which are not linked to the kernel image to prevent linker errors. 47 which are not linked to the kernel image to prevent linker errors.
48 48
49choice
50 prompt "Specify GCOV format"
51 depends on GCOV_KERNEL
52 default GCOV_FORMAT_AUTODETECT
53 ---help---
54 The gcov format is usually determined by the GCC version, but there are
55 exceptions where format changes are integrated in lower-version GCCs.
56 In such a case use this option to adjust the format used in the kernel
57 accordingly.
58
59 If unsure, choose "Autodetect".
60
61config GCOV_FORMAT_AUTODETECT
62 bool "Autodetect"
63 ---help---
64 Select this option to use the format that corresponds to your GCC
65 version.
66
67config GCOV_FORMAT_3_4
68 bool "GCC 3.4 format"
69 ---help---
70 Select this option to use the format defined by GCC 3.4.
71
72config GCOV_FORMAT_4_7
73 bool "GCC 4.7 format"
74 ---help---
75 Select this option to use the format defined by GCC 4.7.
76
77endchoice
78
49endmenu 79endmenu
diff --git a/kernel/gcov/Makefile b/kernel/gcov/Makefile
index e97ca59e2520..52aa7e8de927 100644
--- a/kernel/gcov/Makefile
+++ b/kernel/gcov/Makefile
@@ -1,3 +1,33 @@
1ccflags-y := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"' 1ccflags-y := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"'
2 2
3obj-$(CONFIG_GCOV_KERNEL) := base.o fs.o gcc_3_4.o 3# if-lt
4# Usage VAR := $(call if-lt, $(a), $(b))
5# Returns 1 if (a < b)
6if-lt = $(shell [ $(1) -lt $(2) ] && echo 1)
7
8ifeq ($(CONFIG_GCOV_FORMAT_3_4),y)
9 cc-ver := 0304
10else ifeq ($(CONFIG_GCOV_FORMAT_4_7),y)
11 cc-ver := 0407
12else
13# Use cc-version if available, otherwise set 0
14#
15# scripts/Kbuild.include, which contains cc-version function, is not included
16# during make clean "make -f scripts/Makefile.clean obj=kernel/gcov"
17# Meaning cc-ver is empty causing if-lt test to fail with
18# "/bin/sh: line 0: [: -lt: unary operator expected" error mesage.
19# This has no affect on the clean phase, but the error message could be
20# confusing/annoying. So this dummy workaround sets cc-ver to zero if cc-version
21# is not available. We can probably move if-lt to Kbuild.include, so it's also
22# not defined during clean or to include Kbuild.include in
23# scripts/Makefile.clean. But the following workaround seems least invasive.
24 cc-ver := $(if $(call cc-version),$(call cc-version),0)
25endif
26
27obj-$(CONFIG_GCOV_KERNEL) := base.o fs.o
28
29ifeq ($(call if-lt, $(cc-ver), 0407),1)
30 obj-$(CONFIG_GCOV_KERNEL) += gcc_3_4.o
31else
32 obj-$(CONFIG_GCOV_KERNEL) += gcc_4_7.o
33endif
diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
index 9b22d03cc581..f45b75b713c0 100644
--- a/kernel/gcov/base.c
+++ b/kernel/gcov/base.c
@@ -20,7 +20,6 @@
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include "gcov.h" 21#include "gcov.h"
22 22
23static struct gcov_info *gcov_info_head;
24static int gcov_events_enabled; 23static int gcov_events_enabled;
25static DEFINE_MUTEX(gcov_lock); 24static DEFINE_MUTEX(gcov_lock);
26 25
@@ -34,7 +33,7 @@ void __gcov_init(struct gcov_info *info)
34 33
35 mutex_lock(&gcov_lock); 34 mutex_lock(&gcov_lock);
36 if (gcov_version == 0) { 35 if (gcov_version == 0) {
37 gcov_version = info->version; 36 gcov_version = gcov_info_version(info);
38 /* 37 /*
39 * Printing gcc's version magic may prove useful for debugging 38 * Printing gcc's version magic may prove useful for debugging
40 * incompatibility reports. 39 * incompatibility reports.
@@ -45,8 +44,7 @@ void __gcov_init(struct gcov_info *info)
45 * Add new profiling data structure to list and inform event 44 * Add new profiling data structure to list and inform event
46 * listener. 45 * listener.
47 */ 46 */
48 info->next = gcov_info_head; 47 gcov_info_link(info);
49 gcov_info_head = info;
50 if (gcov_events_enabled) 48 if (gcov_events_enabled)
51 gcov_event(GCOV_ADD, info); 49 gcov_event(GCOV_ADD, info);
52 mutex_unlock(&gcov_lock); 50 mutex_unlock(&gcov_lock);
@@ -81,6 +79,12 @@ void __gcov_merge_delta(gcov_type *counters, unsigned int n_counters)
81} 79}
82EXPORT_SYMBOL(__gcov_merge_delta); 80EXPORT_SYMBOL(__gcov_merge_delta);
83 81
82void __gcov_merge_ior(gcov_type *counters, unsigned int n_counters)
83{
84 /* Unused. */
85}
86EXPORT_SYMBOL(__gcov_merge_ior);
87
84/** 88/**
85 * gcov_enable_events - enable event reporting through gcov_event() 89 * gcov_enable_events - enable event reporting through gcov_event()
86 * 90 *
@@ -91,13 +95,15 @@ EXPORT_SYMBOL(__gcov_merge_delta);
91 */ 95 */
92void gcov_enable_events(void) 96void gcov_enable_events(void)
93{ 97{
94 struct gcov_info *info; 98 struct gcov_info *info = NULL;
95 99
96 mutex_lock(&gcov_lock); 100 mutex_lock(&gcov_lock);
97 gcov_events_enabled = 1; 101 gcov_events_enabled = 1;
102
98 /* Perform event callback for previously registered entries. */ 103 /* Perform event callback for previously registered entries. */
99 for (info = gcov_info_head; info; info = info->next) 104 while ((info = gcov_info_next(info)))
100 gcov_event(GCOV_ADD, info); 105 gcov_event(GCOV_ADD, info);
106
101 mutex_unlock(&gcov_lock); 107 mutex_unlock(&gcov_lock);
102} 108}
103 109
@@ -112,25 +118,23 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
112 void *data) 118 void *data)
113{ 119{
114 struct module *mod = data; 120 struct module *mod = data;
115 struct gcov_info *info; 121 struct gcov_info *info = NULL;
116 struct gcov_info *prev; 122 struct gcov_info *prev = NULL;
117 123
118 if (event != MODULE_STATE_GOING) 124 if (event != MODULE_STATE_GOING)
119 return NOTIFY_OK; 125 return NOTIFY_OK;
120 mutex_lock(&gcov_lock); 126 mutex_lock(&gcov_lock);
121 prev = NULL; 127
122 /* Remove entries located in module from linked list. */ 128 /* Remove entries located in module from linked list. */
123 for (info = gcov_info_head; info; info = info->next) { 129 while ((info = gcov_info_next(info))) {
124 if (within(info, mod->module_core, mod->core_size)) { 130 if (within(info, mod->module_core, mod->core_size)) {
125 if (prev) 131 gcov_info_unlink(prev, info);
126 prev->next = info->next;
127 else
128 gcov_info_head = info->next;
129 if (gcov_events_enabled) 132 if (gcov_events_enabled)
130 gcov_event(GCOV_REMOVE, info); 133 gcov_event(GCOV_REMOVE, info);
131 } else 134 } else
132 prev = info; 135 prev = info;
133 } 136 }
137
134 mutex_unlock(&gcov_lock); 138 mutex_unlock(&gcov_lock);
135 139
136 return NOTIFY_OK; 140 return NOTIFY_OK;
diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 7a7d2ee96d42..15ff01a76379 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -75,7 +75,7 @@ static int __init gcov_persist_setup(char *str)
75 unsigned long val; 75 unsigned long val;
76 76
77 if (kstrtoul(str, 0, &val)) { 77 if (kstrtoul(str, 0, &val)) {
78 pr_warning("invalid gcov_persist parameter '%s'\n", str); 78 pr_warn("invalid gcov_persist parameter '%s'\n", str);
79 return 0; 79 return 0;
80 } 80 }
81 gcov_persist = val; 81 gcov_persist = val;
@@ -242,7 +242,7 @@ static struct gcov_node *get_node_by_name(const char *name)
242 242
243 list_for_each_entry(node, &all_head, all) { 243 list_for_each_entry(node, &all_head, all) {
244 info = get_node_info(node); 244 info = get_node_info(node);
245 if (info && (strcmp(info->filename, name) == 0)) 245 if (info && (strcmp(gcov_info_filename(info), name) == 0))
246 return node; 246 return node;
247 } 247 }
248 248
@@ -279,7 +279,7 @@ static ssize_t gcov_seq_write(struct file *file, const char __user *addr,
279 seq = file->private_data; 279 seq = file->private_data;
280 info = gcov_iter_get_info(seq->private); 280 info = gcov_iter_get_info(seq->private);
281 mutex_lock(&node_lock); 281 mutex_lock(&node_lock);
282 node = get_node_by_name(info->filename); 282 node = get_node_by_name(gcov_info_filename(info));
283 if (node) { 283 if (node) {
284 /* Reset counts or remove node for unloaded modules. */ 284 /* Reset counts or remove node for unloaded modules. */
285 if (node->num_loaded == 0) 285 if (node->num_loaded == 0)
@@ -365,7 +365,7 @@ static const char *deskew(const char *basename)
365 */ 365 */
366static void add_links(struct gcov_node *node, struct dentry *parent) 366static void add_links(struct gcov_node *node, struct dentry *parent)
367{ 367{
368 char *basename; 368 const char *basename;
369 char *target; 369 char *target;
370 int num; 370 int num;
371 int i; 371 int i;
@@ -376,14 +376,14 @@ static void add_links(struct gcov_node *node, struct dentry *parent)
376 if (!node->links) 376 if (!node->links)
377 return; 377 return;
378 for (i = 0; i < num; i++) { 378 for (i = 0; i < num; i++) {
379 target = get_link_target(get_node_info(node)->filename, 379 target = get_link_target(
380 &gcov_link[i]); 380 gcov_info_filename(get_node_info(node)),
381 &gcov_link[i]);
381 if (!target) 382 if (!target)
382 goto out_err; 383 goto out_err;
383 basename = strrchr(target, '/'); 384 basename = kbasename(target);
384 if (!basename) 385 if (basename == target)
385 goto out_err; 386 goto out_err;
386 basename++;
387 node->links[i] = debugfs_create_symlink(deskew(basename), 387 node->links[i] = debugfs_create_symlink(deskew(basename),
388 parent, target); 388 parent, target);
389 if (!node->links[i]) 389 if (!node->links[i])
@@ -450,7 +450,7 @@ static struct gcov_node *new_node(struct gcov_node *parent,
450 } else 450 } else
451 node->dentry = debugfs_create_dir(node->name, parent->dentry); 451 node->dentry = debugfs_create_dir(node->name, parent->dentry);
452 if (!node->dentry) { 452 if (!node->dentry) {
453 pr_warning("could not create file\n"); 453 pr_warn("could not create file\n");
454 kfree(node); 454 kfree(node);
455 return NULL; 455 return NULL;
456 } 456 }
@@ -463,7 +463,7 @@ static struct gcov_node *new_node(struct gcov_node *parent,
463 463
464err_nomem: 464err_nomem:
465 kfree(node); 465 kfree(node);
466 pr_warning("out of memory\n"); 466 pr_warn("out of memory\n");
467 return NULL; 467 return NULL;
468} 468}
469 469
@@ -576,7 +576,7 @@ static void add_node(struct gcov_info *info)
576 struct gcov_node *parent; 576 struct gcov_node *parent;
577 struct gcov_node *node; 577 struct gcov_node *node;
578 578
579 filename = kstrdup(info->filename, GFP_KERNEL); 579 filename = kstrdup(gcov_info_filename(info), GFP_KERNEL);
580 if (!filename) 580 if (!filename)
581 return; 581 return;
582 parent = &root_node; 582 parent = &root_node;
@@ -630,8 +630,8 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
630 */ 630 */
631 loaded_info = kcalloc(num + 1, sizeof(struct gcov_info *), GFP_KERNEL); 631 loaded_info = kcalloc(num + 1, sizeof(struct gcov_info *), GFP_KERNEL);
632 if (!loaded_info) { 632 if (!loaded_info) {
633 pr_warning("could not add '%s' (out of memory)\n", 633 pr_warn("could not add '%s' (out of memory)\n",
634 info->filename); 634 gcov_info_filename(info));
635 return; 635 return;
636 } 636 }
637 memcpy(loaded_info, node->loaded_info, 637 memcpy(loaded_info, node->loaded_info,
@@ -644,8 +644,9 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
644 * data set replaces the copy of the last one. 644 * data set replaces the copy of the last one.
645 */ 645 */
646 if (!gcov_info_is_compatible(node->unloaded_info, info)) { 646 if (!gcov_info_is_compatible(node->unloaded_info, info)) {
647 pr_warning("discarding saved data for %s " 647 pr_warn("discarding saved data for %s "
648 "(incompatible version)\n", info->filename); 648 "(incompatible version)\n",
649 gcov_info_filename(info));
649 gcov_info_free(node->unloaded_info); 650 gcov_info_free(node->unloaded_info);
650 node->unloaded_info = NULL; 651 node->unloaded_info = NULL;
651 } 652 }
@@ -655,8 +656,8 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
655 * The initial one takes precedence. 656 * The initial one takes precedence.
656 */ 657 */
657 if (!gcov_info_is_compatible(node->loaded_info[0], info)) { 658 if (!gcov_info_is_compatible(node->loaded_info[0], info)) {
658 pr_warning("could not add '%s' (incompatible " 659 pr_warn("could not add '%s' (incompatible "
659 "version)\n", info->filename); 660 "version)\n", gcov_info_filename(info));
660 kfree(loaded_info); 661 kfree(loaded_info);
661 return; 662 return;
662 } 663 }
@@ -691,8 +692,9 @@ static void save_info(struct gcov_node *node, struct gcov_info *info)
691 else { 692 else {
692 node->unloaded_info = gcov_info_dup(info); 693 node->unloaded_info = gcov_info_dup(info);
693 if (!node->unloaded_info) { 694 if (!node->unloaded_info) {
694 pr_warning("could not save data for '%s' " 695 pr_warn("could not save data for '%s' "
695 "(out of memory)\n", info->filename); 696 "(out of memory)\n",
697 gcov_info_filename(info));
696 } 698 }
697 } 699 }
698} 700}
@@ -707,8 +709,8 @@ static void remove_info(struct gcov_node *node, struct gcov_info *info)
707 709
708 i = get_info_index(node, info); 710 i = get_info_index(node, info);
709 if (i < 0) { 711 if (i < 0) {
710 pr_warning("could not remove '%s' (not found)\n", 712 pr_warn("could not remove '%s' (not found)\n",
711 info->filename); 713 gcov_info_filename(info));
712 return; 714 return;
713 } 715 }
714 if (gcov_persist) 716 if (gcov_persist)
@@ -735,7 +737,7 @@ void gcov_event(enum gcov_action action, struct gcov_info *info)
735 struct gcov_node *node; 737 struct gcov_node *node;
736 738
737 mutex_lock(&node_lock); 739 mutex_lock(&node_lock);
738 node = get_node_by_name(info->filename); 740 node = get_node_by_name(gcov_info_filename(info));
739 switch (action) { 741 switch (action) {
740 case GCOV_ADD: 742 case GCOV_ADD:
741 if (node) 743 if (node)
@@ -747,8 +749,8 @@ void gcov_event(enum gcov_action action, struct gcov_info *info)
747 if (node) 749 if (node)
748 remove_info(node, info); 750 remove_info(node, info);
749 else { 751 else {
750 pr_warning("could not remove '%s' (not found)\n", 752 pr_warn("could not remove '%s' (not found)\n",
751 info->filename); 753 gcov_info_filename(info));
752 } 754 }
753 break; 755 break;
754 } 756 }
diff --git a/kernel/gcov/gcc_3_4.c b/kernel/gcov/gcc_3_4.c
index ae5bb4260033..27bc88a35013 100644
--- a/kernel/gcov/gcc_3_4.c
+++ b/kernel/gcov/gcc_3_4.c
@@ -21,6 +21,121 @@
21#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
22#include "gcov.h" 22#include "gcov.h"
23 23
24#define GCOV_COUNTERS 5
25
26static struct gcov_info *gcov_info_head;
27
28/**
29 * struct gcov_fn_info - profiling meta data per function
30 * @ident: object file-unique function identifier
31 * @checksum: function checksum
32 * @n_ctrs: number of values per counter type belonging to this function
33 *
34 * This data is generated by gcc during compilation and doesn't change
35 * at run-time.
36 */
37struct gcov_fn_info {
38 unsigned int ident;
39 unsigned int checksum;
40 unsigned int n_ctrs[0];
41};
42
43/**
44 * struct gcov_ctr_info - profiling data per counter type
45 * @num: number of counter values for this type
46 * @values: array of counter values for this type
47 * @merge: merge function for counter values of this type (unused)
48 *
49 * This data is generated by gcc during compilation and doesn't change
50 * at run-time with the exception of the values array.
51 */
52struct gcov_ctr_info {
53 unsigned int num;
54 gcov_type *values;
55 void (*merge)(gcov_type *, unsigned int);
56};
57
58/**
59 * struct gcov_info - profiling data per object file
60 * @version: gcov version magic indicating the gcc version used for compilation
61 * @next: list head for a singly-linked list
62 * @stamp: time stamp
63 * @filename: name of the associated gcov data file
64 * @n_functions: number of instrumented functions
65 * @functions: function data
66 * @ctr_mask: mask specifying which counter types are active
67 * @counts: counter data per counter type
68 *
69 * This data is generated by gcc during compilation and doesn't change
70 * at run-time with the exception of the next pointer.
71 */
72struct gcov_info {
73 unsigned int version;
74 struct gcov_info *next;
75 unsigned int stamp;
76 const char *filename;
77 unsigned int n_functions;
78 const struct gcov_fn_info *functions;
79 unsigned int ctr_mask;
80 struct gcov_ctr_info counts[0];
81};
82
83/**
84 * gcov_info_filename - return info filename
85 * @info: profiling data set
86 */
87const char *gcov_info_filename(struct gcov_info *info)
88{
89 return info->filename;
90}
91
92/**
93 * gcov_info_version - return info version
94 * @info: profiling data set
95 */
96unsigned int gcov_info_version(struct gcov_info *info)
97{
98 return info->version;
99}
100
101/**
102 * gcov_info_next - return next profiling data set
103 * @info: profiling data set
104 *
105 * Returns next gcov_info following @info or first gcov_info in the chain if
106 * @info is %NULL.
107 */
108struct gcov_info *gcov_info_next(struct gcov_info *info)
109{
110 if (!info)
111 return gcov_info_head;
112
113 return info->next;
114}
115
116/**
117 * gcov_info_link - link/add profiling data set to the list
118 * @info: profiling data set
119 */
120void gcov_info_link(struct gcov_info *info)
121{
122 info->next = gcov_info_head;
123 gcov_info_head = info;
124}
125
126/**
127 * gcov_info_unlink - unlink/remove profiling data set from the list
128 * @prev: previous profiling data set
129 * @info: profiling data set
130 */
131void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info)
132{
133 if (prev)
134 prev->next = info->next;
135 else
136 gcov_info_head = info->next;
137}
138
24/* Symbolic links to be created for each profiling data file. */ 139/* Symbolic links to be created for each profiling data file. */
25const struct gcov_link gcov_link[] = { 140const struct gcov_link gcov_link[] = {
26 { OBJ_TREE, "gcno" }, /* Link to .gcno file in $(objtree). */ 141 { OBJ_TREE, "gcno" }, /* Link to .gcno file in $(objtree). */
diff --git a/kernel/gcov/gcc_4_7.c b/kernel/gcov/gcc_4_7.c
new file mode 100644
index 000000000000..2c6e4631c814
--- /dev/null
+++ b/kernel/gcov/gcc_4_7.c
@@ -0,0 +1,560 @@
1/*
2 * This code provides functions to handle gcc's profiling data format
3 * introduced with gcc 4.7.
4 *
5 * This file is based heavily on gcc_3_4.c file.
6 *
7 * For a better understanding, refer to gcc source:
8 * gcc/gcov-io.h
9 * libgcc/libgcov.c
10 *
11 * Uses gcc-internal data definitions.
12 */
13
14#include <linux/errno.h>
15#include <linux/slab.h>
16#include <linux/string.h>
17#include <linux/seq_file.h>
18#include <linux/vmalloc.h>
19#include "gcov.h"
20
21#define GCOV_COUNTERS 8
22#define GCOV_TAG_FUNCTION_LENGTH 3
23
24static struct gcov_info *gcov_info_head;
25
26/**
27 * struct gcov_ctr_info - information about counters for a single function
28 * @num: number of counter values for this type
29 * @values: array of counter values for this type
30 *
31 * This data is generated by gcc during compilation and doesn't change
32 * at run-time with the exception of the values array.
33 */
34struct gcov_ctr_info {
35 unsigned int num;
36 gcov_type *values;
37};
38
39/**
40 * struct gcov_fn_info - profiling meta data per function
41 * @key: comdat key
42 * @ident: unique ident of function
43 * @lineno_checksum: function lineo_checksum
44 * @cfg_checksum: function cfg checksum
45 * @ctrs: instrumented counters
46 *
47 * This data is generated by gcc during compilation and doesn't change
48 * at run-time.
49 *
50 * Information about a single function. This uses the trailing array
51 * idiom. The number of counters is determined from the merge pointer
52 * array in gcov_info. The key is used to detect which of a set of
53 * comdat functions was selected -- it points to the gcov_info object
54 * of the object file containing the selected comdat function.
55 */
56struct gcov_fn_info {
57 const struct gcov_info *key;
58 unsigned int ident;
59 unsigned int lineno_checksum;
60 unsigned int cfg_checksum;
61 struct gcov_ctr_info ctrs[0];
62};
63
64/**
65 * struct gcov_info - profiling data per object file
66 * @version: gcov version magic indicating the gcc version used for compilation
67 * @next: list head for a singly-linked list
68 * @stamp: uniquifying time stamp
69 * @filename: name of the associated gcov data file
70 * @merge: merge functions (null for unused counter type)
71 * @n_functions: number of instrumented functions
72 * @functions: pointer to pointers to function information
73 *
74 * This data is generated by gcc during compilation and doesn't change
75 * at run-time with the exception of the next pointer.
76 */
77struct gcov_info {
78 unsigned int version;
79 struct gcov_info *next;
80 unsigned int stamp;
81 const char *filename;
82 void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
83 unsigned int n_functions;
84 struct gcov_fn_info **functions;
85};
86
87/**
88 * gcov_info_filename - return info filename
89 * @info: profiling data set
90 */
91const char *gcov_info_filename(struct gcov_info *info)
92{
93 return info->filename;
94}
95
96/**
97 * gcov_info_version - return info version
98 * @info: profiling data set
99 */
100unsigned int gcov_info_version(struct gcov_info *info)
101{
102 return info->version;
103}
104
105/**
106 * gcov_info_next - return next profiling data set
107 * @info: profiling data set
108 *
109 * Returns next gcov_info following @info or first gcov_info in the chain if
110 * @info is %NULL.
111 */
112struct gcov_info *gcov_info_next(struct gcov_info *info)
113{
114 if (!info)
115 return gcov_info_head;
116
117 return info->next;
118}
119
120/**
121 * gcov_info_link - link/add profiling data set to the list
122 * @info: profiling data set
123 */
124void gcov_info_link(struct gcov_info *info)
125{
126 info->next = gcov_info_head;
127 gcov_info_head = info;
128}
129
130/**
131 * gcov_info_unlink - unlink/remove profiling data set from the list
132 * @prev: previous profiling data set
133 * @info: profiling data set
134 */
135void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info)
136{
137 if (prev)
138 prev->next = info->next;
139 else
140 gcov_info_head = info->next;
141}
142
143/* Symbolic links to be created for each profiling data file. */
144const struct gcov_link gcov_link[] = {
145 { OBJ_TREE, "gcno" }, /* Link to .gcno file in $(objtree). */
146 { 0, NULL},
147};
148
149/*
150 * Determine whether a counter is active. Doesn't change at run-time.
151 */
152static int counter_active(struct gcov_info *info, unsigned int type)
153{
154 return info->merge[type] ? 1 : 0;
155}
156
157/* Determine number of active counters. Based on gcc magic. */
158static unsigned int num_counter_active(struct gcov_info *info)
159{
160 unsigned int i;
161 unsigned int result = 0;
162
163 for (i = 0; i < GCOV_COUNTERS; i++) {
164 if (counter_active(info, i))
165 result++;
166 }
167 return result;
168}
169
170/**
171 * gcov_info_reset - reset profiling data to zero
172 * @info: profiling data set
173 */
174void gcov_info_reset(struct gcov_info *info)
175{
176 struct gcov_ctr_info *ci_ptr;
177 unsigned int fi_idx;
178 unsigned int ct_idx;
179
180 for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
181 ci_ptr = info->functions[fi_idx]->ctrs;
182
183 for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
184 if (!counter_active(info, ct_idx))
185 continue;
186
187 memset(ci_ptr->values, 0,
188 sizeof(gcov_type) * ci_ptr->num);
189 ci_ptr++;
190 }
191 }
192}
193
194/**
195 * gcov_info_is_compatible - check if profiling data can be added
196 * @info1: first profiling data set
197 * @info2: second profiling data set
198 *
199 * Returns non-zero if profiling data can be added, zero otherwise.
200 */
201int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2)
202{
203 return (info1->stamp == info2->stamp);
204}
205
206/**
207 * gcov_info_add - add up profiling data
208 * @dest: profiling data set to which data is added
209 * @source: profiling data set which is added
210 *
211 * Adds profiling counts of @source to @dest.
212 */
213void gcov_info_add(struct gcov_info *dst, struct gcov_info *src)
214{
215 struct gcov_ctr_info *dci_ptr;
216 struct gcov_ctr_info *sci_ptr;
217 unsigned int fi_idx;
218 unsigned int ct_idx;
219 unsigned int val_idx;
220
221 for (fi_idx = 0; fi_idx < src->n_functions; fi_idx++) {
222 dci_ptr = dst->functions[fi_idx]->ctrs;
223 sci_ptr = src->functions[fi_idx]->ctrs;
224
225 for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
226 if (!counter_active(src, ct_idx))
227 continue;
228
229 for (val_idx = 0; val_idx < sci_ptr->num; val_idx++)
230 dci_ptr->values[val_idx] +=
231 sci_ptr->values[val_idx];
232
233 dci_ptr++;
234 sci_ptr++;
235 }
236 }
237}
238
239/**
240 * gcov_info_dup - duplicate profiling data set
241 * @info: profiling data set to duplicate
242 *
243 * Return newly allocated duplicate on success, %NULL on error.
244 */
245struct gcov_info *gcov_info_dup(struct gcov_info *info)
246{
247 struct gcov_info *dup;
248 struct gcov_ctr_info *dci_ptr; /* dst counter info */
249 struct gcov_ctr_info *sci_ptr; /* src counter info */
250 unsigned int active;
251 unsigned int fi_idx; /* function info idx */
252 unsigned int ct_idx; /* counter type idx */
253 size_t fi_size; /* function info size */
254 size_t cv_size; /* counter values size */
255
256 dup = kmemdup(info, sizeof(*dup), GFP_KERNEL);
257 if (!dup)
258 return NULL;
259
260 dup->next = NULL;
261 dup->filename = NULL;
262 dup->functions = NULL;
263
264 dup->filename = kstrdup(info->filename, GFP_KERNEL);
265 if (!dup->filename)
266 goto err_free;
267
268 dup->functions = kcalloc(info->n_functions,
269 sizeof(struct gcov_fn_info *), GFP_KERNEL);
270 if (!dup->functions)
271 goto err_free;
272
273 active = num_counter_active(info);
274 fi_size = sizeof(struct gcov_fn_info);
275 fi_size += sizeof(struct gcov_ctr_info) * active;
276
277 for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
278 dup->functions[fi_idx] = kzalloc(fi_size, GFP_KERNEL);
279 if (!dup->functions[fi_idx])
280 goto err_free;
281
282 *(dup->functions[fi_idx]) = *(info->functions[fi_idx]);
283
284 sci_ptr = info->functions[fi_idx]->ctrs;
285 dci_ptr = dup->functions[fi_idx]->ctrs;
286
287 for (ct_idx = 0; ct_idx < active; ct_idx++) {
288
289 cv_size = sizeof(gcov_type) * sci_ptr->num;
290
291 dci_ptr->values = vmalloc(cv_size);
292
293 if (!dci_ptr->values)
294 goto err_free;
295
296 dci_ptr->num = sci_ptr->num;
297 memcpy(dci_ptr->values, sci_ptr->values, cv_size);
298
299 sci_ptr++;
300 dci_ptr++;
301 }
302 }
303
304 return dup;
305err_free:
306 gcov_info_free(dup);
307 return NULL;
308}
309
310/**
311 * gcov_info_free - release memory for profiling data set duplicate
312 * @info: profiling data set duplicate to free
313 */
314void gcov_info_free(struct gcov_info *info)
315{
316 unsigned int active;
317 unsigned int fi_idx;
318 unsigned int ct_idx;
319 struct gcov_ctr_info *ci_ptr;
320
321 if (!info->functions)
322 goto free_info;
323
324 active = num_counter_active(info);
325
326 for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
327 if (!info->functions[fi_idx])
328 continue;
329
330 ci_ptr = info->functions[fi_idx]->ctrs;
331
332 for (ct_idx = 0; ct_idx < active; ct_idx++, ci_ptr++)
333 vfree(ci_ptr->values);
334
335 kfree(info->functions[fi_idx]);
336 }
337
338free_info:
339 kfree(info->functions);
340 kfree(info->filename);
341 kfree(info);
342}
343
344#define ITER_STRIDE PAGE_SIZE
345
346/**
347 * struct gcov_iterator - specifies current file position in logical records
348 * @info: associated profiling data
349 * @buffer: buffer containing file data
350 * @size: size of buffer
351 * @pos: current position in file
352 */
353struct gcov_iterator {
354 struct gcov_info *info;
355 void *buffer;
356 size_t size;
357 loff_t pos;
358};
359
360/**
361 * store_gcov_u32 - store 32 bit number in gcov format to buffer
362 * @buffer: target buffer or NULL
363 * @off: offset into the buffer
364 * @v: value to be stored
365 *
366 * Number format defined by gcc: numbers are recorded in the 32 bit
367 * unsigned binary form of the endianness of the machine generating the
368 * file. Returns the number of bytes stored. If @buffer is %NULL, doesn't
369 * store anything.
370 */
371static size_t store_gcov_u32(void *buffer, size_t off, u32 v)
372{
373 u32 *data;
374
375 if (buffer) {
376 data = buffer + off;
377 *data = v;
378 }
379
380 return sizeof(*data);
381}
382
383/**
384 * store_gcov_u64 - store 64 bit number in gcov format to buffer
385 * @buffer: target buffer or NULL
386 * @off: offset into the buffer
387 * @v: value to be stored
388 *
389 * Number format defined by gcc: numbers are recorded in the 32 bit
390 * unsigned binary form of the endianness of the machine generating the
391 * file. 64 bit numbers are stored as two 32 bit numbers, the low part
392 * first. Returns the number of bytes stored. If @buffer is %NULL, doesn't store
393 * anything.
394 */
395static size_t store_gcov_u64(void *buffer, size_t off, u64 v)
396{
397 u32 *data;
398
399 if (buffer) {
400 data = buffer + off;
401
402 data[0] = (v & 0xffffffffUL);
403 data[1] = (v >> 32);
404 }
405
406 return sizeof(*data) * 2;
407}
408
409/**
410 * convert_to_gcda - convert profiling data set to gcda file format
411 * @buffer: the buffer to store file data or %NULL if no data should be stored
412 * @info: profiling data set to be converted
413 *
414 * Returns the number of bytes that were/would have been stored into the buffer.
415 */
416static size_t convert_to_gcda(char *buffer, struct gcov_info *info)
417{
418 struct gcov_fn_info *fi_ptr;
419 struct gcov_ctr_info *ci_ptr;
420 unsigned int fi_idx;
421 unsigned int ct_idx;
422 unsigned int cv_idx;
423 size_t pos = 0;
424
425 /* File header. */
426 pos += store_gcov_u32(buffer, pos, GCOV_DATA_MAGIC);
427 pos += store_gcov_u32(buffer, pos, info->version);
428 pos += store_gcov_u32(buffer, pos, info->stamp);
429
430 for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
431 fi_ptr = info->functions[fi_idx];
432
433 /* Function record. */
434 pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION);
435 pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION_LENGTH);
436 pos += store_gcov_u32(buffer, pos, fi_ptr->ident);
437 pos += store_gcov_u32(buffer, pos, fi_ptr->lineno_checksum);
438 pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
439
440 ci_ptr = fi_ptr->ctrs;
441
442 for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
443 if (!counter_active(info, ct_idx))
444 continue;
445
446 /* Counter record. */
447 pos += store_gcov_u32(buffer, pos,
448 GCOV_TAG_FOR_COUNTER(ct_idx));
449 pos += store_gcov_u32(buffer, pos, ci_ptr->num * 2);
450
451 for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) {
452 pos += store_gcov_u64(buffer, pos,
453 ci_ptr->values[cv_idx]);
454 }
455
456 ci_ptr++;
457 }
458 }
459
460 return pos;
461}
462
463/**
464 * gcov_iter_new - allocate and initialize profiling data iterator
465 * @info: profiling data set to be iterated
466 *
467 * Return file iterator on success, %NULL otherwise.
468 */
469struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
470{
471 struct gcov_iterator *iter;
472
473 iter = kzalloc(sizeof(struct gcov_iterator), GFP_KERNEL);
474 if (!iter)
475 goto err_free;
476
477 iter->info = info;
478 /* Dry-run to get the actual buffer size. */
479 iter->size = convert_to_gcda(NULL, info);
480 iter->buffer = vmalloc(iter->size);
481 if (!iter->buffer)
482 goto err_free;
483
484 convert_to_gcda(iter->buffer, info);
485
486 return iter;
487
488err_free:
489 kfree(iter);
490 return NULL;
491}
492
493
494/**
495 * gcov_iter_get_info - return profiling data set for given file iterator
496 * @iter: file iterator
497 */
498void gcov_iter_free(struct gcov_iterator *iter)
499{
500 vfree(iter->buffer);
501 kfree(iter);
502}
503
504/**
505 * gcov_iter_get_info - return profiling data set for given file iterator
506 * @iter: file iterator
507 */
508struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter)
509{
510 return iter->info;
511}
512
513/**
514 * gcov_iter_start - reset file iterator to starting position
515 * @iter: file iterator
516 */
517void gcov_iter_start(struct gcov_iterator *iter)
518{
519 iter->pos = 0;
520}
521
522/**
523 * gcov_iter_next - advance file iterator to next logical record
524 * @iter: file iterator
525 *
526 * Return zero if new position is valid, non-zero if iterator has reached end.
527 */
528int gcov_iter_next(struct gcov_iterator *iter)
529{
530 if (iter->pos < iter->size)
531 iter->pos += ITER_STRIDE;
532
533 if (iter->pos >= iter->size)
534 return -EINVAL;
535
536 return 0;
537}
538
539/**
540 * gcov_iter_write - write data for current pos to seq_file
541 * @iter: file iterator
542 * @seq: seq_file handle
543 *
544 * Return zero on success, non-zero otherwise.
545 */
546int gcov_iter_write(struct gcov_iterator *iter, struct seq_file *seq)
547{
548 size_t len;
549
550 if (iter->pos >= iter->size)
551 return -EINVAL;
552
553 len = ITER_STRIDE;
554 if (iter->pos + len > iter->size)
555 len = iter->size - iter->pos;
556
557 seq_write(seq, iter->buffer + iter->pos, len);
558
559 return 0;
560}
diff --git a/kernel/gcov/gcov.h b/kernel/gcov/gcov.h
index 060073ebf7a6..92c8e22a29ed 100644
--- a/kernel/gcov/gcov.h
+++ b/kernel/gcov/gcov.h
@@ -21,7 +21,6 @@
21 * gcc and need to be kept as close to the original definition as possible to 21 * gcc and need to be kept as close to the original definition as possible to
22 * remain compatible. 22 * remain compatible.
23 */ 23 */
24#define GCOV_COUNTERS 5
25#define GCOV_DATA_MAGIC ((unsigned int) 0x67636461) 24#define GCOV_DATA_MAGIC ((unsigned int) 0x67636461)
26#define GCOV_TAG_FUNCTION ((unsigned int) 0x01000000) 25#define GCOV_TAG_FUNCTION ((unsigned int) 0x01000000)
27#define GCOV_TAG_COUNTER_BASE ((unsigned int) 0x01a10000) 26#define GCOV_TAG_COUNTER_BASE ((unsigned int) 0x01a10000)
@@ -34,60 +33,18 @@ typedef long gcov_type;
34typedef long long gcov_type; 33typedef long long gcov_type;
35#endif 34#endif
36 35
37/** 36/* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
38 * struct gcov_fn_info - profiling meta data per function 37 * we cannot use full definition here and they need to be placed in gcc specific
39 * @ident: object file-unique function identifier 38 * implementation of gcov. This also means no direct access to the members in
40 * @checksum: function checksum 39 * generic code and usage of the interface below.*/
41 * @n_ctrs: number of values per counter type belonging to this function 40struct gcov_info;
42 *
43 * This data is generated by gcc during compilation and doesn't change
44 * at run-time.
45 */
46struct gcov_fn_info {
47 unsigned int ident;
48 unsigned int checksum;
49 unsigned int n_ctrs[0];
50};
51
52/**
53 * struct gcov_ctr_info - profiling data per counter type
54 * @num: number of counter values for this type
55 * @values: array of counter values for this type
56 * @merge: merge function for counter values of this type (unused)
57 *
58 * This data is generated by gcc during compilation and doesn't change
59 * at run-time with the exception of the values array.
60 */
61struct gcov_ctr_info {
62 unsigned int num;
63 gcov_type *values;
64 void (*merge)(gcov_type *, unsigned int);
65};
66 41
67/** 42/* Interface to access gcov_info data */
68 * struct gcov_info - profiling data per object file 43const char *gcov_info_filename(struct gcov_info *info);
69 * @version: gcov version magic indicating the gcc version used for compilation 44unsigned int gcov_info_version(struct gcov_info *info);
70 * @next: list head for a singly-linked list 45struct gcov_info *gcov_info_next(struct gcov_info *info);
71 * @stamp: time stamp 46void gcov_info_link(struct gcov_info *info);
72 * @filename: name of the associated gcov data file 47void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
73 * @n_functions: number of instrumented functions
74 * @functions: function data
75 * @ctr_mask: mask specifying which counter types are active
76 * @counts: counter data per counter type
77 *
78 * This data is generated by gcc during compilation and doesn't change
79 * at run-time with the exception of the next pointer.
80 */
81struct gcov_info {
82 unsigned int version;
83 struct gcov_info *next;
84 unsigned int stamp;
85 const char *filename;
86 unsigned int n_functions;
87 const struct gcov_fn_info *functions;
88 unsigned int ctr_mask;
89 struct gcov_ctr_info counts[0];
90};
91 48
92/* Base interface. */ 49/* Base interface. */
93enum gcov_action { 50enum gcov_action {
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index a0d367a49122..ceeadfcabb76 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2066,7 +2066,7 @@ static int __init init_kprobes(void)
2066{ 2066{
2067 int i, err = 0; 2067 int i, err = 0;
2068 unsigned long offset = 0, size = 0; 2068 unsigned long offset = 0, size = 0;
2069 char *modname, namebuf[128]; 2069 char *modname, namebuf[KSYM_NAME_LEN];
2070 const char *symbol_name; 2070 const char *symbol_name;
2071 void *addr; 2071 void *addr;
2072 struct kprobe_blackpoint *kb; 2072 struct kprobe_blackpoint *kb;
@@ -2192,7 +2192,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
2192 const char *sym = NULL; 2192 const char *sym = NULL;
2193 unsigned int i = *(loff_t *) v; 2193 unsigned int i = *(loff_t *) v;
2194 unsigned long offset = 0; 2194 unsigned long offset = 0;
2195 char *modname, namebuf[128]; 2195 char *modname, namebuf[KSYM_NAME_LEN];
2196 2196
2197 head = &kprobe_table[i]; 2197 head = &kprobe_table[i];
2198 preempt_disable(); 2198 preempt_disable();
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 760e86df8c20..b5ae3ee860a9 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -33,7 +33,7 @@ struct kthread_create_info
33 33
34 /* Result passed back to kthread_create() from kthreadd. */ 34 /* Result passed back to kthread_create() from kthreadd. */
35 struct task_struct *result; 35 struct task_struct *result;
36 struct completion done; 36 struct completion *done;
37 37
38 struct list_head list; 38 struct list_head list;
39}; 39};
@@ -178,6 +178,7 @@ static int kthread(void *_create)
178 struct kthread_create_info *create = _create; 178 struct kthread_create_info *create = _create;
179 int (*threadfn)(void *data) = create->threadfn; 179 int (*threadfn)(void *data) = create->threadfn;
180 void *data = create->data; 180 void *data = create->data;
181 struct completion *done;
181 struct kthread self; 182 struct kthread self;
182 int ret; 183 int ret;
183 184
@@ -187,10 +188,16 @@ static int kthread(void *_create)
187 init_completion(&self.parked); 188 init_completion(&self.parked);
188 current->vfork_done = &self.exited; 189 current->vfork_done = &self.exited;
189 190
191 /* If user was SIGKILLed, I release the structure. */
192 done = xchg(&create->done, NULL);
193 if (!done) {
194 kfree(create);
195 do_exit(-EINTR);
196 }
190 /* OK, tell user we're spawned, wait for stop or wakeup */ 197 /* OK, tell user we're spawned, wait for stop or wakeup */
191 __set_current_state(TASK_UNINTERRUPTIBLE); 198 __set_current_state(TASK_UNINTERRUPTIBLE);
192 create->result = current; 199 create->result = current;
193 complete(&create->done); 200 complete(done);
194 schedule(); 201 schedule();
195 202
196 ret = -EINTR; 203 ret = -EINTR;
@@ -223,8 +230,15 @@ static void create_kthread(struct kthread_create_info *create)
223 /* We want our own signal handler (we take no signals by default). */ 230 /* We want our own signal handler (we take no signals by default). */
224 pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); 231 pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
225 if (pid < 0) { 232 if (pid < 0) {
233 /* If user was SIGKILLed, I release the structure. */
234 struct completion *done = xchg(&create->done, NULL);
235
236 if (!done) {
237 kfree(create);
238 return;
239 }
226 create->result = ERR_PTR(pid); 240 create->result = ERR_PTR(pid);
227 complete(&create->done); 241 complete(done);
228 } 242 }
229} 243}
230 244
@@ -255,36 +269,59 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
255 const char namefmt[], 269 const char namefmt[],
256 ...) 270 ...)
257{ 271{
258 struct kthread_create_info create; 272 DECLARE_COMPLETION_ONSTACK(done);
259 273 struct task_struct *task;
260 create.threadfn = threadfn; 274 struct kthread_create_info *create = kmalloc(sizeof(*create),
261 create.data = data; 275 GFP_KERNEL);
262 create.node = node; 276
263 init_completion(&create.done); 277 if (!create)
278 return ERR_PTR(-ENOMEM);
279 create->threadfn = threadfn;
280 create->data = data;
281 create->node = node;
282 create->done = &done;
264 283
265 spin_lock(&kthread_create_lock); 284 spin_lock(&kthread_create_lock);
266 list_add_tail(&create.list, &kthread_create_list); 285 list_add_tail(&create->list, &kthread_create_list);
267 spin_unlock(&kthread_create_lock); 286 spin_unlock(&kthread_create_lock);
268 287
269 wake_up_process(kthreadd_task); 288 wake_up_process(kthreadd_task);
270 wait_for_completion(&create.done); 289 /*
271 290 * Wait for completion in killable state, for I might be chosen by
272 if (!IS_ERR(create.result)) { 291 * the OOM killer while kthreadd is trying to allocate memory for
292 * new kernel thread.
293 */
294 if (unlikely(wait_for_completion_killable(&done))) {
295 /*
296 * If I was SIGKILLed before kthreadd (or new kernel thread)
297 * calls complete(), leave the cleanup of this structure to
298 * that thread.
299 */
300 if (xchg(&create->done, NULL))
301 return ERR_PTR(-ENOMEM);
302 /*
303 * kthreadd (or new kernel thread) will call complete()
304 * shortly.
305 */
306 wait_for_completion(&done);
307 }
308 task = create->result;
309 if (!IS_ERR(task)) {
273 static const struct sched_param param = { .sched_priority = 0 }; 310 static const struct sched_param param = { .sched_priority = 0 };
274 va_list args; 311 va_list args;
275 312
276 va_start(args, namefmt); 313 va_start(args, namefmt);
277 vsnprintf(create.result->comm, sizeof(create.result->comm), 314 vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
278 namefmt, args);
279 va_end(args); 315 va_end(args);
280 /* 316 /*
281 * root may have changed our (kthreadd's) priority or CPU mask. 317 * root may have changed our (kthreadd's) priority or CPU mask.
282 * The kernel thread should not inherit these properties. 318 * The kernel thread should not inherit these properties.
283 */ 319 */
284 sched_setscheduler_nocheck(create.result, SCHED_NORMAL, &param); 320 sched_setscheduler_nocheck(task, SCHED_NORMAL, &param);
285 set_cpus_allowed_ptr(create.result, cpu_all_mask); 321 set_cpus_allowed_ptr(task, cpu_all_mask);
286 } 322 }
287 return create.result; 323 kfree(create);
324 return task;
288} 325}
289EXPORT_SYMBOL(kthread_create_on_node); 326EXPORT_SYMBOL(kthread_create_on_node);
290 327
diff --git a/kernel/module.c b/kernel/module.c
index dc582749fa13..af5ebd21d77b 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -378,23 +378,21 @@ static bool check_symbol(const struct symsearch *syms,
378 if (syms->licence == GPL_ONLY) 378 if (syms->licence == GPL_ONLY)
379 return false; 379 return false;
380 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { 380 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
381 printk(KERN_WARNING "Symbol %s is being used " 381 pr_warn("Symbol %s is being used by a non-GPL module, "
382 "by a non-GPL module, which will not " 382 "which will not be allowed in the future\n",
383 "be allowed in the future\n", fsa->name); 383 fsa->name);
384 } 384 }
385 } 385 }
386 386
387#ifdef CONFIG_UNUSED_SYMBOLS 387#ifdef CONFIG_UNUSED_SYMBOLS
388 if (syms->unused && fsa->warn) { 388 if (syms->unused && fsa->warn) {
389 printk(KERN_WARNING "Symbol %s is marked as UNUSED, " 389 pr_warn("Symbol %s is marked as UNUSED, however this module is "
390 "however this module is using it.\n", fsa->name); 390 "using it.\n", fsa->name);
391 printk(KERN_WARNING 391 pr_warn("This symbol will go away in the future.\n");
392 "This symbol will go away in the future.\n"); 392 pr_warn("Please evalute if this is the right api to use and if "
393 printk(KERN_WARNING 393 "it really is, submit a report the linux kernel "
394 "Please evalute if this is the right api to use and if " 394 "mailinglist together with submitting your code for "
395 "it really is, submit a report the linux kernel " 395 "inclusion.\n");
396 "mailinglist together with submitting your code for "
397 "inclusion.\n");
398 } 396 }
399#endif 397#endif
400 398
@@ -492,16 +490,15 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
492 return 0; 490 return 0;
493 491
494 if (align > PAGE_SIZE) { 492 if (align > PAGE_SIZE) {
495 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 493 pr_warn("%s: per-cpu alignment %li > %li\n",
496 mod->name, align, PAGE_SIZE); 494 mod->name, align, PAGE_SIZE);
497 align = PAGE_SIZE; 495 align = PAGE_SIZE;
498 } 496 }
499 497
500 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align); 498 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align);
501 if (!mod->percpu) { 499 if (!mod->percpu) {
502 printk(KERN_WARNING 500 pr_warn("%s: Could not allocate %lu bytes percpu data\n",
503 "%s: Could not allocate %lu bytes percpu data\n", 501 mod->name, (unsigned long)pcpusec->sh_size);
504 mod->name, (unsigned long)pcpusec->sh_size);
505 return -ENOMEM; 502 return -ENOMEM;
506 } 503 }
507 mod->percpu_size = pcpusec->sh_size; 504 mod->percpu_size = pcpusec->sh_size;
@@ -679,7 +676,7 @@ static int add_module_usage(struct module *a, struct module *b)
679 pr_debug("Allocating new usage for %s.\n", a->name); 676 pr_debug("Allocating new usage for %s.\n", a->name);
680 use = kmalloc(sizeof(*use), GFP_ATOMIC); 677 use = kmalloc(sizeof(*use), GFP_ATOMIC);
681 if (!use) { 678 if (!use) {
682 printk(KERN_WARNING "%s: out of memory loading\n", a->name); 679 pr_warn("%s: out of memory loading\n", a->name);
683 return -ENOMEM; 680 return -ENOMEM;
684 } 681 }
685 682
@@ -1145,8 +1142,7 @@ static int try_to_force_load(struct module *mod, const char *reason)
1145{ 1142{
1146#ifdef CONFIG_MODULE_FORCE_LOAD 1143#ifdef CONFIG_MODULE_FORCE_LOAD
1147 if (!test_taint(TAINT_FORCED_MODULE)) 1144 if (!test_taint(TAINT_FORCED_MODULE))
1148 printk(KERN_WARNING "%s: %s: kernel tainted.\n", 1145 pr_warn("%s: %s: kernel tainted.\n", mod->name, reason);
1149 mod->name, reason);
1150 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE); 1146 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
1151 return 0; 1147 return 0;
1152#else 1148#else
@@ -1199,8 +1195,7 @@ static int check_version(Elf_Shdr *sechdrs,
1199 goto bad_version; 1195 goto bad_version;
1200 } 1196 }
1201 1197
1202 printk(KERN_WARNING "%s: no symbol version for %s\n", 1198 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
1203 mod->name, symname);
1204 return 0; 1199 return 0;
1205 1200
1206bad_version: 1201bad_version:
@@ -1309,8 +1304,8 @@ resolve_symbol_wait(struct module *mod,
1309 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) 1304 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
1310 || PTR_ERR(ksym) != -EBUSY, 1305 || PTR_ERR(ksym) != -EBUSY,
1311 30 * HZ) <= 0) { 1306 30 * HZ) <= 0) {
1312 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", 1307 pr_warn("%s: gave up waiting for init of module %s.\n",
1313 mod->name, owner); 1308 mod->name, owner);
1314 } 1309 }
1315 return ksym; 1310 return ksym;
1316} 1311}
@@ -1626,15 +1621,14 @@ static int mod_sysfs_init(struct module *mod)
1626 struct kobject *kobj; 1621 struct kobject *kobj;
1627 1622
1628 if (!module_sysfs_initialized) { 1623 if (!module_sysfs_initialized) {
1629 printk(KERN_ERR "%s: module sysfs not initialized\n", 1624 pr_err("%s: module sysfs not initialized\n", mod->name);
1630 mod->name);
1631 err = -EINVAL; 1625 err = -EINVAL;
1632 goto out; 1626 goto out;
1633 } 1627 }
1634 1628
1635 kobj = kset_find_obj(module_kset, mod->name); 1629 kobj = kset_find_obj(module_kset, mod->name);
1636 if (kobj) { 1630 if (kobj) {
1637 printk(KERN_ERR "%s: module is already loaded\n", mod->name); 1631 pr_err("%s: module is already loaded\n", mod->name);
1638 kobject_put(kobj); 1632 kobject_put(kobj);
1639 err = -EINVAL; 1633 err = -EINVAL;
1640 goto out; 1634 goto out;
@@ -1961,8 +1955,7 @@ static int verify_export_symbols(struct module *mod)
1961 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1955 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1962 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 1956 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1963 if (find_symbol(s->name, &owner, NULL, true, false)) { 1957 if (find_symbol(s->name, &owner, NULL, true, false)) {
1964 printk(KERN_ERR 1958 pr_err("%s: exports duplicate symbol %s"
1965 "%s: exports duplicate symbol %s"
1966 " (owned by %s)\n", 1959 " (owned by %s)\n",
1967 mod->name, s->name, module_name(owner)); 1960 mod->name, s->name, module_name(owner));
1968 return -ENOEXEC; 1961 return -ENOEXEC;
@@ -2013,8 +2006,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
2013 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 2006 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
2014 break; 2007 break;
2015 2008
2016 printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", 2009 pr_warn("%s: Unknown symbol %s (err %li)\n",
2017 mod->name, name, PTR_ERR(ksym)); 2010 mod->name, name, PTR_ERR(ksym));
2018 ret = PTR_ERR(ksym) ?: -ENOENT; 2011 ret = PTR_ERR(ksym) ?: -ENOENT;
2019 break; 2012 break;
2020 2013
@@ -2168,8 +2161,8 @@ static void set_license(struct module *mod, const char *license)
2168 2161
2169 if (!license_is_gpl_compatible(license)) { 2162 if (!license_is_gpl_compatible(license)) {
2170 if (!test_taint(TAINT_PROPRIETARY_MODULE)) 2163 if (!test_taint(TAINT_PROPRIETARY_MODULE))
2171 printk(KERN_WARNING "%s: module license '%s' taints " 2164 pr_warn("%s: module license '%s' taints kernel.\n",
2172 "kernel.\n", mod->name, license); 2165 mod->name, license);
2173 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 2166 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
2174 LOCKDEP_NOW_UNRELIABLE); 2167 LOCKDEP_NOW_UNRELIABLE);
2175 } 2168 }
@@ -2405,8 +2398,8 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
2405 return; 2398 return;
2406#ifdef CONFIG_DYNAMIC_DEBUG 2399#ifdef CONFIG_DYNAMIC_DEBUG
2407 if (ddebug_add_module(debug, num, debug->modname)) 2400 if (ddebug_add_module(debug, num, debug->modname))
2408 printk(KERN_ERR "dynamic debug error adding module: %s\n", 2401 pr_err("dynamic debug error adding module: %s\n",
2409 debug->modname); 2402 debug->modname);
2410#endif 2403#endif
2411} 2404}
2412 2405
@@ -2619,8 +2612,7 @@ static int rewrite_section_headers(struct load_info *info, int flags)
2619 Elf_Shdr *shdr = &info->sechdrs[i]; 2612 Elf_Shdr *shdr = &info->sechdrs[i];
2620 if (shdr->sh_type != SHT_NOBITS 2613 if (shdr->sh_type != SHT_NOBITS
2621 && info->len < shdr->sh_offset + shdr->sh_size) { 2614 && info->len < shdr->sh_offset + shdr->sh_size) {
2622 printk(KERN_ERR "Module len %lu truncated\n", 2615 pr_err("Module len %lu truncated\n", info->len);
2623 info->len);
2624 return -ENOEXEC; 2616 return -ENOEXEC;
2625 } 2617 }
2626 2618
@@ -2682,15 +2674,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
2682 2674
2683 info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); 2675 info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
2684 if (!info->index.mod) { 2676 if (!info->index.mod) {
2685 printk(KERN_WARNING "No module found in object\n"); 2677 pr_warn("No module found in object\n");
2686 return ERR_PTR(-ENOEXEC); 2678 return ERR_PTR(-ENOEXEC);
2687 } 2679 }
2688 /* This is temporary: point mod into copy of data. */ 2680 /* This is temporary: point mod into copy of data. */
2689 mod = (void *)info->sechdrs[info->index.mod].sh_addr; 2681 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2690 2682
2691 if (info->index.sym == 0) { 2683 if (info->index.sym == 0) {
2692 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", 2684 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
2693 mod->name);
2694 return ERR_PTR(-ENOEXEC); 2685 return ERR_PTR(-ENOEXEC);
2695 } 2686 }
2696 2687
@@ -2717,7 +2708,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2717 if (err) 2708 if (err)
2718 return err; 2709 return err;
2719 } else if (!same_magic(modmagic, vermagic, info->index.vers)) { 2710 } else if (!same_magic(modmagic, vermagic, info->index.vers)) {
2720 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", 2711 pr_err("%s: version magic '%s' should be '%s'\n",
2721 mod->name, modmagic, vermagic); 2712 mod->name, modmagic, vermagic);
2722 return -ENOEXEC; 2713 return -ENOEXEC;
2723 } 2714 }
@@ -2727,9 +2718,8 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2727 2718
2728 if (get_modinfo(info, "staging")) { 2719 if (get_modinfo(info, "staging")) {
2729 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); 2720 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
2730 printk(KERN_WARNING "%s: module is from the staging directory," 2721 pr_warn("%s: module is from the staging directory, the quality "
2731 " the quality is unknown, you have been warned.\n", 2722 "is unknown, you have been warned.\n", mod->name);
2732 mod->name);
2733 } 2723 }
2734 2724
2735 /* Set up license info based on the info section */ 2725 /* Set up license info based on the info section */
@@ -2801,8 +2791,7 @@ static void find_module_sections(struct module *mod, struct load_info *info)
2801 sizeof(*mod->extable), &mod->num_exentries); 2791 sizeof(*mod->extable), &mod->num_exentries);
2802 2792
2803 if (section_addr(info, "__obsparm")) 2793 if (section_addr(info, "__obsparm"))
2804 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2794 pr_warn("%s: Ignoring obsolete parameters\n", mod->name);
2805 mod->name);
2806 2795
2807 info->debug = section_objs(info, "__verbose", 2796 info->debug = section_objs(info, "__verbose",
2808 sizeof(*info->debug), &info->num_debug); 2797 sizeof(*info->debug), &info->num_debug);
@@ -3078,11 +3067,10 @@ static int do_init_module(struct module *mod)
3078 return ret; 3067 return ret;
3079 } 3068 }
3080 if (ret > 0) { 3069 if (ret > 0) {
3081 printk(KERN_WARNING 3070 pr_warn("%s: '%s'->init suspiciously returned %d, it should "
3082"%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n" 3071 "follow 0/-E convention\n"
3083"%s: loading module anyway...\n", 3072 "%s: loading module anyway...\n",
3084 __func__, mod->name, ret, 3073 __func__, mod->name, ret, __func__);
3085 __func__);
3086 dump_stack(); 3074 dump_stack();
3087 } 3075 }
3088 3076
@@ -3205,10 +3193,8 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname)
3205{ 3193{
3206 /* Check for magic 'dyndbg' arg */ 3194 /* Check for magic 'dyndbg' arg */
3207 int ret = ddebug_dyndbg_module_param_cb(param, val, modname); 3195 int ret = ddebug_dyndbg_module_param_cb(param, val, modname);
3208 if (ret != 0) { 3196 if (ret != 0)
3209 printk(KERN_WARNING "%s: unknown parameter '%s' ignored\n", 3197 pr_warn("%s: unknown parameter '%s' ignored\n", modname, param);
3210 modname, param);
3211 }
3212 return 0; 3198 return 0;
3213} 3199}
3214 3200
@@ -3243,10 +3229,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3243#ifdef CONFIG_MODULE_SIG 3229#ifdef CONFIG_MODULE_SIG
3244 mod->sig_ok = info->sig_ok; 3230 mod->sig_ok = info->sig_ok;
3245 if (!mod->sig_ok) { 3231 if (!mod->sig_ok) {
3246 printk_once(KERN_NOTICE 3232 pr_notice_once("%s: module verification failed: signature "
3247 "%s: module verification failed: signature and/or" 3233 "and/or required key missing - tainting "
3248 " required key missing - tainting kernel\n", 3234 "kernel\n", mod->name);
3249 mod->name);
3250 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); 3235 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK);
3251 } 3236 }
3252#endif 3237#endif
diff --git a/kernel/panic.c b/kernel/panic.c
index b6c482ccc5db..c00b4ceb39e8 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -233,7 +233,7 @@ static const struct tnt tnts[] = {
233 */ 233 */
234const char *print_tainted(void) 234const char *print_tainted(void)
235{ 235{
236 static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ") + 1]; 236 static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ")];
237 237
238 if (tainted_mask) { 238 if (tainted_mask) {
239 char *s; 239 char *s;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b4e8500afdb3..be7c86bae576 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -705,9 +705,9 @@ const struct file_operations kmsg_fops = {
705 705
706#ifdef CONFIG_KEXEC 706#ifdef CONFIG_KEXEC
707/* 707/*
708 * This appends the listed symbols to /proc/vmcoreinfo 708 * This appends the listed symbols to /proc/vmcore
709 * 709 *
710 * /proc/vmcoreinfo is used by various utiilties, like crash and makedumpfile to 710 * /proc/vmcore is used by various utilities, like crash and makedumpfile to
711 * obtain access to symbols that are otherwise very difficult to locate. These 711 * obtain access to symbols that are otherwise very difficult to locate. These
712 * symbols are specifically used so that utilities can access and extract the 712 * symbols are specifically used so that utilities can access and extract the
713 * dmesg log from a vmcore file after a crash. 713 * dmesg log from a vmcore file after a crash.
@@ -791,7 +791,7 @@ static bool __read_mostly ignore_loglevel;
791static int __init ignore_loglevel_setup(char *str) 791static int __init ignore_loglevel_setup(char *str)
792{ 792{
793 ignore_loglevel = 1; 793 ignore_loglevel = 1;
794 printk(KERN_INFO "debug: ignoring loglevel setting.\n"); 794 pr_info("debug: ignoring loglevel setting.\n");
795 795
796 return 0; 796 return 0;
797} 797}
@@ -820,9 +820,9 @@ static int __init boot_delay_setup(char *str)
820 pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, " 820 pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
821 "HZ: %d, loops_per_msec: %llu\n", 821 "HZ: %d, loops_per_msec: %llu\n",
822 boot_delay, preset_lpj, lpj, HZ, loops_per_msec); 822 boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
823 return 1; 823 return 0;
824} 824}
825__setup("boot_delay=", boot_delay_setup); 825early_param("boot_delay", boot_delay_setup);
826 826
827static void boot_delay_msec(int level) 827static void boot_delay_msec(int level)
828{ 828{
@@ -2193,7 +2193,7 @@ static int __read_mostly keep_bootcon;
2193static int __init keep_bootcon_setup(char *str) 2193static int __init keep_bootcon_setup(char *str)
2194{ 2194{
2195 keep_bootcon = 1; 2195 keep_bootcon = 1;
2196 printk(KERN_INFO "debug: skip boot console de-registration.\n"); 2196 pr_info("debug: skip boot console de-registration.\n");
2197 2197
2198 return 0; 2198 return 0;
2199} 2199}
@@ -2241,7 +2241,7 @@ void register_console(struct console *newcon)
2241 /* find the last or real console */ 2241 /* find the last or real console */
2242 for_each_console(bcon) { 2242 for_each_console(bcon) {
2243 if (!(bcon->flags & CON_BOOT)) { 2243 if (!(bcon->flags & CON_BOOT)) {
2244 printk(KERN_INFO "Too late to register bootconsole %s%d\n", 2244 pr_info("Too late to register bootconsole %s%d\n",
2245 newcon->name, newcon->index); 2245 newcon->name, newcon->index);
2246 return; 2246 return;
2247 } 2247 }
@@ -2358,21 +2358,18 @@ void register_console(struct console *newcon)
2358 * users know there might be something in the kernel's log buffer that 2358 * users know there might be something in the kernel's log buffer that
2359 * went to the bootconsole (that they do not see on the real console) 2359 * went to the bootconsole (that they do not see on the real console)
2360 */ 2360 */
2361 pr_info("%sconsole [%s%d] enabled\n",
2362 (newcon->flags & CON_BOOT) ? "boot" : "" ,
2363 newcon->name, newcon->index);
2361 if (bcon && 2364 if (bcon &&
2362 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && 2365 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
2363 !keep_bootcon) { 2366 !keep_bootcon) {
2364 /* we need to iterate through twice, to make sure we print 2367 /* We need to iterate through all boot consoles, to make
2365 * everything out, before we unregister the console(s) 2368 * sure we print everything out, before we unregister them.
2366 */ 2369 */
2367 printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n",
2368 newcon->name, newcon->index);
2369 for_each_console(bcon) 2370 for_each_console(bcon)
2370 if (bcon->flags & CON_BOOT) 2371 if (bcon->flags & CON_BOOT)
2371 unregister_console(bcon); 2372 unregister_console(bcon);
2372 } else {
2373 printk(KERN_INFO "%sconsole [%s%d] enabled\n",
2374 (newcon->flags & CON_BOOT) ? "boot" : "" ,
2375 newcon->name, newcon->index);
2376 } 2373 }
2377} 2374}
2378EXPORT_SYMBOL(register_console); 2375EXPORT_SYMBOL(register_console);
@@ -2382,6 +2379,10 @@ int unregister_console(struct console *console)
2382 struct console *a, *b; 2379 struct console *a, *b;
2383 int res; 2380 int res;
2384 2381
2382 pr_info("%sconsole [%s%d] disabled\n",
2383 (console->flags & CON_BOOT) ? "boot" : "" ,
2384 console->name, console->index);
2385
2385 res = _braille_unregister_console(console); 2386 res = _braille_unregister_console(console);
2386 if (res) 2387 if (res)
2387 return res; 2388 return res;
@@ -2421,8 +2422,6 @@ static int __init printk_late_init(void)
2421 2422
2422 for_each_console(con) { 2423 for_each_console(con) {
2423 if (!keep_bootcon && con->flags & CON_BOOT) { 2424 if (!keep_bootcon && con->flags & CON_BOOT) {
2424 printk(KERN_INFO "turn off boot console %s%d\n",
2425 con->name, con->index);
2426 unregister_console(con); 2425 unregister_console(con);
2427 } 2426 }
2428 } 2427 }
@@ -2449,7 +2448,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work)
2449 2448
2450 if (pending & PRINTK_PENDING_SCHED) { 2449 if (pending & PRINTK_PENDING_SCHED) {
2451 char *buf = __get_cpu_var(printk_sched_buf); 2450 char *buf = __get_cpu_var(printk_sched_buf);
2452 printk(KERN_WARNING "[sched_delayed] %s", buf); 2451 pr_warn("[sched_delayed] %s", buf);
2453 } 2452 }
2454 2453
2455 if (pending & PRINTK_PENDING_WAKEUP) 2454 if (pending & PRINTK_PENDING_WAKEUP)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index dd562e9aa2c8..1f4bcb3cc21c 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -257,7 +257,8 @@ ok:
257 if (task->mm) 257 if (task->mm)
258 dumpable = get_dumpable(task->mm); 258 dumpable = get_dumpable(task->mm);
259 rcu_read_lock(); 259 rcu_read_lock();
260 if (!dumpable && !ptrace_has_cap(__task_cred(task)->user_ns, mode)) { 260 if (dumpable != SUID_DUMP_USER &&
261 !ptrace_has_cap(__task_cred(task)->user_ns, mode)) {
261 rcu_read_unlock(); 262 rcu_read_unlock();
262 return -EPERM; 263 return -EPERM;
263 } 264 }
diff --git a/kernel/sys.c b/kernel/sys.c
index c18ecca575b4..c72311324ea7 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -16,7 +16,6 @@
16#include <linux/perf_event.h> 16#include <linux/perf_event.h>
17#include <linux/resource.h> 17#include <linux/resource.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/kexec.h>
20#include <linux/workqueue.h> 19#include <linux/workqueue.h>
21#include <linux/capability.h> 20#include <linux/capability.h>
22#include <linux/device.h> 21#include <linux/device.h>
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 36547dddcdb8..d37d9dd8f463 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2222,8 +2222,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
2222 *i = val; 2222 *i = val;
2223 } else { 2223 } else {
2224 val = convdiv * (*i) / convmul; 2224 val = convdiv * (*i) / convmul;
2225 if (!first) 2225 if (!first) {
2226 err = proc_put_char(&buffer, &left, '\t'); 2226 err = proc_put_char(&buffer, &left, '\t');
2227 if (err)
2228 break;
2229 }
2227 err = proc_put_long(&buffer, &left, val, false); 2230 err = proc_put_long(&buffer, &left, val, false);
2228 if (err) 2231 if (err)
2229 break; 2232 break;
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index b609213ca9a2..653cbbd9e7ad 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -1024,7 +1024,7 @@ static ssize_t bin_intvec(struct file *file,
1024 if (get_user(value, vec + i)) 1024 if (get_user(value, vec + i))
1025 goto out_kfree; 1025 goto out_kfree;
1026 1026
1027 str += snprintf(str, end - str, "%lu\t", value); 1027 str += scnprintf(str, end - str, "%lu\t", value);
1028 } 1028 }
1029 1029
1030 result = kernel_write(file, buffer, str - buffer, 0); 1030 result = kernel_write(file, buffer, str - buffer, 0);
@@ -1095,7 +1095,7 @@ static ssize_t bin_ulongvec(struct file *file,
1095 if (get_user(value, vec + i)) 1095 if (get_user(value, vec + i))
1096 goto out_kfree; 1096 goto out_kfree;
1097 1097
1098 str += snprintf(str, end - str, "%lu\t", value); 1098 str += scnprintf(str, end - str, "%lu\t", value);
1099 } 1099 }
1100 1100
1101 result = kernel_write(file, buffer, str - buffer, 0); 1101 result = kernel_write(file, buffer, str - buffer, 0);
@@ -1205,7 +1205,7 @@ static ssize_t bin_dn_node_address(struct file *file,
1205 if (get_user(dnaddr, (__le16 __user *)newval)) 1205 if (get_user(dnaddr, (__le16 __user *)newval))
1206 goto out; 1206 goto out;
1207 1207
1208 len = snprintf(buf, sizeof(buf), "%hu.%hu", 1208 len = scnprintf(buf, sizeof(buf), "%hu.%hu",
1209 le16_to_cpu(dnaddr) >> 10, 1209 le16_to_cpu(dnaddr) >> 10,
1210 le16_to_cpu(dnaddr) & 0x3ff); 1210 le16_to_cpu(dnaddr) & 0x3ff);
1211 1211
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 145bb4d3bd4d..9f4618eb51c8 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -290,6 +290,7 @@ static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
290 struct listener_list *listeners; 290 struct listener_list *listeners;
291 struct listener *s, *tmp, *s2; 291 struct listener *s, *tmp, *s2;
292 unsigned int cpu; 292 unsigned int cpu;
293 int ret = 0;
293 294
294 if (!cpumask_subset(mask, cpu_possible_mask)) 295 if (!cpumask_subset(mask, cpu_possible_mask))
295 return -EINVAL; 296 return -EINVAL;
@@ -304,9 +305,10 @@ static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
304 for_each_cpu(cpu, mask) { 305 for_each_cpu(cpu, mask) {
305 s = kmalloc_node(sizeof(struct listener), 306 s = kmalloc_node(sizeof(struct listener),
306 GFP_KERNEL, cpu_to_node(cpu)); 307 GFP_KERNEL, cpu_to_node(cpu));
307 if (!s) 308 if (!s) {
309 ret = -ENOMEM;
308 goto cleanup; 310 goto cleanup;
309 311 }
310 s->pid = pid; 312 s->pid = pid;
311 s->valid = 1; 313 s->valid = 1;
312 314
@@ -339,7 +341,7 @@ cleanup:
339 } 341 }
340 up_write(&listeners->sem); 342 up_write(&listeners->sem);
341 } 343 }
342 return 0; 344 return ret;
343} 345}
344 346
345static int parse(struct nlattr *na, struct cpumask *mask) 347static int parse(struct nlattr *na, struct cpumask *mask)
@@ -404,11 +406,15 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
404 if (!na) 406 if (!na)
405 goto err; 407 goto err;
406 408
407 if (nla_put(skb, type, sizeof(pid), &pid) < 0) 409 if (nla_put(skb, type, sizeof(pid), &pid) < 0) {
410 nla_nest_cancel(skb, na);
408 goto err; 411 goto err;
412 }
409 ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats)); 413 ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
410 if (!ret) 414 if (!ret) {
415 nla_nest_cancel(skb, na);
411 goto err; 416 goto err;
417 }
412 nla_nest_end(skb, na); 418 nla_nest_end(skb, na);
413 419
414 return nla_data(ret); 420 return nla_data(ret);
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ebef88f61b7d..db25707aa41b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1481,6 +1481,15 @@ config INTERVAL_TREE_TEST
1481 help 1481 help
1482 A benchmark measuring the performance of the interval tree library 1482 A benchmark measuring the performance of the interval tree library
1483 1483
1484config PERCPU_TEST
1485 tristate "Per cpu operations test"
1486 depends on m && DEBUG_KERNEL
1487 help
1488 Enable this option to build test module which validates per-cpu
1489 operations.
1490
1491 If unsure, say N.
1492
1484config ATOMIC64_SELFTEST 1493config ATOMIC64_SELFTEST
1485 bool "Perform an atomic64_t self-test at boot" 1494 bool "Perform an atomic64_t self-test at boot"
1486 help 1495 help
diff --git a/lib/Makefile b/lib/Makefile
index f3bb2cb98adf..bb016e116ba4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -157,6 +157,8 @@ obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
157 157
158interval_tree_test-objs := interval_tree_test_main.o interval_tree.o 158interval_tree_test-objs := interval_tree_test_main.o interval_tree.o
159 159
160obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
161
160obj-$(CONFIG_ASN1) += asn1_decoder.o 162obj-$(CONFIG_ASN1) += asn1_decoder.o
161 163
162obj-$(CONFIG_FONT_SUPPORT) += fonts/ 164obj-$(CONFIG_FONT_SUPPORT) += fonts/
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index bf2c8b1043d8..e0731c3db706 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -196,7 +196,7 @@ static void free_object(struct debug_obj *obj)
196 * initialized: 196 * initialized:
197 */ 197 */
198 if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache) 198 if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache)
199 sched = keventd_up() && !work_pending(&debug_obj_work); 199 sched = keventd_up();
200 hlist_add_head(&obj->node, &obj_pool); 200 hlist_add_head(&obj->node, &obj_pool);
201 obj_pool_free++; 201 obj_pool_free++;
202 obj_pool_used--; 202 obj_pool_used--;
diff --git a/lib/digsig.c b/lib/digsig.c
index 2f31e6a45f0a..8793aeda30ca 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -209,7 +209,7 @@ int digsig_verify(struct key *keyring, const char *sig, int siglen,
209 kref = keyring_search(make_key_ref(keyring, 1UL), 209 kref = keyring_search(make_key_ref(keyring, 1UL),
210 &key_type_user, name); 210 &key_type_user, name);
211 if (IS_ERR(kref)) 211 if (IS_ERR(kref))
212 key = ERR_PTR(PTR_ERR(kref)); 212 key = ERR_CAST(kref);
213 else 213 else
214 key = key_ref_to_ptr(kref); 214 key = key_ref_to_ptr(kref);
215 } else { 215 } else {
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 26cf20be72b7..dda31168844f 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -313,6 +313,34 @@ retry:
313EXPORT_SYMBOL(gen_pool_alloc); 313EXPORT_SYMBOL(gen_pool_alloc);
314 314
315/** 315/**
316 * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
317 * @pool: pool to allocate from
318 * @size: number of bytes to allocate from the pool
319 * @dma: dma-view physical address
320 *
321 * Allocate the requested number of bytes from the specified pool.
322 * Uses the pool allocation function (with first-fit algorithm by default).
323 * Can not be used in NMI handler on architectures without
324 * NMI-safe cmpxchg implementation.
325 */
326void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
327{
328 unsigned long vaddr;
329
330 if (!pool)
331 return NULL;
332
333 vaddr = gen_pool_alloc(pool, size);
334 if (!vaddr)
335 return NULL;
336
337 *dma = gen_pool_virt_to_phys(pool, vaddr);
338
339 return (void *)vaddr;
340}
341EXPORT_SYMBOL(gen_pool_dma_alloc);
342
343/**
316 * gen_pool_free - free allocated special memory back to the pool 344 * gen_pool_free - free allocated special memory back to the pool
317 * @pool: pool to free to 345 * @pool: pool to free to
318 * @addr: starting address of memory to free back to pool 346 * @addr: starting address of memory to free back to pool
diff --git a/lib/percpu_test.c b/lib/percpu_test.c
new file mode 100644
index 000000000000..0b5d14dadd1a
--- /dev/null
+++ b/lib/percpu_test.c
@@ -0,0 +1,138 @@
1#include <linux/module.h>
2
3/* validate @native and @pcp counter values match @expected */
4#define CHECK(native, pcp, expected) \
5 do { \
6 WARN((native) != (expected), \
7 "raw %ld (0x%lx) != expected %lld (0x%llx)", \
8 (native), (native), \
9 (long long)(expected), (long long)(expected)); \
10 WARN(__this_cpu_read(pcp) != (expected), \
11 "pcp %ld (0x%lx) != expected %lld (0x%llx)", \
12 __this_cpu_read(pcp), __this_cpu_read(pcp), \
13 (long long)(expected), (long long)(expected)); \
14 } while (0)
15
16static DEFINE_PER_CPU(long, long_counter);
17static DEFINE_PER_CPU(unsigned long, ulong_counter);
18
19static int __init percpu_test_init(void)
20{
21 /*
22 * volatile prevents compiler from optimizing it uses, otherwise the
23 * +ul_one/-ul_one below would replace with inc/dec instructions.
24 */
25 volatile unsigned int ui_one = 1;
26 long l = 0;
27 unsigned long ul = 0;
28
29 pr_info("percpu test start\n");
30
31 preempt_disable();
32
33 l += -1;
34 __this_cpu_add(long_counter, -1);
35 CHECK(l, long_counter, -1);
36
37 l += 1;
38 __this_cpu_add(long_counter, 1);
39 CHECK(l, long_counter, 0);
40
41 ul = 0;
42 __this_cpu_write(ulong_counter, 0);
43
44 ul += 1UL;
45 __this_cpu_add(ulong_counter, 1UL);
46 CHECK(ul, ulong_counter, 1);
47
48 ul += -1UL;
49 __this_cpu_add(ulong_counter, -1UL);
50 CHECK(ul, ulong_counter, 0);
51
52 ul += -(unsigned long)1;
53 __this_cpu_add(ulong_counter, -(unsigned long)1);
54 CHECK(ul, ulong_counter, -1);
55
56 ul = 0;
57 __this_cpu_write(ulong_counter, 0);
58
59 ul -= 1;
60 __this_cpu_dec(ulong_counter);
61 CHECK(ul, ulong_counter, -1);
62 CHECK(ul, ulong_counter, ULONG_MAX);
63
64 l += -ui_one;
65 __this_cpu_add(long_counter, -ui_one);
66 CHECK(l, long_counter, 0xffffffff);
67
68 l += ui_one;
69 __this_cpu_add(long_counter, ui_one);
70 CHECK(l, long_counter, (long)0x100000000LL);
71
72
73 l = 0;
74 __this_cpu_write(long_counter, 0);
75
76 l -= ui_one;
77 __this_cpu_sub(long_counter, ui_one);
78 CHECK(l, long_counter, -1);
79
80 l = 0;
81 __this_cpu_write(long_counter, 0);
82
83 l += ui_one;
84 __this_cpu_add(long_counter, ui_one);
85 CHECK(l, long_counter, 1);
86
87 l += -ui_one;
88 __this_cpu_add(long_counter, -ui_one);
89 CHECK(l, long_counter, (long)0x100000000LL);
90
91 l = 0;
92 __this_cpu_write(long_counter, 0);
93
94 l -= ui_one;
95 this_cpu_sub(long_counter, ui_one);
96 CHECK(l, long_counter, -1);
97 CHECK(l, long_counter, ULONG_MAX);
98
99 ul = 0;
100 __this_cpu_write(ulong_counter, 0);
101
102 ul += ui_one;
103 __this_cpu_add(ulong_counter, ui_one);
104 CHECK(ul, ulong_counter, 1);
105
106 ul = 0;
107 __this_cpu_write(ulong_counter, 0);
108
109 ul -= ui_one;
110 __this_cpu_sub(ulong_counter, ui_one);
111 CHECK(ul, ulong_counter, -1);
112 CHECK(ul, ulong_counter, ULONG_MAX);
113
114 ul = 3;
115 __this_cpu_write(ulong_counter, 3);
116
117 ul = this_cpu_sub_return(ulong_counter, ui_one);
118 CHECK(ul, ulong_counter, 2);
119
120 ul = __this_cpu_sub_return(ulong_counter, ui_one);
121 CHECK(ul, ulong_counter, 1);
122
123 preempt_enable();
124
125 pr_info("percpu test done\n");
126 return -EAGAIN; /* Fail will directly unload the module */
127}
128
129static void __exit percpu_test_exit(void)
130{
131}
132
133module_init(percpu_test_init)
134module_exit(percpu_test_exit)
135
136MODULE_LICENSE("GPL");
137MODULE_AUTHOR("Greg Thelen");
138MODULE_DESCRIPTION("percpu operations test");
diff --git a/lib/show_mem.c b/lib/show_mem.c
index b7c72311ad0c..5847a4921b8e 100644
--- a/lib/show_mem.c
+++ b/lib/show_mem.c
@@ -12,8 +12,7 @@
12void show_mem(unsigned int filter) 12void show_mem(unsigned int filter)
13{ 13{
14 pg_data_t *pgdat; 14 pg_data_t *pgdat;
15 unsigned long total = 0, reserved = 0, shared = 0, 15 unsigned long total = 0, reserved = 0, highmem = 0;
16 nonshared = 0, highmem = 0;
17 16
18 printk("Mem-Info:\n"); 17 printk("Mem-Info:\n");
19 show_free_areas(filter); 18 show_free_areas(filter);
@@ -22,43 +21,27 @@ void show_mem(unsigned int filter)
22 return; 21 return;
23 22
24 for_each_online_pgdat(pgdat) { 23 for_each_online_pgdat(pgdat) {
25 unsigned long i, flags; 24 unsigned long flags;
25 int zoneid;
26 26
27 pgdat_resize_lock(pgdat, &flags); 27 pgdat_resize_lock(pgdat, &flags);
28 for (i = 0; i < pgdat->node_spanned_pages; i++) { 28 for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
29 struct page *page; 29 struct zone *zone = &pgdat->node_zones[zoneid];
30 unsigned long pfn = pgdat->node_start_pfn + i; 30 if (!populated_zone(zone))
31
32 if (unlikely(!(i % MAX_ORDER_NR_PAGES)))
33 touch_nmi_watchdog();
34
35 if (!pfn_valid(pfn))
36 continue; 31 continue;
37 32
38 page = pfn_to_page(pfn); 33 total += zone->present_pages;
39 34 reserved = zone->present_pages - zone->managed_pages;
40 if (PageHighMem(page))
41 highmem++;
42 35
43 if (PageReserved(page)) 36 if (is_highmem_idx(zoneid))
44 reserved++; 37 highmem += zone->present_pages;
45 else if (page_count(page) == 1)
46 nonshared++;
47 else if (page_count(page) > 1)
48 shared += page_count(page) - 1;
49
50 total++;
51 } 38 }
52 pgdat_resize_unlock(pgdat, &flags); 39 pgdat_resize_unlock(pgdat, &flags);
53 } 40 }
54 41
55 printk("%lu pages RAM\n", total); 42 printk("%lu pages RAM\n", total);
56#ifdef CONFIG_HIGHMEM 43 printk("%lu pages HighMem/MovableOnly\n", highmem);
57 printk("%lu pages HighMem\n", highmem);
58#endif
59 printk("%lu pages reserved\n", reserved); 44 printk("%lu pages reserved\n", reserved);
60 printk("%lu pages shared\n", shared);
61 printk("%lu pages non-shared\n", nonshared);
62#ifdef CONFIG_QUICKLIST 45#ifdef CONFIG_QUICKLIST
63 printk("%lu pages in pagetable cache\n", 46 printk("%lu pages in pagetable cache\n",
64 quicklist_total_size()); 47 quicklist_total_size());
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 26559bdb4c49..48586ac3a62e 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -27,6 +27,7 @@
27#include <linux/uaccess.h> 27#include <linux/uaccess.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/dcache.h> 29#include <linux/dcache.h>
30#include <linux/cred.h>
30#include <net/addrconf.h> 31#include <net/addrconf.h>
31 32
32#include <asm/page.h> /* for PAGE_SIZE */ 33#include <asm/page.h> /* for PAGE_SIZE */
@@ -1218,6 +1219,8 @@ int kptr_restrict __read_mostly;
1218 * The maximum supported length is 64 bytes of the input. Consider 1219 * The maximum supported length is 64 bytes of the input. Consider
1219 * to use print_hex_dump() for the larger input. 1220 * to use print_hex_dump() for the larger input.
1220 * - 'a' For a phys_addr_t type and its derivative types (passed by reference) 1221 * - 'a' For a phys_addr_t type and its derivative types (passed by reference)
1222 * - 'd[234]' For a dentry name (optionally 2-4 last components)
1223 * - 'D[234]' Same as 'd' but for a struct file
1221 * 1224 *
1222 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 1225 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
1223 * function pointers are really function descriptors, which contain a 1226 * function pointers are really function descriptors, which contain a
@@ -1312,11 +1315,37 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1312 spec.field_width = default_width; 1315 spec.field_width = default_width;
1313 return string(buf, end, "pK-error", spec); 1316 return string(buf, end, "pK-error", spec);
1314 } 1317 }
1315 if (!((kptr_restrict == 0) || 1318
1316 (kptr_restrict == 1 && 1319 switch (kptr_restrict) {
1317 has_capability_noaudit(current, CAP_SYSLOG)))) 1320 case 0:
1321 /* Always print %pK values */
1322 break;
1323 case 1: {
1324 /*
1325 * Only print the real pointer value if the current
1326 * process has CAP_SYSLOG and is running with the
1327 * same credentials it started with. This is because
1328 * access to files is checked at open() time, but %pK
1329 * checks permission at read() time. We don't want to
1330 * leak pointer values if a binary opens a file using
1331 * %pK and then elevates privileges before reading it.
1332 */
1333 const struct cred *cred = current_cred();
1334
1335 if (!has_capability_noaudit(current, CAP_SYSLOG) ||
1336 !uid_eq(cred->euid, cred->uid) ||
1337 !gid_eq(cred->egid, cred->gid))
1338 ptr = NULL;
1339 break;
1340 }
1341 case 2:
1342 default:
1343 /* Always print 0's for %pK */
1318 ptr = NULL; 1344 ptr = NULL;
1345 break;
1346 }
1319 break; 1347 break;
1348
1320 case 'N': 1349 case 'N':
1321 switch (fmt[1]) { 1350 switch (fmt[1]) {
1322 case 'F': 1351 case 'F':
diff --git a/mm/Kconfig b/mm/Kconfig
index 394838f489eb..3f4ffda152bb 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -153,11 +153,18 @@ config MOVABLE_NODE
153 help 153 help
154 Allow a node to have only movable memory. Pages used by the kernel, 154 Allow a node to have only movable memory. Pages used by the kernel,
155 such as direct mapping pages cannot be migrated. So the corresponding 155 such as direct mapping pages cannot be migrated. So the corresponding
156 memory device cannot be hotplugged. This option allows users to 156 memory device cannot be hotplugged. This option allows the following
157 online all the memory of a node as movable memory so that the whole 157 two things:
158 node can be hotplugged. Users who don't use the memory hotplug 158 - When the system is booting, node full of hotpluggable memory can
159 feature are fine with this option on since they don't online memory 159 be arranged to have only movable memory so that the whole node can
160 as movable. 160 be hot-removed. (need movable_node boot option specified).
161 - After the system is up, the option allows users to online all the
162 memory of a node as movable memory so that the whole node can be
163 hot-removed.
164
165 Users who don't use the memory hotplug feature are fine with this
166 option on since they don't specify movable_node boot option or they
167 don't online memory as movable.
161 168
162 Say Y here if you want to hotplug a whole node. 169 Say Y here if you want to hotplug a whole node.
163 Say N here if you want kernel to use memory on all nodes evenly. 170 Say N here if you want kernel to use memory on all nodes evenly.
diff --git a/mm/bootmem.c b/mm/bootmem.c
index 6ab7744e692e..90bd3507b413 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -172,11 +172,12 @@ void __init free_bootmem_late(unsigned long physaddr, unsigned long size)
172static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata) 172static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
173{ 173{
174 struct page *page; 174 struct page *page;
175 unsigned long start, end, pages, count = 0; 175 unsigned long *map, start, end, pages, count = 0;
176 176
177 if (!bdata->node_bootmem_map) 177 if (!bdata->node_bootmem_map)
178 return 0; 178 return 0;
179 179
180 map = bdata->node_bootmem_map;
180 start = bdata->node_min_pfn; 181 start = bdata->node_min_pfn;
181 end = bdata->node_low_pfn; 182 end = bdata->node_low_pfn;
182 183
@@ -184,10 +185,9 @@ static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
184 bdata - bootmem_node_data, start, end); 185 bdata - bootmem_node_data, start, end);
185 186
186 while (start < end) { 187 while (start < end) {
187 unsigned long *map, idx, vec; 188 unsigned long idx, vec;
188 unsigned shift; 189 unsigned shift;
189 190
190 map = bdata->node_bootmem_map;
191 idx = start - bdata->node_min_pfn; 191 idx = start - bdata->node_min_pfn;
192 shift = idx & (BITS_PER_LONG - 1); 192 shift = idx & (BITS_PER_LONG - 1);
193 /* 193 /*
@@ -784,7 +784,7 @@ void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size,
784 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); 784 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
785 785
786 /* update goal according ...MAX_DMA32_PFN */ 786 /* update goal according ...MAX_DMA32_PFN */
787 end_pfn = pgdat->node_start_pfn + pgdat->node_spanned_pages; 787 end_pfn = pgdat_end_pfn(pgdat);
788 788
789 if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) && 789 if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) &&
790 (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) { 790 (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) {
diff --git a/mm/compaction.c b/mm/compaction.c
index b5326b141a25..805165bcd3dd 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -235,10 +235,9 @@ static bool suitable_migration_target(struct page *page)
235} 235}
236 236
237/* 237/*
238 * Isolate free pages onto a private freelist. Caller must hold zone->lock. 238 * Isolate free pages onto a private freelist. If @strict is true, will abort
239 * If @strict is true, will abort returning 0 on any invalid PFNs or non-free 239 * returning 0 on any invalid PFNs or non-free pages inside of the pageblock
240 * pages inside of the pageblock (even though it may still end up isolating 240 * (even though it may still end up isolating some pages).
241 * some pages).
242 */ 241 */
243static unsigned long isolate_freepages_block(struct compact_control *cc, 242static unsigned long isolate_freepages_block(struct compact_control *cc,
244 unsigned long blockpfn, 243 unsigned long blockpfn,
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 2612f60f53ee..0556c6a44959 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -27,11 +27,12 @@
27#include "internal.h" 27#include "internal.h"
28 28
29/* 29/*
30 * By default transparent hugepage support is enabled for all mappings 30 * By default transparent hugepage support is disabled in order that avoid
31 * and khugepaged scans all mappings. Defrag is only invoked by 31 * to risk increase the memory footprint of applications without a guaranteed
32 * khugepaged hugepage allocations and by page faults inside 32 * benefit. When transparent hugepage support is enabled, is for all mappings,
33 * MADV_HUGEPAGE regions to avoid the risk of slowing down short lived 33 * and khugepaged scans all mappings.
34 * allocations. 34 * Defrag is invoked by khugepaged hugepage allocations and by page faults
35 * for all hugepage allocations.
35 */ 36 */
36unsigned long transparent_hugepage_flags __read_mostly = 37unsigned long transparent_hugepage_flags __read_mostly =
37#ifdef CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS 38#ifdef CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS
@@ -758,14 +759,6 @@ static inline struct page *alloc_hugepage_vma(int defrag,
758 HPAGE_PMD_ORDER, vma, haddr, nd); 759 HPAGE_PMD_ORDER, vma, haddr, nd);
759} 760}
760 761
761#ifndef CONFIG_NUMA
762static inline struct page *alloc_hugepage(int defrag)
763{
764 return alloc_pages(alloc_hugepage_gfpmask(defrag, 0),
765 HPAGE_PMD_ORDER);
766}
767#endif
768
769static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm, 762static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
770 struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd, 763 struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd,
771 struct page *zero_page) 764 struct page *zero_page)
@@ -2198,7 +2191,34 @@ static void khugepaged_alloc_sleep(void)
2198 msecs_to_jiffies(khugepaged_alloc_sleep_millisecs)); 2191 msecs_to_jiffies(khugepaged_alloc_sleep_millisecs));
2199} 2192}
2200 2193
2194static int khugepaged_node_load[MAX_NUMNODES];
2195
2201#ifdef CONFIG_NUMA 2196#ifdef CONFIG_NUMA
2197static int khugepaged_find_target_node(void)
2198{
2199 static int last_khugepaged_target_node = NUMA_NO_NODE;
2200 int nid, target_node = 0, max_value = 0;
2201
2202 /* find first node with max normal pages hit */
2203 for (nid = 0; nid < MAX_NUMNODES; nid++)
2204 if (khugepaged_node_load[nid] > max_value) {
2205 max_value = khugepaged_node_load[nid];
2206 target_node = nid;
2207 }
2208
2209 /* do some balance if several nodes have the same hit record */
2210 if (target_node <= last_khugepaged_target_node)
2211 for (nid = last_khugepaged_target_node + 1; nid < MAX_NUMNODES;
2212 nid++)
2213 if (max_value == khugepaged_node_load[nid]) {
2214 target_node = nid;
2215 break;
2216 }
2217
2218 last_khugepaged_target_node = target_node;
2219 return target_node;
2220}
2221
2202static bool khugepaged_prealloc_page(struct page **hpage, bool *wait) 2222static bool khugepaged_prealloc_page(struct page **hpage, bool *wait)
2203{ 2223{
2204 if (IS_ERR(*hpage)) { 2224 if (IS_ERR(*hpage)) {
@@ -2232,9 +2252,8 @@ static struct page
2232 * mmap_sem in read mode is good idea also to allow greater 2252 * mmap_sem in read mode is good idea also to allow greater
2233 * scalability. 2253 * scalability.
2234 */ 2254 */
2235 *hpage = alloc_hugepage_vma(khugepaged_defrag(), vma, address, 2255 *hpage = alloc_pages_exact_node(node, alloc_hugepage_gfpmask(
2236 node, __GFP_OTHER_NODE); 2256 khugepaged_defrag(), __GFP_OTHER_NODE), HPAGE_PMD_ORDER);
2237
2238 /* 2257 /*
2239 * After allocating the hugepage, release the mmap_sem read lock in 2258 * After allocating the hugepage, release the mmap_sem read lock in
2240 * preparation for taking it in write mode. 2259 * preparation for taking it in write mode.
@@ -2250,6 +2269,17 @@ static struct page
2250 return *hpage; 2269 return *hpage;
2251} 2270}
2252#else 2271#else
2272static int khugepaged_find_target_node(void)
2273{
2274 return 0;
2275}
2276
2277static inline struct page *alloc_hugepage(int defrag)
2278{
2279 return alloc_pages(alloc_hugepage_gfpmask(defrag, 0),
2280 HPAGE_PMD_ORDER);
2281}
2282
2253static struct page *khugepaged_alloc_hugepage(bool *wait) 2283static struct page *khugepaged_alloc_hugepage(bool *wait)
2254{ 2284{
2255 struct page *hpage; 2285 struct page *hpage;
@@ -2456,6 +2486,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
2456 if (pmd_trans_huge(*pmd)) 2486 if (pmd_trans_huge(*pmd))
2457 goto out; 2487 goto out;
2458 2488
2489 memset(khugepaged_node_load, 0, sizeof(khugepaged_node_load));
2459 pte = pte_offset_map_lock(mm, pmd, address, &ptl); 2490 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
2460 for (_address = address, _pte = pte; _pte < pte+HPAGE_PMD_NR; 2491 for (_address = address, _pte = pte; _pte < pte+HPAGE_PMD_NR;
2461 _pte++, _address += PAGE_SIZE) { 2492 _pte++, _address += PAGE_SIZE) {
@@ -2472,12 +2503,13 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
2472 if (unlikely(!page)) 2503 if (unlikely(!page))
2473 goto out_unmap; 2504 goto out_unmap;
2474 /* 2505 /*
2475 * Chose the node of the first page. This could 2506 * Record which node the original page is from and save this
2476 * be more sophisticated and look at more pages, 2507 * information to khugepaged_node_load[].
2477 * but isn't for now. 2508 * Khupaged will allocate hugepage from the node has the max
2509 * hit record.
2478 */ 2510 */
2479 if (node == NUMA_NO_NODE) 2511 node = page_to_nid(page);
2480 node = page_to_nid(page); 2512 khugepaged_node_load[node]++;
2481 VM_BUG_ON(PageCompound(page)); 2513 VM_BUG_ON(PageCompound(page));
2482 if (!PageLRU(page) || PageLocked(page) || !PageAnon(page)) 2514 if (!PageLRU(page) || PageLocked(page) || !PageAnon(page))
2483 goto out_unmap; 2515 goto out_unmap;
@@ -2492,9 +2524,11 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
2492 ret = 1; 2524 ret = 1;
2493out_unmap: 2525out_unmap:
2494 pte_unmap_unlock(pte, ptl); 2526 pte_unmap_unlock(pte, ptl);
2495 if (ret) 2527 if (ret) {
2528 node = khugepaged_find_target_node();
2496 /* collapse_huge_page will return with the mmap_sem released */ 2529 /* collapse_huge_page will return with the mmap_sem released */
2497 collapse_huge_page(mm, address, hpage, vma, node); 2530 collapse_huge_page(mm, address, hpage, vma, node);
2531 }
2498out: 2532out:
2499 return ret; 2533 return ret;
2500} 2534}
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index e126b0ef9ad2..31f01c5011e5 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -753,7 +753,9 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
753 } 753 }
754 754
755 spin_lock_irqsave(&object->lock, flags); 755 spin_lock_irqsave(&object->lock, flags);
756 if (ptr + size > object->pointer + object->size) { 756 if (size == SIZE_MAX) {
757 size = object->pointer + object->size - ptr;
758 } else if (ptr + size > object->pointer + object->size) {
757 kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr); 759 kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr);
758 dump_object_info(object); 760 dump_object_info(object);
759 kmem_cache_free(scan_area_cache, area); 761 kmem_cache_free(scan_area_cache, area);
diff --git a/mm/ksm.c b/mm/ksm.c
index 0bea2b262a47..175fff79dc95 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2309,8 +2309,8 @@ static ssize_t merge_across_nodes_store(struct kobject *kobj,
2309 * Allocate stable and unstable together: 2309 * Allocate stable and unstable together:
2310 * MAXSMP NODES_SHIFT 10 will use 16kB. 2310 * MAXSMP NODES_SHIFT 10 will use 16kB.
2311 */ 2311 */
2312 buf = kcalloc(nr_node_ids + nr_node_ids, 2312 buf = kcalloc(nr_node_ids + nr_node_ids, sizeof(*buf),
2313 sizeof(*buf), GFP_KERNEL | __GFP_ZERO); 2313 GFP_KERNEL);
2314 /* Let us assume that RB_ROOT is NULL is zero */ 2314 /* Let us assume that RB_ROOT is NULL is zero */
2315 if (!buf) 2315 if (!buf)
2316 err = -ENOMEM; 2316 err = -ENOMEM;
diff --git a/mm/memblock.c b/mm/memblock.c
index 0ac412a0a7ee..53e477bb5558 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -20,6 +20,8 @@
20#include <linux/seq_file.h> 20#include <linux/seq_file.h>
21#include <linux/memblock.h> 21#include <linux/memblock.h>
22 22
23#include <asm-generic/sections.h>
24
23static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; 25static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
24static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; 26static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
25 27
@@ -32,6 +34,7 @@ struct memblock memblock __initdata_memblock = {
32 .reserved.cnt = 1, /* empty dummy entry */ 34 .reserved.cnt = 1, /* empty dummy entry */
33 .reserved.max = INIT_MEMBLOCK_REGIONS, 35 .reserved.max = INIT_MEMBLOCK_REGIONS,
34 36
37 .bottom_up = false,
35 .current_limit = MEMBLOCK_ALLOC_ANYWHERE, 38 .current_limit = MEMBLOCK_ALLOC_ANYWHERE,
36}; 39};
37 40
@@ -82,6 +85,73 @@ static long __init_memblock memblock_overlaps_region(struct memblock_type *type,
82 return (i < type->cnt) ? i : -1; 85 return (i < type->cnt) ? i : -1;
83} 86}
84 87
88/*
89 * __memblock_find_range_bottom_up - find free area utility in bottom-up
90 * @start: start of candidate range
91 * @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE}
92 * @size: size of free area to find
93 * @align: alignment of free area to find
94 * @nid: nid of the free area to find, %MAX_NUMNODES for any node
95 *
96 * Utility called from memblock_find_in_range_node(), find free area bottom-up.
97 *
98 * RETURNS:
99 * Found address on success, 0 on failure.
100 */
101static phys_addr_t __init_memblock
102__memblock_find_range_bottom_up(phys_addr_t start, phys_addr_t end,
103 phys_addr_t size, phys_addr_t align, int nid)
104{
105 phys_addr_t this_start, this_end, cand;
106 u64 i;
107
108 for_each_free_mem_range(i, nid, &this_start, &this_end, NULL) {
109 this_start = clamp(this_start, start, end);
110 this_end = clamp(this_end, start, end);
111
112 cand = round_up(this_start, align);
113 if (cand < this_end && this_end - cand >= size)
114 return cand;
115 }
116
117 return 0;
118}
119
120/**
121 * __memblock_find_range_top_down - find free area utility, in top-down
122 * @start: start of candidate range
123 * @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE}
124 * @size: size of free area to find
125 * @align: alignment of free area to find
126 * @nid: nid of the free area to find, %MAX_NUMNODES for any node
127 *
128 * Utility called from memblock_find_in_range_node(), find free area top-down.
129 *
130 * RETURNS:
131 * Found address on success, 0 on failure.
132 */
133static phys_addr_t __init_memblock
134__memblock_find_range_top_down(phys_addr_t start, phys_addr_t end,
135 phys_addr_t size, phys_addr_t align, int nid)
136{
137 phys_addr_t this_start, this_end, cand;
138 u64 i;
139
140 for_each_free_mem_range_reverse(i, nid, &this_start, &this_end, NULL) {
141 this_start = clamp(this_start, start, end);
142 this_end = clamp(this_end, start, end);
143
144 if (this_end < size)
145 continue;
146
147 cand = round_down(this_end - size, align);
148 if (cand >= this_start)
149 return cand;
150 }
151
152 return 0;
153}
154
85/** 155/**
86 * memblock_find_in_range_node - find free area in given range and node 156 * memblock_find_in_range_node - find free area in given range and node
87 * @start: start of candidate range 157 * @start: start of candidate range
@@ -92,15 +162,23 @@ static long __init_memblock memblock_overlaps_region(struct memblock_type *type,
92 * 162 *
93 * Find @size free area aligned to @align in the specified range and node. 163 * Find @size free area aligned to @align in the specified range and node.
94 * 164 *
165 * When allocation direction is bottom-up, the @start should be greater
166 * than the end of the kernel image. Otherwise, it will be trimmed. The
167 * reason is that we want the bottom-up allocation just near the kernel
168 * image so it is highly likely that the allocated memory and the kernel
169 * will reside in the same node.
170 *
171 * If bottom-up allocation failed, will try to allocate memory top-down.
172 *
95 * RETURNS: 173 * RETURNS:
96 * Found address on success, %0 on failure. 174 * Found address on success, 0 on failure.
97 */ 175 */
98phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t start, 176phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t start,
99 phys_addr_t end, phys_addr_t size, 177 phys_addr_t end, phys_addr_t size,
100 phys_addr_t align, int nid) 178 phys_addr_t align, int nid)
101{ 179{
102 phys_addr_t this_start, this_end, cand; 180 int ret;
103 u64 i; 181 phys_addr_t kernel_end;
104 182
105 /* pump up @end */ 183 /* pump up @end */
106 if (end == MEMBLOCK_ALLOC_ACCESSIBLE) 184 if (end == MEMBLOCK_ALLOC_ACCESSIBLE)
@@ -109,19 +187,39 @@ phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t start,
109 /* avoid allocating the first page */ 187 /* avoid allocating the first page */
110 start = max_t(phys_addr_t, start, PAGE_SIZE); 188 start = max_t(phys_addr_t, start, PAGE_SIZE);
111 end = max(start, end); 189 end = max(start, end);
190 kernel_end = __pa_symbol(_end);
112 191
113 for_each_free_mem_range_reverse(i, nid, &this_start, &this_end, NULL) { 192 /*
114 this_start = clamp(this_start, start, end); 193 * try bottom-up allocation only when bottom-up mode
115 this_end = clamp(this_end, start, end); 194 * is set and @end is above the kernel image.
195 */
196 if (memblock_bottom_up() && end > kernel_end) {
197 phys_addr_t bottom_up_start;
116 198
117 if (this_end < size) 199 /* make sure we will allocate above the kernel */
118 continue; 200 bottom_up_start = max(start, kernel_end);
119 201
120 cand = round_down(this_end - size, align); 202 /* ok, try bottom-up allocation first */
121 if (cand >= this_start) 203 ret = __memblock_find_range_bottom_up(bottom_up_start, end,
122 return cand; 204 size, align, nid);
205 if (ret)
206 return ret;
207
208 /*
209 * we always limit bottom-up allocation above the kernel,
210 * but top-down allocation doesn't have the limit, so
211 * retrying top-down allocation may succeed when bottom-up
212 * allocation failed.
213 *
214 * bottom-up allocation is expected to be fail very rarely,
215 * so we use WARN_ONCE() here to see the stack trace if
216 * fail happens.
217 */
218 WARN_ONCE(1, "memblock: bottom-up allocation failed, "
219 "memory hotunplug may be affected\n");
123 } 220 }
124 return 0; 221
222 return __memblock_find_range_top_down(start, end, size, align, nid);
125} 223}
126 224
127/** 225/**
@@ -134,7 +232,7 @@ phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t start,
134 * Find @size free area aligned to @align in the specified range. 232 * Find @size free area aligned to @align in the specified range.
135 * 233 *
136 * RETURNS: 234 * RETURNS:
137 * Found address on success, %0 on failure. 235 * Found address on success, 0 on failure.
138 */ 236 */
139phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start, 237phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,
140 phys_addr_t end, phys_addr_t size, 238 phys_addr_t end, phys_addr_t size,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 796820925de0..f20a57b7faf2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -59,6 +59,7 @@
59#include <net/sock.h> 59#include <net/sock.h>
60#include <net/ip.h> 60#include <net/ip.h>
61#include <net/tcp_memcontrol.h> 61#include <net/tcp_memcontrol.h>
62#include "slab.h"
62 63
63#include <asm/uaccess.h> 64#include <asm/uaccess.h>
64 65
@@ -2968,7 +2969,7 @@ static struct kmem_cache *memcg_params_to_cache(struct memcg_cache_params *p)
2968 2969
2969 VM_BUG_ON(p->is_root_cache); 2970 VM_BUG_ON(p->is_root_cache);
2970 cachep = p->root_cache; 2971 cachep = p->root_cache;
2971 return cachep->memcg_params->memcg_caches[memcg_cache_id(p->memcg)]; 2972 return cache_from_memcg_idx(cachep, memcg_cache_id(p->memcg));
2972} 2973}
2973 2974
2974#ifdef CONFIG_SLABINFO 2975#ifdef CONFIG_SLABINFO
@@ -2997,21 +2998,14 @@ static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
2997 struct res_counter *fail_res; 2998 struct res_counter *fail_res;
2998 struct mem_cgroup *_memcg; 2999 struct mem_cgroup *_memcg;
2999 int ret = 0; 3000 int ret = 0;
3000 bool may_oom;
3001 3001
3002 ret = res_counter_charge(&memcg->kmem, size, &fail_res); 3002 ret = res_counter_charge(&memcg->kmem, size, &fail_res);
3003 if (ret) 3003 if (ret)
3004 return ret; 3004 return ret;
3005 3005
3006 /*
3007 * Conditions under which we can wait for the oom_killer. Those are
3008 * the same conditions tested by the core page allocator
3009 */
3010 may_oom = (gfp & __GFP_FS) && !(gfp & __GFP_NORETRY);
3011
3012 _memcg = memcg; 3006 _memcg = memcg;
3013 ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, 3007 ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT,
3014 &_memcg, may_oom); 3008 &_memcg, oom_gfp_allowed(gfp));
3015 3009
3016 if (ret == -EINTR) { 3010 if (ret == -EINTR) {
3017 /* 3011 /*
@@ -3151,7 +3145,7 @@ int memcg_update_cache_size(struct kmem_cache *s, int num_groups)
3151{ 3145{
3152 struct memcg_cache_params *cur_params = s->memcg_params; 3146 struct memcg_cache_params *cur_params = s->memcg_params;
3153 3147
3154 VM_BUG_ON(s->memcg_params && !s->memcg_params->is_root_cache); 3148 VM_BUG_ON(!is_root_cache(s));
3155 3149
3156 if (num_groups > memcg_limited_groups_array_size) { 3150 if (num_groups > memcg_limited_groups_array_size) {
3157 int i; 3151 int i;
@@ -3412,7 +3406,7 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
3412 idx = memcg_cache_id(memcg); 3406 idx = memcg_cache_id(memcg);
3413 3407
3414 mutex_lock(&memcg_cache_mutex); 3408 mutex_lock(&memcg_cache_mutex);
3415 new_cachep = cachep->memcg_params->memcg_caches[idx]; 3409 new_cachep = cache_from_memcg_idx(cachep, idx);
3416 if (new_cachep) { 3410 if (new_cachep) {
3417 css_put(&memcg->css); 3411 css_put(&memcg->css);
3418 goto out; 3412 goto out;
@@ -3458,8 +3452,8 @@ void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
3458 * we'll take the set_limit_mutex to protect ourselves against this. 3452 * we'll take the set_limit_mutex to protect ourselves against this.
3459 */ 3453 */
3460 mutex_lock(&set_limit_mutex); 3454 mutex_lock(&set_limit_mutex);
3461 for (i = 0; i < memcg_limited_groups_array_size; i++) { 3455 for_each_memcg_cache_index(i) {
3462 c = s->memcg_params->memcg_caches[i]; 3456 c = cache_from_memcg_idx(s, i);
3463 if (!c) 3457 if (!c)
3464 continue; 3458 continue;
3465 3459
@@ -3592,8 +3586,8 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep,
3592 * code updating memcg_caches will issue a write barrier to match this. 3586 * code updating memcg_caches will issue a write barrier to match this.
3593 */ 3587 */
3594 read_barrier_depends(); 3588 read_barrier_depends();
3595 if (likely(cachep->memcg_params->memcg_caches[idx])) { 3589 if (likely(cache_from_memcg_idx(cachep, idx))) {
3596 cachep = cachep->memcg_params->memcg_caches[idx]; 3590 cachep = cache_from_memcg_idx(cachep, idx);
3597 goto out; 3591 goto out;
3598 } 3592 }
3599 3593
@@ -5389,45 +5383,50 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css,
5389static int memcg_numa_stat_show(struct cgroup_subsys_state *css, 5383static int memcg_numa_stat_show(struct cgroup_subsys_state *css,
5390 struct cftype *cft, struct seq_file *m) 5384 struct cftype *cft, struct seq_file *m)
5391{ 5385{
5386 struct numa_stat {
5387 const char *name;
5388 unsigned int lru_mask;
5389 };
5390
5391 static const struct numa_stat stats[] = {
5392 { "total", LRU_ALL },
5393 { "file", LRU_ALL_FILE },
5394 { "anon", LRU_ALL_ANON },
5395 { "unevictable", BIT(LRU_UNEVICTABLE) },
5396 };
5397 const struct numa_stat *stat;
5392 int nid; 5398 int nid;
5393 unsigned long total_nr, file_nr, anon_nr, unevictable_nr; 5399 unsigned long nr;
5394 unsigned long node_nr;
5395 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 5400 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5396 5401
5397 total_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL); 5402 for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
5398 seq_printf(m, "total=%lu", total_nr); 5403 nr = mem_cgroup_nr_lru_pages(memcg, stat->lru_mask);
5399 for_each_node_state(nid, N_MEMORY) { 5404 seq_printf(m, "%s=%lu", stat->name, nr);
5400 node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid, LRU_ALL); 5405 for_each_node_state(nid, N_MEMORY) {
5401 seq_printf(m, " N%d=%lu", nid, node_nr); 5406 nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
5402 } 5407 stat->lru_mask);
5403 seq_putc(m, '\n'); 5408 seq_printf(m, " N%d=%lu", nid, nr);
5404 5409 }
5405 file_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_FILE); 5410 seq_putc(m, '\n');
5406 seq_printf(m, "file=%lu", file_nr); 5411 }
5407 for_each_node_state(nid, N_MEMORY) { 5412
5408 node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid, 5413 for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
5409 LRU_ALL_FILE); 5414 struct mem_cgroup *iter;
5410 seq_printf(m, " N%d=%lu", nid, node_nr); 5415
5411 } 5416 nr = 0;
5412 seq_putc(m, '\n'); 5417 for_each_mem_cgroup_tree(iter, memcg)
5413 5418 nr += mem_cgroup_nr_lru_pages(iter, stat->lru_mask);
5414 anon_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_ANON); 5419 seq_printf(m, "hierarchical_%s=%lu", stat->name, nr);
5415 seq_printf(m, "anon=%lu", anon_nr); 5420 for_each_node_state(nid, N_MEMORY) {
5416 for_each_node_state(nid, N_MEMORY) { 5421 nr = 0;
5417 node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid, 5422 for_each_mem_cgroup_tree(iter, memcg)
5418 LRU_ALL_ANON); 5423 nr += mem_cgroup_node_nr_lru_pages(
5419 seq_printf(m, " N%d=%lu", nid, node_nr); 5424 iter, nid, stat->lru_mask);
5425 seq_printf(m, " N%d=%lu", nid, nr);
5426 }
5427 seq_putc(m, '\n');
5420 } 5428 }
5421 seq_putc(m, '\n');
5422 5429
5423 unevictable_nr = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_UNEVICTABLE));
5424 seq_printf(m, "unevictable=%lu", unevictable_nr);
5425 for_each_node_state(nid, N_MEMORY) {
5426 node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
5427 BIT(LRU_UNEVICTABLE));
5428 seq_printf(m, " N%d=%lu", nid, node_nr);
5429 }
5430 seq_putc(m, '\n');
5431 return 0; 5430 return 0;
5432} 5431}
5433#endif /* CONFIG_NUMA */ 5432#endif /* CONFIG_NUMA */
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index bf3351b5115e..f9d78ec7831f 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1423,19 +1423,6 @@ static int __get_any_page(struct page *p, unsigned long pfn, int flags)
1423 return 1; 1423 return 1;
1424 1424
1425 /* 1425 /*
1426 * The lock_memory_hotplug prevents a race with memory hotplug.
1427 * This is a big hammer, a better would be nicer.
1428 */
1429 lock_memory_hotplug();
1430
1431 /*
1432 * Isolate the page, so that it doesn't get reallocated if it
1433 * was free. This flag should be kept set until the source page
1434 * is freed and PG_hwpoison on it is set.
1435 */
1436 if (get_pageblock_migratetype(p) != MIGRATE_ISOLATE)
1437 set_migratetype_isolate(p, true);
1438 /*
1439 * When the target page is a free hugepage, just remove it 1426 * When the target page is a free hugepage, just remove it
1440 * from free hugepage list. 1427 * from free hugepage list.
1441 */ 1428 */
@@ -1455,7 +1442,6 @@ static int __get_any_page(struct page *p, unsigned long pfn, int flags)
1455 /* Not a free page */ 1442 /* Not a free page */
1456 ret = 1; 1443 ret = 1;
1457 } 1444 }
1458 unlock_memory_hotplug();
1459 return ret; 1445 return ret;
1460} 1446}
1461 1447
@@ -1654,15 +1640,28 @@ int soft_offline_page(struct page *page, int flags)
1654 } 1640 }
1655 } 1641 }
1656 1642
1643 /*
1644 * The lock_memory_hotplug prevents a race with memory hotplug.
1645 * This is a big hammer, a better would be nicer.
1646 */
1647 lock_memory_hotplug();
1648
1649 /*
1650 * Isolate the page, so that it doesn't get reallocated if it
1651 * was free. This flag should be kept set until the source page
1652 * is freed and PG_hwpoison on it is set.
1653 */
1654 if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
1655 set_migratetype_isolate(page, true);
1656
1657 ret = get_any_page(page, pfn, flags); 1657 ret = get_any_page(page, pfn, flags);
1658 if (ret < 0) 1658 unlock_memory_hotplug();
1659 goto unset; 1659 if (ret > 0) { /* for in-use pages */
1660 if (ret) { /* for in-use pages */
1661 if (PageHuge(page)) 1660 if (PageHuge(page))
1662 ret = soft_offline_huge_page(page, flags); 1661 ret = soft_offline_huge_page(page, flags);
1663 else 1662 else
1664 ret = __soft_offline_page(page, flags); 1663 ret = __soft_offline_page(page, flags);
1665 } else { /* for free pages */ 1664 } else if (ret == 0) { /* for free pages */
1666 if (PageHuge(page)) { 1665 if (PageHuge(page)) {
1667 set_page_hwpoison_huge_page(hpage); 1666 set_page_hwpoison_huge_page(hpage);
1668 dequeue_hwpoisoned_huge_page(hpage); 1667 dequeue_hwpoisoned_huge_page(hpage);
@@ -1673,7 +1672,6 @@ int soft_offline_page(struct page *page, int flags)
1673 atomic_long_inc(&num_poisoned_pages); 1672 atomic_long_inc(&num_poisoned_pages);
1674 } 1673 }
1675 } 1674 }
1676unset:
1677 unset_migratetype_isolate(page, MIGRATE_MOVABLE); 1675 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
1678 return ret; 1676 return ret;
1679} 1677}
diff --git a/mm/memory.c b/mm/memory.c
index 33a3dbec3cc8..bf8665849a5f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -453,8 +453,6 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
453 453
454/* 454/*
455 * This function frees user-level page tables of a process. 455 * This function frees user-level page tables of a process.
456 *
457 * Must be called with pagetable lock held.
458 */ 456 */
459void free_pgd_range(struct mmu_gather *tlb, 457void free_pgd_range(struct mmu_gather *tlb,
460 unsigned long addr, unsigned long end, 458 unsigned long addr, unsigned long end,
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index ed85fe3870e2..489f235502db 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -31,6 +31,7 @@
31#include <linux/firmware-map.h> 31#include <linux/firmware-map.h>
32#include <linux/stop_machine.h> 32#include <linux/stop_machine.h>
33#include <linux/hugetlb.h> 33#include <linux/hugetlb.h>
34#include <linux/memblock.h>
34 35
35#include <asm/tlbflush.h> 36#include <asm/tlbflush.h>
36 37
@@ -365,8 +366,7 @@ out_fail:
365static void grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn, 366static void grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn,
366 unsigned long end_pfn) 367 unsigned long end_pfn)
367{ 368{
368 unsigned long old_pgdat_end_pfn = 369 unsigned long old_pgdat_end_pfn = pgdat_end_pfn(pgdat);
369 pgdat->node_start_pfn + pgdat->node_spanned_pages;
370 370
371 if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn) 371 if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn)
372 pgdat->node_start_pfn = start_pfn; 372 pgdat->node_start_pfn = start_pfn;
@@ -402,13 +402,12 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
402static int __meminit __add_section(int nid, struct zone *zone, 402static int __meminit __add_section(int nid, struct zone *zone,
403 unsigned long phys_start_pfn) 403 unsigned long phys_start_pfn)
404{ 404{
405 int nr_pages = PAGES_PER_SECTION;
406 int ret; 405 int ret;
407 406
408 if (pfn_valid(phys_start_pfn)) 407 if (pfn_valid(phys_start_pfn))
409 return -EEXIST; 408 return -EEXIST;
410 409
411 ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages); 410 ret = sparse_add_one_section(zone, phys_start_pfn);
412 411
413 if (ret < 0) 412 if (ret < 0)
414 return ret; 413 return ret;
@@ -579,9 +578,9 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
579static void shrink_pgdat_span(struct pglist_data *pgdat, 578static void shrink_pgdat_span(struct pglist_data *pgdat,
580 unsigned long start_pfn, unsigned long end_pfn) 579 unsigned long start_pfn, unsigned long end_pfn)
581{ 580{
582 unsigned long pgdat_start_pfn = pgdat->node_start_pfn; 581 unsigned long pgdat_start_pfn = pgdat->node_start_pfn;
583 unsigned long pgdat_end_pfn = 582 unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */
584 pgdat->node_start_pfn + pgdat->node_spanned_pages; 583 unsigned long pgdat_end_pfn = p;
585 unsigned long pfn; 584 unsigned long pfn;
586 struct mem_section *ms; 585 struct mem_section *ms;
587 int nid = pgdat->node_id; 586 int nid = pgdat->node_id;
@@ -935,7 +934,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
935 arg.nr_pages = nr_pages; 934 arg.nr_pages = nr_pages;
936 node_states_check_changes_online(nr_pages, zone, &arg); 935 node_states_check_changes_online(nr_pages, zone, &arg);
937 936
938 nid = page_to_nid(pfn_to_page(pfn)); 937 nid = pfn_to_nid(pfn);
939 938
940 ret = memory_notify(MEM_GOING_ONLINE, &arg); 939 ret = memory_notify(MEM_GOING_ONLINE, &arg);
941 ret = notifier_to_errno(ret); 940 ret = notifier_to_errno(ret);
@@ -1044,17 +1043,23 @@ static void rollback_node_hotadd(int nid, pg_data_t *pgdat)
1044} 1043}
1045 1044
1046 1045
1047/* 1046/**
1047 * try_online_node - online a node if offlined
1048 *
1048 * called by cpu_up() to online a node without onlined memory. 1049 * called by cpu_up() to online a node without onlined memory.
1049 */ 1050 */
1050int mem_online_node(int nid) 1051int try_online_node(int nid)
1051{ 1052{
1052 pg_data_t *pgdat; 1053 pg_data_t *pgdat;
1053 int ret; 1054 int ret;
1054 1055
1056 if (node_online(nid))
1057 return 0;
1058
1055 lock_memory_hotplug(); 1059 lock_memory_hotplug();
1056 pgdat = hotadd_new_pgdat(nid, 0); 1060 pgdat = hotadd_new_pgdat(nid, 0);
1057 if (!pgdat) { 1061 if (!pgdat) {
1062 pr_err("Cannot online node %d due to NULL pgdat\n", nid);
1058 ret = -ENOMEM; 1063 ret = -ENOMEM;
1059 goto out; 1064 goto out;
1060 } 1065 }
@@ -1062,6 +1067,12 @@ int mem_online_node(int nid)
1062 ret = register_one_node(nid); 1067 ret = register_one_node(nid);
1063 BUG_ON(ret); 1068 BUG_ON(ret);
1064 1069
1070 if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
1071 mutex_lock(&zonelists_mutex);
1072 build_all_zonelists(NULL, NULL);
1073 mutex_unlock(&zonelists_mutex);
1074 }
1075
1065out: 1076out:
1066 unlock_memory_hotplug(); 1077 unlock_memory_hotplug();
1067 return ret; 1078 return ret;
@@ -1412,6 +1423,36 @@ static bool can_offline_normal(struct zone *zone, unsigned long nr_pages)
1412} 1423}
1413#endif /* CONFIG_MOVABLE_NODE */ 1424#endif /* CONFIG_MOVABLE_NODE */
1414 1425
1426static int __init cmdline_parse_movable_node(char *p)
1427{
1428#ifdef CONFIG_MOVABLE_NODE
1429 /*
1430 * Memory used by the kernel cannot be hot-removed because Linux
1431 * cannot migrate the kernel pages. When memory hotplug is
1432 * enabled, we should prevent memblock from allocating memory
1433 * for the kernel.
1434 *
1435 * ACPI SRAT records all hotpluggable memory ranges. But before
1436 * SRAT is parsed, we don't know about it.
1437 *
1438 * The kernel image is loaded into memory at very early time. We
1439 * cannot prevent this anyway. So on NUMA system, we set any
1440 * node the kernel resides in as un-hotpluggable.
1441 *
1442 * Since on modern servers, one node could have double-digit
1443 * gigabytes memory, we can assume the memory around the kernel
1444 * image is also un-hotpluggable. So before SRAT is parsed, just
1445 * allocate memory near the kernel image to try the best to keep
1446 * the kernel away from hotpluggable memory.
1447 */
1448 memblock_set_bottom_up(true);
1449#else
1450 pr_warn("movable_node option not supported\n");
1451#endif
1452 return 0;
1453}
1454early_param("movable_node", cmdline_parse_movable_node);
1455
1415/* check which state of node_states will be changed when offline memory */ 1456/* check which state of node_states will be changed when offline memory */
1416static void node_states_check_changes_offline(unsigned long nr_pages, 1457static void node_states_check_changes_offline(unsigned long nr_pages,
1417 struct zone *zone, struct memory_notify *arg) 1458 struct zone *zone, struct memory_notify *arg)
@@ -1702,7 +1743,7 @@ int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
1702} 1743}
1703 1744
1704#ifdef CONFIG_MEMORY_HOTREMOVE 1745#ifdef CONFIG_MEMORY_HOTREMOVE
1705static int is_memblock_offlined_cb(struct memory_block *mem, void *arg) 1746static int check_memblock_offlined_cb(struct memory_block *mem, void *arg)
1706{ 1747{
1707 int ret = !is_memblock_offlined(mem); 1748 int ret = !is_memblock_offlined(mem);
1708 1749
@@ -1854,7 +1895,7 @@ void __ref remove_memory(int nid, u64 start, u64 size)
1854 * if this is not the case. 1895 * if this is not the case.
1855 */ 1896 */
1856 ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL, 1897 ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
1857 is_memblock_offlined_cb); 1898 check_memblock_offlined_cb);
1858 if (ret) { 1899 if (ret) {
1859 unlock_memory_hotplug(); 1900 unlock_memory_hotplug();
1860 BUG(); 1901 BUG();
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 71cb253368cb..4cc19f6ab6c6 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1125,7 +1125,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
1125 tmp = *from; 1125 tmp = *from;
1126 while (!nodes_empty(tmp)) { 1126 while (!nodes_empty(tmp)) {
1127 int s,d; 1127 int s,d;
1128 int source = -1; 1128 int source = NUMA_NO_NODE;
1129 int dest = 0; 1129 int dest = 0;
1130 1130
1131 for_each_node_mask(s, tmp) { 1131 for_each_node_mask(s, tmp) {
@@ -1160,7 +1160,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
1160 if (!node_isset(dest, tmp)) 1160 if (!node_isset(dest, tmp))
1161 break; 1161 break;
1162 } 1162 }
1163 if (source == -1) 1163 if (source == NUMA_NO_NODE)
1164 break; 1164 break;
1165 1165
1166 node_clear(source, tmp); 1166 node_clear(source, tmp);
@@ -1835,7 +1835,7 @@ static unsigned offset_il_node(struct mempolicy *pol,
1835 unsigned nnodes = nodes_weight(pol->v.nodes); 1835 unsigned nnodes = nodes_weight(pol->v.nodes);
1836 unsigned target; 1836 unsigned target;
1837 int c; 1837 int c;
1838 int nid = -1; 1838 int nid = NUMA_NO_NODE;
1839 1839
1840 if (!nnodes) 1840 if (!nnodes)
1841 return numa_node_id(); 1841 return numa_node_id();
@@ -1872,11 +1872,11 @@ static inline unsigned interleave_nid(struct mempolicy *pol,
1872 1872
1873/* 1873/*
1874 * Return the bit number of a random bit set in the nodemask. 1874 * Return the bit number of a random bit set in the nodemask.
1875 * (returns -1 if nodemask is empty) 1875 * (returns NUMA_NO_NODE if nodemask is empty)
1876 */ 1876 */
1877int node_random(const nodemask_t *maskp) 1877int node_random(const nodemask_t *maskp)
1878{ 1878{
1879 int w, bit = -1; 1879 int w, bit = NUMA_NO_NODE;
1880 1880
1881 w = nodes_weight(*maskp); 1881 w = nodes_weight(*maskp);
1882 if (w) 1882 if (w)
@@ -2914,62 +2914,45 @@ out:
2914 * @maxlen: length of @buffer 2914 * @maxlen: length of @buffer
2915 * @pol: pointer to mempolicy to be formatted 2915 * @pol: pointer to mempolicy to be formatted
2916 * 2916 *
2917 * Convert a mempolicy into a string. 2917 * Convert @pol into a string. If @buffer is too short, truncate the string.
2918 * Returns the number of characters in buffer (if positive) 2918 * Recommend a @maxlen of at least 32 for the longest mode, "interleave", the
2919 * or an error (negative) 2919 * longest flag, "relative", and to display at least a few node ids.
2920 */ 2920 */
2921int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) 2921void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
2922{ 2922{
2923 char *p = buffer; 2923 char *p = buffer;
2924 int l; 2924 nodemask_t nodes = NODE_MASK_NONE;
2925 nodemask_t nodes; 2925 unsigned short mode = MPOL_DEFAULT;
2926 unsigned short mode; 2926 unsigned short flags = 0;
2927 unsigned short flags = pol ? pol->flags : 0;
2928
2929 /*
2930 * Sanity check: room for longest mode, flag and some nodes
2931 */
2932 VM_BUG_ON(maxlen < strlen("interleave") + strlen("relative") + 16);
2933 2927
2934 if (!pol || pol == &default_policy) 2928 if (pol && pol != &default_policy) {
2935 mode = MPOL_DEFAULT;
2936 else
2937 mode = pol->mode; 2929 mode = pol->mode;
2930 flags = pol->flags;
2931 }
2938 2932
2939 switch (mode) { 2933 switch (mode) {
2940 case MPOL_DEFAULT: 2934 case MPOL_DEFAULT:
2941 nodes_clear(nodes);
2942 break; 2935 break;
2943
2944 case MPOL_PREFERRED: 2936 case MPOL_PREFERRED:
2945 nodes_clear(nodes);
2946 if (flags & MPOL_F_LOCAL) 2937 if (flags & MPOL_F_LOCAL)
2947 mode = MPOL_LOCAL; 2938 mode = MPOL_LOCAL;
2948 else 2939 else
2949 node_set(pol->v.preferred_node, nodes); 2940 node_set(pol->v.preferred_node, nodes);
2950 break; 2941 break;
2951
2952 case MPOL_BIND: 2942 case MPOL_BIND:
2953 /* Fall through */
2954 case MPOL_INTERLEAVE: 2943 case MPOL_INTERLEAVE:
2955 nodes = pol->v.nodes; 2944 nodes = pol->v.nodes;
2956 break; 2945 break;
2957
2958 default: 2946 default:
2959 return -EINVAL; 2947 WARN_ON_ONCE(1);
2948 snprintf(p, maxlen, "unknown");
2949 return;
2960 } 2950 }
2961 2951
2962 l = strlen(policy_modes[mode]); 2952 p += snprintf(p, maxlen, policy_modes[mode]);
2963 if (buffer + maxlen < p + l + 1)
2964 return -ENOSPC;
2965
2966 strcpy(p, policy_modes[mode]);
2967 p += l;
2968 2953
2969 if (flags & MPOL_MODE_FLAGS) { 2954 if (flags & MPOL_MODE_FLAGS) {
2970 if (buffer + maxlen < p + 2) 2955 p += snprintf(p, buffer + maxlen - p, "=");
2971 return -ENOSPC;
2972 *p++ = '=';
2973 2956
2974 /* 2957 /*
2975 * Currently, the only defined flags are mutually exclusive 2958 * Currently, the only defined flags are mutually exclusive
@@ -2981,10 +2964,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
2981 } 2964 }
2982 2965
2983 if (!nodes_empty(nodes)) { 2966 if (!nodes_empty(nodes)) {
2984 if (buffer + maxlen < p + 2) 2967 p += snprintf(p, buffer + maxlen - p, ":");
2985 return -ENOSPC;
2986 *p++ = ':';
2987 p += nodelist_scnprintf(p, buffer + maxlen - p, nodes); 2968 p += nodelist_scnprintf(p, buffer + maxlen - p, nodes);
2988 } 2969 }
2989 return p - buffer;
2990} 2970}
diff --git a/mm/mmap.c b/mm/mmap.c
index ab199dfc9e26..5a6baddde15d 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -179,14 +179,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
179 goto error; 179 goto error;
180 } 180 }
181 181
182 allowed = (totalram_pages - hugetlb_total_pages()) 182 allowed = vm_commit_limit();
183 * sysctl_overcommit_ratio / 100;
184 /* 183 /*
185 * Reserve some for root 184 * Reserve some for root
186 */ 185 */
187 if (!cap_sys_admin) 186 if (!cap_sys_admin)
188 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10); 187 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
189 allowed += total_swap_pages;
190 188
191 /* 189 /*
192 * Don't let a single process grow so big a user can't recover 190 * Don't let a single process grow so big a user can't recover
@@ -1856,7 +1854,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1856 struct vm_area_struct *vma; 1854 struct vm_area_struct *vma;
1857 struct vm_unmapped_area_info info; 1855 struct vm_unmapped_area_info info;
1858 1856
1859 if (len > TASK_SIZE) 1857 if (len > TASK_SIZE - mmap_min_addr)
1860 return -ENOMEM; 1858 return -ENOMEM;
1861 1859
1862 if (flags & MAP_FIXED) 1860 if (flags & MAP_FIXED)
@@ -1865,14 +1863,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1865 if (addr) { 1863 if (addr) {
1866 addr = PAGE_ALIGN(addr); 1864 addr = PAGE_ALIGN(addr);
1867 vma = find_vma(mm, addr); 1865 vma = find_vma(mm, addr);
1868 if (TASK_SIZE - len >= addr && 1866 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
1869 (!vma || addr + len <= vma->vm_start)) 1867 (!vma || addr + len <= vma->vm_start))
1870 return addr; 1868 return addr;
1871 } 1869 }
1872 1870
1873 info.flags = 0; 1871 info.flags = 0;
1874 info.length = len; 1872 info.length = len;
1875 info.low_limit = TASK_UNMAPPED_BASE; 1873 info.low_limit = mm->mmap_base;
1876 info.high_limit = TASK_SIZE; 1874 info.high_limit = TASK_SIZE;
1877 info.align_mask = 0; 1875 info.align_mask = 0;
1878 return vm_unmapped_area(&info); 1876 return vm_unmapped_area(&info);
@@ -1895,7 +1893,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
1895 struct vm_unmapped_area_info info; 1893 struct vm_unmapped_area_info info;
1896 1894
1897 /* requested length too big for entire address space */ 1895 /* requested length too big for entire address space */
1898 if (len > TASK_SIZE) 1896 if (len > TASK_SIZE - mmap_min_addr)
1899 return -ENOMEM; 1897 return -ENOMEM;
1900 1898
1901 if (flags & MAP_FIXED) 1899 if (flags & MAP_FIXED)
@@ -1905,14 +1903,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
1905 if (addr) { 1903 if (addr) {
1906 addr = PAGE_ALIGN(addr); 1904 addr = PAGE_ALIGN(addr);
1907 vma = find_vma(mm, addr); 1905 vma = find_vma(mm, addr);
1908 if (TASK_SIZE - len >= addr && 1906 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
1909 (!vma || addr + len <= vma->vm_start)) 1907 (!vma || addr + len <= vma->vm_start))
1910 return addr; 1908 return addr;
1911 } 1909 }
1912 1910
1913 info.flags = VM_UNMAPPED_AREA_TOPDOWN; 1911 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
1914 info.length = len; 1912 info.length = len;
1915 info.low_limit = PAGE_SIZE; 1913 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
1916 info.high_limit = mm->mmap_base; 1914 info.high_limit = mm->mmap_base;
1917 info.align_mask = 0; 1915 info.align_mask = 0;
1918 addr = vm_unmapped_area(&info); 1916 addr = vm_unmapped_area(&info);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index a597f2ffcd6f..26667971c824 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -112,6 +112,7 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
112 pmd_t *pmd; 112 pmd_t *pmd;
113 unsigned long next; 113 unsigned long next;
114 unsigned long pages = 0; 114 unsigned long pages = 0;
115 unsigned long nr_huge_updates = 0;
115 116
116 pmd = pmd_offset(pud, addr); 117 pmd = pmd_offset(pud, addr);
117 do { 118 do {
@@ -126,9 +127,10 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
126 newprot, prot_numa); 127 newprot, prot_numa);
127 128
128 if (nr_ptes) { 129 if (nr_ptes) {
129 if (nr_ptes == HPAGE_PMD_NR) 130 if (nr_ptes == HPAGE_PMD_NR) {
130 pages++; 131 pages += HPAGE_PMD_NR;
131 132 nr_huge_updates++;
133 }
132 continue; 134 continue;
133 } 135 }
134 } 136 }
@@ -141,6 +143,8 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
141 pages += this_pages; 143 pages += this_pages;
142 } while (pmd++, addr = next, addr != end); 144 } while (pmd++, addr = next, addr != end);
143 145
146 if (nr_huge_updates)
147 count_vm_numa_events(NUMA_HUGE_PTE_UPDATES, nr_huge_updates);
144 return pages; 148 return pages;
145} 149}
146 150
diff --git a/mm/nobootmem.c b/mm/nobootmem.c
index 61107cf55bb3..2c254d374655 100644
--- a/mm/nobootmem.c
+++ b/mm/nobootmem.c
@@ -82,27 +82,18 @@ void __init free_bootmem_late(unsigned long addr, unsigned long size)
82 82
83static void __init __free_pages_memory(unsigned long start, unsigned long end) 83static void __init __free_pages_memory(unsigned long start, unsigned long end)
84{ 84{
85 unsigned long i, start_aligned, end_aligned; 85 int order;
86 int order = ilog2(BITS_PER_LONG);
87 86
88 start_aligned = (start + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1); 87 while (start < end) {
89 end_aligned = end & ~(BITS_PER_LONG - 1); 88 order = min(MAX_ORDER - 1UL, __ffs(start));
90 89
91 if (end_aligned <= start_aligned) { 90 while (start + (1UL << order) > end)
92 for (i = start; i < end; i++) 91 order--;
93 __free_pages_bootmem(pfn_to_page(i), 0);
94 92
95 return; 93 __free_pages_bootmem(pfn_to_page(start), order);
96 }
97
98 for (i = start; i < start_aligned; i++)
99 __free_pages_bootmem(pfn_to_page(i), 0);
100 94
101 for (i = start_aligned; i < end_aligned; i += BITS_PER_LONG) 95 start += (1UL << order);
102 __free_pages_bootmem(pfn_to_page(i), order); 96 }
103
104 for (i = end_aligned; i < end; i++)
105 __free_pages_bootmem(pfn_to_page(i), 0);
106} 97}
107 98
108static unsigned long __init __free_memory_core(phys_addr_t start, 99static unsigned long __init __free_memory_core(phys_addr_t start,
diff --git a/mm/nommu.c b/mm/nommu.c
index 9e6cb02cba64..fec093adad9c 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1948,13 +1948,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
1948 goto error; 1948 goto error;
1949 } 1949 }
1950 1950
1951 allowed = totalram_pages * sysctl_overcommit_ratio / 100; 1951 allowed = vm_commit_limit();
1952 /* 1952 /*
1953 * Reserve some 3% for root 1953 * Reserve some 3% for root
1954 */ 1954 */
1955 if (!cap_sys_admin) 1955 if (!cap_sys_admin)
1956 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10); 1956 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
1957 allowed += total_swap_pages;
1958 1957
1959 /* 1958 /*
1960 * Don't let a single process grow so big a user can't recover 1959 * Don't let a single process grow so big a user can't recover
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 73d812f16dde..580a5f075ed0 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -234,8 +234,8 @@ int page_group_by_mobility_disabled __read_mostly;
234 234
235void set_pageblock_migratetype(struct page *page, int migratetype) 235void set_pageblock_migratetype(struct page *page, int migratetype)
236{ 236{
237 237 if (unlikely(page_group_by_mobility_disabled &&
238 if (unlikely(page_group_by_mobility_disabled)) 238 migratetype < MIGRATE_PCPTYPES))
239 migratetype = MIGRATE_UNMOVABLE; 239 migratetype = MIGRATE_UNMOVABLE;
240 240
241 set_pageblock_flags_group(page, (unsigned long)migratetype, 241 set_pageblock_flags_group(page, (unsigned long)migratetype,
@@ -1027,6 +1027,10 @@ static int try_to_steal_freepages(struct zone *zone, struct page *page,
1027{ 1027{
1028 int current_order = page_order(page); 1028 int current_order = page_order(page);
1029 1029
1030 /*
1031 * When borrowing from MIGRATE_CMA, we need to release the excess
1032 * buddy pages to CMA itself.
1033 */
1030 if (is_migrate_cma(fallback_type)) 1034 if (is_migrate_cma(fallback_type))
1031 return fallback_type; 1035 return fallback_type;
1032 1036
@@ -1091,21 +1095,11 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype)
1091 list_del(&page->lru); 1095 list_del(&page->lru);
1092 rmv_page_order(page); 1096 rmv_page_order(page);
1093 1097
1094 /*
1095 * Borrow the excess buddy pages as well, irrespective
1096 * of whether we stole freepages, or took ownership of
1097 * the pageblock or not.
1098 *
1099 * Exception: When borrowing from MIGRATE_CMA, release
1100 * the excess buddy pages to CMA itself.
1101 */
1102 expand(zone, page, order, current_order, area, 1098 expand(zone, page, order, current_order, area,
1103 is_migrate_cma(migratetype) 1099 new_type);
1104 ? migratetype : start_migratetype);
1105 1100
1106 trace_mm_page_alloc_extfrag(page, order, 1101 trace_mm_page_alloc_extfrag(page, order, current_order,
1107 current_order, start_migratetype, migratetype, 1102 start_migratetype, migratetype, new_type);
1108 new_type == start_migratetype);
1109 1103
1110 return page; 1104 return page;
1111 } 1105 }
@@ -1711,7 +1705,7 @@ bool zone_watermark_ok_safe(struct zone *z, int order, unsigned long mark,
1711 * comments in mmzone.h. Reduces cache footprint of zonelist scans 1705 * comments in mmzone.h. Reduces cache footprint of zonelist scans
1712 * that have to skip over a lot of full or unallowed zones. 1706 * that have to skip over a lot of full or unallowed zones.
1713 * 1707 *
1714 * If the zonelist cache is present in the passed in zonelist, then 1708 * If the zonelist cache is present in the passed zonelist, then
1715 * returns a pointer to the allowed node mask (either the current 1709 * returns a pointer to the allowed node mask (either the current
1716 * tasks mems_allowed, or node_states[N_MEMORY].) 1710 * tasks mems_allowed, or node_states[N_MEMORY].)
1717 * 1711 *
@@ -2593,7 +2587,7 @@ rebalance:
2593 * running out of options and have to consider going OOM 2587 * running out of options and have to consider going OOM
2594 */ 2588 */
2595 if (!did_some_progress) { 2589 if (!did_some_progress) {
2596 if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { 2590 if (oom_gfp_allowed(gfp_mask)) {
2597 if (oom_killer_disabled) 2591 if (oom_killer_disabled)
2598 goto nopage; 2592 goto nopage;
2599 /* Coredumps can quickly deplete all memory reserves */ 2593 /* Coredumps can quickly deplete all memory reserves */
@@ -3881,8 +3875,6 @@ static inline unsigned long wait_table_bits(unsigned long size)
3881 return ffz(~size); 3875 return ffz(~size);
3882} 3876}
3883 3877
3884#define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
3885
3886/* 3878/*
3887 * Check if a pageblock contains reserved pages 3879 * Check if a pageblock contains reserved pages
3888 */ 3880 */
@@ -4266,7 +4258,7 @@ static __meminit void zone_pcp_init(struct zone *zone)
4266 */ 4258 */
4267 zone->pageset = &boot_pageset; 4259 zone->pageset = &boot_pageset;
4268 4260
4269 if (zone->present_pages) 4261 if (populated_zone(zone))
4270 printk(KERN_DEBUG " %s zone: %lu pages, LIFO batch:%u\n", 4262 printk(KERN_DEBUG " %s zone: %lu pages, LIFO batch:%u\n",
4271 zone->name, zone->present_pages, 4263 zone->name, zone->present_pages,
4272 zone_batchsize(zone)); 4264 zone_batchsize(zone));
@@ -5160,7 +5152,7 @@ static void check_for_memory(pg_data_t *pgdat, int nid)
5160 5152
5161 for (zone_type = 0; zone_type <= ZONE_MOVABLE - 1; zone_type++) { 5153 for (zone_type = 0; zone_type <= ZONE_MOVABLE - 1; zone_type++) {
5162 struct zone *zone = &pgdat->node_zones[zone_type]; 5154 struct zone *zone = &pgdat->node_zones[zone_type];
5163 if (zone->present_pages) { 5155 if (populated_zone(zone)) {
5164 node_set_state(nid, N_HIGH_MEMORY); 5156 node_set_state(nid, N_HIGH_MEMORY);
5165 if (N_NORMAL_MEMORY != N_HIGH_MEMORY && 5157 if (N_NORMAL_MEMORY != N_HIGH_MEMORY &&
5166 zone_type <= ZONE_NORMAL) 5158 zone_type <= ZONE_NORMAL)
diff --git a/mm/readahead.c b/mm/readahead.c
index e4ed04149785..7cdbb44aa90b 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -401,6 +401,7 @@ ondemand_readahead(struct address_space *mapping,
401 unsigned long req_size) 401 unsigned long req_size)
402{ 402{
403 unsigned long max = max_sane_readahead(ra->ra_pages); 403 unsigned long max = max_sane_readahead(ra->ra_pages);
404 pgoff_t prev_offset;
404 405
405 /* 406 /*
406 * start of file 407 * start of file
@@ -452,8 +453,11 @@ ondemand_readahead(struct address_space *mapping,
452 453
453 /* 454 /*
454 * sequential cache miss 455 * sequential cache miss
456 * trivial case: (offset - prev_offset) == 1
457 * unaligned reads: (offset - prev_offset) == 0
455 */ 458 */
456 if (offset - (ra->prev_pos >> PAGE_CACHE_SHIFT) <= 1UL) 459 prev_offset = (unsigned long long)ra->prev_pos >> PAGE_CACHE_SHIFT;
460 if (offset - prev_offset <= 1UL)
457 goto initial_readahead; 461 goto initial_readahead;
458 462
459 /* 463 /*
@@ -569,7 +573,7 @@ static ssize_t
569do_readahead(struct address_space *mapping, struct file *filp, 573do_readahead(struct address_space *mapping, struct file *filp,
570 pgoff_t index, unsigned long nr) 574 pgoff_t index, unsigned long nr)
571{ 575{
572 if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage) 576 if (!mapping || !mapping->a_ops)
573 return -EINVAL; 577 return -EINVAL;
574 578
575 force_page_cache_readahead(mapping, filp, index, nr); 579 force_page_cache_readahead(mapping, filp, index, nr);
diff --git a/mm/slab.c b/mm/slab.c
index 2580db062df9..0c8967bb2018 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3982,7 +3982,7 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
3982 3982
3983 VM_BUG_ON(!mutex_is_locked(&slab_mutex)); 3983 VM_BUG_ON(!mutex_is_locked(&slab_mutex));
3984 for_each_memcg_cache_index(i) { 3984 for_each_memcg_cache_index(i) {
3985 c = cache_from_memcg(cachep, i); 3985 c = cache_from_memcg_idx(cachep, i);
3986 if (c) 3986 if (c)
3987 /* return value determined by the parent cache only */ 3987 /* return value determined by the parent cache only */
3988 __do_tune_cpucache(c, limit, batchcount, shared, gfp); 3988 __do_tune_cpucache(c, limit, batchcount, shared, gfp);
diff --git a/mm/slab.h b/mm/slab.h
index a535033f7e9a..0859c4241ba1 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -160,7 +160,8 @@ static inline const char *cache_name(struct kmem_cache *s)
160 return s->name; 160 return s->name;
161} 161}
162 162
163static inline struct kmem_cache *cache_from_memcg(struct kmem_cache *s, int idx) 163static inline struct kmem_cache *
164cache_from_memcg_idx(struct kmem_cache *s, int idx)
164{ 165{
165 if (!s->memcg_params) 166 if (!s->memcg_params)
166 return NULL; 167 return NULL;
@@ -204,7 +205,8 @@ static inline const char *cache_name(struct kmem_cache *s)
204 return s->name; 205 return s->name;
205} 206}
206 207
207static inline struct kmem_cache *cache_from_memcg(struct kmem_cache *s, int idx) 208static inline struct kmem_cache *
209cache_from_memcg_idx(struct kmem_cache *s, int idx)
208{ 210{
209 return NULL; 211 return NULL;
210} 212}
diff --git a/mm/slab_common.c b/mm/slab_common.c
index e2e98af703ea..0b7bb399b0e4 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -571,7 +571,7 @@ memcg_accumulate_slabinfo(struct kmem_cache *s, struct slabinfo *info)
571 return; 571 return;
572 572
573 for_each_memcg_cache_index(i) { 573 for_each_memcg_cache_index(i) {
574 c = cache_from_memcg(s, i); 574 c = cache_from_memcg_idx(s, i);
575 if (!c) 575 if (!c)
576 continue; 576 continue;
577 577
diff --git a/mm/slub.c b/mm/slub.c
index c3eb3d3ca835..92737a0b787b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4983,7 +4983,7 @@ static ssize_t slab_attr_store(struct kobject *kobj,
4983 * through the descendants with best-effort propagation. 4983 * through the descendants with best-effort propagation.
4984 */ 4984 */
4985 for_each_memcg_cache_index(i) { 4985 for_each_memcg_cache_index(i) {
4986 struct kmem_cache *c = cache_from_memcg(s, i); 4986 struct kmem_cache *c = cache_from_memcg_idx(s, i);
4987 if (c) 4987 if (c)
4988 attribute->store(c, buf, len); 4988 attribute->store(c, buf, len);
4989 } 4989 }
diff --git a/mm/sparse.c b/mm/sparse.c
index 4ac1d7ef548f..8cc7be0e9590 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -590,33 +590,32 @@ void __init sparse_init(void)
590 590
591#ifdef CONFIG_MEMORY_HOTPLUG 591#ifdef CONFIG_MEMORY_HOTPLUG
592#ifdef CONFIG_SPARSEMEM_VMEMMAP 592#ifdef CONFIG_SPARSEMEM_VMEMMAP
593static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 593static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
594 unsigned long nr_pages)
595{ 594{
596 /* This will make the necessary allocations eventually. */ 595 /* This will make the necessary allocations eventually. */
597 return sparse_mem_map_populate(pnum, nid); 596 return sparse_mem_map_populate(pnum, nid);
598} 597}
599static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) 598static void __kfree_section_memmap(struct page *memmap)
600{ 599{
601 unsigned long start = (unsigned long)memmap; 600 unsigned long start = (unsigned long)memmap;
602 unsigned long end = (unsigned long)(memmap + nr_pages); 601 unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION);
603 602
604 vmemmap_free(start, end); 603 vmemmap_free(start, end);
605} 604}
606#ifdef CONFIG_MEMORY_HOTREMOVE 605#ifdef CONFIG_MEMORY_HOTREMOVE
607static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) 606static void free_map_bootmem(struct page *memmap)
608{ 607{
609 unsigned long start = (unsigned long)memmap; 608 unsigned long start = (unsigned long)memmap;
610 unsigned long end = (unsigned long)(memmap + nr_pages); 609 unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION);
611 610
612 vmemmap_free(start, end); 611 vmemmap_free(start, end);
613} 612}
614#endif /* CONFIG_MEMORY_HOTREMOVE */ 613#endif /* CONFIG_MEMORY_HOTREMOVE */
615#else 614#else
616static struct page *__kmalloc_section_memmap(unsigned long nr_pages) 615static struct page *__kmalloc_section_memmap(void)
617{ 616{
618 struct page *page, *ret; 617 struct page *page, *ret;
619 unsigned long memmap_size = sizeof(struct page) * nr_pages; 618 unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
620 619
621 page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size)); 620 page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size));
622 if (page) 621 if (page)
@@ -634,28 +633,30 @@ got_map_ptr:
634 return ret; 633 return ret;
635} 634}
636 635
637static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 636static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
638 unsigned long nr_pages)
639{ 637{
640 return __kmalloc_section_memmap(nr_pages); 638 return __kmalloc_section_memmap();
641} 639}
642 640
643static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) 641static void __kfree_section_memmap(struct page *memmap)
644{ 642{
645 if (is_vmalloc_addr(memmap)) 643 if (is_vmalloc_addr(memmap))
646 vfree(memmap); 644 vfree(memmap);
647 else 645 else
648 free_pages((unsigned long)memmap, 646 free_pages((unsigned long)memmap,
649 get_order(sizeof(struct page) * nr_pages)); 647 get_order(sizeof(struct page) * PAGES_PER_SECTION));
650} 648}
651 649
652#ifdef CONFIG_MEMORY_HOTREMOVE 650#ifdef CONFIG_MEMORY_HOTREMOVE
653static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) 651static void free_map_bootmem(struct page *memmap)
654{ 652{
655 unsigned long maps_section_nr, removing_section_nr, i; 653 unsigned long maps_section_nr, removing_section_nr, i;
656 unsigned long magic; 654 unsigned long magic, nr_pages;
657 struct page *page = virt_to_page(memmap); 655 struct page *page = virt_to_page(memmap);
658 656
657 nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page))
658 >> PAGE_SHIFT;
659
659 for (i = 0; i < nr_pages; i++, page++) { 660 for (i = 0; i < nr_pages; i++, page++) {
660 magic = (unsigned long) page->lru.next; 661 magic = (unsigned long) page->lru.next;
661 662
@@ -684,8 +685,7 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
684 * set. If this is <=0, then that means that the passed-in 685 * set. If this is <=0, then that means that the passed-in
685 * map was not consumed and must be freed. 686 * map was not consumed and must be freed.
686 */ 687 */
687int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn, 688int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn)
688 int nr_pages)
689{ 689{
690 unsigned long section_nr = pfn_to_section_nr(start_pfn); 690 unsigned long section_nr = pfn_to_section_nr(start_pfn);
691 struct pglist_data *pgdat = zone->zone_pgdat; 691 struct pglist_data *pgdat = zone->zone_pgdat;
@@ -702,12 +702,12 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
702 ret = sparse_index_init(section_nr, pgdat->node_id); 702 ret = sparse_index_init(section_nr, pgdat->node_id);
703 if (ret < 0 && ret != -EEXIST) 703 if (ret < 0 && ret != -EEXIST)
704 return ret; 704 return ret;
705 memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages); 705 memmap = kmalloc_section_memmap(section_nr, pgdat->node_id);
706 if (!memmap) 706 if (!memmap)
707 return -ENOMEM; 707 return -ENOMEM;
708 usemap = __kmalloc_section_usemap(); 708 usemap = __kmalloc_section_usemap();
709 if (!usemap) { 709 if (!usemap) {
710 __kfree_section_memmap(memmap, nr_pages); 710 __kfree_section_memmap(memmap);
711 return -ENOMEM; 711 return -ENOMEM;
712 } 712 }
713 713
@@ -719,7 +719,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
719 goto out; 719 goto out;
720 } 720 }
721 721
722 memset(memmap, 0, sizeof(struct page) * nr_pages); 722 memset(memmap, 0, sizeof(struct page) * PAGES_PER_SECTION);
723 723
724 ms->section_mem_map |= SECTION_MARKED_PRESENT; 724 ms->section_mem_map |= SECTION_MARKED_PRESENT;
725 725
@@ -729,7 +729,7 @@ out:
729 pgdat_resize_unlock(pgdat, &flags); 729 pgdat_resize_unlock(pgdat, &flags);
730 if (ret <= 0) { 730 if (ret <= 0) {
731 kfree(usemap); 731 kfree(usemap);
732 __kfree_section_memmap(memmap, nr_pages); 732 __kfree_section_memmap(memmap);
733 } 733 }
734 return ret; 734 return ret;
735} 735}
@@ -759,7 +759,6 @@ static inline void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
759static void free_section_usemap(struct page *memmap, unsigned long *usemap) 759static void free_section_usemap(struct page *memmap, unsigned long *usemap)
760{ 760{
761 struct page *usemap_page; 761 struct page *usemap_page;
762 unsigned long nr_pages;
763 762
764 if (!usemap) 763 if (!usemap)
765 return; 764 return;
@@ -771,7 +770,7 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap)
771 if (PageSlab(usemap_page) || PageCompound(usemap_page)) { 770 if (PageSlab(usemap_page) || PageCompound(usemap_page)) {
772 kfree(usemap); 771 kfree(usemap);
773 if (memmap) 772 if (memmap)
774 __kfree_section_memmap(memmap, PAGES_PER_SECTION); 773 __kfree_section_memmap(memmap);
775 return; 774 return;
776 } 775 }
777 776
@@ -780,12 +779,8 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap)
780 * on the section which has pgdat at boot time. Just keep it as is now. 779 * on the section which has pgdat at boot time. Just keep it as is now.
781 */ 780 */
782 781
783 if (memmap) { 782 if (memmap)
784 nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page)) 783 free_map_bootmem(memmap);
785 >> PAGE_SHIFT;
786
787 free_map_bootmem(memmap, nr_pages);
788 }
789} 784}
790 785
791void sparse_remove_one_section(struct zone *zone, struct mem_section *ms) 786void sparse_remove_one_section(struct zone *zone, struct mem_section *ms)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index de7c904e52e5..612a7c9795f6 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -707,7 +707,7 @@ noswap:
707 return (swp_entry_t) {0}; 707 return (swp_entry_t) {0};
708} 708}
709 709
710/* The only caller of this function is now susupend routine */ 710/* The only caller of this function is now suspend routine */
711swp_entry_t get_swap_page_of_type(int type) 711swp_entry_t get_swap_page_of_type(int type)
712{ 712{
713 struct swap_info_struct *si; 713 struct swap_info_struct *si;
@@ -845,7 +845,7 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
845} 845}
846 846
847/* 847/*
848 * Caller has made sure that the swapdevice corresponding to entry 848 * Caller has made sure that the swap device corresponding to entry
849 * is still around or has not been recycled. 849 * is still around or has not been recycled.
850 */ 850 */
851void swap_free(swp_entry_t entry) 851void swap_free(swp_entry_t entry)
@@ -947,7 +947,7 @@ int try_to_free_swap(struct page *page)
947 * original page might be freed under memory pressure, then 947 * original page might be freed under memory pressure, then
948 * later read back in from swap, now with the wrong data. 948 * later read back in from swap, now with the wrong data.
949 * 949 *
950 * Hibration suspends storage while it is writing the image 950 * Hibernation suspends storage while it is writing the image
951 * to disk so check that here. 951 * to disk so check that here.
952 */ 952 */
953 if (pm_suspended_storage()) 953 if (pm_suspended_storage())
@@ -1179,7 +1179,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
1179 * some architectures (e.g. x86_32 with PAE) we might catch a glimpse 1179 * some architectures (e.g. x86_32 with PAE) we might catch a glimpse
1180 * of unmatched parts which look like swp_pte, so unuse_pte must 1180 * of unmatched parts which look like swp_pte, so unuse_pte must
1181 * recheck under pte lock. Scanning without pte lock lets it be 1181 * recheck under pte lock. Scanning without pte lock lets it be
1182 * preemptible whenever CONFIG_PREEMPT but not CONFIG_HIGHPTE. 1182 * preemptable whenever CONFIG_PREEMPT but not CONFIG_HIGHPTE.
1183 */ 1183 */
1184 pte = pte_offset_map(pmd, addr); 1184 pte = pte_offset_map(pmd, addr);
1185 do { 1185 do {
@@ -1924,17 +1924,17 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1924 p->cluster_info = NULL; 1924 p->cluster_info = NULL;
1925 p->flags = 0; 1925 p->flags = 0;
1926 frontswap_map = frontswap_map_get(p); 1926 frontswap_map = frontswap_map_get(p);
1927 frontswap_map_set(p, NULL);
1928 spin_unlock(&p->lock); 1927 spin_unlock(&p->lock);
1929 spin_unlock(&swap_lock); 1928 spin_unlock(&swap_lock);
1930 frontswap_invalidate_area(type); 1929 frontswap_invalidate_area(type);
1930 frontswap_map_set(p, NULL);
1931 mutex_unlock(&swapon_mutex); 1931 mutex_unlock(&swapon_mutex);
1932 free_percpu(p->percpu_cluster); 1932 free_percpu(p->percpu_cluster);
1933 p->percpu_cluster = NULL; 1933 p->percpu_cluster = NULL;
1934 vfree(swap_map); 1934 vfree(swap_map);
1935 vfree(cluster_info); 1935 vfree(cluster_info);
1936 vfree(frontswap_map); 1936 vfree(frontswap_map);
1937 /* Destroy swap account informatin */ 1937 /* Destroy swap account information */
1938 swap_cgroup_swapoff(type); 1938 swap_cgroup_swapoff(type);
1939 1939
1940 inode = mapping->host; 1940 inode = mapping->host;
@@ -2786,8 +2786,8 @@ int add_swap_count_continuation(swp_entry_t entry, gfp_t gfp_mask)
2786 2786
2787 /* 2787 /*
2788 * We are fortunate that although vmalloc_to_page uses pte_offset_map, 2788 * We are fortunate that although vmalloc_to_page uses pte_offset_map,
2789 * no architecture is using highmem pages for kernel pagetables: so it 2789 * no architecture is using highmem pages for kernel page tables: so it
2790 * will not corrupt the GFP_ATOMIC caller's atomic pagetable kmaps. 2790 * will not corrupt the GFP_ATOMIC caller's atomic page table kmaps.
2791 */ 2791 */
2792 head = vmalloc_to_page(si->swap_map + offset); 2792 head = vmalloc_to_page(si->swap_map + offset);
2793 offset &= ~PAGE_MASK; 2793 offset &= ~PAGE_MASK;
diff --git a/mm/util.c b/mm/util.c
index eaf63fc2c92f..f7bc2096071c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -7,6 +7,9 @@
7#include <linux/security.h> 7#include <linux/security.h>
8#include <linux/swap.h> 8#include <linux/swap.h>
9#include <linux/swapops.h> 9#include <linux/swapops.h>
10#include <linux/mman.h>
11#include <linux/hugetlb.h>
12
10#include <asm/uaccess.h> 13#include <asm/uaccess.h>
11 14
12#include "internal.h" 15#include "internal.h"
@@ -398,6 +401,16 @@ struct address_space *page_mapping(struct page *page)
398 return mapping; 401 return mapping;
399} 402}
400 403
404/*
405 * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
406 */
407unsigned long vm_commit_limit(void)
408{
409 return ((totalram_pages - hugetlb_total_pages())
410 * sysctl_overcommit_ratio / 100) + total_swap_pages;
411}
412
413
401/* Tracepoints definitions. */ 414/* Tracepoints definitions. */
402EXPORT_TRACEPOINT_SYMBOL(kmalloc); 415EXPORT_TRACEPOINT_SYMBOL(kmalloc);
403EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); 416EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 107454312d5e..0fdf96803c5b 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -359,6 +359,12 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
359 if (unlikely(!va)) 359 if (unlikely(!va))
360 return ERR_PTR(-ENOMEM); 360 return ERR_PTR(-ENOMEM);
361 361
362 /*
363 * Only scan the relevant parts containing pointers to other objects
364 * to avoid false negatives.
365 */
366 kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask & GFP_RECLAIM_MASK);
367
362retry: 368retry:
363 spin_lock(&vmap_area_lock); 369 spin_lock(&vmap_area_lock);
364 /* 370 /*
@@ -1546,7 +1552,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
1546 gfp_t gfp_mask, pgprot_t prot, 1552 gfp_t gfp_mask, pgprot_t prot,
1547 int node, const void *caller); 1553 int node, const void *caller);
1548static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, 1554static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
1549 pgprot_t prot, int node, const void *caller) 1555 pgprot_t prot, int node)
1550{ 1556{
1551 const int order = 0; 1557 const int order = 0;
1552 struct page **pages; 1558 struct page **pages;
@@ -1560,13 +1566,12 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
1560 /* Please note that the recursion is strictly bounded. */ 1566 /* Please note that the recursion is strictly bounded. */
1561 if (array_size > PAGE_SIZE) { 1567 if (array_size > PAGE_SIZE) {
1562 pages = __vmalloc_node(array_size, 1, nested_gfp|__GFP_HIGHMEM, 1568 pages = __vmalloc_node(array_size, 1, nested_gfp|__GFP_HIGHMEM,
1563 PAGE_KERNEL, node, caller); 1569 PAGE_KERNEL, node, area->caller);
1564 area->flags |= VM_VPAGES; 1570 area->flags |= VM_VPAGES;
1565 } else { 1571 } else {
1566 pages = kmalloc_node(array_size, nested_gfp, node); 1572 pages = kmalloc_node(array_size, nested_gfp, node);
1567 } 1573 }
1568 area->pages = pages; 1574 area->pages = pages;
1569 area->caller = caller;
1570 if (!area->pages) { 1575 if (!area->pages) {
1571 remove_vm_area(area->addr); 1576 remove_vm_area(area->addr);
1572 kfree(area); 1577 kfree(area);
@@ -1577,7 +1582,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
1577 struct page *page; 1582 struct page *page;
1578 gfp_t tmp_mask = gfp_mask | __GFP_NOWARN; 1583 gfp_t tmp_mask = gfp_mask | __GFP_NOWARN;
1579 1584
1580 if (node < 0) 1585 if (node == NUMA_NO_NODE)
1581 page = alloc_page(tmp_mask); 1586 page = alloc_page(tmp_mask);
1582 else 1587 else
1583 page = alloc_pages_node(node, tmp_mask, order); 1588 page = alloc_pages_node(node, tmp_mask, order);
@@ -1634,9 +1639,9 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
1634 if (!area) 1639 if (!area)
1635 goto fail; 1640 goto fail;
1636 1641
1637 addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller); 1642 addr = __vmalloc_area_node(area, gfp_mask, prot, node);
1638 if (!addr) 1643 if (!addr)
1639 goto fail; 1644 return NULL;
1640 1645
1641 /* 1646 /*
1642 * In this function, newly allocated vm_struct has VM_UNINITIALIZED 1647 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
@@ -1646,11 +1651,11 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
1646 clear_vm_uninitialized_flag(area); 1651 clear_vm_uninitialized_flag(area);
1647 1652
1648 /* 1653 /*
1649 * A ref_count = 3 is needed because the vm_struct and vmap_area 1654 * A ref_count = 2 is needed because vm_struct allocated in
1650 * structures allocated in the __get_vm_area_node() function contain 1655 * __get_vm_area_node() contains a reference to the virtual address of
1651 * references to the virtual address of the vmalloc'ed block. 1656 * the vmalloc'ed block.
1652 */ 1657 */
1653 kmemleak_alloc(addr, real_size, 3, gfp_mask); 1658 kmemleak_alloc(addr, real_size, 2, gfp_mask);
1654 1659
1655 return addr; 1660 return addr;
1656 1661
@@ -2563,6 +2568,11 @@ static void show_numa_info(struct seq_file *m, struct vm_struct *v)
2563 if (!counters) 2568 if (!counters)
2564 return; 2569 return;
2565 2570
2571 /* Pair with smp_wmb() in clear_vm_uninitialized_flag() */
2572 smp_rmb();
2573 if (v->flags & VM_UNINITIALIZED)
2574 return;
2575
2566 memset(counters, 0, nr_node_ids * sizeof(unsigned int)); 2576 memset(counters, 0, nr_node_ids * sizeof(unsigned int));
2567 2577
2568 for (nr = 0; nr < v->nr_pages; nr++) 2578 for (nr = 0; nr < v->nr_pages; nr++)
@@ -2579,23 +2589,15 @@ static int s_show(struct seq_file *m, void *p)
2579 struct vmap_area *va = p; 2589 struct vmap_area *va = p;
2580 struct vm_struct *v; 2590 struct vm_struct *v;
2581 2591
2582 if (va->flags & (VM_LAZY_FREE | VM_LAZY_FREEING)) 2592 /*
2593 * s_show can encounter race with remove_vm_area, !VM_VM_AREA on
2594 * behalf of vmap area is being tear down or vm_map_ram allocation.
2595 */
2596 if (!(va->flags & VM_VM_AREA))
2583 return 0; 2597 return 0;
2584 2598
2585 if (!(va->flags & VM_VM_AREA)) {
2586 seq_printf(m, "0x%pK-0x%pK %7ld vm_map_ram\n",
2587 (void *)va->va_start, (void *)va->va_end,
2588 va->va_end - va->va_start);
2589 return 0;
2590 }
2591
2592 v = va->vm; 2599 v = va->vm;
2593 2600
2594 /* Pair with smp_wmb() in clear_vm_uninitialized_flag() */
2595 smp_rmb();
2596 if (v->flags & VM_UNINITIALIZED)
2597 return 0;
2598
2599 seq_printf(m, "0x%pK-0x%pK %7ld", 2601 seq_printf(m, "0x%pK-0x%pK %7ld",
2600 v->addr, v->addr + v->size, v->size); 2602 v->addr, v->addr + v->size, v->size);
2601 2603
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 9bb314577911..72496140ac08 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -812,6 +812,7 @@ const char * const vmstat_text[] = {
812 812
813#ifdef CONFIG_NUMA_BALANCING 813#ifdef CONFIG_NUMA_BALANCING
814 "numa_pte_updates", 814 "numa_pte_updates",
815 "numa_huge_pte_updates",
815 "numa_hint_faults", 816 "numa_hint_faults",
816 "numa_hint_faults_local", 817 "numa_hint_faults_local",
817 "numa_pages_migrated", 818 "numa_pages_migrated",
@@ -1229,6 +1230,20 @@ static void start_cpu_timer(int cpu)
1229 schedule_delayed_work_on(cpu, work, __round_jiffies_relative(HZ, cpu)); 1230 schedule_delayed_work_on(cpu, work, __round_jiffies_relative(HZ, cpu));
1230} 1231}
1231 1232
1233static void vmstat_cpu_dead(int node)
1234{
1235 int cpu;
1236
1237 get_online_cpus();
1238 for_each_online_cpu(cpu)
1239 if (cpu_to_node(cpu) == node)
1240 goto end;
1241
1242 node_clear_state(node, N_CPU);
1243end:
1244 put_online_cpus();
1245}
1246
1232/* 1247/*
1233 * Use the cpu notifier to insure that the thresholds are recalculated 1248 * Use the cpu notifier to insure that the thresholds are recalculated
1234 * when necessary. 1249 * when necessary.
@@ -1258,6 +1273,7 @@ static int vmstat_cpuup_callback(struct notifier_block *nfb,
1258 case CPU_DEAD: 1273 case CPU_DEAD:
1259 case CPU_DEAD_FROZEN: 1274 case CPU_DEAD_FROZEN:
1260 refresh_zone_stat_thresholds(); 1275 refresh_zone_stat_thresholds();
1276 vmstat_cpu_dead(cpu_to_node(cpu));
1261 break; 1277 break;
1262 default: 1278 default:
1263 break; 1279 break;
@@ -1276,8 +1292,12 @@ static int __init setup_vmstat(void)
1276 1292
1277 register_cpu_notifier(&vmstat_notifier); 1293 register_cpu_notifier(&vmstat_notifier);
1278 1294
1279 for_each_online_cpu(cpu) 1295 get_online_cpus();
1296 for_each_online_cpu(cpu) {
1280 start_cpu_timer(cpu); 1297 start_cpu_timer(cpu);
1298 node_set_state(cpu_to_node(cpu), N_CPU);
1299 }
1300 put_online_cpus();
1281#endif 1301#endif
1282#ifdef CONFIG_PROC_FS 1302#ifdef CONFIG_PROC_FS
1283 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); 1303 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
diff --git a/mm/zswap.c b/mm/zswap.c
index d93510c6aa2d..5a63f78a5601 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -217,6 +217,7 @@ static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp)
217 if (!entry) 217 if (!entry)
218 return NULL; 218 return NULL;
219 entry->refcount = 1; 219 entry->refcount = 1;
220 RB_CLEAR_NODE(&entry->rbnode);
220 return entry; 221 return entry;
221} 222}
222 223
@@ -225,19 +226,6 @@ static void zswap_entry_cache_free(struct zswap_entry *entry)
225 kmem_cache_free(zswap_entry_cache, entry); 226 kmem_cache_free(zswap_entry_cache, entry);
226} 227}
227 228
228/* caller must hold the tree lock */
229static void zswap_entry_get(struct zswap_entry *entry)
230{
231 entry->refcount++;
232}
233
234/* caller must hold the tree lock */
235static int zswap_entry_put(struct zswap_entry *entry)
236{
237 entry->refcount--;
238 return entry->refcount;
239}
240
241/********************************* 229/*********************************
242* rbtree functions 230* rbtree functions
243**********************************/ 231**********************************/
@@ -285,6 +273,61 @@ static int zswap_rb_insert(struct rb_root *root, struct zswap_entry *entry,
285 return 0; 273 return 0;
286} 274}
287 275
276static void zswap_rb_erase(struct rb_root *root, struct zswap_entry *entry)
277{
278 if (!RB_EMPTY_NODE(&entry->rbnode)) {
279 rb_erase(&entry->rbnode, root);
280 RB_CLEAR_NODE(&entry->rbnode);
281 }
282}
283
284/*
285 * Carries out the common pattern of freeing and entry's zsmalloc allocation,
286 * freeing the entry itself, and decrementing the number of stored pages.
287 */
288static void zswap_free_entry(struct zswap_tree *tree,
289 struct zswap_entry *entry)
290{
291 zbud_free(tree->pool, entry->handle);
292 zswap_entry_cache_free(entry);
293 atomic_dec(&zswap_stored_pages);
294 zswap_pool_pages = zbud_get_pool_size(tree->pool);
295}
296
297/* caller must hold the tree lock */
298static void zswap_entry_get(struct zswap_entry *entry)
299{
300 entry->refcount++;
301}
302
303/* caller must hold the tree lock
304* remove from the tree and free it, if nobody reference the entry
305*/
306static void zswap_entry_put(struct zswap_tree *tree,
307 struct zswap_entry *entry)
308{
309 int refcount = --entry->refcount;
310
311 BUG_ON(refcount < 0);
312 if (refcount == 0) {
313 zswap_rb_erase(&tree->rbroot, entry);
314 zswap_free_entry(tree, entry);
315 }
316}
317
318/* caller must hold the tree lock */
319static struct zswap_entry *zswap_entry_find_get(struct rb_root *root,
320 pgoff_t offset)
321{
322 struct zswap_entry *entry = NULL;
323
324 entry = zswap_rb_search(root, offset);
325 if (entry)
326 zswap_entry_get(entry);
327
328 return entry;
329}
330
288/********************************* 331/*********************************
289* per-cpu code 332* per-cpu code
290**********************************/ 333**********************************/
@@ -368,18 +411,6 @@ static bool zswap_is_full(void)
368 zswap_pool_pages); 411 zswap_pool_pages);
369} 412}
370 413
371/*
372 * Carries out the common pattern of freeing and entry's zsmalloc allocation,
373 * freeing the entry itself, and decrementing the number of stored pages.
374 */
375static void zswap_free_entry(struct zswap_tree *tree, struct zswap_entry *entry)
376{
377 zbud_free(tree->pool, entry->handle);
378 zswap_entry_cache_free(entry);
379 atomic_dec(&zswap_stored_pages);
380 zswap_pool_pages = zbud_get_pool_size(tree->pool);
381}
382
383/********************************* 414/*********************************
384* writeback code 415* writeback code
385**********************************/ 416**********************************/
@@ -387,7 +418,7 @@ static void zswap_free_entry(struct zswap_tree *tree, struct zswap_entry *entry)
387enum zswap_get_swap_ret { 418enum zswap_get_swap_ret {
388 ZSWAP_SWAPCACHE_NEW, 419 ZSWAP_SWAPCACHE_NEW,
389 ZSWAP_SWAPCACHE_EXIST, 420 ZSWAP_SWAPCACHE_EXIST,
390 ZSWAP_SWAPCACHE_NOMEM 421 ZSWAP_SWAPCACHE_FAIL,
391}; 422};
392 423
393/* 424/*
@@ -401,9 +432,10 @@ enum zswap_get_swap_ret {
401 * added to the swap cache, and returned in retpage. 432 * added to the swap cache, and returned in retpage.
402 * 433 *
403 * If success, the swap cache page is returned in retpage 434 * If success, the swap cache page is returned in retpage
404 * Returns 0 if page was already in the swap cache, page is not locked 435 * Returns ZSWAP_SWAPCACHE_EXIST if page was already in the swap cache
405 * Returns 1 if the new page needs to be populated, page is locked 436 * Returns ZSWAP_SWAPCACHE_NEW if the new page needs to be populated,
406 * Returns <0 on error 437 * the new page is added to swapcache and locked
438 * Returns ZSWAP_SWAPCACHE_FAIL on error
407 */ 439 */
408static int zswap_get_swap_cache_page(swp_entry_t entry, 440static int zswap_get_swap_cache_page(swp_entry_t entry,
409 struct page **retpage) 441 struct page **retpage)
@@ -475,7 +507,7 @@ static int zswap_get_swap_cache_page(swp_entry_t entry,
475 if (new_page) 507 if (new_page)
476 page_cache_release(new_page); 508 page_cache_release(new_page);
477 if (!found_page) 509 if (!found_page)
478 return ZSWAP_SWAPCACHE_NOMEM; 510 return ZSWAP_SWAPCACHE_FAIL;
479 *retpage = found_page; 511 *retpage = found_page;
480 return ZSWAP_SWAPCACHE_EXIST; 512 return ZSWAP_SWAPCACHE_EXIST;
481} 513}
@@ -502,7 +534,7 @@ static int zswap_writeback_entry(struct zbud_pool *pool, unsigned long handle)
502 struct page *page; 534 struct page *page;
503 u8 *src, *dst; 535 u8 *src, *dst;
504 unsigned int dlen; 536 unsigned int dlen;
505 int ret, refcount; 537 int ret;
506 struct writeback_control wbc = { 538 struct writeback_control wbc = {
507 .sync_mode = WB_SYNC_NONE, 539 .sync_mode = WB_SYNC_NONE,
508 }; 540 };
@@ -517,23 +549,22 @@ static int zswap_writeback_entry(struct zbud_pool *pool, unsigned long handle)
517 549
518 /* find and ref zswap entry */ 550 /* find and ref zswap entry */
519 spin_lock(&tree->lock); 551 spin_lock(&tree->lock);
520 entry = zswap_rb_search(&tree->rbroot, offset); 552 entry = zswap_entry_find_get(&tree->rbroot, offset);
521 if (!entry) { 553 if (!entry) {
522 /* entry was invalidated */ 554 /* entry was invalidated */
523 spin_unlock(&tree->lock); 555 spin_unlock(&tree->lock);
524 return 0; 556 return 0;
525 } 557 }
526 zswap_entry_get(entry);
527 spin_unlock(&tree->lock); 558 spin_unlock(&tree->lock);
528 BUG_ON(offset != entry->offset); 559 BUG_ON(offset != entry->offset);
529 560
530 /* try to allocate swap cache page */ 561 /* try to allocate swap cache page */
531 switch (zswap_get_swap_cache_page(swpentry, &page)) { 562 switch (zswap_get_swap_cache_page(swpentry, &page)) {
532 case ZSWAP_SWAPCACHE_NOMEM: /* no memory */ 563 case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */
533 ret = -ENOMEM; 564 ret = -ENOMEM;
534 goto fail; 565 goto fail;
535 566
536 case ZSWAP_SWAPCACHE_EXIST: /* page is unlocked */ 567 case ZSWAP_SWAPCACHE_EXIST:
537 /* page is already in the swap cache, ignore for now */ 568 /* page is already in the swap cache, ignore for now */
538 page_cache_release(page); 569 page_cache_release(page);
539 ret = -EEXIST; 570 ret = -EEXIST;
@@ -556,43 +587,44 @@ static int zswap_writeback_entry(struct zbud_pool *pool, unsigned long handle)
556 SetPageUptodate(page); 587 SetPageUptodate(page);
557 } 588 }
558 589
590 /* move it to the tail of the inactive list after end_writeback */
591 SetPageReclaim(page);
592
559 /* start writeback */ 593 /* start writeback */
560 __swap_writepage(page, &wbc, end_swap_bio_write); 594 __swap_writepage(page, &wbc, end_swap_bio_write);
561 page_cache_release(page); 595 page_cache_release(page);
562 zswap_written_back_pages++; 596 zswap_written_back_pages++;
563 597
564 spin_lock(&tree->lock); 598 spin_lock(&tree->lock);
565
566 /* drop local reference */ 599 /* drop local reference */
567 zswap_entry_put(entry); 600 zswap_entry_put(tree, entry);
568 /* drop the initial reference from entry creation */
569 refcount = zswap_entry_put(entry);
570 601
571 /* 602 /*
572 * There are three possible values for refcount here: 603 * There are two possible situations for entry here:
573 * (1) refcount is 1, load is in progress, unlink from rbtree, 604 * (1) refcount is 1(normal case), entry is valid and on the tree
574 * load will free 605 * (2) refcount is 0, entry is freed and not on the tree
575 * (2) refcount is 0, (normal case) entry is valid, 606 * because invalidate happened during writeback
576 * remove from rbtree and free entry 607 * search the tree and free the entry if find entry
577 * (3) refcount is -1, invalidate happened during writeback, 608 */
578 * free entry 609 if (entry == zswap_rb_search(&tree->rbroot, offset))
579 */ 610 zswap_entry_put(tree, entry);
580 if (refcount >= 0) {
581 /* no invalidate yet, remove from rbtree */
582 rb_erase(&entry->rbnode, &tree->rbroot);
583 }
584 spin_unlock(&tree->lock); 611 spin_unlock(&tree->lock);
585 if (refcount <= 0) {
586 /* free the entry */
587 zswap_free_entry(tree, entry);
588 return 0;
589 }
590 return -EAGAIN;
591 612
613 goto end;
614
615 /*
616 * if we get here due to ZSWAP_SWAPCACHE_EXIST
617 * a load may happening concurrently
618 * it is safe and okay to not free the entry
619 * if we free the entry in the following put
620 * it it either okay to return !0
621 */
592fail: 622fail:
593 spin_lock(&tree->lock); 623 spin_lock(&tree->lock);
594 zswap_entry_put(entry); 624 zswap_entry_put(tree, entry);
595 spin_unlock(&tree->lock); 625 spin_unlock(&tree->lock);
626
627end:
596 return ret; 628 return ret;
597} 629}
598 630
@@ -676,11 +708,8 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
676 if (ret == -EEXIST) { 708 if (ret == -EEXIST) {
677 zswap_duplicate_entry++; 709 zswap_duplicate_entry++;
678 /* remove from rbtree */ 710 /* remove from rbtree */
679 rb_erase(&dupentry->rbnode, &tree->rbroot); 711 zswap_rb_erase(&tree->rbroot, dupentry);
680 if (!zswap_entry_put(dupentry)) { 712 zswap_entry_put(tree, dupentry);
681 /* free */
682 zswap_free_entry(tree, dupentry);
683 }
684 } 713 }
685 } while (ret == -EEXIST); 714 } while (ret == -EEXIST);
686 spin_unlock(&tree->lock); 715 spin_unlock(&tree->lock);
@@ -709,17 +738,16 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset,
709 struct zswap_entry *entry; 738 struct zswap_entry *entry;
710 u8 *src, *dst; 739 u8 *src, *dst;
711 unsigned int dlen; 740 unsigned int dlen;
712 int refcount, ret; 741 int ret;
713 742
714 /* find */ 743 /* find */
715 spin_lock(&tree->lock); 744 spin_lock(&tree->lock);
716 entry = zswap_rb_search(&tree->rbroot, offset); 745 entry = zswap_entry_find_get(&tree->rbroot, offset);
717 if (!entry) { 746 if (!entry) {
718 /* entry was written back */ 747 /* entry was written back */
719 spin_unlock(&tree->lock); 748 spin_unlock(&tree->lock);
720 return -1; 749 return -1;
721 } 750 }
722 zswap_entry_get(entry);
723 spin_unlock(&tree->lock); 751 spin_unlock(&tree->lock);
724 752
725 /* decompress */ 753 /* decompress */
@@ -734,22 +762,9 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset,
734 BUG_ON(ret); 762 BUG_ON(ret);
735 763
736 spin_lock(&tree->lock); 764 spin_lock(&tree->lock);
737 refcount = zswap_entry_put(entry); 765 zswap_entry_put(tree, entry);
738 if (likely(refcount)) {
739 spin_unlock(&tree->lock);
740 return 0;
741 }
742 spin_unlock(&tree->lock); 766 spin_unlock(&tree->lock);
743 767
744 /*
745 * We don't have to unlink from the rbtree because
746 * zswap_writeback_entry() or zswap_frontswap_invalidate page()
747 * has already done this for us if we are the last reference.
748 */
749 /* free */
750
751 zswap_free_entry(tree, entry);
752
753 return 0; 768 return 0;
754} 769}
755 770
@@ -758,7 +773,6 @@ static void zswap_frontswap_invalidate_page(unsigned type, pgoff_t offset)
758{ 773{
759 struct zswap_tree *tree = zswap_trees[type]; 774 struct zswap_tree *tree = zswap_trees[type];
760 struct zswap_entry *entry; 775 struct zswap_entry *entry;
761 int refcount;
762 776
763 /* find */ 777 /* find */
764 spin_lock(&tree->lock); 778 spin_lock(&tree->lock);
@@ -770,20 +784,12 @@ static void zswap_frontswap_invalidate_page(unsigned type, pgoff_t offset)
770 } 784 }
771 785
772 /* remove from rbtree */ 786 /* remove from rbtree */
773 rb_erase(&entry->rbnode, &tree->rbroot); 787 zswap_rb_erase(&tree->rbroot, entry);
774 788
775 /* drop the initial reference from entry creation */ 789 /* drop the initial reference from entry creation */
776 refcount = zswap_entry_put(entry); 790 zswap_entry_put(tree, entry);
777 791
778 spin_unlock(&tree->lock); 792 spin_unlock(&tree->lock);
779
780 if (refcount) {
781 /* writeback in progress, writeback will free */
782 return;
783 }
784
785 /* free */
786 zswap_free_entry(tree, entry);
787} 793}
788 794
789/* frees all zswap entries for the given swap type */ 795/* frees all zswap entries for the given swap type */
@@ -797,11 +803,8 @@ static void zswap_frontswap_invalidate_area(unsigned type)
797 803
798 /* walk the tree and free everything */ 804 /* walk the tree and free everything */
799 spin_lock(&tree->lock); 805 spin_lock(&tree->lock);
800 rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, rbnode) { 806 rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, rbnode)
801 zbud_free(tree->pool, entry->handle); 807 zswap_free_entry(tree, entry);
802 zswap_entry_cache_free(entry);
803 atomic_dec(&zswap_stored_pages);
804 }
805 tree->rbroot = RB_ROOT; 808 tree->rbroot = RB_ROOT;
806 spin_unlock(&tree->lock); 809 spin_unlock(&tree->lock);
807 810
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 66cad506b8a2..61090e0ff613 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -241,8 +241,11 @@ our $Sparse = qr{
241 __ref| 241 __ref|
242 __rcu 242 __rcu
243 }x; 243 }x;
244 244our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
245our $InitAttribute = qr{__(?:mem|cpu|dev|net_|)(?:initdata|initconst|init\b)}; 245our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
246our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
247our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
248our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
246 249
247# Notes to $Attribute: 250# Notes to $Attribute:
248# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check 251# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
@@ -323,7 +326,8 @@ our $logFunctions = qr{(?x:
323 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| 326 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
324 WARN(?:_RATELIMIT|_ONCE|)| 327 WARN(?:_RATELIMIT|_ONCE|)|
325 panic| 328 panic|
326 MODULE_[A-Z_]+ 329 MODULE_[A-Z_]+|
330 seq_vprintf|seq_printf|seq_puts
327)}; 331)};
328 332
329our $signature_tags = qr{(?xi: 333our $signature_tags = qr{(?xi:
@@ -442,8 +446,9 @@ sub seed_camelcase_file {
442 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/); 446 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
443 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) { 447 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
444 $camelcase{$1} = 1; 448 $camelcase{$1} = 1;
445 } 449 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
446 elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*\(/) { 450 $camelcase{$1} = 1;
451 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
447 $camelcase{$1} = 1; 452 $camelcase{$1} = 1;
448 } 453 }
449 } 454 }
@@ -1512,6 +1517,14 @@ sub rtrim {
1512 return $string; 1517 return $string;
1513} 1518}
1514 1519
1520sub string_find_replace {
1521 my ($string, $find, $replace) = @_;
1522
1523 $string =~ s/$find/$replace/g;
1524
1525 return $string;
1526}
1527
1515sub tabify { 1528sub tabify {
1516 my ($leading) = @_; 1529 my ($leading) = @_;
1517 1530
@@ -1612,6 +1625,8 @@ sub process {
1612 my @setup_docs = (); 1625 my @setup_docs = ();
1613 my $setup_docs = 0; 1626 my $setup_docs = 0;
1614 1627
1628 my $camelcase_file_seeded = 0;
1629
1615 sanitise_line_reset(); 1630 sanitise_line_reset();
1616 my $line; 1631 my $line;
1617 foreach my $rawline (@rawlines) { 1632 foreach my $rawline (@rawlines) {
@@ -1754,11 +1769,11 @@ sub process {
1754 # extract the filename as it passes 1769 # extract the filename as it passes
1755 if ($line =~ /^diff --git.*?(\S+)$/) { 1770 if ($line =~ /^diff --git.*?(\S+)$/) {
1756 $realfile = $1; 1771 $realfile = $1;
1757 $realfile =~ s@^([^/]*)/@@; 1772 $realfile =~ s@^([^/]*)/@@ if (!$file);
1758 $in_commit_log = 0; 1773 $in_commit_log = 0;
1759 } elsif ($line =~ /^\+\+\+\s+(\S+)/) { 1774 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1760 $realfile = $1; 1775 $realfile = $1;
1761 $realfile =~ s@^([^/]*)/@@; 1776 $realfile =~ s@^([^/]*)/@@ if (!$file);
1762 $in_commit_log = 0; 1777 $in_commit_log = 0;
1763 1778
1764 $p1_prefix = $1; 1779 $p1_prefix = $1;
@@ -1947,6 +1962,18 @@ sub process {
1947 $rpt_cleaners = 1; 1962 $rpt_cleaners = 1;
1948 } 1963 }
1949 1964
1965# Check for FSF mailing addresses.
1966 if ($rawline =~ /You should have received a copy/ ||
1967 $rawline =~ /write to the Free Software/ ||
1968 $rawline =~ /59 Temple Place/ ||
1969 $rawline =~ /51 Franklin Street/) {
1970 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1971 my $msg_type = \&ERROR;
1972 $msg_type = \&CHK if ($file);
1973 &{$msg_type}("FSF_MAILING_ADDRESS",
1974 "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
1975 }
1976
1950# check for Kconfig help text having a real description 1977# check for Kconfig help text having a real description
1951# Only applies when adding the entry originally, after that we do not have 1978# Only applies when adding the entry originally, after that we do not have
1952# sufficient context to determine whether it is indeed long enough. 1979# sufficient context to determine whether it is indeed long enough.
@@ -2838,7 +2865,7 @@ sub process {
2838 \+=|-=|\*=|\/=|%=|\^=|\|=|&=| 2865 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
2839 =>|->|<<|>>|<|>|=|!|~| 2866 =>|->|<<|>>|<|>|=|!|~|
2840 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| 2867 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
2841 \?|: 2868 \?:|\?|:
2842 }x; 2869 }x;
2843 my @elements = split(/($ops|;)/, $opline); 2870 my @elements = split(/($ops|;)/, $opline);
2844 2871
@@ -3061,15 +3088,13 @@ sub process {
3061 $ok = 1; 3088 $ok = 1;
3062 } 3089 }
3063 3090
3064 # Ignore ?: 3091 # messages are ERROR, but ?: are CHK
3065 if (($opv eq ':O' && $ca =~ /\?$/) ||
3066 ($op eq '?' && $cc =~ /^:/)) {
3067 $ok = 1;
3068 }
3069
3070 if ($ok == 0) { 3092 if ($ok == 0) {
3071 if (ERROR("SPACING", 3093 my $msg_type = \&ERROR;
3072 "spaces required around that '$op' $at\n" . $hereptr)) { 3094 $msg_type = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
3095
3096 if (&{$msg_type}("SPACING",
3097 "spaces required around that '$op' $at\n" . $hereptr)) {
3073 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; 3098 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
3074 if (defined $fix_elements[$n + 2]) { 3099 if (defined $fix_elements[$n + 2]) {
3075 $fix_elements[$n + 2] =~ s/^\s+//; 3100 $fix_elements[$n + 2] =~ s/^\s+//;
@@ -3208,21 +3233,10 @@ sub process {
3208 } 3233 }
3209 3234
3210# Return is not a function. 3235# Return is not a function.
3211 if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) { 3236 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
3212 my $spacing = $1; 3237 my $spacing = $1;
3213 my $value = $2; 3238 if ($^V && $^V ge 5.10.0 &&
3214 3239 $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
3215 # Flatten any parentheses
3216 $value =~ s/\(/ \(/g;
3217 $value =~ s/\)/\) /g;
3218 while ($value =~ s/\[[^\[\]]*\]/1/ ||
3219 $value !~ /(?:$Ident|-?$Constant)\s*
3220 $Compare\s*
3221 (?:$Ident|-?$Constant)/x &&
3222 $value =~ s/\([^\(\)]*\)/1/) {
3223 }
3224#print "value<$value>\n";
3225 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
3226 ERROR("RETURN_PARENTHESES", 3240 ERROR("RETURN_PARENTHESES",
3227 "return is not a function, parentheses are not required\n" . $herecurr); 3241 "return is not a function, parentheses are not required\n" . $herecurr);
3228 3242
@@ -3231,6 +3245,7 @@ sub process {
3231 "space required before the open parenthesis '('\n" . $herecurr); 3245 "space required before the open parenthesis '('\n" . $herecurr);
3232 } 3246 }
3233 } 3247 }
3248
3234# Return of what appears to be an errno should normally be -'ve 3249# Return of what appears to be an errno should normally be -'ve
3235 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { 3250 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
3236 my $name = $1; 3251 my $name = $1;
@@ -3396,7 +3411,13 @@ sub process {
3396 while ($var =~ m{($Ident)}g) { 3411 while ($var =~ m{($Ident)}g) {
3397 my $word = $1; 3412 my $word = $1;
3398 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/); 3413 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
3399 seed_camelcase_includes() if ($check); 3414 if ($check) {
3415 seed_camelcase_includes();
3416 if (!$file && !$camelcase_file_seeded) {
3417 seed_camelcase_file($realfile);
3418 $camelcase_file_seeded = 1;
3419 }
3420 }
3400 if (!defined $camelcase{$word}) { 3421 if (!defined $camelcase{$word}) {
3401 $camelcase{$word} = 1; 3422 $camelcase{$word} = 1;
3402 CHK("CAMELCASE", 3423 CHK("CAMELCASE",
@@ -3725,14 +3746,6 @@ sub process {
3725 } 3746 }
3726 } 3747 }
3727 3748
3728sub string_find_replace {
3729 my ($string, $find, $replace) = @_;
3730
3731 $string =~ s/$find/$replace/g;
3732
3733 return $string;
3734}
3735
3736# check for bad placement of section $InitAttribute (e.g.: __initdata) 3749# check for bad placement of section $InitAttribute (e.g.: __initdata)
3737 if ($line =~ /(\b$InitAttribute\b)/) { 3750 if ($line =~ /(\b$InitAttribute\b)/) {
3738 my $attr = $1; 3751 my $attr = $1;
@@ -3751,6 +3764,35 @@ sub string_find_replace {
3751 } 3764 }
3752 } 3765 }
3753 3766
3767# check for $InitAttributeData (ie: __initdata) with const
3768 if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
3769 my $attr = $1;
3770 $attr =~ /($InitAttributePrefix)(.*)/;
3771 my $attr_prefix = $1;
3772 my $attr_type = $2;
3773 if (ERROR("INIT_ATTRIBUTE",
3774 "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
3775 $fix) {
3776 $fixed[$linenr - 1] =~
3777 s/$InitAttributeData/${attr_prefix}initconst/;
3778 }
3779 }
3780
3781# check for $InitAttributeConst (ie: __initconst) without const
3782 if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
3783 my $attr = $1;
3784 if (ERROR("INIT_ATTRIBUTE",
3785 "Use of $attr requires a separate use of const\n" . $herecurr) &&
3786 $fix) {
3787 my $lead = $fixed[$linenr - 1] =~
3788 /(^\+\s*(?:static\s+))/;
3789 $lead = rtrim($1);
3790 $lead = "$lead " if ($lead !~ /^\+$/);
3791 $lead = "${lead}const ";
3792 $fixed[$linenr - 1] =~ s/(^\+\s*(?:static\s+))/$lead/;
3793 }
3794 }
3795
3754# prefer usleep_range over udelay 3796# prefer usleep_range over udelay
3755 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { 3797 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
3756 # ignore udelay's < 10, however 3798 # ignore udelay's < 10, however
@@ -3810,8 +3852,8 @@ sub string_find_replace {
3810# check for memory barriers without a comment. 3852# check for memory barriers without a comment.
3811 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { 3853 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
3812 if (!ctx_has_comment($first_line, $linenr)) { 3854 if (!ctx_has_comment($first_line, $linenr)) {
3813 CHK("MEMORY_BARRIER", 3855 WARN("MEMORY_BARRIER",
3814 "memory barrier without comment\n" . $herecurr); 3856 "memory barrier without comment\n" . $herecurr);
3815 } 3857 }
3816 } 3858 }
3817# check of hardware specific defines 3859# check of hardware specific defines
@@ -3835,7 +3877,8 @@ sub string_find_replace {
3835 } 3877 }
3836 3878
3837# Check for __inline__ and __inline, prefer inline 3879# Check for __inline__ and __inline, prefer inline
3838 if ($line =~ /\b(__inline__|__inline)\b/) { 3880 if ($realfile !~ m@\binclude/uapi/@ &&
3881 $line =~ /\b(__inline__|__inline)\b/) {
3839 if (WARN("INLINE", 3882 if (WARN("INLINE",
3840 "plain inline is preferred over $1\n" . $herecurr) && 3883 "plain inline is preferred over $1\n" . $herecurr) &&
3841 $fix) { 3884 $fix) {
@@ -3845,19 +3888,22 @@ sub string_find_replace {
3845 } 3888 }
3846 3889
3847# Check for __attribute__ packed, prefer __packed 3890# Check for __attribute__ packed, prefer __packed
3848 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { 3891 if ($realfile !~ m@\binclude/uapi/@ &&
3892 $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
3849 WARN("PREFER_PACKED", 3893 WARN("PREFER_PACKED",
3850 "__packed is preferred over __attribute__((packed))\n" . $herecurr); 3894 "__packed is preferred over __attribute__((packed))\n" . $herecurr);
3851 } 3895 }
3852 3896
3853# Check for __attribute__ aligned, prefer __aligned 3897# Check for __attribute__ aligned, prefer __aligned
3854 if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { 3898 if ($realfile !~ m@\binclude/uapi/@ &&
3899 $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
3855 WARN("PREFER_ALIGNED", 3900 WARN("PREFER_ALIGNED",
3856 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); 3901 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
3857 } 3902 }
3858 3903
3859# Check for __attribute__ format(printf, prefer __printf 3904# Check for __attribute__ format(printf, prefer __printf
3860 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { 3905 if ($realfile !~ m@\binclude/uapi/@ &&
3906 $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
3861 if (WARN("PREFER_PRINTF", 3907 if (WARN("PREFER_PRINTF",
3862 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && 3908 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
3863 $fix) { 3909 $fix) {
@@ -3867,7 +3913,8 @@ sub string_find_replace {
3867 } 3913 }
3868 3914
3869# Check for __attribute__ format(scanf, prefer __scanf 3915# Check for __attribute__ format(scanf, prefer __scanf
3870 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { 3916 if ($realfile !~ m@\binclude/uapi/@ &&
3917 $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
3871 if (WARN("PREFER_SCANF", 3918 if (WARN("PREFER_SCANF",
3872 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && 3919 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
3873 $fix) { 3920 $fix) {
@@ -3903,9 +3950,9 @@ sub string_find_replace {
3903 } 3950 }
3904 3951
3905# check for seq_printf uses that could be seq_puts 3952# check for seq_printf uses that could be seq_puts
3906 if ($line =~ /\bseq_printf\s*\(/) { 3953 if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
3907 my $fmt = get_quoted_string($line, $rawline); 3954 my $fmt = get_quoted_string($line, $rawline);
3908 if ($fmt !~ /[^\\]\%/) { 3955 if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
3909 if (WARN("PREFER_SEQ_PUTS", 3956 if (WARN("PREFER_SEQ_PUTS",
3910 "Prefer seq_puts to seq_printf\n" . $herecurr) && 3957 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
3911 $fix) { 3958 $fix) {
@@ -3972,6 +4019,23 @@ sub string_find_replace {
3972 } 4019 }
3973 } 4020 }
3974 4021
4022# check for naked sscanf
4023 if ($^V && $^V ge 5.10.0 &&
4024 defined $stat &&
4025 $stat =~ /\bsscanf\b/ &&
4026 ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
4027 $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
4028 $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
4029 my $lc = $stat =~ tr@\n@@;
4030 $lc = $lc + $linenr;
4031 my $stat_real = raw_line($linenr, 0);
4032 for (my $count = $linenr + 1; $count <= $lc; $count++) {
4033 $stat_real = $stat_real . "\n" . raw_line($count, 0);
4034 }
4035 WARN("NAKED_SSCANF",
4036 "unchecked sscanf return value\n" . "$here\n$stat_real\n");
4037 }
4038
3975# check for new externs in .h files. 4039# check for new externs in .h files.
3976 if ($realfile =~ /\.h$/ && 4040 if ($realfile =~ /\.h$/ &&
3977 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { 4041 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
@@ -4190,6 +4254,12 @@ sub string_find_replace {
4190 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); 4254 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
4191 } 4255 }
4192 4256
4257# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
4258 if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
4259 ERROR("DEFINE_ARCH_HAS",
4260 "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
4261 }
4262
4193# check for %L{u,d,i} in strings 4263# check for %L{u,d,i} in strings
4194 my $string; 4264 my $string;
4195 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) { 4265 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
diff --git a/scripts/docproc.c b/scripts/docproc.c
index 4cfdc1797eb8..2b69eaf5b646 100644
--- a/scripts/docproc.c
+++ b/scripts/docproc.c
@@ -72,6 +72,7 @@ FILELINE * docsection;
72#define FUNCTION "-function" 72#define FUNCTION "-function"
73#define NOFUNCTION "-nofunction" 73#define NOFUNCTION "-nofunction"
74#define NODOCSECTIONS "-no-doc-sections" 74#define NODOCSECTIONS "-no-doc-sections"
75#define SHOWNOTFOUND "-show-not-found"
75 76
76static char *srctree, *kernsrctree; 77static char *srctree, *kernsrctree;
77 78
@@ -294,6 +295,7 @@ static void singfunc(char * filename, char * line)
294 int startofsym = 1; 295 int startofsym = 1;
295 vec[idx++] = KERNELDOC; 296 vec[idx++] = KERNELDOC;
296 vec[idx++] = DOCBOOK; 297 vec[idx++] = DOCBOOK;
298 vec[idx++] = SHOWNOTFOUND;
297 299
298 /* Split line up in individual parameters preceded by FUNCTION */ 300 /* Split line up in individual parameters preceded by FUNCTION */
299 for (i=0; line[i]; i++) { 301 for (i=0; line[i]; i++) {
@@ -325,7 +327,8 @@ static void singfunc(char * filename, char * line)
325 */ 327 */
326static void docsect(char *filename, char *line) 328static void docsect(char *filename, char *line)
327{ 329{
328 char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */ 330 /* kerneldoc -docbook -show-not-found -function "section" file NULL */
331 char *vec[7];
329 char *s; 332 char *s;
330 333
331 for (s = line; *s; s++) 334 for (s = line; *s; s++)
@@ -341,10 +344,11 @@ static void docsect(char *filename, char *line)
341 344
342 vec[0] = KERNELDOC; 345 vec[0] = KERNELDOC;
343 vec[1] = DOCBOOK; 346 vec[1] = DOCBOOK;
344 vec[2] = FUNCTION; 347 vec[2] = SHOWNOTFOUND;
345 vec[3] = line; 348 vec[3] = FUNCTION;
346 vec[4] = filename; 349 vec[4] = line;
347 vec[5] = NULL; 350 vec[5] = filename;
351 vec[6] = NULL;
348 exec_kernel_doc(vec); 352 exec_kernel_doc(vec);
349} 353}
350 354
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index b482f162a18a..ef474098d9f1 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -240,12 +240,24 @@ case "$arg" in
240 output_file="$1" 240 output_file="$1"
241 cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" 241 cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
242 output=${cpio_list} 242 output=${cpio_list}
243 echo "$output_file" | grep -q "\.gz$" && compr="gzip -n -9 -f" 243 echo "$output_file" | grep -q "\.gz$" \
244 echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f" 244 && [ -x "`which gzip 2> /dev/null`" ] \
245 echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f" 245 && compr="gzip -n -9 -f"
246 echo "$output_file" | grep -q "\.xz$" && \ 246 echo "$output_file" | grep -q "\.bz2$" \
247 compr="xz --check=crc32 --lzma2=dict=1MiB" 247 && [ -x "`which bzip2 2> /dev/null`" ] \
248 echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f" 248 && compr="bzip2 -9 -f"
249 echo "$output_file" | grep -q "\.lzma$" \
250 && [ -x "`which lzma 2> /dev/null`" ] \
251 && compr="lzma -9 -f"
252 echo "$output_file" | grep -q "\.xz$" \
253 && [ -x "`which xz 2> /dev/null`" ] \
254 && compr="xz --check=crc32 --lzma2=dict=1MiB"
255 echo "$output_file" | grep -q "\.lzo$" \
256 && [ -x "`which lzop 2> /dev/null`" ] \
257 && compr="lzop -9 -f"
258 echo "$output_file" | grep -q "\.lz4$" \
259 && [ -x "`which lz4 2> /dev/null`" ] \
260 && compr="lz4 -9 -f"
249 echo "$output_file" | grep -q "\.cpio$" && compr="cat" 261 echo "$output_file" | grep -q "\.cpio$" && compr="cat"
250 shift 262 shift
251 ;; 263 ;;
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 4305b2f2ec5e..dbd3e1ebbdad 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -257,6 +257,7 @@ my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
257 'July', 'August', 'September', 'October', 257 'July', 'August', 'September', 'October',
258 'November', 'December')[(localtime)[4]] . 258 'November', 'December')[(localtime)[4]] .
259 " " . ((localtime)[5]+1900); 259 " " . ((localtime)[5]+1900);
260my $show_not_found = 0;
260 261
261# Essentially these are globals. 262# Essentially these are globals.
262# They probably want to be tidied up, made more localised or something. 263# They probably want to be tidied up, made more localised or something.
@@ -369,6 +370,8 @@ while ($ARGV[0] =~ m/^-(.*)/) {
369 usage(); 370 usage();
370 } elsif ($cmd eq '-no-doc-sections') { 371 } elsif ($cmd eq '-no-doc-sections') {
371 $no_doc_sections = 1; 372 $no_doc_sections = 1;
373 } elsif ($cmd eq '-show-not-found') {
374 $show_not_found = 1;
372 } 375 }
373} 376}
374 377
@@ -2536,6 +2539,9 @@ sub process_file($) {
2536 } 2539 }
2537 if ($initial_section_counter == $section_counter) { 2540 if ($initial_section_counter == $section_counter) {
2538 print STDERR "Warning(${file}): no structured comments found\n"; 2541 print STDERR "Warning(${file}): no structured comments found\n";
2542 if (($function_only == 1) && ($show_not_found == 1)) {
2543 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2544 }
2539 if ($output_mode eq "xml") { 2545 if ($output_mode eq "xml") {
2540 # The template wants at least one RefEntry here; make one. 2546 # The template wants at least one RefEntry here; make one.
2541 print "<refentry>\n"; 2547 print "<refentry>\n";
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8247979e8f64..bfcea5d3b27d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -599,18 +599,17 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
599 else 599 else
600 export = export_from_sec(info, get_secindex(info, sym)); 600 export = export_from_sec(info, get_secindex(info, sym));
601 601
602 /* CRC'd symbol */
603 if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
604 crc = (unsigned int) sym->st_value;
605 sym_update_crc(symname + strlen(CRC_PFX), mod, crc,
606 export);
607 }
608
602 switch (sym->st_shndx) { 609 switch (sym->st_shndx) {
603 case SHN_COMMON: 610 case SHN_COMMON:
604 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); 611 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
605 break; 612 break;
606 case SHN_ABS:
607 /* CRC'd symbol */
608 if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
609 crc = (unsigned int) sym->st_value;
610 sym_update_crc(symname + strlen(CRC_PFX), mod, crc,
611 export);
612 }
613 break;
614 case SHN_UNDEF: 613 case SHN_UNDEF:
615 /* undefined symbol */ 614 /* undefined symbol */
616 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && 615 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index 7c2310c5b996..5f7a8b663cb9 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -152,6 +152,30 @@ static void (*w2)(uint16_t, uint16_t *);
152 152
153typedef void (*table_sort_t)(char *, int); 153typedef void (*table_sort_t)(char *, int);
154 154
155/*
156 * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
157 * the way to -256..-1, to avoid conflicting with real section
158 * indices.
159 */
160#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
161
162static inline int is_shndx_special(unsigned int i)
163{
164 return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
165}
166
167/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
168static inline unsigned int get_secindex(unsigned int shndx,
169 unsigned int sym_offs,
170 const Elf32_Word *symtab_shndx_start)
171{
172 if (is_shndx_special(shndx))
173 return SPECIAL(shndx);
174 if (shndx != SHN_XINDEX)
175 return shndx;
176 return r(&symtab_shndx_start[sym_offs]);
177}
178
155/* 32 bit and 64 bit are very similar */ 179/* 32 bit and 64 bit are very similar */
156#include "sortextable.h" 180#include "sortextable.h"
157#define SORTEXTABLE_64 181#define SORTEXTABLE_64
diff --git a/scripts/sortextable.h b/scripts/sortextable.h
index f5eb43d42926..8fac3fd697a6 100644
--- a/scripts/sortextable.h
+++ b/scripts/sortextable.h
@@ -98,6 +98,8 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
98 Elf_Shdr *symtab_sec = NULL; 98 Elf_Shdr *symtab_sec = NULL;
99 Elf_Shdr *extab_sec = NULL; 99 Elf_Shdr *extab_sec = NULL;
100 Elf_Sym *sym; 100 Elf_Sym *sym;
101 const Elf_Sym *symtab;
102 Elf32_Word *symtab_shndx_start = NULL;
101 Elf_Sym *sort_needed_sym; 103 Elf_Sym *sort_needed_sym;
102 Elf_Shdr *sort_needed_sec; 104 Elf_Shdr *sort_needed_sec;
103 Elf_Rel *relocs = NULL; 105 Elf_Rel *relocs = NULL;
@@ -109,11 +111,22 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
109 int extab_index = 0; 111 int extab_index = 0;
110 int i; 112 int i;
111 int idx; 113 int idx;
114 unsigned int num_sections;
115 unsigned int secindex_strings;
112 116
113 shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff)); 117 shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff));
114 shstrtab_sec = shdr + r2(&ehdr->e_shstrndx); 118
119 num_sections = r2(&ehdr->e_shnum);
120 if (num_sections == SHN_UNDEF)
121 num_sections = _r(&shdr[0].sh_size);
122
123 secindex_strings = r2(&ehdr->e_shstrndx);
124 if (secindex_strings == SHN_XINDEX)
125 secindex_strings = r(&shdr[0].sh_link);
126
127 shstrtab_sec = shdr + secindex_strings;
115 secstrtab = (const char *)ehdr + _r(&shstrtab_sec->sh_offset); 128 secstrtab = (const char *)ehdr + _r(&shstrtab_sec->sh_offset);
116 for (i = 0; i < r2(&ehdr->e_shnum); i++) { 129 for (i = 0; i < num_sections; i++) {
117 idx = r(&shdr[i].sh_name); 130 idx = r(&shdr[i].sh_name);
118 if (strcmp(secstrtab + idx, "__ex_table") == 0) { 131 if (strcmp(secstrtab + idx, "__ex_table") == 0) {
119 extab_sec = shdr + i; 132 extab_sec = shdr + i;
@@ -129,6 +142,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
129 symtab_sec = shdr + i; 142 symtab_sec = shdr + i;
130 if (strcmp(secstrtab + idx, ".strtab") == 0) 143 if (strcmp(secstrtab + idx, ".strtab") == 0)
131 strtab_sec = shdr + i; 144 strtab_sec = shdr + i;
145 if (r(&shdr[i].sh_type) == SHT_SYMTAB_SHNDX)
146 symtab_shndx_start = (Elf32_Word *)(
147 (const char *)ehdr + _r(&shdr[i].sh_offset));
132 } 148 }
133 if (strtab_sec == NULL) { 149 if (strtab_sec == NULL) {
134 fprintf(stderr, "no .strtab in file: %s\n", fname); 150 fprintf(stderr, "no .strtab in file: %s\n", fname);
@@ -138,6 +154,8 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
138 fprintf(stderr, "no .symtab in file: %s\n", fname); 154 fprintf(stderr, "no .symtab in file: %s\n", fname);
139 fail_file(); 155 fail_file();
140 } 156 }
157 symtab = (const Elf_Sym *)((const char *)ehdr +
158 _r(&symtab_sec->sh_offset));
141 if (extab_sec == NULL) { 159 if (extab_sec == NULL) {
142 fprintf(stderr, "no __ex_table in file: %s\n", fname); 160 fprintf(stderr, "no __ex_table in file: %s\n", fname);
143 fail_file(); 161 fail_file();
@@ -176,7 +194,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
176 fname); 194 fname);
177 fail_file(); 195 fail_file();
178 } 196 }
179 sort_needed_sec = &shdr[r2(&sort_needed_sym->st_shndx)]; 197 sort_needed_sec = &shdr[get_secindex(r2(&sym->st_shndx),
198 sort_needed_sym - symtab,
199 symtab_shndx_start)];
180 sort_done_location = (void *)ehdr + 200 sort_done_location = (void *)ehdr +
181 _r(&sort_needed_sec->sh_offset) + 201 _r(&sort_needed_sec->sh_offset) +
182 _r(&sort_needed_sym->st_value) - 202 _r(&sort_needed_sym->st_value) -
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 8460edce1c3b..443e9e599a75 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -267,10 +267,9 @@ static int allocate_sram(struct snd_pcm_substream *substream,
267 return 0; 267 return 0;
268 268
269 ppcm->period_bytes_max = size; 269 ppcm->period_bytes_max = size;
270 iram_virt = (void *)gen_pool_alloc(sram_pool, size); 270 iram_virt = gen_pool_dma_alloc(sram_pool, size, &iram_phys);
271 if (!iram_virt) 271 if (!iram_virt)
272 goto exit1; 272 goto exit1;
273 iram_phys = gen_pool_virt_to_phys(sram_pool, (unsigned)iram_virt);
274 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL); 273 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
275 if (!iram_dma) 274 if (!iram_dma)
276 goto exit2; 275 goto exit2;
diff --git a/sound/soc/pxa/mmp-pcm.c b/sound/soc/pxa/mmp-pcm.c
index 8235e231d89c..7929e19b0ef5 100644
--- a/sound/soc/pxa/mmp-pcm.c
+++ b/sound/soc/pxa/mmp-pcm.c
@@ -201,10 +201,9 @@ static int mmp_pcm_preallocate_dma_buffer(struct snd_pcm_substream *substream,
201 if (!gpool) 201 if (!gpool)
202 return -ENOMEM; 202 return -ENOMEM;
203 203
204 buf->area = (unsigned char *)gen_pool_alloc(gpool, size); 204 buf->area = gen_pool_dma_alloc(gpool, size, &buf->addr);
205 if (!buf->area) 205 if (!buf->area)
206 return -ENOMEM; 206 return -ENOMEM;
207 buf->addr = gen_pool_virt_to_phys(gpool, (unsigned long)buf->area);
208 buf->bytes = size; 207 buf->bytes = size;
209 return 0; 208 return 0;
210} 209}
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index 71c9c2511ee7..d5e9d6d185c8 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -59,12 +59,14 @@
59#define PM_PSHIFT_BITS 6 59#define PM_PSHIFT_BITS 6
60#define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS) 60#define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS)
61#define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET) 61#define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET)
62#define PM_PSHIFT(x) (((u64) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK) 62#define __PM_PSHIFT(x) (((uint64_t) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK)
63#define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1) 63#define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1)
64#define PM_PFRAME(x) ((x) & PM_PFRAME_MASK) 64#define PM_PFRAME(x) ((x) & PM_PFRAME_MASK)
65 65
66#define __PM_SOFT_DIRTY (1LL)
66#define PM_PRESENT PM_STATUS(4LL) 67#define PM_PRESENT PM_STATUS(4LL)
67#define PM_SWAP PM_STATUS(2LL) 68#define PM_SWAP PM_STATUS(2LL)
69#define PM_SOFT_DIRTY __PM_PSHIFT(__PM_SOFT_DIRTY)
68 70
69 71
70/* 72/*
@@ -83,6 +85,7 @@
83#define KPF_OWNER_PRIVATE 37 85#define KPF_OWNER_PRIVATE 37
84#define KPF_ARCH 38 86#define KPF_ARCH 38
85#define KPF_UNCACHED 39 87#define KPF_UNCACHED 39
88#define KPF_SOFTDIRTY 40
86 89
87/* [48-] take some arbitrary free slots for expanding overloaded flags 90/* [48-] take some arbitrary free slots for expanding overloaded flags
88 * not part of kernel API 91 * not part of kernel API
@@ -132,6 +135,7 @@ static const char * const page_flag_names[] = {
132 [KPF_OWNER_PRIVATE] = "O:owner_private", 135 [KPF_OWNER_PRIVATE] = "O:owner_private",
133 [KPF_ARCH] = "h:arch", 136 [KPF_ARCH] = "h:arch",
134 [KPF_UNCACHED] = "c:uncached", 137 [KPF_UNCACHED] = "c:uncached",
138 [KPF_SOFTDIRTY] = "f:softdirty",
135 139
136 [KPF_READAHEAD] = "I:readahead", 140 [KPF_READAHEAD] = "I:readahead",
137 [KPF_SLOB_FREE] = "P:slob_free", 141 [KPF_SLOB_FREE] = "P:slob_free",
@@ -417,7 +421,7 @@ static int bit_mask_ok(uint64_t flags)
417 return 1; 421 return 1;
418} 422}
419 423
420static uint64_t expand_overloaded_flags(uint64_t flags) 424static uint64_t expand_overloaded_flags(uint64_t flags, uint64_t pme)
421{ 425{
422 /* SLOB/SLUB overload several page flags */ 426 /* SLOB/SLUB overload several page flags */
423 if (flags & BIT(SLAB)) { 427 if (flags & BIT(SLAB)) {
@@ -433,6 +437,9 @@ static uint64_t expand_overloaded_flags(uint64_t flags)
433 if ((flags & (BIT(RECLAIM) | BIT(WRITEBACK))) == BIT(RECLAIM)) 437 if ((flags & (BIT(RECLAIM) | BIT(WRITEBACK))) == BIT(RECLAIM))
434 flags ^= BIT(RECLAIM) | BIT(READAHEAD); 438 flags ^= BIT(RECLAIM) | BIT(READAHEAD);
435 439
440 if (pme & PM_SOFT_DIRTY)
441 flags |= BIT(SOFTDIRTY);
442
436 return flags; 443 return flags;
437} 444}
438 445
@@ -448,11 +455,11 @@ static uint64_t well_known_flags(uint64_t flags)
448 return flags; 455 return flags;
449} 456}
450 457
451static uint64_t kpageflags_flags(uint64_t flags) 458static uint64_t kpageflags_flags(uint64_t flags, uint64_t pme)
452{ 459{
453 flags = expand_overloaded_flags(flags); 460 if (opt_raw)
454 461 flags = expand_overloaded_flags(flags, pme);
455 if (!opt_raw) 462 else
456 flags = well_known_flags(flags); 463 flags = well_known_flags(flags);
457 464
458 return flags; 465 return flags;
@@ -545,9 +552,9 @@ static size_t hash_slot(uint64_t flags)
545} 552}
546 553
547static void add_page(unsigned long voffset, 554static void add_page(unsigned long voffset,
548 unsigned long offset, uint64_t flags) 555 unsigned long offset, uint64_t flags, uint64_t pme)
549{ 556{
550 flags = kpageflags_flags(flags); 557 flags = kpageflags_flags(flags, pme);
551 558
552 if (!bit_mask_ok(flags)) 559 if (!bit_mask_ok(flags))
553 return; 560 return;
@@ -569,7 +576,8 @@ static void add_page(unsigned long voffset,
569#define KPAGEFLAGS_BATCH (64 << 10) /* 64k pages */ 576#define KPAGEFLAGS_BATCH (64 << 10) /* 64k pages */
570static void walk_pfn(unsigned long voffset, 577static void walk_pfn(unsigned long voffset,
571 unsigned long index, 578 unsigned long index,
572 unsigned long count) 579 unsigned long count,
580 uint64_t pme)
573{ 581{
574 uint64_t buf[KPAGEFLAGS_BATCH]; 582 uint64_t buf[KPAGEFLAGS_BATCH];
575 unsigned long batch; 583 unsigned long batch;
@@ -583,7 +591,7 @@ static void walk_pfn(unsigned long voffset,
583 break; 591 break;
584 592
585 for (i = 0; i < pages; i++) 593 for (i = 0; i < pages; i++)
586 add_page(voffset + i, index + i, buf[i]); 594 add_page(voffset + i, index + i, buf[i], pme);
587 595
588 index += pages; 596 index += pages;
589 count -= pages; 597 count -= pages;
@@ -608,7 +616,7 @@ static void walk_vma(unsigned long index, unsigned long count)
608 for (i = 0; i < pages; i++) { 616 for (i = 0; i < pages; i++) {
609 pfn = pagemap_pfn(buf[i]); 617 pfn = pagemap_pfn(buf[i]);
610 if (pfn) 618 if (pfn)
611 walk_pfn(index + i, pfn, 1); 619 walk_pfn(index + i, pfn, 1, buf[i]);
612 } 620 }
613 621
614 index += pages; 622 index += pages;
@@ -659,7 +667,7 @@ static void walk_addr_ranges(void)
659 667
660 for (i = 0; i < nr_addr_ranges; i++) 668 for (i = 0; i < nr_addr_ranges; i++)
661 if (!opt_pid) 669 if (!opt_pid)
662 walk_pfn(0, opt_offset[i], opt_size[i]); 670 walk_pfn(0, opt_offset[i], opt_size[i], 0);
663 else 671 else
664 walk_task(opt_offset[i], opt_size[i]); 672 walk_task(opt_offset[i], opt_size[i]);
665 673
diff --git a/usr/Makefile b/usr/Makefile
index 029ffe6cd0d8..e767f019accf 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -6,20 +6,23 @@ klibcdirs:;
6PHONY += klibcdirs 6PHONY += klibcdirs
7 7
8 8
9# Gzip
10suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP) = .gz
11
12# Bzip2 9# Bzip2
13suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) = .bz2 10suffix_$(CONFIG_RD_BZIP2) = .bz2
14 11
15# Lzma 12# Lzma
16suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma 13suffix_$(CONFIG_RD_LZMA) = .lzma
17 14
18# XZ 15# XZ
19suffix_$(CONFIG_INITRAMFS_COMPRESSION_XZ) = .xz 16suffix_$(CONFIG_RD_XZ) = .xz
20 17
21# Lzo 18# Lzo
22suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo 19suffix_$(CONFIG_RD_LZO) = .lzo
20
21# Lz4
22suffix_$(CONFIG_RD_LZ4) = .lz4
23
24# Gzip
25suffix_$(CONFIG_RD_GZIP) = .gz
23 26
24AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/initramfs_data.cpio$(suffix_y)" 27AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/initramfs_data.cpio$(suffix_y)"
25 28
@@ -53,7 +56,10 @@ endif
53quiet_cmd_initfs = GEN $@ 56quiet_cmd_initfs = GEN $@
54 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input) 57 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
55 58
56targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.xz initramfs_data.cpio.lzo initramfs_data.cpio 59targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 \
60 initramfs_data.cpio.lzma initramfs_data.cpio.xz \
61 initramfs_data.cpio.lzo initramfs_data.cpio.lz4 \
62 initramfs_data.cpio
57# do not try to update files included in initramfs 63# do not try to update files included in initramfs
58$(deps_initramfs): ; 64$(deps_initramfs): ;
59 65
@@ -66,4 +72,3 @@ $(deps_initramfs): klibcdirs
66$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs 72$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
67 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d 73 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
68 $(call if_changed,initfs) 74 $(call if_changed,initfs)
69
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index af8c925e93eb..225ad244cf88 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -382,24 +382,15 @@ error:
382static char *cpio_replace_env(char *new_location) 382static char *cpio_replace_env(char *new_location)
383{ 383{
384 char expanded[PATH_MAX + 1]; 384 char expanded[PATH_MAX + 1];
385 char env_var[PATH_MAX + 1]; 385 char *start, *end, *var;
386 char *start; 386
387 char *end; 387 while ((start = strstr(new_location, "${")) &&
388 388 (end = strchr(start + 2, '}'))) {
389 for (start = NULL; (start = strstr(new_location, "${")); ) { 389 *start = *end = 0;
390 end = strchr(start, '}'); 390 var = getenv(start + 2);
391 if (start < end) { 391 snprintf(expanded, sizeof expanded, "%s%s%s",
392 *env_var = *expanded = '\0'; 392 new_location, var ? var : "", end + 1);
393 strncat(env_var, start + 2, end - start - 2); 393 strcpy(new_location, expanded);
394 strncat(expanded, new_location, start - new_location);
395 strncat(expanded, getenv(env_var),
396 PATH_MAX - strlen(expanded));
397 strncat(expanded, end + 1,
398 PATH_MAX - strlen(expanded));
399 strncpy(new_location, expanded, PATH_MAX);
400 new_location[PATH_MAX] = 0;
401 } else
402 break;
403 } 394 }
404 395
405 return new_location; 396 return new_location;