Merge branch 'akpm' (patches from Andrew)

Merge third patchbomb from Andrew Morton:

- various misc things

- a couple of lib/ optimisations

- provide DIV_ROUND_CLOSEST_ULL()

- checkpatch updates

- rtc tree

- befs, nilfs2, hfs, hfsplus, fatfs, adfs, affs, bfs

- ptrace fixes

- fork() fixes

- seccomp cleanups

- more mmap_sem hold time reductions from Davidlohr

* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (138 commits)
proc: show locks in /proc/pid/fdinfo/X
docs: add missing and new /proc/PID/status file entries, fix typos
drivers/rtc/rtc-at91rm9200.c: make IO endian agnostic
Documentation/spi/spidev_test.c: fix warning
drivers/rtc/rtc-s5m.c: allow usage on device type different than main MFD type
.gitignore: ignore *.tar
MAINTAINERS: add Mediatek SoC mailing list
tomoyo: reduce mmap_sem hold for mm->exe_file
powerpc/oprofile: reduce mmap_sem hold for exe_file
oprofile: reduce mmap_sem hold for mm->exe_file
mips: ip32: add platform data hooks to use DS1685 driver
lib/Kconfig: fix up HAVE_ARCH_BITREVERSE help text
x86: switch to using asm-generic for seccomp.h
sparc: switch to using asm-generic for seccomp.h
powerpc: switch to using asm-generic for seccomp.h
parisc: switch to using asm-generic for seccomp.h
mips: switch to using asm-generic for seccomp.h
microblaze: use asm-generic for seccomp.h
arm: use asm-generic for seccomp.h
seccomp: allow COMPAT sigreturn overrides
...

Changed files
+2194 -1555
Documentation
arch
alpha
include
arc
arm
include
microblaze
include
asm
mips
configs
include
asm
sgi-ip32
parisc
include
powerpc
include
asm
uapi
oprofile
sparc
include
asm
x86
drivers
firmware
fs
include
init
kernel
lib
scripts
security
tomoyo
sound
soc
codecs
+1
.gitignore
··· 24 *.order 25 *.elf 26 *.bin 27 *.gz 28 *.bz2 29 *.lzma
··· 24 *.order 25 *.elf 26 *.bin 27 + *.tar 28 *.gz 29 *.bz2 30 *.lzma
+13
Documentation/CodingStyle
··· 659 #define CONSTANT 0x4000 660 #define CONSTEXP (CONSTANT | 3) 661 662 The cpp manual deals with macros exhaustively. The gcc internals manual also 663 covers RTL which is used frequently with assembly language in the kernel. 664
··· 659 #define CONSTANT 0x4000 660 #define CONSTEXP (CONSTANT | 3) 661 662 + 5) namespace collisions when defining local variables in macros resembling 663 + functions: 664 + 665 + #define FOO(x) \ 666 + ({ \ 667 + typeof(x) ret; \ 668 + ret = calc_ret(x); \ 669 + (ret); \ 670 + )} 671 + 672 + ret is a common name for a local variable - __foo_ret is less likely 673 + to collide with an existing variable. 674 + 675 The cpp manual deals with macros exhaustively. The gcc internals manual also 676 covers RTL which is used frequently with assembly language in the kernel. 677
+2 -2
Documentation/SubmittingPatches
··· 614 615 - An empty line. 616 617 - - The body of the explanation, which will be copied to the 618 - permanent changelog to describe this patch. 619 620 - The "Signed-off-by:" lines, described above, which will 621 also go in the changelog.
··· 614 615 - An empty line. 616 617 + - The body of the explanation, line wrapped at 75 columns, which will 618 + be copied to the permanent changelog to describe this patch. 619 620 - The "Signed-off-by:" lines, described above, which will 621 also go in the changelog.
+17
Documentation/devicetree/bindings/rtc/digicolor-rtc.txt
···
··· 1 + Conexant Digicolor Real Time Clock controller 2 + 3 + This binding currently supports the CX92755 SoC. 4 + 5 + Required properties: 6 + - compatible: should be "cnxt,cx92755-rtc" 7 + - reg: physical base address of the controller and length of memory mapped 8 + region. 9 + - interrupts: rtc alarm interrupt 10 + 11 + Example: 12 + 13 + rtc@f0000c30 { 14 + compatible = "cnxt,cx92755-rtc"; 15 + reg = <0xf0000c30 0x18>; 16 + interrupts = <25>; 17 + };
+5
Documentation/devicetree/bindings/rtc/stmp3xxx-rtc.txt
··· 7 region. 8 - interrupts: rtc alarm interrupt 9 10 Example: 11 12 rtc@80056000 {
··· 7 region. 8 - interrupts: rtc alarm interrupt 9 10 + Optional properties: 11 + - stmp,crystal-freq: override crystal frequency as determined from fuse bits. 12 + Only <32000> and <32768> are possible for the hardware. Use <0> for 13 + "no crystal". 14 + 15 Example: 16 17 rtc@80056000 {
+12 -3
Documentation/filesystems/proc.txt
··· 200 explained in Table 1-4. 201 202 (for SMP CONFIG users) 203 - For making accounting scalable, RSS related information are handled in 204 - asynchronous manner and the vaule may not be very precise. To see a precise 205 snapshot of a moment, you can see /proc/<pid>/smaps file and scan page table. 206 It's slow but very precise. 207 208 - Table 1-2: Contents of the status files (as of 2.6.30-rc7) 209 .............................................................................. 210 Field Content 211 Name filename of the executable ··· 213 in an uninterruptible wait, Z is zombie, 214 T is traced or stopped) 215 Tgid thread group ID 216 Pid process id 217 PPid process id of the parent process 218 TracerPid PID of process tracing this process (0 if not) ··· 221 Gid Real, effective, saved set, and file system GIDs 222 FDSize number of file descriptor slots currently allocated 223 Groups supplementary group list 224 VmPeak peak virtual memory size 225 VmSize total program size 226 VmLck locked memory size ··· 1708 pos: 0 1709 flags: 0100002 1710 mnt_id: 19 1711 1712 The files such as eventfd, fsnotify, signalfd, epoll among the regular pos/flags 1713 pair provide additional information particular to the objects they represent.
··· 200 explained in Table 1-4. 201 202 (for SMP CONFIG users) 203 + For making accounting scalable, RSS related information are handled in an 204 + asynchronous manner and the value may not be very precise. To see a precise 205 snapshot of a moment, you can see /proc/<pid>/smaps file and scan page table. 206 It's slow but very precise. 207 208 + Table 1-2: Contents of the status files (as of 3.20.0) 209 .............................................................................. 210 Field Content 211 Name filename of the executable ··· 213 in an uninterruptible wait, Z is zombie, 214 T is traced or stopped) 215 Tgid thread group ID 216 + Ngid NUMA group ID (0 if none) 217 Pid process id 218 PPid process id of the parent process 219 TracerPid PID of process tracing this process (0 if not) ··· 220 Gid Real, effective, saved set, and file system GIDs 221 FDSize number of file descriptor slots currently allocated 222 Groups supplementary group list 223 + NStgid descendant namespace thread group ID hierarchy 224 + NSpid descendant namespace process ID hierarchy 225 + NSpgid descendant namespace process group ID hierarchy 226 + NSsid descendant namespace session ID hierarchy 227 VmPeak peak virtual memory size 228 VmSize total program size 229 VmLck locked memory size ··· 1703 pos: 0 1704 flags: 0100002 1705 mnt_id: 19 1706 + 1707 + All locks associated with a file descriptor are shown in its fdinfo too. 1708 + 1709 + lock: 1: FLOCK ADVISORY WRITE 359 00:13:11691 0 EOF 1710 1711 The files such as eventfd, fsnotify, signalfd, epoll among the regular pos/flags 1712 pair provide additional information particular to the objects they represent.
+2 -2
Documentation/spi/spidev_test.c
··· 80 * Unescape - process hexadecimal escape character 81 * converts shell input "\x23" -> 0x23 82 */ 83 - int unespcape(char *_dst, char *_src, size_t len) 84 { 85 int ret = 0; 86 char *src = _src; ··· 304 size = strlen(input_tx+1); 305 tx = malloc(size); 306 rx = malloc(size); 307 - size = unespcape((char *)tx, input_tx, size); 308 transfer(fd, tx, rx, size); 309 free(rx); 310 free(tx);
··· 80 * Unescape - process hexadecimal escape character 81 * converts shell input "\x23" -> 0x23 82 */ 83 + static int unescape(char *_dst, char *_src, size_t len) 84 { 85 int ret = 0; 86 char *src = _src; ··· 304 size = strlen(input_tx+1); 305 tx = malloc(size); 306 rx = malloc(size); 307 + size = unescape((char *)tx, input_tx, size); 308 transfer(fd, tx, rx, size); 309 free(rx); 310 free(tx);
+21
Documentation/sysctl/kernel.txt
··· 872 873 ============================================================== 874 875 unknown_nmi_panic: 876 877 The value in this file affects behavior of handling NMI. When the
··· 872 873 ============================================================== 874 875 + threads-max 876 + 877 + This value controls the maximum number of threads that can be created 878 + using fork(). 879 + 880 + During initialization the kernel sets this value such that even if the 881 + maximum number of threads is created, the thread structures occupy only 882 + a part (1/8th) of the available RAM pages. 883 + 884 + The minimum value that can be written to threads-max is 20. 885 + The maximum value that can be written to threads-max is given by the 886 + constant FUTEX_TID_MASK (0x3fffffff). 887 + If a value outside of this range is written to threads-max an error 888 + EINVAL occurs. 889 + 890 + The value written is checked against the available RAM pages. If the 891 + thread structures would occupy too much (more than 1/8th) of the 892 + available RAM pages threads-max is reduced accordingly. 893 + 894 + ============================================================== 895 + 896 unknown_nmi_panic: 897 898 The value in this file affects behavior of handling NMI. When the
+2
MAINTAINERS
··· 1215 ARM/Mediatek SoC support 1216 M: Matthias Brugger <matthias.bgg@gmail.com> 1217 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1218 S: Maintained 1219 F: arch/arm/boot/dts/mt6* 1220 F: arch/arm/boot/dts/mt8* ··· 8184 8185 REAL TIME CLOCK (RTC) SUBSYSTEM 8186 M: Alessandro Zummo <a.zummo@towertech.it> 8187 L: rtc-linux@googlegroups.com 8188 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 8189 S: Maintained
··· 1215 ARM/Mediatek SoC support 1216 M: Matthias Brugger <matthias.bgg@gmail.com> 1217 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1218 + L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 1219 S: Maintained 1220 F: arch/arm/boot/dts/mt6* 1221 F: arch/arm/boot/dts/mt8* ··· 8183 8184 REAL TIME CLOCK (RTC) SUBSYSTEM 8185 M: Alessandro Zummo <a.zummo@towertech.it> 8186 + M: Alexandre Belloni <alexandre.belloni@free-electrons.com> 8187 L: rtc-linux@googlegroups.com 8188 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 8189 S: Maintained
+1
arch/alpha/include/asm/processor.h
··· 44 extern unsigned long thread_saved_pc(struct task_struct *); 45 46 /* Do necessary setup to start up a newly executed thread. */ 47 extern void start_thread(struct pt_regs *, unsigned long, unsigned long); 48 49 /* Free all resources held by a thread. */
··· 44 extern unsigned long thread_saved_pc(struct task_struct *); 45 46 /* Do necessary setup to start up a newly executed thread. */ 47 + struct pt_regs; 48 extern void start_thread(struct pt_regs *, unsigned long, unsigned long); 49 50 /* Free all resources held by a thread. */
+1 -2
arch/arc/kernel/troubleshoot.c
··· 52 print_reg_file(&(cregs->r13), 13); 53 } 54 55 - void print_task_path_n_nm(struct task_struct *tsk, char *buf) 56 { 57 struct path path; 58 char *path_nm = NULL; ··· 77 done: 78 pr_info("Path: %s\n", path_nm); 79 } 80 - EXPORT_SYMBOL(print_task_path_n_nm); 81 82 static void show_faulting_vma(unsigned long address, char *buf) 83 {
··· 52 print_reg_file(&(cregs->r13), 13); 53 } 54 55 + static void print_task_path_n_nm(struct task_struct *tsk, char *buf) 56 { 57 struct path path; 58 char *path_nm = NULL; ··· 77 done: 78 pr_info("Path: %s\n", path_nm); 79 } 80 81 static void show_faulting_vma(unsigned long address, char *buf) 82 {
+1
arch/arm/include/asm/Kbuild
··· 21 generic-y += resource.h 22 generic-y += rwsem.h 23 generic-y += scatterlist.h 24 generic-y += sections.h 25 generic-y += segment.h 26 generic-y += sembuf.h
··· 21 generic-y += resource.h 22 generic-y += rwsem.h 23 generic-y += scatterlist.h 24 + generic-y += seccomp.h 25 generic-y += sections.h 26 generic-y += segment.h 27 generic-y += sembuf.h
-11
arch/arm/include/asm/seccomp.h
··· 1 - #ifndef _ASM_ARM_SECCOMP_H 2 - #define _ASM_ARM_SECCOMP_H 3 - 4 - #include <linux/unistd.h> 5 - 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 10 - 11 - #endif /* _ASM_ARM_SECCOMP_H */
···
+1 -7
arch/microblaze/include/asm/seccomp.h
··· 3 4 #include <linux/unistd.h> 5 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 #define __NR_seccomp_sigreturn __NR_sigreturn 10 11 - #define __NR_seccomp_read_32 __NR_read 12 - #define __NR_seccomp_write_32 __NR_write 13 - #define __NR_seccomp_exit_32 __NR_exit 14 - #define __NR_seccomp_sigreturn_32 __NR_sigreturn 15 16 #endif /* _ASM_MICROBLAZE_SECCOMP_H */
··· 3 4 #include <linux/unistd.h> 5 6 #define __NR_seccomp_sigreturn __NR_sigreturn 7 8 + #include <asm-generic/seccomp.h> 9 10 #endif /* _ASM_MICROBLAZE_SECCOMP_H */
+2 -1
arch/mips/configs/ip32_defconfig
··· 105 # CONFIG_RTC_HCTOSYS is not set 106 # CONFIG_RTC_INTF_SYSFS is not set 107 # CONFIG_RTC_INTF_PROC is not set 108 - CONFIG_RTC_DRV_CMOS=y 109 CONFIG_EXT2_FS=y 110 CONFIG_EXT2_FS_XATTR=y 111 CONFIG_EXT2_FS_POSIX_ACL=y
··· 105 # CONFIG_RTC_HCTOSYS is not set 106 # CONFIG_RTC_INTF_SYSFS is not set 107 # CONFIG_RTC_INTF_PROC is not set 108 + CONFIG_RTC_DRV_DS1685_FAMILY=y 109 + CONFIG_RTC_DRV_DS1685=y 110 CONFIG_EXT2_FS=y 111 CONFIG_EXT2_FS_XATTR=y 112 CONFIG_EXT2_FS_POSIX_ACL=y
-36
arch/mips/include/asm/mach-ip32/mc146818rtc.h
··· 1 - /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * Copyright (C) 1998, 2001, 03 by Ralf Baechle 7 - * Copyright (C) 2000 Harald Koerfgen 8 - * 9 - * RTC routines for IP32 style attached Dallas chip. 10 - */ 11 - #ifndef __ASM_MACH_IP32_MC146818RTC_H 12 - #define __ASM_MACH_IP32_MC146818RTC_H 13 - 14 - #include <asm/ip32/mace.h> 15 - 16 - #define RTC_PORT(x) (0x70 + (x)) 17 - 18 - static unsigned char CMOS_READ(unsigned long addr) 19 - { 20 - return mace->isa.rtc[addr << 8]; 21 - } 22 - 23 - static inline void CMOS_WRITE(unsigned char data, unsigned long addr) 24 - { 25 - mace->isa.rtc[addr << 8] = data; 26 - } 27 - 28 - /* 29 - * FIXME: Do it right. For now just assume that no one lives in 20th century 30 - * and no O2 user in 22th century ;-) 31 - */ 32 - #define mc146818_decode_year(year) ((year) + 2000) 33 - 34 - #define RTC_ALWAYS_BCD 0 35 - 36 - #endif /* __ASM_MACH_IP32_MC146818RTC_H */
···
+2 -5
arch/mips/include/asm/seccomp.h
··· 2 3 #include <linux/unistd.h> 4 5 - #define __NR_seccomp_read __NR_read 6 - #define __NR_seccomp_write __NR_write 7 - #define __NR_seccomp_exit __NR_exit 8 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 9 - 10 /* 11 * Kludge alert: 12 * ··· 23 #define __NR_seccomp_sigreturn_32 6211 /* rt_sigreturn */ 24 25 #endif /* CONFIG_MIPS32_O32 */ 26 27 #endif /* __ASM_SECCOMP_H */
··· 2 3 #include <linux/unistd.h> 4 5 /* 6 * Kludge alert: 7 * ··· 28 #define __NR_seccomp_sigreturn_32 6211 /* rt_sigreturn */ 29 30 #endif /* CONFIG_MIPS32_O32 */ 31 + 32 + #include <asm-generic/seccomp.h> 33 34 #endif /* __ASM_SECCOMP_H */
+39 -7
arch/mips/sgi-ip32/ip32-platform.c
··· 9 #include <linux/init.h> 10 #include <linux/platform_device.h> 11 #include <linux/serial_8250.h> 12 13 #include <asm/ip32/mace.h> 14 #include <asm/ip32/ip32_ints.h> 15 16 #define MACEISA_SERIAL1_OFFS offsetof(struct sgi_mace, isa.serial1) 17 #define MACEISA_SERIAL2_OFFS offsetof(struct sgi_mace, isa.serial2) ··· 93 94 device_initcall(sgio2btns_devinit); 95 96 - static struct resource sgio2_cmos_rsrc[] = { 97 { 98 - .start = 0x70, 99 - .end = 0x71, 100 - .flags = IORESOURCE_IO 101 } 102 }; 103 104 - static __init int sgio2_cmos_devinit(void) 105 { 106 - return IS_ERR(platform_device_register_simple("rtc_cmos", -1, 107 - sgio2_cmos_rsrc, 1)); 108 } 109 110 device_initcall(sgio2_cmos_devinit);
··· 9 #include <linux/init.h> 10 #include <linux/platform_device.h> 11 #include <linux/serial_8250.h> 12 + #include <linux/rtc/ds1685.h> 13 14 #include <asm/ip32/mace.h> 15 #include <asm/ip32/ip32_ints.h> 16 + 17 + extern void ip32_prepare_poweroff(void); 18 19 #define MACEISA_SERIAL1_OFFS offsetof(struct sgi_mace, isa.serial1) 20 #define MACEISA_SERIAL2_OFFS offsetof(struct sgi_mace, isa.serial2) ··· 90 91 device_initcall(sgio2btns_devinit); 92 93 + #define MACE_RTC_RES_START (MACE_BASE + offsetof(struct sgi_mace, isa.rtc)) 94 + #define MACE_RTC_RES_END (MACE_RTC_RES_START + 32767) 95 + 96 + static struct resource ip32_rtc_resources[] = { 97 { 98 + .start = MACEISA_RTC_IRQ, 99 + .end = MACEISA_RTC_IRQ, 100 + .flags = IORESOURCE_IRQ 101 + }, { 102 + .start = MACE_RTC_RES_START, 103 + .end = MACE_RTC_RES_END, 104 + .flags = IORESOURCE_MEM, 105 } 106 }; 107 108 + /* RTC registers on IP32 are each padded by 256 bytes (0x100). */ 109 + static struct ds1685_rtc_platform_data 110 + ip32_rtc_platform_data[] = { 111 + { 112 + .regstep = 0x100, 113 + .bcd_mode = true, 114 + .no_irq = false, 115 + .uie_unsupported = false, 116 + .alloc_io_resources = true, 117 + .plat_prepare_poweroff = ip32_prepare_poweroff, 118 + }, 119 + }; 120 + 121 + struct platform_device ip32_rtc_device = { 122 + .name = "rtc-ds1685", 123 + .id = -1, 124 + .dev = { 125 + .platform_data = ip32_rtc_platform_data, 126 + }, 127 + .num_resources = ARRAY_SIZE(ip32_rtc_resources), 128 + .resource = ip32_rtc_resources, 129 + }; 130 + 131 + +static int __init sgio2_rtc_devinit(void) 132 { 133 + return platform_device_register(&ip32_rtc_device); 134 } 135 136 device_initcall(sgio2_cmos_devinit);
+43 -96
arch/mips/sgi-ip32/ip32-reset.c
··· 11 #include <linux/compiler.h> 12 #include <linux/init.h> 13 #include <linux/kernel.h> 14 #include <linux/sched.h> 15 #include <linux/notifier.h> 16 #include <linux/delay.h> 17 - #include <linux/ds17287rtc.h> 18 #include <linux/interrupt.h> 19 #include <linux/pm.h> 20 ··· 34 #define POWERDOWN_FREQ (HZ / 4) 35 #define PANIC_FREQ (HZ / 8) 36 37 - static struct timer_list power_timer, blink_timer, debounce_timer; 38 - static int has_panicked, shuting_down; 39 40 - static void ip32_machine_restart(char *command) __noreturn; 41 - static void ip32_machine_halt(void) __noreturn; 42 - static void ip32_machine_power_off(void) __noreturn; 43 44 static void ip32_machine_restart(char *cmd) 45 { 46 crime->control = CRIME_CONTROL_HARD_RESET; 47 - while (1); 48 - } 49 - 50 - static inline void ip32_machine_halt(void) 51 - { 52 - ip32_machine_power_off(); 53 - } 54 - 55 - static void ip32_machine_power_off(void) 56 - { 57 - unsigned char reg_a, xctrl_a, xctrl_b; 58 - 59 - disable_irq(MACEISA_RTC_IRQ); 60 - reg_a = CMOS_READ(RTC_REG_A); 61 - 62 - /* setup for kickstart & wake-up (DS12287 Ref. Man. p. 19) */ 63 - reg_a &= ~DS_REGA_DV2; 64 - reg_a |= DS_REGA_DV1; 65 - 66 - CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A); 67 - wbflush(); 68 - xctrl_b = CMOS_READ(DS_B1_XCTRL4B) 69 - | DS_XCTRL4B_ABE | DS_XCTRL4B_KFE; 70 - CMOS_WRITE(xctrl_b, DS_B1_XCTRL4B); 71 - xctrl_a = CMOS_READ(DS_B1_XCTRL4A) & ~DS_XCTRL4A_IFS; 72 - CMOS_WRITE(xctrl_a, DS_B1_XCTRL4A); 73 - wbflush(); 74 - /* adios amigos... */ 75 - CMOS_WRITE(xctrl_a | DS_XCTRL4A_PAB, DS_B1_XCTRL4A); 76 - CMOS_WRITE(reg_a, RTC_REG_A); 77 - wbflush(); 78 - while (1); 79 - } 80 - 81 - static void power_timeout(unsigned long data) 82 - { 83 - ip32_machine_power_off(); 84 } 85 86 static void blink_timeout(unsigned long data) ··· 77 mod_timer(&blink_timer, jiffies + data); 78 } 79 80 - static void debounce(unsigned long data) 81 { 82 - unsigned char reg_a, reg_c, xctrl_a; 83 - 84 - reg_c = CMOS_READ(RTC_INTR_FLAGS); 85 - reg_a = CMOS_READ(RTC_REG_A); 86 - CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A); 87 - wbflush(); 88 - xctrl_a = CMOS_READ(DS_B1_XCTRL4A); 89 - if ((xctrl_a & DS_XCTRL4A_IFS) || (reg_c & RTC_IRQF )) { 90 - /* Interrupt still being sent. */ 91 - debounce_timer.expires = jiffies + 50; 92 - add_timer(&debounce_timer); 93 - 94 - /* clear interrupt source */ 95 - CMOS_WRITE(xctrl_a & ~DS_XCTRL4A_IFS, DS_B1_XCTRL4A); 96 - CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A); 97 - return; 98 - } 99 - CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A); 100 - 101 - if (has_panicked) 102 - ip32_machine_restart(NULL); 103 - 104 - enable_irq(MACEISA_RTC_IRQ); 105 } 106 107 - static inline void ip32_power_button(void) 108 { 109 if (has_panicked) 110 return; 111 112 - if (shuting_down || kill_cad_pid(SIGINT, 1)) { 113 /* No init process or button pressed twice. */ 114 - ip32_machine_power_off(); 115 } 116 117 - shuting_down = 1; 118 blink_timer.data = POWERDOWN_FREQ; 119 blink_timeout(POWERDOWN_FREQ); 120 ··· 105 power_timer.function = power_timeout; 106 power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ; 107 add_timer(&power_timer); 108 - } 109 - 110 - static irqreturn_t ip32_rtc_int(int irq, void *dev_id) 111 - { 112 - unsigned char reg_c; 113 - 114 - reg_c = CMOS_READ(RTC_INTR_FLAGS); 115 - if (!(reg_c & RTC_IRQF)) { 116 - printk(KERN_WARNING 117 - "%s: RTC IRQ without RTC_IRQF\n", __func__); 118 - } 119 - /* Wait until interrupt goes away */ 120 - disable_irq_nosync(MACEISA_RTC_IRQ); 121 - init_timer(&debounce_timer); 122 - debounce_timer.function = debounce; 123 - debounce_timer.expires = jiffies + 50; 124 - add_timer(&debounce_timer); 125 - 126 - printk(KERN_DEBUG "Power button pressed\n"); 127 - ip32_power_button(); 128 - return IRQ_HANDLED; 129 } 130 131 static int panic_event(struct notifier_block *this, unsigned long event, ··· 140 141 _machine_restart = ip32_machine_restart; 142 _machine_halt = ip32_machine_halt; 143 - pm_power_off = ip32_machine_power_off; 144 145 init_timer(&blink_timer); 146 blink_timer.function = blink_timeout; 147 atomic_notifier_chain_register(&panic_notifier_list, &panic_block); 148 - 149 - if (request_irq(MACEISA_RTC_IRQ, ip32_rtc_int, 0, "rtc", NULL)) 150 - panic("Can't allocate MACEISA RTC IRQ"); 151 152 return 0; 153 }
··· 11 #include <linux/compiler.h> 12 #include <linux/init.h> 13 #include <linux/kernel.h> 14 + #include <linux/module.h> 15 #include <linux/sched.h> 16 #include <linux/notifier.h> 17 #include <linux/delay.h> 18 + #include <linux/rtc/ds1685.h> 19 #include <linux/interrupt.h> 20 #include <linux/pm.h> 21 ··· 33 #define POWERDOWN_FREQ (HZ / 4) 34 #define PANIC_FREQ (HZ / 8) 35 36 + extern struct platform_device ip32_rtc_device; 37 38 + static struct timer_list power_timer, blink_timer; 39 + static int has_panicked, shutting_down; 40 41 + static __noreturn void ip32_poweroff(void *data) 42 + { 43 + void (*poweroff_func)(struct platform_device *) = 44 + symbol_get(ds1685_rtc_poweroff); 45 + 46 + #ifdef CONFIG_MODULES 47 + /* If the first __symbol_get failed, our module wasn't loaded. */ 48 + if (!poweroff_func) { 49 + request_module("rtc-ds1685"); 50 + poweroff_func = symbol_get(ds1685_rtc_poweroff); 51 + } 52 + #endif 53 + 54 + if (!poweroff_func) 55 + pr_emerg("RTC not available for power-off. Spinning forever ...\n"); 56 + else { 57 + (*poweroff_func)((struct platform_device *)data); 58 + symbol_put(ds1685_rtc_poweroff); 59 + } 60 + 61 + unreachable(); 62 + } 63 + 64 + static void ip32_machine_restart(char *cmd) __noreturn; 65 static void ip32_machine_restart(char *cmd) 66 { 67 + msleep(20); 68 crime->control = CRIME_CONTROL_HARD_RESET; 69 + unreachable(); 70 } 71 72 static void blink_timeout(unsigned long data) ··· 89 mod_timer(&blink_timer, jiffies + data); 90 } 91 92 + static void ip32_machine_halt(void) 93 { 94 + ip32_poweroff(&ip32_rtc_device); 95 } 96 97 + static void power_timeout(unsigned long data) 98 + { 99 + ip32_poweroff(&ip32_rtc_device); 100 + } 101 + 102 + void ip32_prepare_poweroff(void) 103 { 104 if (has_panicked) 105 return; 106 107 + if (shutting_down || kill_cad_pid(SIGINT, 1)) { 108 /* No init process or button pressed twice. */ 109 + ip32_poweroff(&ip32_rtc_device); 110 } 111 112 + shutting_down = 1; 113 blink_timer.data = POWERDOWN_FREQ; 114 blink_timeout(POWERDOWN_FREQ); 115 ··· 134 power_timer.function = power_timeout; 135 power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ; 136 add_timer(&power_timer); 137 } 138 139 static int panic_event(struct notifier_block *this, unsigned long event, ··· 190 191 _machine_restart = ip32_machine_restart; 192 _machine_halt = ip32_machine_halt; 193 + pm_power_off = ip32_machine_halt; 194 195 init_timer(&blink_timer); 196 blink_timer.function = blink_timeout; 197 atomic_notifier_chain_register(&panic_notifier_list, &panic_block); 198 199 return 0; 200 }
+1
arch/parisc/include/asm/Kbuild
··· 20 generic-y += percpu.h 21 generic-y += poll.h 22 generic-y += preempt.h 23 generic-y += segment.h 24 generic-y += topology.h 25 generic-y += trace_clock.h
··· 20 generic-y += percpu.h 21 generic-y += poll.h 22 generic-y += preempt.h 23 + generic-y += seccomp.h 24 generic-y += segment.h 25 generic-y += topology.h 26 generic-y += trace_clock.h
-16
arch/parisc/include/asm/seccomp.h
··· 1 - #ifndef _ASM_PARISC_SECCOMP_H 2 - #define _ASM_PARISC_SECCOMP_H 3 - 4 - #include <linux/unistd.h> 5 - 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 10 - 11 - #define __NR_seccomp_read_32 __NR_read 12 - #define __NR_seccomp_write_32 __NR_write 13 - #define __NR_seccomp_exit_32 __NR_exit 14 - #define __NR_seccomp_sigreturn_32 __NR_rt_sigreturn 15 - 16 - #endif /* _ASM_PARISC_SECCOMP_H */
···
+10
arch/powerpc/include/asm/seccomp.h
···
··· 1 + #ifndef _ASM_POWERPC_SECCOMP_H 2 + #define _ASM_POWERPC_SECCOMP_H 3 + 4 + #include <linux/unistd.h> 5 + 6 + #define __NR_seccomp_sigreturn_32 __NR_sigreturn 7 + 8 + #include <asm-generic/seccomp.h> 9 + 10 + #endif /* _ASM_POWERPC_SECCOMP_H */
-1
arch/powerpc/include/uapi/asm/Kbuild
··· 25 header-y += ps3fb.h 26 header-y += ptrace.h 27 header-y += resource.h 28 - header-y += seccomp.h 29 header-y += sembuf.h 30 header-y += setup.h 31 header-y += shmbuf.h
··· 25 header-y += ps3fb.h 26 header-y += ptrace.h 27 header-y += resource.h 28 header-y += sembuf.h 29 header-y += setup.h 30 header-y += shmbuf.h
-16
arch/powerpc/include/uapi/asm/seccomp.h
··· 1 - #ifndef _ASM_POWERPC_SECCOMP_H 2 - #define _ASM_POWERPC_SECCOMP_H 3 - 4 - #include <linux/unistd.h> 5 - 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 10 - 11 - #define __NR_seccomp_read_32 __NR_read 12 - #define __NR_seccomp_write_32 __NR_write 13 - #define __NR_seccomp_exit_32 __NR_exit 14 - #define __NR_seccomp_sigreturn_32 __NR_sigreturn 15 - 16 - #endif /* _ASM_POWERPC_SECCOMP_H */
···
+8 -5
arch/powerpc/oprofile/cell/spu_task_sync.c
··· 22 #include <linux/kref.h> 23 #include <linux/mm.h> 24 #include <linux/fs.h> 25 #include <linux/module.h> 26 #include <linux/notifier.h> 27 #include <linux/numa.h> ··· 323 unsigned long app_cookie = 0; 324 unsigned int my_offset = 0; 325 struct vm_area_struct *vma; 326 struct mm_struct *mm = spu->mm; 327 328 if (!mm) 329 goto out; 330 331 - down_read(&mm->mmap_sem); 332 - 333 - if (mm->exe_file) { 334 - app_cookie = fast_get_dcookie(&mm->exe_file->f_path); 335 - pr_debug("got dcookie for %pD\n", mm->exe_file); 336 } 337 338 for (vma = mm->mmap; vma; vma = vma->vm_next) { 339 if (vma->vm_start > spu_ref || vma->vm_end <= spu_ref) 340 continue;
··· 22 #include <linux/kref.h> 23 #include <linux/mm.h> 24 #include <linux/fs.h> 25 + #include <linux/file.h> 26 #include <linux/module.h> 27 #include <linux/notifier.h> 28 #include <linux/numa.h> ··· 322 unsigned long app_cookie = 0; 323 unsigned int my_offset = 0; 324 struct vm_area_struct *vma; 325 + struct file *exe_file; 326 struct mm_struct *mm = spu->mm; 327 328 if (!mm) 329 goto out; 330 331 + exe_file = get_mm_exe_file(mm); 332 + if (exe_file) { 333 + app_cookie = fast_get_dcookie(&exe_file->f_path); 334 + pr_debug("got dcookie for %pD\n", exe_file); 335 + fput(exe_file); 336 } 337 338 + down_read(&mm->mmap_sem); 339 for (vma = mm->mmap; vma; vma = vma->vm_next) { 340 if (vma->vm_start > spu_ref || vma->vm_end <= spu_ref) 341 continue;
+3 -8
arch/sparc/include/asm/seccomp.h
··· 1 #ifndef _ASM_SECCOMP_H 2 3 #include <linux/unistd.h> 4 5 - #define __NR_seccomp_read __NR_read 6 - #define __NR_seccomp_write __NR_write 7 - #define __NR_seccomp_exit __NR_exit 8 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 9 - 10 - #define __NR_seccomp_read_32 __NR_read 11 - #define __NR_seccomp_write_32 __NR_write 12 - #define __NR_seccomp_exit_32 __NR_exit 13 #define __NR_seccomp_sigreturn_32 __NR_sigreturn 14 15 #endif /* _ASM_SECCOMP_H */
··· 1 #ifndef _ASM_SECCOMP_H 2 + #define _ASM_SECCOMP_H 3 4 #include <linux/unistd.h> 5 6 #define __NR_seccomp_sigreturn_32 __NR_sigreturn 7 + 8 + #include <asm-generic/seccomp.h> 9 10 #endif /* _ASM_SECCOMP_H */
+18 -3
arch/x86/include/asm/seccomp.h
··· 1 #ifdef CONFIG_X86_32 2 - # include <asm/seccomp_32.h> 3 - #else 4 - # include <asm/seccomp_64.h> 5 #endif
··· 1 + #ifndef _ASM_X86_SECCOMP_H 2 + #define _ASM_X86_SECCOMP_H 3 + 4 + #include <asm/unistd.h> 5 + 6 #ifdef CONFIG_X86_32 7 + #define __NR_seccomp_sigreturn __NR_sigreturn 8 #endif 9 + 10 + #ifdef CONFIG_COMPAT 11 + #include <asm/ia32_unistd.h> 12 + #define __NR_seccomp_read_32 __NR_ia32_read 13 + #define __NR_seccomp_write_32 __NR_ia32_write 14 + #define __NR_seccomp_exit_32 __NR_ia32_exit 15 + #define __NR_seccomp_sigreturn_32 __NR_ia32_sigreturn 16 + #endif 17 + 18 + #include <asm-generic/seccomp.h> 19 + 20 + #endif /* _ASM_X86_SECCOMP_H */
-11
arch/x86/include/asm/seccomp_32.h
··· 1 - #ifndef _ASM_X86_SECCOMP_32_H 2 - #define _ASM_X86_SECCOMP_32_H 3 - 4 - #include <linux/unistd.h> 5 - 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 - #define __NR_seccomp_sigreturn __NR_sigreturn 10 - 11 - #endif /* _ASM_X86_SECCOMP_32_H */
···
-17
arch/x86/include/asm/seccomp_64.h
··· 1 - #ifndef _ASM_X86_SECCOMP_64_H 2 - #define _ASM_X86_SECCOMP_64_H 3 - 4 - #include <linux/unistd.h> 5 - #include <asm/ia32_unistd.h> 6 - 7 - #define __NR_seccomp_read __NR_read 8 - #define __NR_seccomp_write __NR_write 9 - #define __NR_seccomp_exit __NR_exit 10 - #define __NR_seccomp_sigreturn __NR_rt_sigreturn 11 - 12 - #define __NR_seccomp_read_32 __NR_ia32_read 13 - #define __NR_seccomp_write_32 __NR_ia32_write 14 - #define __NR_seccomp_exit_32 __NR_ia32_exit 15 - #define __NR_seccomp_sigreturn_32 __NR_ia32_sigreturn 16 - 17 - #endif /* _ASM_X86_SECCOMP_64_H */
···
+7 -21
drivers/clk/bcm/clk-kona.c
··· 15 #include "clk-kona.h" 16 17 #include <linux/delay.h> 18 19 /* 20 * "Policies" affect the frequencies of bus clocks provided by a ··· 52 53 /* Divider and scaling helpers */ 54 55 - /* 56 - * Implement DIV_ROUND_CLOSEST() for 64-bit dividend and both values 57 - * unsigned. Note that unlike do_div(), the remainder is discarded 58 - * and the return value is the quotient (not the remainder). 59 - */ 60 - u64 do_div_round_closest(u64 dividend, unsigned long divisor) 61 - { 62 - u64 result; 63 - 64 - result = dividend + ((u64)divisor >> 1); 65 - (void)do_div(result, divisor); 66 - 67 - return result; 68 - } 69 - 70 /* Convert a divider into the scaled divisor value it represents. */ 71 static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) 72 { ··· 73 combined = (u64)div_value * BILLION + billionths; 74 combined <<= div->u.s.frac_width; 75 76 - return do_div_round_closest(combined, BILLION); 77 } 78 79 /* The scaled minimum divisor representable by a divider */ ··· 717 scaled_rate = scale_rate(pre_div, parent_rate); 718 scaled_rate = scale_rate(div, scaled_rate); 719 scaled_div = divider_read_scaled(ccu, pre_div); 720 - scaled_parent_rate = do_div_round_closest(scaled_rate, 721 scaled_div); 722 } else { 723 scaled_parent_rate = scale_rate(div, parent_rate); ··· 729 * rate. 730 */ 731 scaled_div = divider_read_scaled(ccu, div); 732 - result = do_div_round_closest(scaled_parent_rate, scaled_div); 733 734 return (unsigned long)result; 735 } ··· 776 scaled_rate = scale_rate(pre_div, parent_rate); 777 scaled_rate = scale_rate(div, scaled_rate); 778 scaled_pre_div = divider_read_scaled(ccu, pre_div); 779 - scaled_parent_rate = do_div_round_closest(scaled_rate, 780 scaled_pre_div); 781 } else { 782 scaled_parent_rate = scale_rate(div, parent_rate); ··· 788 * the best we can do. 789 */ 790 if (!divider_is_fixed(div)) { 791 - best_scaled_div = do_div_round_closest(scaled_parent_rate, 792 rate); 793 min_scaled_div = scaled_div_min(div); 794 max_scaled_div = scaled_div_max(div); ··· 801 } 802 803 /* OK, figure out the resulting rate */ 804 - result = do_div_round_closest(scaled_parent_rate, best_scaled_div); 805 806 if (scaled_div) 807 *scaled_div = best_scaled_div;
··· 15 #include "clk-kona.h" 16 17 #include <linux/delay.h> 18 + #include <linux/kernel.h> 19 20 /* 21 * "Policies" affect the frequencies of bus clocks provided by a ··· 51 52 /* Divider and scaling helpers */ 53 54 /* Convert a divider into the scaled divisor value it represents. */ 55 static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) 56 { ··· 87 combined = (u64)div_value * BILLION + billionths; 88 combined <<= div->u.s.frac_width; 89 90 + return DIV_ROUND_CLOSEST_ULL(combined, BILLION); 91 } 92 93 /* The scaled minimum divisor representable by a divider */ ··· 731 scaled_rate = scale_rate(pre_div, parent_rate); 732 scaled_rate = scale_rate(div, scaled_rate); 733 scaled_div = divider_read_scaled(ccu, pre_div); 734 + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, 735 scaled_div); 736 } else { 737 scaled_parent_rate = scale_rate(div, parent_rate); ··· 743 * rate. 744 */ 745 scaled_div = divider_read_scaled(ccu, div); 746 + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div); 747 748 return (unsigned long)result; 749 } ··· 790 scaled_rate = scale_rate(pre_div, parent_rate); 791 scaled_rate = scale_rate(div, scaled_rate); 792 scaled_pre_div = divider_read_scaled(ccu, pre_div); 793 + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, 794 scaled_pre_div); 795 } else { 796 scaled_parent_rate = scale_rate(div, parent_rate); ··· 802 * the best we can do. 803 */ 804 if (!divider_is_fixed(div)) { 805 + best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, 806 rate); 807 min_scaled_div = scaled_div_min(div); 808 max_scaled_div = scaled_div_max(div); ··· 815 } 816 817 /* OK, figure out the resulting rate */ 818 + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div); 819 820 if (scaled_div) 821 *scaled_div = best_scaled_div;
-1
drivers/clk/bcm/clk-kona.h
··· 503 504 /* Externally visible functions */ 505 506 - extern u64 do_div_round_closest(u64 dividend, unsigned long divisor); 507 extern u64 scaled_div_max(struct bcm_clk_div *div); 508 extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, 509 u32 billionths);
··· 503 504 /* Externally visible functions */ 505 506 extern u64 scaled_div_max(struct bcm_clk_div *div); 507 extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, 508 u32 billionths);
+1 -7
drivers/cpuidle/governors/menu.c
··· 190 191 static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); 192 193 - /* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */ 194 - static u64 div_round64(u64 dividend, u32 divisor) 195 - { 196 - return div_u64(dividend + (divisor / 2), divisor); 197 - } 198 - 199 /* 200 * Try detecting repeating patterns by keeping track of the last 8 201 * intervals, and checking if the standard deviation of that set ··· 311 * operands are 32 bits. 312 * Make sure to round up for half microseconds. 313 */ 314 - data->predicted_us = div_round64((uint64_t)data->next_timer_us * 315 data->correction_factor[data->bucket], 316 RESOLUTION * DECAY); 317
··· 190 191 static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); 192 193 /* 194 * Try detecting repeating patterns by keeping track of the last 8 195 * intervals, and checking if the standard deviation of that set ··· 317 * operands are 32 bits. 318 * Make sure to round up for half microseconds. 319 */ 320 + data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us * 321 data->correction_factor[data->bucket], 322 RESOLUTION * DECAY); 323
-3
drivers/gpu/drm/i915/intel_drv.h
··· 36 #include <drm/drm_dp_mst_helper.h> 37 #include <drm/drm_rect.h> 38 39 - #define DIV_ROUND_CLOSEST_ULL(ll, d) \ 40 - ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; }) 41 - 42 /** 43 * _wait_for - magic (register) wait macro 44 *
··· 36 #include <drm/drm_dp_mst_helper.h> 37 #include <drm/drm_rect.h> 38 39 /** 40 * _wait_for - magic (register) wait macro 41 *
+1
drivers/gpu/drm/i915/intel_panel.c
··· 30 31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 33 #include <linux/moduleparam.h> 34 #include "intel_drv.h" 35
··· 30 31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 33 + #include <linux/kernel.h> 34 #include <linux/moduleparam.h> 35 #include "intel_drv.h" 36
+3 -14
drivers/hwmon/ina2xx.c
··· 36 #include <linux/jiffies.h> 37 #include <linux/of.h> 38 #include <linux/delay.h> 39 40 #include <linux/platform_data/ina2xx.h> 41 ··· 142 */ 143 static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; 144 145 - static int ina226_avg_bits(int avg) 146 - { 147 - int i; 148 - 149 - /* Get the closest average from the tab. */ 150 - for (i = 0; i < ARRAY_SIZE(ina226_avg_tab) - 1; i++) { 151 - if (avg <= (ina226_avg_tab[i] + ina226_avg_tab[i + 1]) / 2) 152 - break; 153 - } 154 - 155 - return i; /* Return 0b0111 for values greater than 1024. */ 156 - } 157 - 158 static int ina226_reg_to_interval(u16 config) 159 { 160 int avg = ina226_avg_tab[INA226_READ_AVG(config)]; ··· 159 160 avg = DIV_ROUND_CLOSEST(interval * 1000, 161 INA226_TOTAL_CONV_TIME_DEFAULT); 162 - avg_bits = ina226_avg_bits(avg); 163 164 return (config & ~INA226_AVG_RD_MASK) | INA226_SHIFT_AVG(avg_bits); 165 }
··· 36 #include <linux/jiffies.h> 37 #include <linux/of.h> 38 #include <linux/delay.h> 39 + #include <linux/util_macros.h> 40 41 #include <linux/platform_data/ina2xx.h> 42 ··· 141 */ 142 static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; 143 144 static int ina226_reg_to_interval(u16 config) 145 { 146 int avg = ina226_avg_tab[INA226_READ_AVG(config)]; ··· 171 172 avg = DIV_ROUND_CLOSEST(interval * 1000, 173 INA226_TOTAL_CONV_TIME_DEFAULT); 174 + avg_bits = find_closest(avg, ina226_avg_tab, 175 + ARRAY_SIZE(ina226_avg_tab)); 176 177 return (config & ~INA226_AVG_RD_MASK) | INA226_SHIFT_AVG(avg_bits); 178 }
+8 -18
drivers/hwmon/lm85.c
··· 34 #include <linux/hwmon-sysfs.h> 35 #include <linux/err.h> 36 #include <linux/mutex.h> 37 38 /* Addresses to scan */ 39 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; ··· 191 192 static int RANGE_TO_REG(long range) 193 { 194 - int i; 195 - 196 - /* Find the closest match */ 197 - for (i = 0; i < 15; ++i) { 198 - if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2) 199 - break; 200 - } 201 - 202 - return i; 203 } 204 #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 205 ··· 202 static const int adm1027_freq_map[8] = { /* 1 Hz */ 203 11, 15, 22, 29, 35, 44, 59, 88 204 }; 205 206 - static int FREQ_TO_REG(const int *map, unsigned long freq) 207 { 208 - int i; 209 - 210 - /* Find the closest match */ 211 - for (i = 0; i < 7; ++i) 212 - if (freq <= (map[i] + map[i + 1]) / 2) 213 - break; 214 - return i; 215 } 216 217 static int FREQ_FROM_REG(const int *map, u8 reg) ··· 817 data->cfg5 &= ~ADT7468_HFPWM; 818 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 819 } else { /* Low freq. mode */ 820 - data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); 821 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 822 (data->zone[nr].range << 4) 823 | data->pwm_freq[nr]);
··· 34 #include <linux/hwmon-sysfs.h> 35 #include <linux/err.h> 36 #include <linux/mutex.h> 37 + #include <linux/util_macros.h> 38 39 /* Addresses to scan */ 40 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; ··· 190 191 static int RANGE_TO_REG(long range) 192 { 193 + return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map)); 194 } 195 #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 196 ··· 209 static const int adm1027_freq_map[8] = { /* 1 Hz */ 210 11, 15, 22, 29, 35, 44, 59, 88 211 }; 212 + #define FREQ_MAP_LEN 8 213 214 + static int FREQ_TO_REG(const int *map, 215 + unsigned int map_size, unsigned long freq) 216 { 217 + return find_closest(freq, map, map_size); 218 } 219 220 static int FREQ_FROM_REG(const int *map, u8 reg) ··· 828 data->cfg5 &= ~ADT7468_HFPWM; 829 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 830 } else { /* Low freq. mode */ 831 + data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, 832 + FREQ_MAP_LEN, val); 833 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 834 (data->zone[nr].range << 4) 835 | data->pwm_freq[nr]);
+3 -5
drivers/hwmon/w83795.c
··· 35 #include <linux/err.h> 36 #include <linux/mutex.h> 37 #include <linux/jiffies.h> 38 39 /* Addresses to scan */ 40 static const unsigned short normal_i2c[] = { ··· 309 unsigned long best0, best1; 310 311 /* Best fit for cksel = 0 */ 312 - for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { 313 - if (val > (pwm_freq_cksel0[reg0] + 314 - pwm_freq_cksel0[reg0 + 1]) / 2) 315 - break; 316 - } 317 if (val < 375) /* cksel = 1 can't beat this */ 318 return reg0; 319 best0 = pwm_freq_cksel0[reg0];
··· 35 #include <linux/err.h> 36 #include <linux/mutex.h> 37 #include <linux/jiffies.h> 38 + #include <linux/util_macros.h> 39 40 /* Addresses to scan */ 41 static const unsigned short normal_i2c[] = { ··· 308 unsigned long best0, best1; 309 310 /* Best fit for cksel = 0 */ 311 + reg0 = find_closest_descending(val, pwm_freq_cksel0, 312 + ARRAY_SIZE(pwm_freq_cksel0)); 313 if (val < 375) /* cksel = 1 can't beat this */ 314 return reg0; 315 best0 = pwm_freq_cksel0[reg0];
+1 -1
drivers/media/dvb-frontends/cxd2820r_c.c
··· 79 80 num = if_freq / 1000; /* Hz => kHz */ 81 num *= 0x4000; 82 - if_ctl = 0x4000 - cxd2820r_div_u64_round_closest(num, 41000); 83 buf[0] = (if_ctl >> 8) & 0x3f; 84 buf[1] = (if_ctl >> 0) & 0xff; 85
··· 79 80 num = if_freq / 1000; /* Hz => kHz */ 81 num *= 0x4000; 82 + if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000); 83 buf[0] = (if_ctl >> 8) & 0x3f; 84 buf[1] = (if_ctl >> 0) & 0xff; 85
-6
drivers/media/dvb-frontends/cxd2820r_core.c
··· 244 return ret; 245 } 246 247 - /* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */ 248 - u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor) 249 - { 250 - return div_u64(dividend + (divisor / 2), divisor); 251 - } 252 - 253 static int cxd2820r_set_frontend(struct dvb_frontend *fe) 254 { 255 struct cxd2820r_priv *priv = fe->demodulator_priv;
··· 244 return ret; 245 } 246 247 static int cxd2820r_set_frontend(struct dvb_frontend *fe) 248 { 249 struct cxd2820r_priv *priv = fe->demodulator_priv;
-2
drivers/media/dvb-frontends/cxd2820r_priv.h
··· 64 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 65 int len); 66 67 - u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor); 68 - 69 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 70 int len); 71
··· 64 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 65 int len); 66 67 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 68 int len); 69
+1 -1
drivers/media/dvb-frontends/cxd2820r_t.c
··· 103 104 num = if_freq / 1000; /* Hz => kHz */ 105 num *= 0x1000000; 106 - if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 107 buf[0] = ((if_ctl >> 16) & 0xff); 108 buf[1] = ((if_ctl >> 8) & 0xff); 109 buf[2] = ((if_ctl >> 0) & 0xff);
··· 103 104 num = if_freq / 1000; /* Hz => kHz */ 105 num *= 0x1000000; 106 + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000); 107 buf[0] = ((if_ctl >> 16) & 0xff); 108 buf[1] = ((if_ctl >> 8) & 0xff); 109 buf[2] = ((if_ctl >> 0) & 0xff);
+1 -1
drivers/media/dvb-frontends/cxd2820r_t2.c
··· 120 121 num = if_freq / 1000; /* Hz => kHz */ 122 num *= 0x1000000; 123 - if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 124 buf[0] = ((if_ctl >> 16) & 0xff); 125 buf[1] = ((if_ctl >> 8) & 0xff); 126 buf[2] = ((if_ctl >> 0) & 0xff);
··· 120 121 num = if_freq / 1000; /* Hz => kHz */ 122 num *= 0x1000000; 123 + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000); 124 buf[0] = ((if_ctl >> 16) & 0xff); 125 buf[1] = ((if_ctl >> 8) & 0xff); 126 buf[2] = ((if_ctl >> 0) & 0xff);
+2 -1
drivers/memstick/core/mspro_block.c
··· 758 759 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { 760 if (msb->data_dir == READ) { 761 - for (cnt = 0; cnt < msb->current_seg; cnt++) 762 t_len += msb->req_sg[cnt].length 763 / msb->page_size; 764 ··· 766 t_len += msb->current_page - 1; 767 768 t_len *= msb->page_size; 769 } 770 } else 771 t_len = blk_rq_bytes(msb->block_req);
··· 758 759 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { 760 if (msb->data_dir == READ) { 761 + for (cnt = 0; cnt < msb->current_seg; cnt++) { 762 t_len += msb->req_sg[cnt].length 763 / msb->page_size; 764 ··· 766 t_len += msb->current_page - 1; 767 768 t_len *= msb->page_size; 769 + } 770 } 771 } else 772 t_len = blk_rq_bytes(msb->block_req);
+16 -14
drivers/oprofile/buffer_sync.c
··· 21 * objects. 22 */ 23 24 #include <linux/mm.h> 25 #include <linux/workqueue.h> 26 #include <linux/notifier.h> ··· 225 static unsigned long get_exec_dcookie(struct mm_struct *mm) 226 { 227 unsigned long cookie = NO_COOKIE; 228 229 - if (mm && mm->exe_file) 230 - cookie = fast_get_dcookie(&mm->exe_file->f_path); 231 232 return cookie; 233 } 234 ··· 245 * pair that can then be added to the global event buffer. We make 246 * sure to do this lookup before a mm->mmap modification happens so 247 * we don't lose track. 248 */ 249 static unsigned long 250 lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset) ··· 254 unsigned long cookie = NO_COOKIE; 255 struct vm_area_struct *vma; 256 257 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 258 259 if (addr < vma->vm_start || addr >= vma->vm_end) ··· 274 275 if (!vma) 276 cookie = INVALID_COOKIE; 277 278 return cookie; 279 } ··· 415 { 416 if (!mm) 417 return; 418 - up_read(&mm->mmap_sem); 419 mmput(mm); 420 } 421 - 422 - 423 - static struct mm_struct *take_tasks_mm(struct task_struct *task) 424 - { 425 - struct mm_struct *mm = get_task_mm(task); 426 - if (mm) 427 - down_read(&mm->mmap_sem); 428 - return mm; 429 - } 430 - 431 432 static inline int is_code(unsigned long val) 433 { ··· 534 new = (struct task_struct *)val; 535 oldmm = mm; 536 release_mm(oldmm); 537 - mm = take_tasks_mm(new); 538 if (mm != oldmm) 539 cookie = get_exec_dcookie(mm); 540 add_user_ctx_switch(new, cookie);
··· 21 * objects. 22 */ 23 24 + #include <linux/file.h> 25 #include <linux/mm.h> 26 #include <linux/workqueue.h> 27 #include <linux/notifier.h> ··· 224 static unsigned long get_exec_dcookie(struct mm_struct *mm) 225 { 226 unsigned long cookie = NO_COOKIE; 227 + struct file *exe_file; 228 229 + if (!mm) 230 + goto done; 231 232 + exe_file = get_mm_exe_file(mm); 233 + if (!exe_file) 234 + goto done; 235 + 236 + cookie = fast_get_dcookie(&exe_file->f_path); 237 + fput(exe_file); 238 + done: 239 return cookie; 240 } 241 ··· 236 * pair that can then be added to the global event buffer. We make 237 * sure to do this lookup before a mm->mmap modification happens so 238 * we don't lose track. 239 + * 240 + * The caller must ensure the mm is not nil (ie: not a kernel thread). 241 */ 242 static unsigned long 243 lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset) ··· 243 unsigned long cookie = NO_COOKIE; 244 struct vm_area_struct *vma; 245 246 + down_read(&mm->mmap_sem); 247 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 248 249 if (addr < vma->vm_start || addr >= vma->vm_end) ··· 262 263 if (!vma) 264 cookie = INVALID_COOKIE; 265 + up_read(&mm->mmap_sem); 266 267 return cookie; 268 } ··· 402 { 403 if (!mm) 404 return; 405 mmput(mm); 406 } 407 408 static inline int is_code(unsigned long val) 409 { ··· 532 new = (struct task_struct *)val; 533 oldmm = mm; 534 release_mm(oldmm); 535 + mm = get_task_mm(new); 536 if (mm != oldmm) 537 cookie = get_exec_dcookie(mm); 538 add_user_ctx_switch(new, cookie);
+13 -3
drivers/rtc/Kconfig
··· 1111 This driver can also be built as a module. If so, the module 1112 will be called rtc-davinci. 1113 1114 config RTC_DRV_IMXDI 1115 tristate "Freescale IMX DryIce Real Time Clock" 1116 depends on ARCH_MXC ··· 1131 will be called "rtc-imxdi". 1132 1133 config RTC_DRV_OMAP 1134 - tristate "TI OMAP1" 1135 - depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX || SOC_AM33XX 1136 help 1137 Say "yes" here to support the on chip real time clock 1138 - present on TI OMAP1, AM33xx and DA8xx/OMAP-L13x. 1139 1140 This driver can also be built as a module, if so, module 1141 will be called rtc-omap.
··· 1111 This driver can also be built as a module. If so, the module 1112 will be called rtc-davinci. 1113 1114 + config RTC_DRV_DIGICOLOR 1115 + tristate "Conexant Digicolor RTC" 1116 + depends on ARCH_DIGICOLOR 1117 + help 1118 + If you say yes here you get support for the RTC on Conexant 1119 + Digicolor platforms. This currently includes the CX92755 SoC. 1120 + 1121 + This driver can also be built as a module. If so, the module 1122 + will be called rtc-digicolor. 1123 + 1124 config RTC_DRV_IMXDI 1125 tristate "Freescale IMX DryIce Real Time Clock" 1126 depends on ARCH_MXC ··· 1121 will be called "rtc-imxdi". 1122 1123 config RTC_DRV_OMAP 1124 + tristate "TI OMAP Real Time Clock" 1125 + depends on ARCH_OMAP || ARCH_DAVINCI 1126 help 1127 Say "yes" here to support the on chip real time clock 1128 + present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx. 1129 1130 This driver can also be built as a module, if so, module 1131 will be called rtc-omap.
+1
drivers/rtc/Makefile
··· 40 obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o 41 obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o 42 obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o 43 obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o 44 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 45 obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
··· 40 obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o 41 obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o 42 obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o 43 + obj-$(CONFIG_RTC_DRV_DIGICOLOR) += rtc-digicolor.o 44 obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o 45 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 46 obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
+3 -3
drivers/rtc/class.c
··· 221 rtc->pie_timer.function = rtc_pie_update_irq; 222 rtc->pie_enabled = 0; 223 224 /* Check to see if there is an ALARM already set in hw */ 225 err = __rtc_read_alarm(rtc, &alrm); 226 227 if (!err && !rtc_valid_tm(&alrm.time)) 228 rtc_initialize_alarm(rtc, &alrm); 229 - 230 - strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); 231 - dev_set_name(&rtc->dev, "rtc%d", id); 232 233 rtc_dev_prepare(rtc); 234
··· 221 rtc->pie_timer.function = rtc_pie_update_irq; 222 rtc->pie_enabled = 0; 223 224 + strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); 225 + dev_set_name(&rtc->dev, "rtc%d", id); 226 + 227 /* Check to see if there is an ALARM already set in hw */ 228 err = __rtc_read_alarm(rtc, &alrm); 229 230 if (!err && !rtc_valid_tm(&alrm.time)) 231 rtc_initialize_alarm(rtc, &alrm); 232 233 rtc_dev_prepare(rtc); 234
+4 -2
drivers/rtc/hctosys.c
··· 9 * published by the Free Software Foundation. 10 */ 11 12 #include <linux/rtc.h> 13 14 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary ··· 34 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 35 36 if (rtc == NULL) { 37 - pr_err("%s: unable to open rtc device (%s)\n", 38 - __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); 39 goto err_open; 40 } 41
··· 9 * published by the Free Software Foundation. 10 */ 11 12 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 + 14 #include <linux/rtc.h> 15 16 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary ··· 32 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 33 34 if (rtc == NULL) { 35 + pr_info("unable to open rtc device (%s)\n", 36 + CONFIG_RTC_HCTOSYS_DEVICE); 37 goto err_open; 38 } 39
+3 -2
drivers/rtc/interface.c
··· 31 memset(tm, 0, sizeof(struct rtc_time)); 32 err = rtc->ops->read_time(rtc->dev.parent, tm); 33 if (err < 0) { 34 - dev_err(&rtc->dev, "read_time: fail to read\n"); 35 return err; 36 } 37 38 err = rtc_valid_tm(tm); 39 if (err < 0) 40 - dev_err(&rtc->dev, "read_time: rtc_time isn't valid\n"); 41 } 42 return err; 43 }
··· 31 memset(tm, 0, sizeof(struct rtc_time)); 32 err = rtc->ops->read_time(rtc->dev.parent, tm); 33 if (err < 0) { 34 + dev_dbg(&rtc->dev, "read_time: fail to read: %d\n", 35 + err); 36 return err; 37 } 38 39 err = rtc_valid_tm(tm); 40 if (err < 0) 41 + dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n"); 42 } 43 return err; 44 }
+1 -1
drivers/rtc/rtc-ab-b5ze-s3.c
··· 881 .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, 882 }; 883 884 - static struct regmap_config abb5zes3_rtc_regmap_config = { 885 .reg_bits = 8, 886 .val_bits = 8, 887 };
··· 881 .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, 882 }; 883 884 + static const struct regmap_config abb5zes3_rtc_regmap_config = { 885 .reg_bits = 8, 886 .val_bits = 8, 887 };
+2 -2
drivers/rtc/rtc-at91rm9200.c
··· 37 #include "rtc-at91rm9200.h" 38 39 #define at91_rtc_read(field) \ 40 - __raw_readl(at91_rtc_regs + field) 41 #define at91_rtc_write(field, val) \ 42 - __raw_writel((val), at91_rtc_regs + field) 43 44 #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 45
··· 37 #include "rtc-at91rm9200.h" 38 39 #define at91_rtc_read(field) \ 40 + readl_relaxed(at91_rtc_regs + field) 41 #define at91_rtc_write(field, val) \ 42 + writel_relaxed((val), at91_rtc_regs + field) 43 44 #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 45
+4 -2
drivers/rtc/rtc-cmos.c
··· 28 * interrupts disabled, holding the global rtc_lock, to exclude those 29 * other drivers and utilities on correctly configured systems. 30 */ 31 #include <linux/kernel.h> 32 #include <linux/module.h> 33 #include <linux/init.h> ··· 388 static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) 389 { 390 alarm_disable_quirk = true; 391 - pr_info("rtc-cmos: BIOS has alarm-disable quirk. "); 392 - pr_info("RTC alarms disabled\n"); 393 return 0; 394 } 395
··· 28 * interrupts disabled, holding the global rtc_lock, to exclude those 29 * other drivers and utilities on correctly configured systems. 30 */ 31 + 32 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 33 + 34 #include <linux/kernel.h> 35 #include <linux/module.h> 36 #include <linux/init.h> ··· 385 static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) 386 { 387 alarm_disable_quirk = true; 388 + pr_info("BIOS has alarm-disable quirk - RTC alarms disabled\n"); 389 return 0; 390 } 391
+76 -21
drivers/rtc/rtc-da9052.c
··· 16 #include <linux/platform_device.h> 17 #include <linux/rtc.h> 18 #include <linux/err.h> 19 20 #include <linux/mfd/da9052/da9052.h> 21 #include <linux/mfd/da9052/reg.h> 22 23 #define rtc_err(rtc, fmt, ...) \ 24 dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) 25 26 struct da9052_rtc { 27 struct rtc_device *rtc; ··· 61 static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) 62 { 63 int ret; 64 - uint8_t v[5]; 65 66 - ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, v); 67 - if (ret != 0) { 68 rtc_err(rtc, "Failed to group read ALM: %d\n", ret); 69 return ret; 70 } 71 72 - rtc_tm->tm_year = (v[4] & DA9052_RTC_YEAR) + 100; 73 - rtc_tm->tm_mon = (v[3] & DA9052_RTC_MONTH) - 1; 74 - rtc_tm->tm_mday = v[2] & DA9052_RTC_DAY; 75 - rtc_tm->tm_hour = v[1] & DA9052_RTC_HOUR; 76 - rtc_tm->tm_min = v[0] & DA9052_RTC_MIN; 77 78 - ret = rtc_valid_tm(rtc_tm); 79 - return ret; 80 } 81 82 static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) ··· 159 static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) 160 { 161 struct da9052_rtc *rtc = dev_get_drvdata(dev); 162 - uint8_t v[6]; 163 int ret; 164 165 - ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, v); 166 - if (ret < 0) { 167 rtc_err(rtc, "Failed to read RTC time : %d\n", ret); 168 return ret; 169 } 170 171 - rtc_tm->tm_year = (v[5] & DA9052_RTC_YEAR) + 100; 172 - rtc_tm->tm_mon = (v[4] & DA9052_RTC_MONTH) - 1; 173 - rtc_tm->tm_mday = v[3] & DA9052_RTC_DAY; 174 - rtc_tm->tm_hour = v[2] & DA9052_RTC_HOUR; 175 - rtc_tm->tm_min = v[1] & DA9052_RTC_MIN; 176 - rtc_tm->tm_sec = v[0] & DA9052_RTC_SEC; 177 178 - ret = rtc_valid_tm(rtc_tm); 179 - return ret; 180 } 181 182 static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 205 struct da9052_rtc *rtc; 206 uint8_t v[6]; 207 int ret; 208 209 rtc = dev_get_drvdata(dev); 210 ··· 246 int ret; 247 struct rtc_time *tm = &alrm->time; 248 struct da9052_rtc *rtc = dev_get_drvdata(dev); 249 250 ret = da9052_rtc_enable_alarm(rtc, 0); 251 if (ret < 0) ··· 308 rtc_err(rtc, "irq registration failed: %d\n", ret); 309 return ret; 310 } 311 312 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 313 &da9052_rtc_ops, THIS_MODULE);
··· 16 #include <linux/platform_device.h> 17 #include <linux/rtc.h> 18 #include <linux/err.h> 19 + #include <linux/delay.h> 20 21 #include <linux/mfd/da9052/da9052.h> 22 #include <linux/mfd/da9052/reg.h> 23 24 #define rtc_err(rtc, fmt, ...) \ 25 dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) 26 + 27 + #define DA9052_GET_TIME_RETRIES 5 28 29 struct da9052_rtc { 30 struct rtc_device *rtc; ··· 58 static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) 59 { 60 int ret; 61 + uint8_t v[2][5]; 62 + int idx = 1; 63 + int timeout = DA9052_GET_TIME_RETRIES; 64 65 + ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, &v[0][0]); 66 + if (ret) { 67 rtc_err(rtc, "Failed to group read ALM: %d\n", ret); 68 return ret; 69 } 70 71 + do { 72 + ret = da9052_group_read(rtc->da9052, 73 + DA9052_ALARM_MI_REG, 5, &v[idx][0]); 74 + if (ret) { 75 + rtc_err(rtc, "Failed to group read ALM: %d\n", ret); 76 + return ret; 77 + } 78 79 + if (memcmp(&v[0][0], &v[1][0], 5) == 0) { 80 + rtc_tm->tm_year = (v[0][4] & DA9052_RTC_YEAR) + 100; 81 + rtc_tm->tm_mon = (v[0][3] & DA9052_RTC_MONTH) - 1; 82 + rtc_tm->tm_mday = v[0][2] & DA9052_RTC_DAY; 83 + rtc_tm->tm_hour = v[0][1] & DA9052_RTC_HOUR; 84 + rtc_tm->tm_min = v[0][0] & DA9052_RTC_MIN; 85 + 86 + ret = rtc_valid_tm(rtc_tm); 87 + return ret; 88 + } 89 + 90 + idx = (1-idx); 91 + msleep(20); 92 + 93 + } while (timeout--); 94 + 95 + rtc_err(rtc, "Timed out reading alarm time\n"); 96 + 97 + return -EIO; 98 } 99 100 static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) ··· 135 static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) 136 { 137 struct da9052_rtc *rtc = dev_get_drvdata(dev); 138 int ret; 139 + uint8_t v[2][6]; 140 + int idx = 1; 141 + int timeout = DA9052_GET_TIME_RETRIES; 142 143 + ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, &v[0][0]); 144 + if (ret) { 145 rtc_err(rtc, "Failed to read RTC time : %d\n", ret); 146 return ret; 147 } 148 149 + do { 150 + ret = da9052_group_read(rtc->da9052, 151 + DA9052_COUNT_S_REG, 6, &v[idx][0]); 152 + if (ret) { 153 + rtc_err(rtc, "Failed to read RTC time : %d\n", ret); 154 + return ret; 155 + } 156 157 + if (memcmp(&v[0][0], &v[1][0], 6) == 0) { 158 + rtc_tm->tm_year = (v[0][5] & DA9052_RTC_YEAR) + 100; 159 + rtc_tm->tm_mon = (v[0][4] & DA9052_RTC_MONTH) - 1; 160 + rtc_tm->tm_mday = v[0][3] & DA9052_RTC_DAY; 161 + rtc_tm->tm_hour = v[0][2] & DA9052_RTC_HOUR; 162 + rtc_tm->tm_min = v[0][1] & DA9052_RTC_MIN; 163 + rtc_tm->tm_sec = v[0][0] & DA9052_RTC_SEC; 164 + 165 + ret = rtc_valid_tm(rtc_tm); 166 + return ret; 167 + } 168 + 169 + idx = (1-idx); 170 + msleep(20); 171 + 172 + } while (timeout--); 173 + 174 + rtc_err(rtc, "Timed out reading time\n"); 175 + 176 + return -EIO; 177 } 178 179 static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 160 struct da9052_rtc *rtc; 161 uint8_t v[6]; 162 int ret; 163 + 164 + /* DA9052 only has 6 bits for year - to represent 2000-2063 */ 165 + if ((tm->tm_year < 100) || (tm->tm_year > 163)) 166 + return -EINVAL; 167 168 rtc = dev_get_drvdata(dev); 169 ··· 197 int ret; 198 struct rtc_time *tm = &alrm->time; 199 struct da9052_rtc *rtc = dev_get_drvdata(dev); 200 + 201 + /* DA9052 only has 6 bits for year - to represent 2000-2063 */ 202 + if ((tm->tm_year < 100) || (tm->tm_year > 163)) 203 + return -EINVAL; 204 205 ret = da9052_rtc_enable_alarm(rtc, 0); 206 if (ret < 0) ··· 255 rtc_err(rtc, "irq registration failed: %d\n", ret); 256 return ret; 257 } 258 + 259 + device_init_wakeup(&pdev->dev, true); 260 261 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 262 &da9052_rtc_ops, THIS_MODULE);
+227
drivers/rtc/rtc-digicolor.c
···
··· 1 + /* 2 + * Real Time Clock driver for Conexant Digicolor 3 + * 4 + * Copyright (C) 2015 Paradox Innovation Ltd. 5 + * 6 + * Author: Baruch Siach <baruch@tkos.co.il> 7 + * 8 + * This program is free software; you can redistribute it and/or modify it 9 + * under the terms of the GNU General Public License as published by the 10 + * Free Software Foundation; either version 2 of the License, or (at your 11 + * option) any later version. 12 + */ 13 + 14 + #include <linux/io.h> 15 + #include <linux/iopoll.h> 16 + #include <linux/delay.h> 17 + #include <linux/module.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/rtc.h> 20 + #include <linux/of.h> 21 + 22 + #define DC_RTC_CONTROL 0x0 23 + #define DC_RTC_TIME 0x8 24 + #define DC_RTC_REFERENCE 0xc 25 + #define DC_RTC_ALARM 0x10 26 + #define DC_RTC_INTFLAG_CLEAR 0x14 27 + #define DC_RTC_INTENABLE 0x16 28 + 29 + #define DC_RTC_CMD_MASK 0xf 30 + #define DC_RTC_GO_BUSY BIT(7) 31 + 32 + #define CMD_NOP 0 33 + #define CMD_RESET 1 34 + #define CMD_WRITE 3 35 + #define CMD_READ 4 36 + 37 + #define CMD_DELAY_US (10*1000) 38 + #define CMD_TIMEOUT_US (500*CMD_DELAY_US) 39 + 40 + struct dc_rtc { 41 + struct rtc_device *rtc_dev; 42 + void __iomem *regs; 43 + }; 44 + 45 + static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len) 46 + { 47 + u8 val; 48 + int i, ret; 49 + 50 + for (i = 0; i < len; i++) { 51 + writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY, 52 + rtc->regs + DC_RTC_CONTROL); 53 + ret = readb_relaxed_poll_timeout( 54 + rtc->regs + DC_RTC_CONTROL, val, 55 + !(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US); 56 + if (ret < 0) 57 + return ret; 58 + } 59 + 60 + return 0; 61 + } 62 + 63 + static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val) 64 + { 65 + static const u8 read_cmds[] = {CMD_READ, CMD_NOP}; 66 + u32 reference, time1, time2; 67 + int ret; 68 + 69 + ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds)); 70 + if (ret < 0) 71 + return ret; 72 + 73 + reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); 74 + time1 = readl_relaxed(rtc->regs + DC_RTC_TIME); 75 + /* Read twice to ensure consistency */ 76 + while (1) { 77 + time2 = readl_relaxed(rtc->regs + DC_RTC_TIME); 78 + if (time1 == time2) 79 + break; 80 + time1 = time2; 81 + } 82 + 83 + *val = reference + time1; 84 + return 0; 85 + } 86 + 87 + static int dc_rtc_write(struct dc_rtc *rtc, u32 val) 88 + { 89 + static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP}; 90 + 91 + writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE); 92 + return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds)); 93 + } 94 + 95 + static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm) 96 + { 97 + struct dc_rtc *rtc = dev_get_drvdata(dev); 98 + unsigned long now; 99 + int ret; 100 + 101 + ret = dc_rtc_read(rtc, &now); 102 + if (ret < 0) 103 + return ret; 104 + rtc_time64_to_tm(now, tm); 105 + 106 + return 0; 107 + } 108 + 109 + static int dc_rtc_set_mmss(struct device *dev, unsigned long secs) 110 + { 111 + struct dc_rtc *rtc = dev_get_drvdata(dev); 112 + 113 + return dc_rtc_write(rtc, secs); 114 + } 115 + 116 + static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 117 + { 118 + struct dc_rtc *rtc = dev_get_drvdata(dev); 119 + u32 alarm_reg, reference; 120 + unsigned long now; 121 + int ret; 122 + 123 + alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM); 124 + reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); 125 + rtc_time64_to_tm(reference + alarm_reg, &alarm->time); 126 + 127 + ret = dc_rtc_read(rtc, &now); 128 + if (ret < 0) 129 + return ret; 130 + 131 + alarm->pending = alarm_reg + reference > now; 132 + alarm->enabled = readl_relaxed(rtc->regs + DC_RTC_INTENABLE); 133 + 134 + return 0; 135 + } 136 + 137 + static int dc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 138 + { 139 + struct dc_rtc *rtc = dev_get_drvdata(dev); 140 + time64_t alarm_time; 141 + u32 reference; 142 + 143 + alarm_time = rtc_tm_to_time64(&alarm->time); 144 + 145 + reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); 146 + writel_relaxed(alarm_time - reference, rtc->regs + DC_RTC_ALARM); 147 + 148 + writeb_relaxed(!!alarm->enabled, rtc->regs + DC_RTC_INTENABLE); 149 + 150 + return 0; 151 + } 152 + 153 + static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 154 + { 155 + struct dc_rtc *rtc = dev_get_drvdata(dev); 156 + 157 + writeb_relaxed(!!enabled, rtc->regs + DC_RTC_INTENABLE); 158 + 159 + return 0; 160 + } 161 + 162 + static struct rtc_class_ops dc_rtc_ops = { 163 + .read_time = dc_rtc_read_time, 164 + .set_mmss = dc_rtc_set_mmss, 165 + .read_alarm = dc_rtc_read_alarm, 166 + .set_alarm = dc_rtc_set_alarm, 167 + .alarm_irq_enable = dc_rtc_alarm_irq_enable, 168 + }; 169 + 170 + static irqreturn_t dc_rtc_irq(int irq, void *dev_id) 171 + { 172 + struct dc_rtc *rtc = dev_id; 173 + 174 + writeb_relaxed(1, rtc->regs + DC_RTC_INTFLAG_CLEAR); 175 + rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF); 176 + 177 + return IRQ_HANDLED; 178 + } 179 + 180 + static int __init dc_rtc_probe(struct platform_device *pdev) 181 + { 182 + struct resource *res; 183 + struct dc_rtc *rtc; 184 + int irq, ret; 185 + 186 + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); 187 + if (!rtc) 188 + return -ENOMEM; 189 + 190 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 191 + rtc->regs = devm_ioremap_resource(&pdev->dev, res); 192 + if (IS_ERR(rtc->regs)) 193 + return PTR_ERR(rtc->regs); 194 + 195 + irq = platform_get_irq(pdev, 0); 196 + if (irq < 0) 197 + return irq; 198 + ret = devm_request_irq(&pdev->dev, irq, dc_rtc_irq, 0, pdev->name, rtc); 199 + if (ret < 0) 200 + return ret; 201 + 202 + platform_set_drvdata(pdev, rtc); 203 + rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, 204 + &dc_rtc_ops, THIS_MODULE); 205 + if (IS_ERR(rtc->rtc_dev)) 206 + return PTR_ERR(rtc->rtc_dev); 207 + 208 + return 0; 209 + } 210 + 211 + static const struct of_device_id dc_dt_ids[] = { 212 + { .compatible = "cnxt,cx92755-rtc" }, 213 + { /* sentinel */ } 214 + }; 215 + MODULE_DEVICE_TABLE(of, dc_dt_ids); 216 + 217 + static struct platform_driver dc_rtc_driver = { 218 + .driver = { 219 + .name = "digicolor_rtc", 220 + .of_match_table = of_match_ptr(dc_dt_ids), 221 + }, 222 + }; 223 + module_platform_driver_probe(dc_rtc_driver, dc_rtc_probe); 224 + 225 + MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 226 + MODULE_DESCRIPTION("Conexant Digicolor Realtime Clock Driver (RTC)"); 227 + MODULE_LICENSE("GPL");
+5 -3
drivers/rtc/rtc-ds1374.c
··· 18 * "Sending and receiving", using SMBus level communication is preferred. 19 */ 20 21 #include <linux/kernel.h> 22 #include <linux/module.h> 23 #include <linux/interrupt.h> ··· 408 /* Set new watchdog time */ 409 ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); 410 if (ret) { 411 - pr_info("rtc-ds1374 - couldn't set new watchdog time\n"); 412 goto out; 413 } 414 ··· 541 return -EFAULT; 542 543 if (options & WDIOS_DISABLECARD) { 544 - pr_info("rtc-ds1374: disable watchdog\n"); 545 ds1374_wdt_disable(); 546 } 547 548 if (options & WDIOS_ENABLECARD) { 549 - pr_info("rtc-ds1374: enable watchdog\n"); 550 ds1374_wdt_settimeout(wdt_margin); 551 ds1374_wdt_ping(); 552 }
··· 18 * "Sending and receiving", using SMBus level communication is preferred. 19 */ 20 21 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 + 23 #include <linux/kernel.h> 24 #include <linux/module.h> 25 #include <linux/interrupt.h> ··· 406 /* Set new watchdog time */ 407 ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); 408 if (ret) { 409 + pr_info("couldn't set new watchdog time\n"); 410 goto out; 411 } 412 ··· 539 return -EFAULT; 540 541 if (options & WDIOS_DISABLECARD) { 542 + pr_info("disable watchdog\n"); 543 ds1374_wdt_disable(); 544 } 545 546 if (options & WDIOS_ENABLECARD) { 547 + pr_info("enable watchdog\n"); 548 ds1374_wdt_settimeout(wdt_margin); 549 ds1374_wdt_ping(); 550 }
+5 -4
drivers/rtc/rtc-ds1685.c
··· 16 * published by the Free Software Foundation. 17 */ 18 19 #include <linux/bcd.h> 20 #include <linux/delay.h> 21 #include <linux/io.h> ··· 801 struct platform_device *pdev = to_platform_device(dev); 802 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 803 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; 804 - char *model = '\0'; 805 #ifdef CONFIG_RTC_DS1685_PROC_REGS 806 char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; 807 #endif ··· 2141 static struct platform_driver ds1685_rtc_driver = { 2142 .driver = { 2143 .name = "rtc-ds1685", 2144 - .owner = THIS_MODULE, 2145 }, 2146 .probe = ds1685_rtc_probe, 2147 .remove = ds1685_rtc_remove, ··· 2176 * ds1685_rtc_poweroff - uses the RTC chip to power the system off. 2177 * @pdev: pointer to platform_device structure. 2178 */ 2179 - extern void __noreturn 2180 ds1685_rtc_poweroff(struct platform_device *pdev) 2181 { 2182 u8 ctrla, ctrl4a, ctrl4b; ··· 2184 2185 /* Check for valid RTC data, else, spin forever. */ 2186 if (unlikely(!pdev)) { 2187 - pr_emerg("rtc-ds1685: platform device data not available, spinning forever ...\n"); 2188 unreachable(); 2189 } else { 2190 /* Get the rtc data. */
··· 16 * published by the Free Software Foundation. 17 */ 18 19 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20 + 21 #include <linux/bcd.h> 22 #include <linux/delay.h> 23 #include <linux/io.h> ··· 799 struct platform_device *pdev = to_platform_device(dev); 800 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 801 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; 802 + char *model; 803 #ifdef CONFIG_RTC_DS1685_PROC_REGS 804 char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; 805 #endif ··· 2139 static struct platform_driver ds1685_rtc_driver = { 2140 .driver = { 2141 .name = "rtc-ds1685", 2142 }, 2143 .probe = ds1685_rtc_probe, 2144 .remove = ds1685_rtc_remove, ··· 2175 * ds1685_rtc_poweroff - uses the RTC chip to power the system off. 2176 * @pdev: pointer to platform_device structure. 2177 */ 2178 + void __noreturn 2179 ds1685_rtc_poweroff(struct platform_device *pdev) 2180 { 2181 u8 ctrla, ctrl4a, ctrl4b; ··· 2183 2184 /* Check for valid RTC data, else, spin forever. */ 2185 if (unlikely(!pdev)) { 2186 + pr_emerg("platform device data not available, spinning forever ...\n"); 2187 unreachable(); 2188 } else { 2189 /* Get the rtc data. */
+4 -2
drivers/rtc/rtc-ds3232.c
··· 15 * "Sending and receiving", using SMBus level communication is preferred. 16 */ 17 18 #include <linux/kernel.h> 19 #include <linux/module.h> 20 #include <linux/interrupt.h> ··· 375 if (stat & DS3232_REG_SR_A1F) { 376 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 377 if (control < 0) { 378 - pr_warn("Read DS3232 Control Register error." 379 - "Disable IRQ%d.\n", client->irq); 380 } else { 381 /* disable alarm1 interrupt */ 382 control &= ~(DS3232_REG_CR_A1IE);
··· 15 * "Sending and receiving", using SMBus level communication is preferred. 16 */ 17 18 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 19 + 20 #include <linux/kernel.h> 21 #include <linux/module.h> 22 #include <linux/interrupt.h> ··· 373 if (stat & DS3232_REG_SR_A1F) { 374 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 375 if (control < 0) { 376 + pr_warn("Read Control Register error - Disable IRQ%d\n", 377 + client->irq); 378 } else { 379 /* disable alarm1 interrupt */ 380 control &= ~(DS3232_REG_CR_A1IE);
+3
drivers/rtc/rtc-efi-platform.c
··· 8 * Copyright (C) 1999-2000 VA Linux Systems 9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> 10 */ 11 #include <linux/init.h> 12 #include <linux/kernel.h> 13 #include <linux/module.h>
··· 8 * Copyright (C) 1999-2000 VA Linux Systems 9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> 10 */ 11 + 12 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 + 14 #include <linux/init.h> 15 #include <linux/kernel.h> 16 #include <linux/module.h>
+11
drivers/rtc/rtc-em3027.c
··· 15 #include <linux/rtc.h> 16 #include <linux/bcd.h> 17 #include <linux/module.h> 18 19 /* Registers */ 20 #define EM3027_REG_ON_OFF_CTRL 0x00 ··· 136 { "em3027", 0 }, 137 { } 138 }; 139 140 static struct i2c_driver em3027_driver = { 141 .driver = { 142 .name = "rtc-em3027", 143 }, 144 .probe = &em3027_probe, 145 .id_table = em3027_id,
··· 15 #include <linux/rtc.h> 16 #include <linux/bcd.h> 17 #include <linux/module.h> 18 + #include <linux/of.h> 19 20 /* Registers */ 21 #define EM3027_REG_ON_OFF_CTRL 0x00 ··· 135 { "em3027", 0 }, 136 { } 137 }; 138 + MODULE_DEVICE_TABLE(i2c, em3027_id); 139 + 140 + #ifdef CONFIG_OF 141 + static const struct of_device_id em3027_of_match[] = { 142 + { .compatible = "emmicro,em3027", }, 143 + {} 144 + }; 145 + MODULE_DEVICE_TABLE(of, em3027_of_match); 146 + #endif 147 148 static struct i2c_driver em3027_driver = { 149 .driver = { 150 .name = "rtc-em3027", 151 + .of_match_table = of_match_ptr(em3027_of_match), 152 }, 153 .probe = &em3027_probe, 154 .id_table = em3027_id,
+6 -6
drivers/rtc/rtc-hym8563.c
··· 66 #define HYM8563_ALM_BIT_DISABLE BIT(7) 67 68 #define HYM8563_CLKOUT 0x0d 69 - #define HYM8563_CLKOUT_DISABLE BIT(7) 70 #define HYM8563_CLKOUT_32768 0 71 #define HYM8563_CLKOUT_1024 1 72 #define HYM8563_CLKOUT_32 2 ··· 309 struct i2c_client *client = hym8563->client; 310 int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); 311 312 - if (ret < 0 || ret & HYM8563_CLKOUT_DISABLE) 313 return 0; 314 315 ret &= HYM8563_CLKOUT_MASK; ··· 360 return ret; 361 362 if (enable) 363 - ret &= ~HYM8563_CLKOUT_DISABLE; 364 else 365 - ret |= HYM8563_CLKOUT_DISABLE; 366 367 return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); 368 } ··· 386 if (ret < 0) 387 return ret; 388 389 - return !(ret & HYM8563_CLKOUT_DISABLE); 390 } 391 392 static const struct clk_ops hym8563_clkout_ops = { ··· 407 int ret; 408 409 ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, 410 - HYM8563_CLKOUT_DISABLE); 411 if (ret < 0) 412 return ERR_PTR(ret); 413
··· 66 #define HYM8563_ALM_BIT_DISABLE BIT(7) 67 68 #define HYM8563_CLKOUT 0x0d 69 + #define HYM8563_CLKOUT_ENABLE BIT(7) 70 #define HYM8563_CLKOUT_32768 0 71 #define HYM8563_CLKOUT_1024 1 72 #define HYM8563_CLKOUT_32 2 ··· 309 struct i2c_client *client = hym8563->client; 310 int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); 311 312 + if (ret < 0) 313 return 0; 314 315 ret &= HYM8563_CLKOUT_MASK; ··· 360 return ret; 361 362 if (enable) 363 + ret |= HYM8563_CLKOUT_ENABLE; 364 else 365 + ret &= ~HYM8563_CLKOUT_ENABLE; 366 367 return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); 368 } ··· 386 if (ret < 0) 387 return ret; 388 389 + return !!(ret & HYM8563_CLKOUT_ENABLE); 390 } 391 392 static const struct clk_ops hym8563_clkout_ops = { ··· 407 int ret; 408 409 ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, 410 + 0); 411 if (ret < 0) 412 return ERR_PTR(ret); 413
+4 -2
drivers/rtc/rtc-m41t80.c
··· 13 * 14 */ 15 16 #include <linux/bcd.h> 17 #include <linux/i2c.h> 18 #include <linux/init.h> ··· 515 return -EFAULT; 516 517 if (rv & WDIOS_DISABLECARD) { 518 - pr_info("rtc-m41t80: disable watchdog\n"); 519 wdt_disable(); 520 } 521 522 if (rv & WDIOS_ENABLECARD) { 523 - pr_info("rtc-m41t80: enable watchdog\n"); 524 wdt_ping(); 525 } 526
··· 13 * 14 */ 15 16 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 + 18 #include <linux/bcd.h> 19 #include <linux/i2c.h> 20 #include <linux/init.h> ··· 513 return -EFAULT; 514 515 if (rv & WDIOS_DISABLECARD) { 516 + pr_info("disable watchdog\n"); 517 wdt_disable(); 518 } 519 520 if (rv & WDIOS_ENABLECARD) { 521 + pr_info("enable watchdog\n"); 522 wdt_ping(); 523 } 524
+4 -2
drivers/rtc/rtc-max77686.c
··· 12 * 13 */ 14 15 #include <linux/slab.h> 16 #include <linux/rtc.h> 17 #include <linux/delay.h> ··· 105 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 106 107 if (tm->tm_year < 100) { 108 - pr_warn("%s: MAX77686 RTC cannot handle the year %d." 109 - "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); 110 return -EINVAL; 111 } 112 return 0;
··· 12 * 13 */ 14 15 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16 + 17 #include <linux/slab.h> 18 #include <linux/rtc.h> 19 #include <linux/delay.h> ··· 103 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 104 105 if (tm->tm_year < 100) { 106 + pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", 107 + 1900 + tm->tm_year); 108 return -EINVAL; 109 } 110 return 0;
+5 -3
drivers/rtc/rtc-max8997.c
··· 12 * 13 */ 14 15 #include <linux/slab.h> 16 #include <linux/rtc.h> 17 #include <linux/delay.h> ··· 109 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 110 111 if (tm->tm_year < 100) { 112 - pr_warn("%s: MAX8997 RTC cannot handle the year %d." 113 - "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); 114 return -EINVAL; 115 } 116 return 0; ··· 426 427 val = 0; 428 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); 429 - pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); 430 } 431 432 static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
··· 12 * 13 */ 14 15 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16 + 17 #include <linux/slab.h> 18 #include <linux/rtc.h> 19 #include <linux/delay.h> ··· 107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 108 109 if (tm->tm_year < 100) { 110 + pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", 111 + 1900 + tm->tm_year); 112 return -EINVAL; 113 } 114 return 0; ··· 424 425 val = 0; 426 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); 427 + pr_info("WTSR_SMPL(0x%02x)\n", val); 428 } 429 430 static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
+3 -1
drivers/rtc/rtc-msm6242.c
··· 7 * Copyright (C) 1993 Hamish Macdonald 8 */ 9 10 #include <linux/delay.h> 11 #include <linux/io.h> 12 #include <linux/kernel.h> ··· 113 } 114 115 if (!cnt) 116 - pr_warn("msm6242: timed out waiting for RTC (0x%x)\n", 117 msm6242_read(priv, MSM6242_CD)); 118 } 119
··· 7 * Copyright (C) 1993 Hamish Macdonald 8 */ 9 10 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 + 12 #include <linux/delay.h> 13 #include <linux/io.h> 14 #include <linux/kernel.h> ··· 111 } 112 113 if (!cnt) 114 + pr_warn("timed out waiting for RTC (0x%x)\n", 115 msm6242_read(priv, MSM6242_CD)); 116 } 117
+55 -13
drivers/rtc/rtc-omap.c
··· 118 #define KICK0_VALUE 0x83e70b13 119 #define KICK1_VALUE 0x95a4f1e0 120 121 struct omap_rtc_device_type { 122 bool has_32kclk_en; 123 - bool has_kicker; 124 bool has_irqwakeen; 125 bool has_pmic_mode; 126 bool has_power_up_reset; 127 }; 128 129 struct omap_rtc { ··· 159 writel(val, rtc->base + reg); 160 } 161 162 /* 163 * We rely on the rtc framework to handle locking (rtc->ops_lock), 164 * so the only other requirement is that register accesses which ··· 209 210 /* alarm irq? */ 211 if (irq_data & OMAP_RTC_STATUS_ALARM) { 212 rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); 213 events |= RTC_IRQF | RTC_AF; 214 } 215 ··· 243 irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; 244 } 245 rtc_wait_not_busy(rtc); 246 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 247 if (rtc->type->has_irqwakeen) 248 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 249 local_irq_enable(); 250 251 return 0; ··· 320 local_irq_disable(); 321 rtc_wait_not_busy(rtc); 322 323 rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); 324 rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); 325 rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); 326 rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); 327 rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); 328 rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); 329 330 local_irq_enable(); 331 ··· 370 local_irq_disable(); 371 rtc_wait_not_busy(rtc); 372 373 rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); 374 rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); 375 rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); ··· 392 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 393 if (rtc->type->has_irqwakeen) 394 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 395 396 local_irq_enable(); 397 ··· 422 unsigned long now; 423 u32 val; 424 425 /* enable pmic_power_en control */ 426 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); 427 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); ··· 455 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 456 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 457 val | OMAP_RTC_INTERRUPTS_IT_ALARM2); 458 459 /* 460 * Wait for alarm to trigger (within two seconds) and external PMIC to ··· 475 476 static const struct omap_rtc_device_type omap_rtc_default_type = { 477 .has_power_up_reset = true, 478 }; 479 480 static const struct omap_rtc_device_type omap_rtc_am3352_type = { 481 .has_32kclk_en = true, 482 - .has_kicker = true, 483 .has_irqwakeen = true, 484 .has_pmic_mode = true, 485 }; 486 487 static const struct omap_rtc_device_type omap_rtc_da830_type = { 488 - .has_kicker = true, 489 }; 490 491 static const struct platform_device_id omap_rtc_id_table[] = { ··· 521 }; 522 MODULE_DEVICE_TABLE(of, omap_rtc_of_match); 523 524 - static int __init omap_rtc_probe(struct platform_device *pdev) 525 { 526 struct omap_rtc *rtc; 527 struct resource *res; ··· 564 pm_runtime_enable(&pdev->dev); 565 pm_runtime_get_sync(&pdev->dev); 566 567 - if (rtc->type->has_kicker) { 568 - rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); 569 - rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); 570 - } 571 572 /* 573 * disable interrupts ··· 627 if (reg != new_ctrl) 628 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 629 630 device_init_wakeup(&pdev->dev, true); 631 632 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, ··· 662 663 err: 664 device_init_wakeup(&pdev->dev, false); 665 - if (rtc->type->has_kicker) 666 - rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); 667 pm_runtime_put_sync(&pdev->dev); 668 pm_runtime_disable(&pdev->dev); 669 ··· 681 682 device_init_wakeup(&pdev->dev, 0); 683 684 /* leave rtc running, but disable irqs */ 685 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 686 687 - if (rtc->type->has_kicker) 688 - rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); 689 690 /* Disable the clock/module */ 691 pm_runtime_put_sync(&pdev->dev); ··· 701 702 rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 703 704 /* 705 * FIXME: the RTC alarm is not currently acting as a wakeup event 706 * source on some platforms, and in fact this enable() call is just ··· 711 enable_irq_wake(rtc->irq_alarm); 712 else 713 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 714 715 /* Disable the clock/module */ 716 pm_runtime_put_sync(dev); ··· 726 /* Enable the clock/module so that we can access the registers */ 727 pm_runtime_get_sync(dev); 728 729 if (device_may_wakeup(dev)) 730 disable_irq_wake(rtc->irq_alarm); 731 else 732 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); 733 734 return 0; 735 } ··· 748 * Keep the ALARM interrupt enabled to allow the system to power up on 749 * alarm events. 750 */ 751 mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 752 mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; 753 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); 754 } 755 756 static struct platform_driver omap_rtc_driver = { 757 .remove = __exit_p(omap_rtc_remove), 758 .shutdown = omap_rtc_shutdown, 759 .driver = { ··· 767 .id_table = omap_rtc_id_table, 768 }; 769 770 - module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); 771 772 MODULE_ALIAS("platform:omap_rtc"); 773 MODULE_AUTHOR("George G. Davis (and others)");
··· 118 #define KICK0_VALUE 0x83e70b13 119 #define KICK1_VALUE 0x95a4f1e0 120 121 + struct omap_rtc; 122 + 123 struct omap_rtc_device_type { 124 bool has_32kclk_en; 125 bool has_irqwakeen; 126 bool has_pmic_mode; 127 bool has_power_up_reset; 128 + void (*lock)(struct omap_rtc *rtc); 129 + void (*unlock)(struct omap_rtc *rtc); 130 }; 131 132 struct omap_rtc { ··· 156 writel(val, rtc->base + reg); 157 } 158 159 + static void am3352_rtc_unlock(struct omap_rtc *rtc) 160 + { 161 + rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); 162 + rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); 163 + } 164 + 165 + static void am3352_rtc_lock(struct omap_rtc *rtc) 166 + { 167 + rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); 168 + rtc_writel(rtc, OMAP_RTC_KICK1_REG, 0); 169 + } 170 + 171 + static void default_rtc_unlock(struct omap_rtc *rtc) 172 + { 173 + } 174 + 175 + static void default_rtc_lock(struct omap_rtc *rtc) 176 + { 177 + } 178 + 179 /* 180 * We rely on the rtc framework to handle locking (rtc->ops_lock), 181 * so the only other requirement is that register accesses which ··· 186 187 /* alarm irq? */ 188 if (irq_data & OMAP_RTC_STATUS_ALARM) { 189 + rtc->type->unlock(rtc); 190 rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); 191 + rtc->type->lock(rtc); 192 events |= RTC_IRQF | RTC_AF; 193 } 194 ··· 218 irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; 219 } 220 rtc_wait_not_busy(rtc); 221 + rtc->type->unlock(rtc); 222 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 223 if (rtc->type->has_irqwakeen) 224 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 225 + rtc->type->lock(rtc); 226 local_irq_enable(); 227 228 return 0; ··· 293 local_irq_disable(); 294 rtc_wait_not_busy(rtc); 295 296 + rtc->type->unlock(rtc); 297 rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); 298 rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); 299 rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); 300 rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); 301 rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); 302 rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); 303 + rtc->type->lock(rtc); 304 305 local_irq_enable(); 306 ··· 341 local_irq_disable(); 342 rtc_wait_not_busy(rtc); 343 344 + rtc->type->unlock(rtc); 345 rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); 346 rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); 347 rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); ··· 362 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 363 if (rtc->type->has_irqwakeen) 364 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 365 + rtc->type->lock(rtc); 366 367 local_irq_enable(); 368 ··· 391 unsigned long now; 392 u32 val; 393 394 + rtc->type->unlock(rtc); 395 /* enable pmic_power_en control */ 396 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); 397 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); ··· 423 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 424 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 425 val | OMAP_RTC_INTERRUPTS_IT_ALARM2); 426 + rtc->type->lock(rtc); 427 428 /* 429 * Wait for alarm to trigger (within two seconds) and external PMIC to ··· 442 443 static const struct omap_rtc_device_type omap_rtc_default_type = { 444 .has_power_up_reset = true, 445 + .lock = default_rtc_lock, 446 + .unlock = default_rtc_unlock, 447 }; 448 449 static const struct omap_rtc_device_type omap_rtc_am3352_type = { 450 .has_32kclk_en = true, 451 .has_irqwakeen = true, 452 .has_pmic_mode = true, 453 + .lock = am3352_rtc_lock, 454 + .unlock = am3352_rtc_unlock, 455 }; 456 457 static const struct omap_rtc_device_type omap_rtc_da830_type = { 458 + .lock = am3352_rtc_lock, 459 + .unlock = am3352_rtc_unlock, 460 }; 461 462 static const struct platform_device_id omap_rtc_id_table[] = { ··· 484 }; 485 MODULE_DEVICE_TABLE(of, omap_rtc_of_match); 486 487 + static int omap_rtc_probe(struct platform_device *pdev) 488 { 489 struct omap_rtc *rtc; 490 struct resource *res; ··· 527 pm_runtime_enable(&pdev->dev); 528 pm_runtime_get_sync(&pdev->dev); 529 530 + rtc->type->unlock(rtc); 531 532 /* 533 * disable interrupts ··· 593 if (reg != new_ctrl) 594 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 595 596 + rtc->type->lock(rtc); 597 + 598 device_init_wakeup(&pdev->dev, true); 599 600 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, ··· 626 627 err: 628 device_init_wakeup(&pdev->dev, false); 629 + rtc->type->lock(rtc); 630 pm_runtime_put_sync(&pdev->dev); 631 pm_runtime_disable(&pdev->dev); 632 ··· 646 647 device_init_wakeup(&pdev->dev, 0); 648 649 + rtc->type->unlock(rtc); 650 /* leave rtc running, but disable irqs */ 651 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 652 653 + rtc->type->lock(rtc); 654 655 /* Disable the clock/module */ 656 pm_runtime_put_sync(&pdev->dev); ··· 666 667 rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 668 669 + rtc->type->unlock(rtc); 670 /* 671 * FIXME: the RTC alarm is not currently acting as a wakeup event 672 * source on some platforms, and in fact this enable() call is just ··· 675 enable_irq_wake(rtc->irq_alarm); 676 else 677 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 678 + rtc->type->lock(rtc); 679 680 /* Disable the clock/module */ 681 pm_runtime_put_sync(dev); ··· 689 /* Enable the clock/module so that we can access the registers */ 690 pm_runtime_get_sync(dev); 691 692 + rtc->type->unlock(rtc); 693 if (device_may_wakeup(dev)) 694 disable_irq_wake(rtc->irq_alarm); 695 else 696 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); 697 + rtc->type->lock(rtc); 698 699 return 0; 700 } ··· 709 * Keep the ALARM interrupt enabled to allow the system to power up on 710 * alarm events. 711 */ 712 + rtc->type->unlock(rtc); 713 mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 714 mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; 715 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); 716 + rtc->type->lock(rtc); 717 } 718 719 static struct platform_driver omap_rtc_driver = { 720 + .probe = omap_rtc_probe, 721 .remove = __exit_p(omap_rtc_remove), 722 .shutdown = omap_rtc_shutdown, 723 .driver = { ··· 725 .id_table = omap_rtc_id_table, 726 }; 727 728 + module_platform_driver(omap_rtc_driver); 729 730 MODULE_ALIAS("platform:omap_rtc"); 731 MODULE_AUTHOR("George G. Davis (and others)");
+2 -1
drivers/rtc/rtc-opal.c
··· 16 * along with this program. 17 */ 18 19 #define DRVNAME "rtc-opal" 20 - #define pr_fmt(fmt) DRVNAME ": " fmt 21 22 #include <linux/module.h> 23 #include <linux/err.h>
··· 16 * along with this program. 17 */ 18 19 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20 + 21 #define DRVNAME "rtc-opal" 22 23 #include <linux/module.h> 24 #include <linux/err.h>
+1 -6
drivers/rtc/rtc-pcf8563.c
··· 246 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 247 { 248 struct pcf8563 *pcf8563 = i2c_get_clientdata(client); 249 - int err; 250 unsigned char buf[9]; 251 252 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " ··· 271 272 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; 273 274 - err = pcf8563_write_block_data(client, PCF8563_REG_SC, 275 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); 276 - if (err) 277 - return err; 278 - 279 - return 0; 280 } 281 282 #ifdef CONFIG_RTC_INTF_DEV
··· 246 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 247 { 248 struct pcf8563 *pcf8563 = i2c_get_clientdata(client); 249 unsigned char buf[9]; 250 251 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " ··· 272 273 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; 274 275 + return pcf8563_write_block_data(client, PCF8563_REG_SC, 276 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); 277 } 278 279 #ifdef CONFIG_RTC_INTF_DEV
+53 -140
drivers/rtc/rtc-s3c.c
··· 39 void __iomem *base; 40 struct clk *rtc_clk; 41 struct clk *rtc_src_clk; 42 - bool enabled; 43 44 struct s3c_rtc_data *data; 45 ··· 66 void (*disable) (struct s3c_rtc *info); 67 }; 68 69 - static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable) 70 { 71 unsigned long irq_flags; 72 73 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 74 - if (enable) { 75 - if (!info->enabled) { 76 - clk_enable(info->rtc_clk); 77 - if (info->data->needs_src_clk) 78 - clk_enable(info->rtc_src_clk); 79 - info->enabled = true; 80 - } 81 - } else { 82 - if (info->enabled) { 83 - if (info->data->needs_src_clk) 84 - clk_disable(info->rtc_src_clk); 85 - clk_disable(info->rtc_clk); 86 - info->enabled = false; 87 - } 88 - } 89 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 90 } 91 ··· 117 118 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); 119 120 - clk_enable(info->rtc_clk); 121 - if (info->data->needs_src_clk) 122 - clk_enable(info->rtc_src_clk); 123 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 124 125 if (enabled) 126 tmp |= S3C2410_RTCALM_ALMEN; 127 128 writeb(tmp, info->base + S3C2410_RTCALM); 129 - if (info->data->needs_src_clk) 130 - clk_disable(info->rtc_src_clk); 131 - clk_disable(info->rtc_clk); 132 133 - s3c_rtc_alarm_clk_enable(info, enabled); 134 135 return 0; 136 } ··· 137 if (!is_power_of_2(freq)) 138 return -EINVAL; 139 140 - clk_enable(info->rtc_clk); 141 - if (info->data->needs_src_clk) 142 - clk_enable(info->rtc_src_clk); 143 spin_lock_irq(&info->pie_lock); 144 145 if (info->data->set_freq) 146 info->data->set_freq(info, freq); 147 148 spin_unlock_irq(&info->pie_lock); 149 - if (info->data->needs_src_clk) 150 - clk_disable(info->rtc_src_clk); 151 - clk_disable(info->rtc_clk); 152 153 return 0; 154 } ··· 153 struct s3c_rtc *info = dev_get_drvdata(dev); 154 unsigned int have_retried = 0; 155 156 - clk_enable(info->rtc_clk); 157 - if (info->data->needs_src_clk) 158 - clk_enable(info->rtc_src_clk); 159 160 retry_get_time: 161 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); ··· 180 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); 181 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); 182 183 rtc_tm->tm_year += 100; 184 185 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", ··· 189 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 190 191 rtc_tm->tm_mon -= 1; 192 - 193 - if (info->data->needs_src_clk) 194 - clk_disable(info->rtc_src_clk); 195 - clk_disable(info->rtc_clk); 196 197 return rtc_valid_tm(rtc_tm); 198 } ··· 209 return -EINVAL; 210 } 211 212 - clk_enable(info->rtc_clk); 213 - if (info->data->needs_src_clk) 214 - clk_enable(info->rtc_src_clk); 215 216 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); 217 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); ··· 218 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); 219 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); 220 221 - if (info->data->needs_src_clk) 222 - clk_disable(info->rtc_src_clk); 223 - clk_disable(info->rtc_clk); 224 225 return 0; 226 } ··· 229 struct rtc_time *alm_tm = &alrm->time; 230 unsigned int alm_en; 231 232 - clk_enable(info->rtc_clk); 233 - if (info->data->needs_src_clk) 234 - clk_enable(info->rtc_src_clk); 235 236 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); 237 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); ··· 240 241 alm_en = readb(info->base + S3C2410_RTCALM); 242 243 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 244 245 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", ··· 249 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 250 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 251 252 - 253 /* decode the alarm enable field */ 254 - 255 if (alm_en & S3C2410_RTCALM_SECEN) 256 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 257 else ··· 282 else 283 alm_tm->tm_year = -1; 284 285 - if (info->data->needs_src_clk) 286 - clk_disable(info->rtc_src_clk); 287 - clk_disable(info->rtc_clk); 288 - 289 return 0; 290 } 291 ··· 291 struct rtc_time *tm = &alrm->time; 292 unsigned int alrm_en; 293 294 - clk_enable(info->rtc_clk); 295 - if (info->data->needs_src_clk) 296 - clk_enable(info->rtc_src_clk); 297 - 298 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 299 alrm->enabled, 300 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 301 tm->tm_hour, tm->tm_min, tm->tm_sec); 302 303 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 304 writeb(0x00, info->base + S3C2410_RTCALM); ··· 320 321 writeb(alrm_en, info->base + S3C2410_RTCALM); 322 323 - s3c_rtc_setaie(dev, alrm->enabled); 324 325 - if (info->data->needs_src_clk) 326 - clk_disable(info->rtc_src_clk); 327 - clk_disable(info->rtc_clk); 328 329 return 0; 330 } ··· 331 { 332 struct s3c_rtc *info = dev_get_drvdata(dev); 333 334 - clk_enable(info->rtc_clk); 335 - if (info->data->needs_src_clk) 336 - clk_enable(info->rtc_src_clk); 337 338 if (info->data->enable_tick) 339 info->data->enable_tick(info, seq); 340 341 - if (info->data->needs_src_clk) 342 - clk_disable(info->rtc_src_clk); 343 - clk_disable(info->rtc_clk); 344 345 return 0; 346 } ··· 353 static void s3c24xx_rtc_enable(struct s3c_rtc *info) 354 { 355 unsigned int con, tmp; 356 - 357 - clk_enable(info->rtc_clk); 358 - if (info->data->needs_src_clk) 359 - clk_enable(info->rtc_src_clk); 360 361 con = readw(info->base + S3C2410_RTCCON); 362 /* re-enable the device, and check it is ok */ ··· 379 writew(tmp & ~S3C2410_RTCCON_CLKRST, 380 info->base + S3C2410_RTCCON); 381 } 382 - 383 - if (info->data->needs_src_clk) 384 - clk_disable(info->rtc_src_clk); 385 - clk_disable(info->rtc_clk); 386 } 387 388 static void s3c24xx_rtc_disable(struct s3c_rtc *info) 389 { 390 unsigned int con; 391 - 392 - clk_enable(info->rtc_clk); 393 - if (info->data->needs_src_clk) 394 - clk_enable(info->rtc_src_clk); 395 396 con = readw(info->base + S3C2410_RTCCON); 397 con &= ~S3C2410_RTCCON_RTCEN; ··· 392 con = readb(info->base + S3C2410_TICNT); 393 con &= ~S3C2410_TICNT_ENABLE; 394 writeb(con, info->base + S3C2410_TICNT); 395 - 396 - if (info->data->needs_src_clk) 397 - clk_disable(info->rtc_src_clk); 398 - clk_disable(info->rtc_clk); 399 } 400 401 static void s3c6410_rtc_disable(struct s3c_rtc *info) 402 { 403 unsigned int con; 404 405 - clk_enable(info->rtc_clk); 406 - if (info->data->needs_src_clk) 407 - clk_enable(info->rtc_src_clk); 408 - 409 con = readw(info->base + S3C2410_RTCCON); 410 con &= ~S3C64XX_RTCCON_TICEN; 411 con &= ~S3C2410_RTCCON_RTCEN; 412 writew(con, info->base + S3C2410_RTCCON); 413 - 414 - if (info->data->needs_src_clk) 415 - clk_disable(info->rtc_src_clk); 416 - clk_disable(info->rtc_clk); 417 } 418 419 static int s3c_rtc_remove(struct platform_device *pdev) ··· 496 497 device_init_wakeup(&pdev->dev, 1); 498 499 /* register RTC and exit */ 500 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, 501 THIS_MODULE); ··· 533 goto err_nortc; 534 } 535 536 - /* Check RTC Time */ 537 - s3c_rtc_gettime(&pdev->dev, &rtc_tm); 538 - 539 - if (rtc_valid_tm(&rtc_tm)) { 540 - rtc_tm.tm_year = 100; 541 - rtc_tm.tm_mon = 0; 542 - rtc_tm.tm_mday = 1; 543 - rtc_tm.tm_hour = 0; 544 - rtc_tm.tm_min = 0; 545 - rtc_tm.tm_sec = 0; 546 - 547 - s3c_rtc_settime(&pdev->dev, &rtc_tm); 548 - 549 - dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); 550 - } 551 - 552 if (info->data->select_tick_clk) 553 info->data->select_tick_clk(info); 554 555 s3c_rtc_setfreq(info, 1); 556 557 - if (info->data->needs_src_clk) 558 - clk_disable(info->rtc_src_clk); 559 - clk_disable(info->rtc_clk); 560 561 return 0; 562 563 err_nortc: 564 if (info->data->disable) 565 info->data->disable(info); 566 clk_disable_unprepare(info->rtc_clk); 567 568 return ret; ··· 559 { 560 struct s3c_rtc *info = dev_get_drvdata(dev); 561 562 - clk_enable(info->rtc_clk); 563 - if (info->data->needs_src_clk) 564 - clk_enable(info->rtc_src_clk); 565 566 /* save TICNT for anyone using periodic interrupts */ 567 if (info->data->save_tick_cnt) ··· 575 dev_err(dev, "enable_irq_wake failed\n"); 576 } 577 578 - if (info->data->needs_src_clk) 579 - clk_disable(info->rtc_src_clk); 580 - clk_disable(info->rtc_clk); 581 - 582 return 0; 583 } 584 ··· 582 { 583 struct s3c_rtc *info = dev_get_drvdata(dev); 584 585 - clk_enable(info->rtc_clk); 586 - if (info->data->needs_src_clk) 587 - clk_enable(info->rtc_src_clk); 588 - 589 if (info->data->enable) 590 info->data->enable(info); 591 592 if (info->data->restore_tick_cnt) 593 info->data->restore_tick_cnt(info); 594 595 if (device_may_wakeup(dev) && info->wake_en) { 596 disable_irq_wake(info->irq_alarm); 597 info->wake_en = false; 598 } 599 - 600 - if (info->data->needs_src_clk) 601 - clk_disable(info->rtc_src_clk); 602 - clk_disable(info->rtc_clk); 603 604 return 0; 605 } ··· 602 603 static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) 604 { 605 - clk_enable(info->rtc_clk); 606 - if (info->data->needs_src_clk) 607 - clk_enable(info->rtc_src_clk); 608 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 609 - if (info->data->needs_src_clk) 610 - clk_disable(info->rtc_src_clk); 611 - clk_disable(info->rtc_clk); 612 - 613 - s3c_rtc_alarm_clk_enable(info, false); 614 } 615 616 static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) 617 { 618 - clk_enable(info->rtc_clk); 619 - if (info->data->needs_src_clk) 620 - clk_enable(info->rtc_src_clk); 621 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 622 writeb(mask, info->base + S3C2410_INTP); 623 - if (info->data->needs_src_clk) 624 - clk_disable(info->rtc_src_clk); 625 - clk_disable(info->rtc_clk); 626 - 627 - s3c_rtc_alarm_clk_enable(info, false); 628 } 629 630 static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq)
··· 39 void __iomem *base; 40 struct clk *rtc_clk; 41 struct clk *rtc_src_clk; 42 43 struct s3c_rtc_data *data; 44 ··· 67 void (*disable) (struct s3c_rtc *info); 68 }; 69 70 + static void s3c_rtc_enable_clk(struct s3c_rtc *info) 71 { 72 unsigned long irq_flags; 73 74 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 75 + clk_enable(info->rtc_clk); 76 + if (info->data->needs_src_clk) 77 + clk_enable(info->rtc_src_clk); 78 + spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 79 + } 80 + 81 + static void s3c_rtc_disable_clk(struct s3c_rtc *info) 82 + { 83 + unsigned long irq_flags; 84 + 85 + spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 86 + if (info->data->needs_src_clk) 87 + clk_disable(info->rtc_src_clk); 88 + clk_disable(info->rtc_clk); 89 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 90 } 91 ··· 119 120 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); 121 122 + s3c_rtc_enable_clk(info); 123 + 124 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 125 126 if (enabled) 127 tmp |= S3C2410_RTCALM_ALMEN; 128 129 writeb(tmp, info->base + S3C2410_RTCALM); 130 131 + s3c_rtc_disable_clk(info); 132 133 return 0; 134 } ··· 143 if (!is_power_of_2(freq)) 144 return -EINVAL; 145 146 spin_lock_irq(&info->pie_lock); 147 148 if (info->data->set_freq) 149 info->data->set_freq(info, freq); 150 151 spin_unlock_irq(&info->pie_lock); 152 153 return 0; 154 } ··· 165 struct s3c_rtc *info = dev_get_drvdata(dev); 166 unsigned int have_retried = 0; 167 168 + s3c_rtc_enable_clk(info); 169 170 retry_get_time: 171 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); ··· 194 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); 195 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); 196 197 + s3c_rtc_disable_clk(info); 198 + 199 rtc_tm->tm_year += 100; 200 201 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", ··· 201 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 202 203 rtc_tm->tm_mon -= 1; 204 205 return rtc_valid_tm(rtc_tm); 206 } ··· 225 return -EINVAL; 226 } 227 228 + s3c_rtc_enable_clk(info); 229 230 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); 231 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); ··· 236 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); 237 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); 238 239 + s3c_rtc_disable_clk(info); 240 241 return 0; 242 } ··· 249 struct rtc_time *alm_tm = &alrm->time; 250 unsigned int alm_en; 251 252 + s3c_rtc_enable_clk(info); 253 254 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); 255 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); ··· 262 263 alm_en = readb(info->base + S3C2410_RTCALM); 264 265 + s3c_rtc_disable_clk(info); 266 + 267 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 268 269 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", ··· 269 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 270 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 271 272 /* decode the alarm enable field */ 273 if (alm_en & S3C2410_RTCALM_SECEN) 274 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 275 else ··· 304 else 305 alm_tm->tm_year = -1; 306 307 return 0; 308 } 309 ··· 317 struct rtc_time *tm = &alrm->time; 318 unsigned int alrm_en; 319 320 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 321 alrm->enabled, 322 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 323 tm->tm_hour, tm->tm_min, tm->tm_sec); 324 + 325 + s3c_rtc_enable_clk(info); 326 327 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 328 writeb(0x00, info->base + S3C2410_RTCALM); ··· 348 349 writeb(alrm_en, info->base + S3C2410_RTCALM); 350 351 + s3c_rtc_disable_clk(info); 352 353 + s3c_rtc_setaie(dev, alrm->enabled); 354 355 return 0; 356 } ··· 361 { 362 struct s3c_rtc *info = dev_get_drvdata(dev); 363 364 + s3c_rtc_enable_clk(info); 365 366 if (info->data->enable_tick) 367 info->data->enable_tick(info, seq); 368 369 + s3c_rtc_disable_clk(info); 370 371 return 0; 372 } ··· 387 static void s3c24xx_rtc_enable(struct s3c_rtc *info) 388 { 389 unsigned int con, tmp; 390 391 con = readw(info->base + S3C2410_RTCCON); 392 /* re-enable the device, and check it is ok */ ··· 417 writew(tmp & ~S3C2410_RTCCON_CLKRST, 418 info->base + S3C2410_RTCCON); 419 } 420 } 421 422 static void s3c24xx_rtc_disable(struct s3c_rtc *info) 423 { 424 unsigned int con; 425 426 con = readw(info->base + S3C2410_RTCCON); 427 con &= ~S3C2410_RTCCON_RTCEN; ··· 438 con = readb(info->base + S3C2410_TICNT); 439 con &= ~S3C2410_TICNT_ENABLE; 440 writeb(con, info->base + S3C2410_TICNT); 441 } 442 443 static void s3c6410_rtc_disable(struct s3c_rtc *info) 444 { 445 unsigned int con; 446 447 con = readw(info->base + S3C2410_RTCCON); 448 con &= ~S3C64XX_RTCCON_TICEN; 449 con &= ~S3C2410_RTCCON_RTCEN; 450 writew(con, info->base + S3C2410_RTCCON); 451 } 452 453 static int s3c_rtc_remove(struct platform_device *pdev) ··· 554 555 device_init_wakeup(&pdev->dev, 1); 556 557 + /* Check RTC Time */ 558 + if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) { 559 + rtc_tm.tm_year = 100; 560 + rtc_tm.tm_mon = 0; 561 + rtc_tm.tm_mday = 1; 562 + rtc_tm.tm_hour = 0; 563 + rtc_tm.tm_min = 0; 564 + rtc_tm.tm_sec = 0; 565 + 566 + s3c_rtc_settime(&pdev->dev, &rtc_tm); 567 + 568 + dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); 569 + } 570 + 571 /* register RTC and exit */ 572 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, 573 THIS_MODULE); ··· 577 goto err_nortc; 578 } 579 580 if (info->data->select_tick_clk) 581 info->data->select_tick_clk(info); 582 583 s3c_rtc_setfreq(info, 1); 584 585 + s3c_rtc_disable_clk(info); 586 587 return 0; 588 589 err_nortc: 590 if (info->data->disable) 591 info->data->disable(info); 592 + 593 + if (info->data->needs_src_clk) 594 + clk_disable_unprepare(info->rtc_src_clk); 595 clk_disable_unprepare(info->rtc_clk); 596 597 return ret; ··· 618 { 619 struct s3c_rtc *info = dev_get_drvdata(dev); 620 621 + s3c_rtc_enable_clk(info); 622 623 /* save TICNT for anyone using periodic interrupts */ 624 if (info->data->save_tick_cnt) ··· 636 dev_err(dev, "enable_irq_wake failed\n"); 637 } 638 639 return 0; 640 } 641 ··· 647 { 648 struct s3c_rtc *info = dev_get_drvdata(dev); 649 650 if (info->data->enable) 651 info->data->enable(info); 652 653 if (info->data->restore_tick_cnt) 654 info->data->restore_tick_cnt(info); 655 656 + s3c_rtc_disable_clk(info); 657 + 658 if (device_may_wakeup(dev) && info->wake_en) { 659 disable_irq_wake(info->irq_alarm); 660 info->wake_en = false; 661 } 662 663 return 0; 664 } ··· 673 674 static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) 675 { 676 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 677 } 678 679 static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) 680 { 681 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 682 writeb(mask, info->base + S3C2410_INTP); 683 } 684 685 static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq)
+28 -6
drivers/rtc/rtc-s5m.c
··· 15 * GNU General Public License for more details. 16 */ 17 18 #include <linux/module.h> 19 #include <linux/i2c.h> 20 #include <linux/bcd.h> ··· 92 struct regmap *regmap; 93 struct rtc_device *rtc_dev; 94 int irq; 95 - int device_type; 96 int rtc_24hr_mode; 97 const struct s5m_rtc_reg_config *regs; 98 }; ··· 148 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 149 150 if (tm->tm_year < 100) { 151 - pr_err("s5m8767 RTC cannot handle the year %d.\n", 152 1900 + tm->tm_year); 153 return -EINVAL; 154 } else { ··· 189 val &= S5M_ALARM0_STATUS; 190 break; 191 case S2MPS14X: 192 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, 193 &val); 194 val &= S2MPS_ALARM0_STATUS; ··· 255 case S2MPS14X: 256 data |= S2MPS_RTC_RUDR_MASK; 257 break; 258 default: 259 return -EINVAL; 260 } ··· 270 } 271 272 ret = s5m8767_wait_for_udr_update(info); 273 274 return ret; 275 } ··· 317 u8 data[info->regs->regs_count]; 318 int ret; 319 320 - if (info->device_type == S2MPS14X) { 321 ret = regmap_update_bits(info->regmap, 322 info->regs->rtc_udr_update, 323 S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); ··· 340 341 case S5M8767X: 342 case S2MPS14X: 343 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); 344 break; 345 ··· 367 break; 368 case S5M8767X: 369 case S2MPS14X: 370 ret = s5m8767_tm_to_data(tm, data); 371 break; 372 default: ··· 415 416 case S5M8767X: 417 case S2MPS14X: 418 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 419 alrm->enabled = 0; 420 for (i = 0; i < info->regs->regs_count; i++) { ··· 464 465 case S5M8767X: 466 case S2MPS14X: 467 for (i = 0; i < info->regs->regs_count; i++) 468 data[i] &= ~ALARM_ENABLE_MASK; 469 ··· 509 510 case S5M8767X: 511 case S2MPS14X: 512 data[RTC_SEC] |= ALARM_ENABLE_MASK; 513 data[RTC_MIN] |= ALARM_ENABLE_MASK; 514 data[RTC_HOUR] |= ALARM_ENABLE_MASK; ··· 549 550 case S5M8767X: 551 case S2MPS14X: 552 s5m8767_tm_to_data(&alrm->time, data); 553 break; 554 ··· 632 break; 633 634 case S2MPS14X: 635 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 636 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); 637 break; ··· 668 if (!info) 669 return -ENOMEM; 670 671 - switch (pdata->device_type) { 672 case S2MPS14X: 673 regmap_cfg = &s2mps14_rtc_regmap_config; 674 info->regs = &s2mps_rtc_regs; 675 alarm_irq = S2MPS14_IRQ_RTCA0; ··· 686 alarm_irq = S5M8767_IRQ_RTCA1; 687 break; 688 default: 689 - dev_err(&pdev->dev, "Device type is not supported by RTC driver\n"); 690 return -ENODEV; 691 } 692 ··· 708 709 info->dev = &pdev->dev; 710 info->s5m87xx = s5m87xx; 711 - info->device_type = s5m87xx->device_type; 712 713 if (s5m87xx->irq_data) { 714 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); ··· 793 794 static const struct platform_device_id s5m_rtc_id[] = { 795 { "s5m-rtc", S5M8767X }, 796 { "s2mps14-rtc", S2MPS14X }, 797 { }, 798 };
··· 15 * GNU General Public License for more details. 16 */ 17 18 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 19 + 20 #include <linux/module.h> 21 #include <linux/i2c.h> 22 #include <linux/bcd.h> ··· 90 struct regmap *regmap; 91 struct rtc_device *rtc_dev; 92 int irq; 93 + enum sec_device_type device_type; 94 int rtc_24hr_mode; 95 const struct s5m_rtc_reg_config *regs; 96 }; ··· 146 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 147 148 if (tm->tm_year < 100) { 149 + pr_err("RTC cannot handle the year %d\n", 150 1900 + tm->tm_year); 151 return -EINVAL; 152 } else { ··· 187 val &= S5M_ALARM0_STATUS; 188 break; 189 case S2MPS14X: 190 + case S2MPS13X: 191 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, 192 &val); 193 val &= S2MPS_ALARM0_STATUS; ··· 252 case S2MPS14X: 253 data |= S2MPS_RTC_RUDR_MASK; 254 break; 255 + case S2MPS13X: 256 + data |= S2MPS13_RTC_AUDR_MASK; 257 + break; 258 default: 259 return -EINVAL; 260 } ··· 264 } 265 266 ret = s5m8767_wait_for_udr_update(info); 267 + 268 + /* On S2MPS13 the AUDR is not auto-cleared */ 269 + if (info->device_type == S2MPS13X) 270 + regmap_update_bits(info->regmap, info->regs->rtc_udr_update, 271 + S2MPS13_RTC_AUDR_MASK, 0); 272 273 return ret; 274 } ··· 306 u8 data[info->regs->regs_count]; 307 int ret; 308 309 + if (info->device_type == S2MPS14X || info->device_type == S2MPS13X) { 310 ret = regmap_update_bits(info->regmap, 311 info->regs->rtc_udr_update, 312 S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); ··· 329 330 case S5M8767X: 331 case S2MPS14X: 332 + case S2MPS13X: 333 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); 334 break; 335 ··· 355 break; 356 case S5M8767X: 357 case S2MPS14X: 358 + case S2MPS13X: 359 ret = s5m8767_tm_to_data(tm, data); 360 break; 361 default: ··· 402 403 case S5M8767X: 404 case S2MPS14X: 405 + case S2MPS13X: 406 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 407 alrm->enabled = 0; 408 for (i = 0; i < info->regs->regs_count; i++) { ··· 450 451 case S5M8767X: 452 case S2MPS14X: 453 + case S2MPS13X: 454 for (i = 0; i < info->regs->regs_count; i++) 455 data[i] &= ~ALARM_ENABLE_MASK; 456 ··· 494 495 case S5M8767X: 496 case S2MPS14X: 497 + case S2MPS13X: 498 data[RTC_SEC] |= ALARM_ENABLE_MASK; 499 data[RTC_MIN] |= ALARM_ENABLE_MASK; 500 data[RTC_HOUR] |= ALARM_ENABLE_MASK; ··· 533 534 case S5M8767X: 535 case S2MPS14X: 536 + case S2MPS13X: 537 s5m8767_tm_to_data(&alrm->time, data); 538 break; 539 ··· 615 break; 616 617 case S2MPS14X: 618 + case S2MPS13X: 619 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 620 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); 621 break; ··· 650 if (!info) 651 return -ENOMEM; 652 653 + switch (platform_get_device_id(pdev)->driver_data) { 654 case S2MPS14X: 655 + case S2MPS13X: 656 regmap_cfg = &s2mps14_rtc_regmap_config; 657 info->regs = &s2mps_rtc_regs; 658 alarm_irq = S2MPS14_IRQ_RTCA0; ··· 667 alarm_irq = S5M8767_IRQ_RTCA1; 668 break; 669 default: 670 + dev_err(&pdev->dev, 671 + "Device type %lu is not supported by RTC driver\n", 672 + platform_get_device_id(pdev)->driver_data); 673 return -ENODEV; 674 } 675 ··· 687 688 info->dev = &pdev->dev; 689 info->s5m87xx = s5m87xx; 690 + info->device_type = platform_get_device_id(pdev)->driver_data; 691 692 if (s5m87xx->irq_data) { 693 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); ··· 772 773 static const struct platform_device_id s5m_rtc_id[] = { 774 { "s5m-rtc", S5M8767X }, 775 + { "s2mps13-rtc", S2MPS13X }, 776 { "s2mps14-rtc", S2MPS14X }, 777 { }, 778 };
+60 -6
drivers/rtc/rtc-stmp3xxx.c
··· 42 #define STMP3XXX_RTC_STAT 0x10 43 #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 44 #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 45 46 #define STMP3XXX_RTC_SECONDS 0x30 47 ··· 54 #define STMP3XXX_RTC_PERSISTENT0 0x60 55 #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 56 #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 57 - #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN 0x00000002 58 - #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN 0x00000004 59 - #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE 0x00000080 60 61 #define STMP3XXX_RTC_PERSISTENT1 0x70 62 /* missing bitmask in headers */ ··· 254 { 255 struct stmp3xxx_rtc_data *rtc_data; 256 struct resource *r; 257 int err; 258 259 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); ··· 277 278 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 279 280 - if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & 281 - STMP3XXX_RTC_STAT_RTC_PRESENT)) { 282 dev_err(&pdev->dev, "no device onboard\n"); 283 return -ENODEV; 284 } ··· 291 return err; 292 } 293 294 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 295 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 296 - STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 297 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 298 299 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN |
··· 42 #define STMP3XXX_RTC_STAT 0x10 43 #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 44 #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 45 + #define STMP3XXX_RTC_STAT_XTAL32000_PRESENT 0x10000000 46 + #define STMP3XXX_RTC_STAT_XTAL32768_PRESENT 0x08000000 47 48 #define STMP3XXX_RTC_SECONDS 0x30 49 ··· 52 #define STMP3XXX_RTC_PERSISTENT0 0x60 53 #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 54 #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 55 + #define STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE (1 << 0) 56 + #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN (1 << 1) 57 + #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN (1 << 2) 58 + #define STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP (1 << 4) 59 + #define STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP (1 << 5) 60 + #define STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ (1 << 6) 61 + #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE (1 << 7) 62 63 #define STMP3XXX_RTC_PERSISTENT1 0x70 64 /* missing bitmask in headers */ ··· 248 { 249 struct stmp3xxx_rtc_data *rtc_data; 250 struct resource *r; 251 + u32 rtc_stat; 252 + u32 pers0_set, pers0_clr; 253 + u32 crystalfreq = 0; 254 int err; 255 256 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); ··· 268 269 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 270 271 + rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT); 272 + if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) { 273 dev_err(&pdev->dev, "no device onboard\n"); 274 return -ENODEV; 275 } ··· 282 return err; 283 } 284 285 + /* 286 + * Obviously the rtc needs a clock input to be able to run. 287 + * This clock can be provided by an external 32k crystal. If that one is 288 + * missing XTAL must not be disabled in suspend which consumes a 289 + * lot of power. Normally the presence and exact frequency (supported 290 + * are 32000 Hz and 32768 Hz) is detectable from fuses, but as reality 291 + * proves these fuses are not blown correctly on all machines, so the 292 + * frequency can be overridden in the device tree. 293 + */ 294 + if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32000_PRESENT) 295 + crystalfreq = 32000; 296 + else if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32768_PRESENT) 297 + crystalfreq = 32768; 298 + 299 + of_property_read_u32(pdev->dev.of_node, "stmp,crystal-freq", 300 + &crystalfreq); 301 + 302 + switch (crystalfreq) { 303 + case 32000: 304 + /* keep 32kHz crystal running in low-power mode */ 305 + pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ | 306 + STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | 307 + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; 308 + pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP; 309 + break; 310 + case 32768: 311 + /* keep 32.768kHz crystal running in low-power mode */ 312 + pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | 313 + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; 314 + pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP | 315 + STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ; 316 + break; 317 + default: 318 + dev_warn(&pdev->dev, 319 + "invalid crystal-freq specified in device-tree. Assuming no crystal\n"); 320 + /* fall-through */ 321 + case 0: 322 + /* keep XTAL on in low-power mode */ 323 + pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP; 324 + pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | 325 + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; 326 + } 327 + 328 + writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); 329 + 330 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 331 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 332 + STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr, 333 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 334 335 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN |
+5 -4
drivers/rtc/rtc-twl.c
··· 18 * 2 of the License, or (at your option) any later version. 19 */ 20 21 #include <linux/kernel.h> 22 #include <linux/errno.h> 23 #include <linux/init.h> ··· 147 148 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 149 if (ret < 0) 150 - pr_err("twl_rtc: Could not read TWL" 151 - "register %X - error %d\n", reg, ret); 152 return ret; 153 } 154 ··· 160 161 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 162 if (ret < 0) 163 - pr_err("twl_rtc: Could not write TWL" 164 - "register %X - error %d\n", reg, ret); 165 return ret; 166 } 167
··· 18 * 2 of the License, or (at your option) any later version. 19 */ 20 21 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 + 23 #include <linux/kernel.h> 24 #include <linux/errno.h> 25 #include <linux/init.h> ··· 145 146 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 147 if (ret < 0) 148 + pr_err("Could not read TWL register %X - error %d\n", reg, ret); 149 return ret; 150 } 151 ··· 159 160 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 161 if (ret < 0) 162 + pr_err("Could not write TWL register %X - error %d\n", 163 + reg, ret); 164 return ret; 165 } 166
+2 -2
drivers/rtc/rtc-x1205.c
··· 22 #include <linux/rtc.h> 23 #include <linux/delay.h> 24 #include <linux/module.h> 25 26 #define DRV_VERSION "1.0.8" 27 ··· 367 * perform sign extension. The formula is 368 * Catr = (atr * 0.25pF) + 11.00pF. 369 */ 370 - if (atr & 0x20) 371 - atr |= 0xC0; 372 373 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); 374
··· 22 #include <linux/rtc.h> 23 #include <linux/delay.h> 24 #include <linux/module.h> 25 + #include <linux/bitops.h> 26 27 #define DRV_VERSION "1.0.8" 28 ··· 366 * perform sign extension. The formula is 367 * Catr = (atr * 0.25pF) + 11.00pF. 368 */ 369 + atr = sign_extend32(atr, 5); 370 371 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); 372
+9 -13
drivers/scsi/bfa/bfad.c
··· 1079 int 1080 bfad_worker(void *ptr) 1081 { 1082 - struct bfad_s *bfad; 1083 - unsigned long flags; 1084 1085 - bfad = (struct bfad_s *)ptr; 1086 1087 - while (!kthread_should_stop()) { 1088 1089 - /* Send event BFAD_E_INIT_SUCCESS */ 1090 - bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); 1091 - 1092 - spin_lock_irqsave(&bfad->bfad_lock, flags); 1093 - bfad->bfad_tsk = NULL; 1094 - spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1095 - 1096 - break; 1097 - } 1098 1099 return 0; 1100 }
··· 1079 int 1080 bfad_worker(void *ptr) 1081 { 1082 + struct bfad_s *bfad = ptr; 1083 + unsigned long flags; 1084 1085 + if (kthread_should_stop()) 1086 + return 0; 1087 1088 + /* Send event BFAD_E_INIT_SUCCESS */ 1089 + bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); 1090 1091 + spin_lock_irqsave(&bfad->bfad_lock, flags); 1092 + bfad->bfad_tsk = NULL; 1093 + spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1094 1095 return 0; 1096 }
+1
firmware/ihex2fw.c
··· 86 case 'j': 87 include_jump = 1; 88 break; 89 return usage(); 90 } 91 }
··· 86 case 'j': 87 include_jump = 1; 88 break; 89 + default: 90 return usage(); 91 } 92 }
+1
fs/adfs/dir_fplus.c
··· 61 kcalloc(size, sizeof(struct buffer_head *), 62 GFP_KERNEL); 63 if (!bh_fplus) { 64 adfs_error(sb, "not enough memory for" 65 " dir object %X (%d blocks)", id, size); 66 goto out;
··· 61 kcalloc(size, sizeof(struct buffer_head *), 62 GFP_KERNEL); 63 if (!bh_fplus) { 64 + ret = -ENOMEM; 65 adfs_error(sb, "not enough memory for" 66 " dir object %X (%d blocks)", id, size); 67 goto out;
+15 -5
fs/adfs/super.c
··· 316 dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL); 317 if (dm == NULL) { 318 adfs_error(sb, "not enough memory"); 319 - return NULL; 320 } 321 322 for (zone = 0; zone < nzones; zone++, map_addr++) { ··· 349 brelse(dm[zone].dm_bh); 350 351 kfree(dm); 352 - return NULL; 353 } 354 355 static inline unsigned long adfs_discsize(struct adfs_discrecord *dr, int block_bits) ··· 370 unsigned char *b_data; 371 struct adfs_sb_info *asb; 372 struct inode *root; 373 374 sb->s_flags |= MS_NODIRATIME; 375 ··· 392 sb_set_blocksize(sb, BLOCK_SIZE); 393 if (!(bh = sb_bread(sb, ADFS_DISCRECORD / BLOCK_SIZE))) { 394 adfs_error(sb, "unable to read superblock"); 395 goto error; 396 } 397 ··· 402 if (!silent) 403 printk("VFS: Can't find an adfs filesystem on dev " 404 "%s.\n", sb->s_id); 405 goto error_free_bh; 406 } 407 ··· 415 if (!silent) 416 printk("VPS: Can't find an adfs filesystem on dev " 417 "%s.\n", sb->s_id); 418 goto error_free_bh; 419 } 420 ··· 425 if (!bh) { 426 adfs_error(sb, "couldn't read superblock on " 427 "2nd try."); 428 goto error; 429 } 430 b_data = bh->b_data + (ADFS_DISCRECORD % sb->s_blocksize); 431 if (adfs_checkbblk(b_data)) { 432 adfs_error(sb, "disc record mismatch, very weird!"); 433 goto error_free_bh; 434 } 435 dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET); ··· 439 if (!silent) 440 printk(KERN_ERR "VFS: Unsupported blocksize on dev " 441 "%s.\n", sb->s_id); 442 goto error; 443 } 444 ··· 454 asb->s_size = adfs_discsize(dr, sb->s_blocksize_bits); 455 asb->s_version = dr->format_version; 456 asb->s_log2sharesize = dr->log2sharesize; 457 - 458 asb->s_map = adfs_read_map(sb, dr); 459 - if (!asb->s_map) 460 goto error_free_bh; 461 462 brelse(bh); 463 ··· 508 brelse(asb->s_map[i].dm_bh); 509 kfree(asb->s_map); 510 adfs_error(sb, "get root inode failed\n"); 511 goto error; 512 } 513 return 0; ··· 518 error: 519 sb->s_fs_info = NULL; 520 kfree(asb); 521 - return -EINVAL; 522 } 523 524 static struct dentry *adfs_mount(struct file_system_type *fs_type,
··· 316 dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL); 317 if (dm == NULL) { 318 adfs_error(sb, "not enough memory"); 319 + return ERR_PTR(-ENOMEM); 320 } 321 322 for (zone = 0; zone < nzones; zone++, map_addr++) { ··· 349 brelse(dm[zone].dm_bh); 350 351 kfree(dm); 352 + return ERR_PTR(-EIO); 353 } 354 355 static inline unsigned long adfs_discsize(struct adfs_discrecord *dr, int block_bits) ··· 370 unsigned char *b_data; 371 struct adfs_sb_info *asb; 372 struct inode *root; 373 + int ret = -EINVAL; 374 375 sb->s_flags |= MS_NODIRATIME; 376 ··· 391 sb_set_blocksize(sb, BLOCK_SIZE); 392 if (!(bh = sb_bread(sb, ADFS_DISCRECORD / BLOCK_SIZE))) { 393 adfs_error(sb, "unable to read superblock"); 394 + ret = -EIO; 395 goto error; 396 } 397 ··· 400 if (!silent) 401 printk("VFS: Can't find an adfs filesystem on dev " 402 "%s.\n", sb->s_id); 403 + ret = -EINVAL; 404 goto error_free_bh; 405 } 406 ··· 412 if (!silent) 413 printk("VPS: Can't find an adfs filesystem on dev " 414 "%s.\n", sb->s_id); 415 + ret = -EINVAL; 416 goto error_free_bh; 417 } 418 ··· 421 if (!bh) { 422 adfs_error(sb, "couldn't read superblock on " 423 "2nd try."); 424 + ret = -EIO; 425 goto error; 426 } 427 b_data = bh->b_data + (ADFS_DISCRECORD % sb->s_blocksize); 428 if (adfs_checkbblk(b_data)) { 429 adfs_error(sb, "disc record mismatch, very weird!"); 430 + ret = -EINVAL; 431 goto error_free_bh; 432 } 433 dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET); ··· 433 if (!silent) 434 printk(KERN_ERR "VFS: Unsupported blocksize on dev " 435 "%s.\n", sb->s_id); 436 + ret = -EINVAL; 437 goto error; 438 } 439 ··· 447 asb->s_size = adfs_discsize(dr, sb->s_blocksize_bits); 448 asb->s_version = dr->format_version; 449 asb->s_log2sharesize = dr->log2sharesize; 450 + 451 asb->s_map = adfs_read_map(sb, dr); 452 + if (IS_ERR(asb->s_map)) { 453 + ret = PTR_ERR(asb->s_map); 454 goto error_free_bh; 455 + } 456 457 brelse(bh); 458 ··· 499 brelse(asb->s_map[i].dm_bh); 500 kfree(asb->s_map); 501 adfs_error(sb, "get root inode failed\n"); 502 + ret = -EIO; 503 goto error; 504 } 505 return 0; ··· 508 error: 509 sb->s_fs_info = NULL; 510 kfree(asb); 511 + return ret; 512 } 513 514 static struct dentry *adfs_mount(struct file_system_type *fs_type,
+16 -12
fs/affs/affs.h
··· 106 spinlock_t work_lock; /* protects sb_work and work_queued */ 107 }; 108 109 - #define SF_INTL 0x0001 /* International filesystem. */ 110 - #define SF_BM_VALID 0x0002 /* Bitmap is valid. */ 111 - #define SF_IMMUTABLE 0x0004 /* Protection bits cannot be changed */ 112 - #define SF_QUIET 0x0008 /* chmod errors will be not reported */ 113 - #define SF_SETUID 0x0010 /* Ignore Amiga uid */ 114 - #define SF_SETGID 0x0020 /* Ignore Amiga gid */ 115 - #define SF_SETMODE 0x0040 /* Ignore Amiga protection bits */ 116 - #define SF_MUFS 0x0100 /* Use MUFS uid/gid mapping */ 117 - #define SF_OFS 0x0200 /* Old filesystem */ 118 - #define SF_PREFIX 0x0400 /* Buffer for prefix is allocated */ 119 - #define SF_VERBOSE 0x0800 /* Talk about fs when mounting */ 120 - #define SF_NO_TRUNCATE 0x1000 /* Don't truncate filenames */ 121 122 /* short cut to get to the affs specific sb data */ 123 static inline struct affs_sb_info *AFFS_SB(struct super_block *sb)
··· 106 spinlock_t work_lock; /* protects sb_work and work_queued */ 107 }; 108 109 + #define AFFS_MOUNT_SF_INTL 0x0001 /* International filesystem. */ 110 + #define AFFS_MOUNT_SF_BM_VALID 0x0002 /* Bitmap is valid. */ 111 + #define AFFS_MOUNT_SF_IMMUTABLE 0x0004 /* Protection bits cannot be changed */ 112 + #define AFFS_MOUNT_SF_QUIET 0x0008 /* chmod errors will be not reported */ 113 + #define AFFS_MOUNT_SF_SETUID 0x0010 /* Ignore Amiga uid */ 114 + #define AFFS_MOUNT_SF_SETGID 0x0020 /* Ignore Amiga gid */ 115 + #define AFFS_MOUNT_SF_SETMODE 0x0040 /* Ignore Amiga protection bits */ 116 + #define AFFS_MOUNT_SF_MUFS 0x0100 /* Use MUFS uid/gid mapping */ 117 + #define AFFS_MOUNT_SF_OFS 0x0200 /* Old filesystem */ 118 + #define AFFS_MOUNT_SF_PREFIX 0x0400 /* Buffer for prefix is allocated */ 119 + #define AFFS_MOUNT_SF_VERBOSE 0x0800 /* Talk about fs when mounting */ 120 + #define AFFS_MOUNT_SF_NO_TRUNCATE 0x1000 /* Don't truncate filenames */ 121 + 122 + #define affs_clear_opt(o, opt) (o &= ~AFFS_MOUNT_##opt) 123 + #define affs_set_opt(o, opt) (o |= AFFS_MOUNT_##opt) 124 + #define affs_test_opt(o, opt) ((o) & AFFS_MOUNT_##opt) 125 126 /* short cut to get to the affs specific sb data */ 127 static inline struct affs_sb_info *AFFS_SB(struct super_block *sb)
+2 -1
fs/affs/amigaffs.c
··· 472 affs_nofilenametruncate(const struct dentry *dentry) 473 { 474 struct inode *inode = dentry->d_inode; 475 - return AFFS_SB(inode->i_sb)->s_flags & SF_NO_TRUNCATE; 476 477 } 478
··· 472 affs_nofilenametruncate(const struct dentry *dentry) 473 { 474 struct inode *inode = dentry->d_inode; 475 + 476 + return affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_NO_TRUNCATE); 477 478 } 479
+1 -1
fs/affs/file.c
··· 914 if (inode->i_size) { 915 AFFS_I(inode)->i_blkcnt = last_blk + 1; 916 AFFS_I(inode)->i_extcnt = ext + 1; 917 - if (AFFS_SB(sb)->s_flags & SF_OFS) { 918 struct buffer_head *bh = affs_bread_ino(inode, last_blk, 0); 919 u32 tmp; 920 if (IS_ERR(bh)) {
··· 914 if (inode->i_size) { 915 AFFS_I(inode)->i_blkcnt = last_blk + 1; 916 AFFS_I(inode)->i_extcnt = ext + 1; 917 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS)) { 918 struct buffer_head *bh = affs_bread_ino(inode, last_blk, 0); 919 u32 tmp; 920 if (IS_ERR(bh)) {
+18 -14
fs/affs/inode.c
··· 66 AFFS_I(inode)->i_lastalloc = 0; 67 AFFS_I(inode)->i_pa_cnt = 0; 68 69 - if (sbi->s_flags & SF_SETMODE) 70 inode->i_mode = sbi->s_mode; 71 else 72 inode->i_mode = prot_to_mode(prot); 73 74 id = be16_to_cpu(tail->uid); 75 - if (id == 0 || sbi->s_flags & SF_SETUID) 76 inode->i_uid = sbi->s_uid; 77 - else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) 78 i_uid_write(inode, 0); 79 else 80 i_uid_write(inode, id); 81 82 id = be16_to_cpu(tail->gid); 83 - if (id == 0 || sbi->s_flags & SF_SETGID) 84 inode->i_gid = sbi->s_gid; 85 - else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) 86 i_gid_write(inode, 0); 87 else 88 i_gid_write(inode, id); ··· 94 /* fall through */ 95 case ST_USERDIR: 96 if (be32_to_cpu(tail->stype) == ST_USERDIR || 97 - sbi->s_flags & SF_SETMODE) { 98 if (inode->i_mode & S_IRUSR) 99 inode->i_mode |= S_IXUSR; 100 if (inode->i_mode & S_IRGRP) ··· 133 } 134 if (tail->link_chain) 135 set_nlink(inode, 2); 136 - inode->i_mapping->a_ops = (sbi->s_flags & SF_OFS) ? &affs_aops_ofs : &affs_aops; 137 inode->i_op = &affs_file_inode_operations; 138 inode->i_fop = &affs_file_operations; 139 break; ··· 191 if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) { 192 uid = i_uid_read(inode); 193 gid = i_gid_read(inode); 194 - if (AFFS_SB(sb)->s_flags & SF_MUFS) { 195 if (uid == 0 || uid == 0xFFFF) 196 uid = uid ^ ~0; 197 if (gid == 0 || gid == 0xFFFF) 198 gid = gid ^ ~0; 199 } 200 - if (!(AFFS_SB(sb)->s_flags & SF_SETUID)) 201 tail->uid = cpu_to_be16(uid); 202 - if (!(AFFS_SB(sb)->s_flags & SF_SETGID)) 203 tail->gid = cpu_to_be16(gid); 204 } 205 } ··· 222 if (error) 223 goto out; 224 225 - if (((attr->ia_valid & ATTR_UID) && (AFFS_SB(inode->i_sb)->s_flags & SF_SETUID)) || 226 - ((attr->ia_valid & ATTR_GID) && (AFFS_SB(inode->i_sb)->s_flags & SF_SETGID)) || 227 ((attr->ia_valid & ATTR_MODE) && 228 - (AFFS_SB(inode->i_sb)->s_flags & (SF_SETMODE | SF_IMMUTABLE)))) { 229 - if (!(AFFS_SB(inode->i_sb)->s_flags & SF_QUIET)) 230 error = -EPERM; 231 goto out; 232 }
··· 66 AFFS_I(inode)->i_lastalloc = 0; 67 AFFS_I(inode)->i_pa_cnt = 0; 68 69 + if (affs_test_opt(sbi->s_flags, SF_SETMODE)) 70 inode->i_mode = sbi->s_mode; 71 else 72 inode->i_mode = prot_to_mode(prot); 73 74 id = be16_to_cpu(tail->uid); 75 + if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETUID)) 76 inode->i_uid = sbi->s_uid; 77 + else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS)) 78 i_uid_write(inode, 0); 79 else 80 i_uid_write(inode, id); 81 82 id = be16_to_cpu(tail->gid); 83 + if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETGID)) 84 inode->i_gid = sbi->s_gid; 85 + else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS)) 86 i_gid_write(inode, 0); 87 else 88 i_gid_write(inode, id); ··· 94 /* fall through */ 95 case ST_USERDIR: 96 if (be32_to_cpu(tail->stype) == ST_USERDIR || 97 + affs_test_opt(sbi->s_flags, SF_SETMODE)) { 98 if (inode->i_mode & S_IRUSR) 99 inode->i_mode |= S_IXUSR; 100 if (inode->i_mode & S_IRGRP) ··· 133 } 134 if (tail->link_chain) 135 set_nlink(inode, 2); 136 + inode->i_mapping->a_ops = affs_test_opt(sbi->s_flags, SF_OFS) ? 137 + &affs_aops_ofs : &affs_aops; 138 inode->i_op = &affs_file_inode_operations; 139 inode->i_fop = &affs_file_operations; 140 break; ··· 190 if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) { 191 uid = i_uid_read(inode); 192 gid = i_gid_read(inode); 193 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_MUFS)) { 194 if (uid == 0 || uid == 0xFFFF) 195 uid = uid ^ ~0; 196 if (gid == 0 || gid == 0xFFFF) 197 gid = gid ^ ~0; 198 } 199 + if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETUID)) 200 tail->uid = cpu_to_be16(uid); 201 + if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETGID)) 202 tail->gid = cpu_to_be16(gid); 203 } 204 } ··· 221 if (error) 222 goto out; 223 224 + if (((attr->ia_valid & ATTR_UID) && 225 + affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_SETUID)) || 226 + ((attr->ia_valid & ATTR_GID) && 227 + affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_SETGID)) || 228 ((attr->ia_valid & ATTR_MODE) && 229 + (AFFS_SB(inode->i_sb)->s_flags & 230 + (AFFS_MOUNT_SF_SETMODE | AFFS_MOUNT_SF_IMMUTABLE)))) { 231 + if (!affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_QUIET)) 232 error = -EPERM; 233 goto out; 234 }
+4 -2
fs/affs/namei.c
··· 53 static inline toupper_t 54 affs_get_toupper(struct super_block *sb) 55 { 56 - return AFFS_SB(sb)->s_flags & SF_INTL ? affs_intl_toupper : affs_toupper; 57 } 58 59 /* ··· 276 277 inode->i_op = &affs_file_inode_operations; 278 inode->i_fop = &affs_file_operations; 279 - inode->i_mapping->a_ops = (AFFS_SB(sb)->s_flags & SF_OFS) ? &affs_aops_ofs : &affs_aops; 280 error = affs_add_entry(dir, inode, dentry, ST_FILE); 281 if (error) { 282 clear_nlink(inode);
··· 53 static inline toupper_t 54 affs_get_toupper(struct super_block *sb) 55 { 56 + return affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL) ? 57 + affs_intl_toupper : affs_toupper; 58 } 59 60 /* ··· 275 276 inode->i_op = &affs_file_inode_operations; 277 inode->i_fop = &affs_file_operations; 278 + inode->i_mapping->a_ops = affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS) ? 279 + &affs_aops_ofs : &affs_aops; 280 error = affs_add_entry(dir, inode, dentry, ST_FILE); 281 if (error) { 282 clear_nlink(inode);
+24 -19
fs/affs/super.c
··· 227 if (match_octal(&args[0], &option)) 228 return 0; 229 *mode = option & 0777; 230 - *mount_opts |= SF_SETMODE; 231 break; 232 case Opt_mufs: 233 - *mount_opts |= SF_MUFS; 234 break; 235 case Opt_notruncate: 236 - *mount_opts |= SF_NO_TRUNCATE; 237 break; 238 case Opt_prefix: 239 *prefix = match_strdup(&args[0]); 240 if (!*prefix) 241 return 0; 242 - *mount_opts |= SF_PREFIX; 243 break; 244 case Opt_protect: 245 - *mount_opts |= SF_IMMUTABLE; 246 break; 247 case Opt_reserved: 248 if (match_int(&args[0], reserved)) ··· 258 *gid = make_kgid(current_user_ns(), option); 259 if (!gid_valid(*gid)) 260 return 0; 261 - *mount_opts |= SF_SETGID; 262 break; 263 case Opt_setuid: 264 if (match_int(&args[0], &option)) ··· 266 *uid = make_kuid(current_user_ns(), option); 267 if (!uid_valid(*uid)) 268 return 0; 269 - *mount_opts |= SF_SETUID; 270 break; 271 case Opt_verbose: 272 - *mount_opts |= SF_VERBOSE; 273 break; 274 case Opt_volume: { 275 char *vol = match_strdup(&args[0]); ··· 435 case MUFS_FS: 436 case MUFS_INTLFFS: 437 case MUFS_DCFFS: 438 - sbi->s_flags |= SF_MUFS; 439 /* fall thru */ 440 case FS_INTLFFS: 441 case FS_DCFFS: 442 - sbi->s_flags |= SF_INTL; 443 break; 444 case MUFS_FFS: 445 - sbi->s_flags |= SF_MUFS; 446 break; 447 case FS_FFS: 448 break; 449 case MUFS_OFS: 450 - sbi->s_flags |= SF_MUFS; 451 /* fall thru */ 452 case FS_OFS: 453 - sbi->s_flags |= SF_OFS; 454 sb->s_flags |= MS_NOEXEC; 455 break; 456 case MUFS_DCOFS: 457 case MUFS_INTLOFS: 458 - sbi->s_flags |= SF_MUFS; 459 case FS_DCOFS: 460 case FS_INTLOFS: 461 - sbi->s_flags |= SF_INTL | SF_OFS; 462 sb->s_flags |= MS_NOEXEC; 463 break; 464 default: ··· 468 return -EINVAL; 469 } 470 471 - if (mount_flags & SF_VERBOSE) { 472 u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; 473 pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", 474 len > 31 ? 31 : len, ··· 479 sb->s_flags |= MS_NODEV | MS_NOSUID; 480 481 sbi->s_data_blksize = sb->s_blocksize; 482 - if (sbi->s_flags & SF_OFS) 483 sbi->s_data_blksize -= 24; 484 485 tmp_flags = sb->s_flags; ··· 494 if (IS_ERR(root_inode)) 495 return PTR_ERR(root_inode); 496 497 - if (AFFS_SB(sb)->s_flags & SF_INTL) 498 sb->s_d_op = &affs_intl_dentry_operations; 499 else 500 sb->s_d_op = &affs_dentry_operations; ··· 521 int root_block; 522 unsigned long mount_flags; 523 int res = 0; 524 - char *new_opts = kstrdup(data, GFP_KERNEL); 525 char volume[32]; 526 char *prefix = NULL; 527 528 pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data); 529
··· 227 if (match_octal(&args[0], &option)) 228 return 0; 229 *mode = option & 0777; 230 + affs_set_opt(*mount_opts, SF_SETMODE); 231 break; 232 case Opt_mufs: 233 + affs_set_opt(*mount_opts, SF_MUFS); 234 break; 235 case Opt_notruncate: 236 + affs_set_opt(*mount_opts, SF_NO_TRUNCATE); 237 break; 238 case Opt_prefix: 239 *prefix = match_strdup(&args[0]); 240 if (!*prefix) 241 return 0; 242 + affs_set_opt(*mount_opts, SF_PREFIX); 243 break; 244 case Opt_protect: 245 + affs_set_opt(*mount_opts, SF_IMMUTABLE); 246 break; 247 case Opt_reserved: 248 if (match_int(&args[0], reserved)) ··· 258 *gid = make_kgid(current_user_ns(), option); 259 if (!gid_valid(*gid)) 260 return 0; 261 + affs_set_opt(*mount_opts, SF_SETGID); 262 break; 263 case Opt_setuid: 264 if (match_int(&args[0], &option)) ··· 266 *uid = make_kuid(current_user_ns(), option); 267 if (!uid_valid(*uid)) 268 return 0; 269 + affs_set_opt(*mount_opts, SF_SETUID); 270 break; 271 case Opt_verbose: 272 + affs_set_opt(*mount_opts, SF_VERBOSE); 273 break; 274 case Opt_volume: { 275 char *vol = match_strdup(&args[0]); ··· 435 case MUFS_FS: 436 case MUFS_INTLFFS: 437 case MUFS_DCFFS: 438 + affs_set_opt(sbi->s_flags, SF_MUFS); 439 /* fall thru */ 440 case FS_INTLFFS: 441 case FS_DCFFS: 442 + affs_set_opt(sbi->s_flags, SF_INTL); 443 break; 444 case MUFS_FFS: 445 + affs_set_opt(sbi->s_flags, SF_MUFS); 446 break; 447 case FS_FFS: 448 break; 449 case MUFS_OFS: 450 + affs_set_opt(sbi->s_flags, SF_MUFS); 451 /* fall thru */ 452 case FS_OFS: 453 + affs_set_opt(sbi->s_flags, SF_OFS); 454 sb->s_flags |= MS_NOEXEC; 455 break; 456 case MUFS_DCOFS: 457 case MUFS_INTLOFS: 458 + affs_set_opt(sbi->s_flags, SF_MUFS); 459 case FS_DCOFS: 460 case FS_INTLOFS: 461 + affs_set_opt(sbi->s_flags, SF_INTL); 462 + affs_set_opt(sbi->s_flags, SF_OFS); 463 sb->s_flags |= MS_NOEXEC; 464 break; 465 default: ··· 467 return -EINVAL; 468 } 469 470 + if (affs_test_opt(mount_flags, SF_VERBOSE)) { 471 u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; 472 pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", 473 len > 31 ? 31 : len, ··· 478 sb->s_flags |= MS_NODEV | MS_NOSUID; 479 480 sbi->s_data_blksize = sb->s_blocksize; 481 + if (affs_test_opt(sbi->s_flags, SF_OFS)) 482 sbi->s_data_blksize -= 24; 483 484 tmp_flags = sb->s_flags; ··· 493 if (IS_ERR(root_inode)) 494 return PTR_ERR(root_inode); 495 496 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL)) 497 sb->s_d_op = &affs_intl_dentry_operations; 498 else 499 sb->s_d_op = &affs_dentry_operations; ··· 520 int root_block; 521 unsigned long mount_flags; 522 int res = 0; 523 + char *new_opts; 524 char volume[32]; 525 char *prefix = NULL; 526 + 527 + new_opts = kstrdup(data, GFP_KERNEL); 528 + if (!new_opts) 529 + return -ENOMEM; 530 531 pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data); 532
+10 -12
fs/befs/befs.h
··· 19 * BeFS in memory structures 20 */ 21 22 - typedef struct befs_mount_options { 23 kgid_t gid; 24 kuid_t uid; 25 int use_gid; 26 int use_uid; 27 int debug; 28 char *iocharset; 29 - } befs_mount_options; 30 31 - typedef struct befs_sb_info { 32 u32 magic1; 33 u32 block_size; 34 u32 block_shift; ··· 52 befs_inode_addr indices; 53 u32 magic3; 54 55 - befs_mount_options mount_opts; 56 struct nls_table *nls; 57 58 - } befs_sb_info; 59 - 60 - typedef struct befs_inode_info { 61 u32 i_flags; 62 u32 i_type; 63 ··· 70 } i_data; 71 72 struct inode vfs_inode; 73 - 74 - } befs_inode_info; 75 76 enum befs_err { 77 BEFS_OK, ··· 103 /* Gets a pointer to the private portion of the super_block 104 * structure from the public part 105 */ 106 - static inline befs_sb_info * 107 BEFS_SB(const struct super_block *super) 108 { 109 - return (befs_sb_info *) super->s_fs_info; 110 } 111 112 - static inline befs_inode_info * 113 BEFS_I(const struct inode *inode) 114 { 115 return list_entry(inode, struct befs_inode_info, vfs_inode);
··· 19 * BeFS in memory structures 20 */ 21 22 + struct befs_mount_options { 23 kgid_t gid; 24 kuid_t uid; 25 int use_gid; 26 int use_uid; 27 int debug; 28 char *iocharset; 29 + }; 30 31 + struct befs_sb_info { 32 u32 magic1; 33 u32 block_size; 34 u32 block_shift; ··· 52 befs_inode_addr indices; 53 u32 magic3; 54 55 + struct befs_mount_options mount_opts; 56 struct nls_table *nls; 57 + }; 58 59 + struct befs_inode_info { 60 u32 i_flags; 61 u32 i_type; 62 ··· 71 } i_data; 72 73 struct inode vfs_inode; 74 + }; 75 76 enum befs_err { 77 BEFS_OK, ··· 105 /* Gets a pointer to the private portion of the super_block 106 * structure from the public part 107 */ 108 + static inline struct befs_sb_info * 109 BEFS_SB(const struct super_block *super) 110 { 111 + return (struct befs_sb_info *) super->s_fs_info; 112 } 113 114 + static inline struct befs_inode_info * 115 BEFS_I(const struct inode *inode) 116 { 117 return list_entry(inode, struct befs_inode_info, vfs_inode);
+2 -2
fs/befs/datastream.c
··· 168 befs_blocknr_t blocks; 169 befs_blocknr_t datablocks; /* File data blocks */ 170 befs_blocknr_t metablocks; /* FS metadata blocks */ 171 - befs_sb_info *befs_sb = BEFS_SB(sb); 172 173 befs_debug(sb, "---> %s", __func__); 174 ··· 428 struct buffer_head *indir_block; 429 befs_block_run indir_run; 430 befs_disk_inode_addr *iaddr_array = NULL; 431 - befs_sb_info *befs_sb = BEFS_SB(sb); 432 433 befs_blocknr_t indir_start_blk = 434 data->max_indirect_range >> befs_sb->block_shift;
··· 168 befs_blocknr_t blocks; 169 befs_blocknr_t datablocks; /* File data blocks */ 170 befs_blocknr_t metablocks; /* FS metadata blocks */ 171 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 172 173 befs_debug(sb, "---> %s", __func__); 174 ··· 428 struct buffer_head *indir_block; 429 befs_block_run indir_run; 430 befs_disk_inode_addr *iaddr_array = NULL; 431 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 432 433 befs_blocknr_t indir_start_blk = 434 data->max_indirect_range >> befs_sb->block_shift;
+1 -1
fs/befs/io.c
··· 28 { 29 struct buffer_head *bh = NULL; 30 befs_blocknr_t block = 0; 31 - befs_sb_info *befs_sb = BEFS_SB(sb); 32 33 befs_debug(sb, "---> Enter %s " 34 "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
··· 28 { 29 struct buffer_head *bh = NULL; 30 befs_blocknr_t block = 0; 31 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 32 33 befs_debug(sb, "---> Enter %s " 34 "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
+8 -8
fs/befs/linuxvfs.c
··· 51 static void befs_put_super(struct super_block *); 52 static int befs_remount(struct super_block *, int *, char *); 53 static int befs_statfs(struct dentry *, struct kstatfs *); 54 - static int parse_options(char *, befs_mount_options *); 55 56 static const struct super_operations befs_sops = { 57 .alloc_inode = befs_alloc_inode, /* allocate a new inode */ ··· 304 { 305 struct buffer_head *bh = NULL; 306 befs_inode *raw_inode = NULL; 307 - 308 - befs_sb_info *befs_sb = BEFS_SB(sb); 309 - befs_inode_info *befs_ino = NULL; 310 struct inode *inode; 311 long ret = -EIO; 312 ··· 471 befs_follow_link(struct dentry *dentry, struct nameidata *nd) 472 { 473 struct super_block *sb = dentry->d_sb; 474 - befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 475 befs_data_stream *data = &befs_ino->i_data.ds; 476 befs_off_t len = data->size; 477 char *link; ··· 501 static void * 502 befs_fast_follow_link(struct dentry *dentry, struct nameidata *nd) 503 { 504 - befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 505 nd_set_link(nd, befs_ino->i_data.symlink); 506 return NULL; 507 } ··· 669 }; 670 671 static int 672 - parse_options(char *options, befs_mount_options * opts) 673 { 674 char *p; 675 substring_t args[MAX_OPT_ARGS]; ··· 769 befs_fill_super(struct super_block *sb, void *data, int silent) 770 { 771 struct buffer_head *bh; 772 - befs_sb_info *befs_sb; 773 befs_super_block *disk_sb; 774 struct inode *root; 775 long ret = -EINVAL;
··· 51 static void befs_put_super(struct super_block *); 52 static int befs_remount(struct super_block *, int *, char *); 53 static int befs_statfs(struct dentry *, struct kstatfs *); 54 + static int parse_options(char *, struct befs_mount_options *); 55 56 static const struct super_operations befs_sops = { 57 .alloc_inode = befs_alloc_inode, /* allocate a new inode */ ··· 304 { 305 struct buffer_head *bh = NULL; 306 befs_inode *raw_inode = NULL; 307 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 308 + struct befs_inode_info *befs_ino = NULL; 309 struct inode *inode; 310 long ret = -EIO; 311 ··· 472 befs_follow_link(struct dentry *dentry, struct nameidata *nd) 473 { 474 struct super_block *sb = dentry->d_sb; 475 + struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 476 befs_data_stream *data = &befs_ino->i_data.ds; 477 befs_off_t len = data->size; 478 char *link; ··· 502 static void * 503 befs_fast_follow_link(struct dentry *dentry, struct nameidata *nd) 504 { 505 + struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 506 + 507 nd_set_link(nd, befs_ino->i_data.symlink); 508 return NULL; 509 } ··· 669 }; 670 671 static int 672 + parse_options(char *options, struct befs_mount_options *opts) 673 { 674 char *p; 675 substring_t args[MAX_OPT_ARGS]; ··· 769 befs_fill_super(struct super_block *sb, void *data, int silent) 770 { 771 struct buffer_head *bh; 772 + struct befs_sb_info *befs_sb; 773 befs_super_block *disk_sb; 774 struct inode *root; 775 long ret = -EINVAL;
+2 -2
fs/befs/super.c
··· 24 int 25 befs_load_sb(struct super_block *sb, befs_super_block * disk_sb) 26 { 27 - befs_sb_info *befs_sb = BEFS_SB(sb); 28 29 /* Check the byte order of the filesystem */ 30 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE) ··· 59 int 60 befs_check_sb(struct super_block *sb) 61 { 62 - befs_sb_info *befs_sb = BEFS_SB(sb); 63 64 /* Check magic headers of super block */ 65 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
··· 24 int 25 befs_load_sb(struct super_block *sb, befs_super_block * disk_sb) 26 { 27 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 28 29 /* Check the byte order of the filesystem */ 30 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE) ··· 59 int 60 befs_check_sb(struct super_block *sb) 61 { 62 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 63 64 /* Check magic headers of super block */ 65 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
+2 -2
fs/bfs/dir.c
··· 86 87 inode = new_inode(s); 88 if (!inode) 89 - return -ENOSPC; 90 mutex_lock(&info->bfs_lock); 91 ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1); 92 if (ino > info->si_lasti) { ··· 293 for (block = sblock; block <= eblock; block++) { 294 bh = sb_bread(dir->i_sb, block); 295 if (!bh) 296 - return -ENOSPC; 297 for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) { 298 de = (struct bfs_dirent *)(bh->b_data + off); 299 if (!de->ino) {
··· 86 87 inode = new_inode(s); 88 if (!inode) 89 + return -ENOMEM; 90 mutex_lock(&info->bfs_lock); 91 ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1); 92 if (ino > info->si_lasti) { ··· 293 for (block = sblock; block <= eblock; block++) { 294 bh = sb_bread(dir->i_sb, block); 295 if (!bh) 296 + return -EIO; 297 for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) { 298 de = (struct bfs_dirent *)(bh->b_data + off); 299 if (!de->ino) {
+9 -21
fs/binfmt_misc.c
··· 9 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 12 #include <linux/module.h> 13 #include <linux/init.h> 14 #include <linux/sched.h> ··· 522 523 static void entry_status(Node *e, char *page) 524 { 525 - char *dp; 526 - char *status = "disabled"; 527 - const char *flags = "flags: "; 528 529 if (test_bit(Enabled, &e->flags)) 530 status = "enabled"; ··· 533 return; 534 } 535 536 - sprintf(page, "%s\ninterpreter %s\n", status, e->interpreter); 537 - dp = page + strlen(page); 538 539 /* print the special flags */ 540 - sprintf(dp, "%s", flags); 541 - dp += strlen(flags); 542 if (e->flags & MISC_FMT_PRESERVE_ARGV0) 543 *dp++ = 'P'; 544 if (e->flags & MISC_FMT_OPEN_BINARY) ··· 548 if (!test_bit(Magic, &e->flags)) { 549 sprintf(dp, "extension .%s\n", e->magic); 550 } else { 551 - int i; 552 - 553 - sprintf(dp, "offset %i\nmagic ", e->offset); 554 - dp = page + strlen(page); 555 - for (i = 0; i < e->size; i++) { 556 - sprintf(dp, "%02x", 0xff & (int) (e->magic[i])); 557 - dp += 2; 558 - } 559 if (e->mask) { 560 - sprintf(dp, "\nmask "); 561 - dp += 6; 562 - for (i = 0; i < e->size; i++) { 563 - sprintf(dp, "%02x", 0xff & (int) (e->mask[i])); 564 - dp += 2; 565 - } 566 } 567 *dp++ = '\n'; 568 *dp = '\0';
··· 9 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 12 + #include <linux/kernel.h> 13 #include <linux/module.h> 14 #include <linux/init.h> 15 #include <linux/sched.h> ··· 521 522 static void entry_status(Node *e, char *page) 523 { 524 + char *dp = page; 525 + const char *status = "disabled"; 526 527 if (test_bit(Enabled, &e->flags)) 528 status = "enabled"; ··· 533 return; 534 } 535 536 + dp += sprintf(dp, "%s\ninterpreter %s\n", status, e->interpreter); 537 538 /* print the special flags */ 539 + dp += sprintf(dp, "flags: "); 540 if (e->flags & MISC_FMT_PRESERVE_ARGV0) 541 *dp++ = 'P'; 542 if (e->flags & MISC_FMT_OPEN_BINARY) ··· 550 if (!test_bit(Magic, &e->flags)) { 551 sprintf(dp, "extension .%s\n", e->magic); 552 } else { 553 + dp += sprintf(dp, "offset %i\nmagic ", e->offset); 554 + dp = bin2hex(dp, e->magic, e->size); 555 if (e->mask) { 556 + dp += sprintf(dp, "\nmask "); 557 + dp = bin2hex(dp, e->mask, e->size); 558 } 559 *dp++ = '\n'; 560 *dp = '\0';
+11 -1
fs/exec.c
··· 926 if (!thread_group_leader(tsk)) { 927 struct task_struct *leader = tsk->group_leader; 928 929 - sig->notify_count = -1; /* for exit_notify() */ 930 for (;;) { 931 threadgroup_change_begin(tsk); 932 write_lock_irq(&tasklist_lock); 933 if (likely(leader->exit_state)) 934 break; 935 __set_current_state(TASK_KILLABLE); ··· 1082 if (retval) 1083 goto out; 1084 1085 set_mm_exe_file(bprm->mm, bprm->file); 1086 /* 1087 * Release all of the old mmap stuff 1088 */
··· 926 if (!thread_group_leader(tsk)) { 927 struct task_struct *leader = tsk->group_leader; 928 929 for (;;) { 930 threadgroup_change_begin(tsk); 931 write_lock_irq(&tasklist_lock); 932 + /* 933 + * Do this under tasklist_lock to ensure that 934 + * exit_notify() can't miss ->group_exit_task 935 + */ 936 + sig->notify_count = -1; 937 if (likely(leader->exit_state)) 938 break; 939 __set_current_state(TASK_KILLABLE); ··· 1078 if (retval) 1079 goto out; 1080 1081 + /* 1082 + * Must be called _before_ exec_mmap() as bprm->mm is 1083 + * not visibile until then. This also enables the update 1084 + * to be lockless. 1085 + */ 1086 set_mm_exe_file(bprm->mm, bprm->file); 1087 + 1088 /* 1089 * Release all of the old mmap stuff 1090 */
-2
fs/fat/cache.c
··· 8 * May 1999. AV. Fixed the bogosity with FAT32 (read "FAT28"). Fscking lusers. 9 */ 10 11 - #include <linux/fs.h> 12 #include <linux/slab.h> 13 - #include <linux/buffer_head.h> 14 #include "fat.h" 15 16 /* this must be > 0. */
··· 8 * May 1999. AV. Fixed the bogosity with FAT32 (read "FAT28"). Fscking lusers. 9 */ 10 11 #include <linux/slab.h> 12 #include "fat.h" 13 14 /* this must be > 0. */
-4
fs/fat/dir.c
··· 13 * Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de> 14 */ 15 16 - #include <linux/module.h> 17 #include <linux/slab.h> 18 - #include <linux/time.h> 19 - #include <linux/buffer_head.h> 20 #include <linux/compat.h> 21 #include <linux/uaccess.h> 22 - #include <linux/kernel.h> 23 #include "fat.h" 24 25 /*
··· 13 * Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de> 14 */ 15 16 #include <linux/slab.h> 17 #include <linux/compat.h> 18 #include <linux/uaccess.h> 19 #include "fat.h" 20 21 /*
+1 -4
fs/fat/fat.h
··· 2 #define _FAT_H 3 4 #include <linux/buffer_head.h> 5 - #include <linux/string.h> 6 #include <linux/nls.h> 7 - #include <linux/fs.h> 8 #include <linux/hash.h> 9 - #include <linux/mutex.h> 10 #include <linux/ratelimit.h> 11 #include <linux/msdos_fs.h> 12 ··· 63 unsigned short sec_per_clus; /* sectors/cluster */ 64 unsigned short cluster_bits; /* log2(cluster_size) */ 65 unsigned int cluster_size; /* cluster size */ 66 - unsigned char fats, fat_bits; /* number of FATs, FAT bits (12 or 16) */ 67 unsigned short fat_start; 68 unsigned long fat_length; /* FAT start & length (sec.) */ 69 unsigned long dir_start;
··· 2 #define _FAT_H 3 4 #include <linux/buffer_head.h> 5 #include <linux/nls.h> 6 #include <linux/hash.h> 7 #include <linux/ratelimit.h> 8 #include <linux/msdos_fs.h> 9 ··· 66 unsigned short sec_per_clus; /* sectors/cluster */ 67 unsigned short cluster_bits; /* log2(cluster_size) */ 68 unsigned int cluster_size; /* cluster size */ 69 + unsigned char fats, fat_bits; /* number of FATs, FAT bits (12,16 or 32) */ 70 unsigned short fat_start; 71 unsigned long fat_length; /* FAT start & length (sec.) */ 72 unsigned long dir_start;
-3
fs/fat/fatent.c
··· 3 * Released under GPL v2. 4 */ 5 6 - #include <linux/module.h> 7 - #include <linux/fs.h> 8 - #include <linux/msdos_fs.h> 9 #include <linux/blkdev.h> 10 #include "fat.h" 11
··· 3 * Released under GPL v2. 4 */ 5 6 #include <linux/blkdev.h> 7 #include "fat.h" 8
-4
fs/fat/file.c
··· 10 #include <linux/module.h> 11 #include <linux/compat.h> 12 #include <linux/mount.h> 13 - #include <linux/time.h> 14 - #include <linux/buffer_head.h> 15 - #include <linux/writeback.h> 16 - #include <linux/backing-dev.h> 17 #include <linux/blkdev.h> 18 #include <linux/fsnotify.h> 19 #include <linux/security.h>
··· 10 #include <linux/module.h> 11 #include <linux/compat.h> 12 #include <linux/mount.h> 13 #include <linux/blkdev.h> 14 #include <linux/fsnotify.h> 15 #include <linux/security.h>
+2 -11
fs/fat/inode.c
··· 11 */ 12 13 #include <linux/module.h> 14 - #include <linux/init.h> 15 - #include <linux/time.h> 16 - #include <linux/slab.h> 17 - #include <linux/seq_file.h> 18 #include <linux/pagemap.h> 19 #include <linux/mpage.h> 20 - #include <linux/buffer_head.h> 21 - #include <linux/mount.h> 22 #include <linux/vfs.h> 23 #include <linux/parser.h> 24 #include <linux/uio.h> 25 - #include <linux/writeback.h> 26 - #include <linux/log2.h> 27 - #include <linux/hash.h> 28 #include <linux/blkdev.h> 29 #include <asm/unaligned.h> 30 #include "fat.h" ··· 1270 1271 static int fat_read_root(struct inode *inode) 1272 { 1273 - struct super_block *sb = inode->i_sb; 1274 - struct msdos_sb_info *sbi = MSDOS_SB(sb); 1275 int error; 1276 1277 MSDOS_I(inode)->i_pos = MSDOS_ROOT_INO;
··· 11 */ 12 13 #include <linux/module.h> 14 #include <linux/pagemap.h> 15 #include <linux/mpage.h> 16 #include <linux/vfs.h> 17 + #include <linux/seq_file.h> 18 #include <linux/parser.h> 19 #include <linux/uio.h> 20 #include <linux/blkdev.h> 21 #include <asm/unaligned.h> 22 #include "fat.h" ··· 1278 1279 static int fat_read_root(struct inode *inode) 1280 { 1281 + struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); 1282 int error; 1283 1284 MSDOS_I(inode)->i_pos = MSDOS_ROOT_INO;
-4
fs/fat/misc.c
··· 6 * and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru) 7 */ 8 9 - #include <linux/module.h> 10 - #include <linux/fs.h> 11 - #include <linux/buffer_head.h> 12 - #include <linux/time.h> 13 #include "fat.h" 14 15 /*
··· 6 * and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru) 7 */ 8 9 #include "fat.h" 10 11 /*
-2
fs/fat/namei_msdos.c
··· 7 */ 8 9 #include <linux/module.h> 10 - #include <linux/time.h> 11 - #include <linux/buffer_head.h> 12 #include "fat.h" 13 14 /* Characters that are undesirable in an MS-DOS file name */
··· 7 */ 8 9 #include <linux/module.h> 10 #include "fat.h" 11 12 /* Characters that are undesirable in an MS-DOS file name */
-2
fs/fat/namei_vfat.c
··· 16 */ 17 18 #include <linux/module.h> 19 - #include <linux/jiffies.h> 20 #include <linux/ctype.h> 21 #include <linux/slab.h> 22 - #include <linux/buffer_head.h> 23 #include <linux/namei.h> 24 #include "fat.h" 25
··· 16 */ 17 18 #include <linux/module.h> 19 #include <linux/ctype.h> 20 #include <linux/slab.h> 21 #include <linux/namei.h> 22 #include "fat.h" 23
+1 -2
fs/file.c
··· 638 file = fcheck_files(files, fd); 639 if (file) { 640 /* File object ref couldn't be taken */ 641 - if ((file->f_mode & mask) || 642 - !atomic_long_inc_not_zero(&file->f_count)) 643 file = NULL; 644 } 645 rcu_read_unlock();
··· 638 file = fcheck_files(files, fd); 639 if (file) { 640 /* File object ref couldn't be taken */ 641 + if ((file->f_mode & mask) || !get_file_rcu(file)) 642 file = NULL; 643 } 644 rcu_read_unlock();
+2 -2
fs/hfs/dir.c
··· 197 198 inode = hfs_new_inode(dir, &dentry->d_name, mode); 199 if (!inode) 200 - return -ENOSPC; 201 202 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 203 if (res) { ··· 226 227 inode = hfs_new_inode(dir, &dentry->d_name, S_IFDIR | mode); 228 if (!inode) 229 - return -ENOSPC; 230 231 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 232 if (res) {
··· 197 198 inode = hfs_new_inode(dir, &dentry->d_name, mode); 199 if (!inode) 200 + return -ENOMEM; 201 202 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 203 if (res) { ··· 226 227 inode = hfs_new_inode(dir, &dentry->d_name, S_IFDIR | mode); 228 if (!inode) 229 + return -ENOMEM; 230 231 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 232 if (res) {
+1 -3
fs/hfsplus/bfind.c
··· 118 int b, e; 119 int res; 120 121 - if (!rec_found) 122 - BUG(); 123 - 124 b = 0; 125 e = bnode->num_recs - 1; 126 res = -ENOENT;
··· 118 int b, e; 119 int res; 120 121 + BUG_ON(!rec_found); 122 b = 0; 123 e = bnode->num_recs - 1; 124 res = -ENOENT;
+2 -1
fs/hfsplus/catalog.c
··· 350 &fd.search_key->cat.name.unicode, 351 off + 2, len); 352 fd.search_key->key_len = cpu_to_be16(6 + len); 353 - } else 354 err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str); 355 if (unlikely(err)) 356 goto out; 357 358 err = hfs_brec_find(&fd, hfs_find_rec_by_key); 359 if (err)
··· 350 &fd.search_key->cat.name.unicode, 351 off + 2, len); 352 fd.search_key->key_len = cpu_to_be16(6 + len); 353 + } else { 354 err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str); 355 if (unlikely(err)) 356 goto out; 357 + } 358 359 err = hfs_brec_find(&fd, hfs_find_rec_by_key); 360 if (err)
+2 -2
fs/hfsplus/dir.c
··· 434 { 435 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 436 struct inode *inode; 437 - int res = -ENOSPC; 438 439 mutex_lock(&sbi->vh_mutex); 440 inode = hfsplus_new_inode(dir->i_sb, S_IFLNK | S_IRWXUGO); ··· 476 { 477 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 478 struct inode *inode; 479 - int res = -ENOSPC; 480 481 mutex_lock(&sbi->vh_mutex); 482 inode = hfsplus_new_inode(dir->i_sb, mode);
··· 434 { 435 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 436 struct inode *inode; 437 + int res = -ENOMEM; 438 439 mutex_lock(&sbi->vh_mutex); 440 inode = hfsplus_new_inode(dir->i_sb, S_IFLNK | S_IRWXUGO); ··· 476 { 477 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 478 struct inode *inode; 479 + int res = -ENOMEM; 480 481 mutex_lock(&sbi->vh_mutex); 482 inode = hfsplus_new_inode(dir->i_sb, mode);
+6
fs/hfsplus/inode.c
··· 253 if ((attr->ia_valid & ATTR_SIZE) && 254 attr->ia_size != i_size_read(inode)) { 255 inode_dio_wait(inode); 256 truncate_setsize(inode, attr->ia_size); 257 hfsplus_file_truncate(inode); 258 }
··· 253 if ((attr->ia_valid & ATTR_SIZE) && 254 attr->ia_size != i_size_read(inode)) { 255 inode_dio_wait(inode); 256 + if (attr->ia_size > inode->i_size) { 257 + error = generic_cont_expand_simple(inode, 258 + attr->ia_size); 259 + if (error) 260 + return error; 261 + } 262 truncate_setsize(inode, attr->ia_size); 263 hfsplus_file_truncate(inode); 264 }
+5 -7
fs/hfsplus/ioctl.c
··· 76 { 77 struct inode *inode = file_inode(file); 78 struct hfsplus_inode_info *hip = HFSPLUS_I(inode); 79 - unsigned int flags; 80 int err = 0; 81 82 err = mnt_want_write_file(file); ··· 110 } 111 112 if (flags & FS_IMMUTABLE_FL) 113 - inode->i_flags |= S_IMMUTABLE; 114 - else 115 - inode->i_flags &= ~S_IMMUTABLE; 116 117 if (flags & FS_APPEND_FL) 118 - inode->i_flags |= S_APPEND; 119 - else 120 - inode->i_flags &= ~S_APPEND; 121 122 if (flags & FS_NODUMP_FL) 123 hip->userflags |= HFSPLUS_FLG_NODUMP;
··· 76 { 77 struct inode *inode = file_inode(file); 78 struct hfsplus_inode_info *hip = HFSPLUS_I(inode); 79 + unsigned int flags, new_fl = 0; 80 int err = 0; 81 82 err = mnt_want_write_file(file); ··· 110 } 111 112 if (flags & FS_IMMUTABLE_FL) 113 + new_fl |= S_IMMUTABLE; 114 115 if (flags & FS_APPEND_FL) 116 + new_fl |= S_APPEND; 117 + 118 + inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND); 119 120 if (flags & FS_NODUMP_FL) 121 hip->userflags |= HFSPLUS_FLG_NODUMP;
+61 -25
fs/hfsplus/xattr.c
··· 44 return -1; 45 } 46 47 - static inline int is_known_namespace(const char *name) 48 { 49 if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) && 50 strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && ··· 424 return len; 425 } 426 427 static ssize_t hfsplus_getxattr_finder_info(struct inode *inode, 428 void *value, size_t size) 429 { ··· 580 failed_getxattr_init: 581 hfsplus_destroy_attr_entry(entry); 582 return res; 583 } 584 585 static inline int can_list(const char *xattr_name) ··· 852 static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, 853 void *buffer, size_t size, int type) 854 { 855 - char *xattr_name; 856 - int res; 857 - 858 if (!strcmp(name, "")) 859 return -EINVAL; 860 ··· 861 */ 862 if (is_known_namespace(name)) 863 return -EOPNOTSUPP; 864 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN 865 - + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); 866 - if (!xattr_name) 867 - return -ENOMEM; 868 - strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); 869 - strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); 870 871 - res = hfsplus_getxattr(dentry, xattr_name, buffer, size); 872 - kfree(xattr_name); 873 - return res; 874 } 875 876 static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, 877 const void *buffer, size_t size, int flags, int type) 878 { 879 - char *xattr_name; 880 - int res; 881 - 882 if (!strcmp(name, "")) 883 return -EINVAL; 884 ··· 883 */ 884 if (is_known_namespace(name)) 885 return -EOPNOTSUPP; 886 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN 887 - + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); 888 - if (!xattr_name) 889 - return -ENOMEM; 890 - strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); 891 - strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); 892 893 - res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); 894 - kfree(xattr_name); 895 - return res; 896 } 897 898 static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
··· 44 return -1; 45 } 46 47 + static bool is_known_namespace(const char *name) 48 { 49 if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) && 50 strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && ··· 424 return len; 425 } 426 427 + int hfsplus_setxattr(struct dentry *dentry, const char *name, 428 + const void *value, size_t size, int flags, 429 + const char *prefix, size_t prefixlen) 430 + { 431 + char *xattr_name; 432 + int res; 433 + 434 + if (!strcmp(name, "")) 435 + return -EINVAL; 436 + 437 + xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 438 + GFP_KERNEL); 439 + if (!xattr_name) 440 + return -ENOMEM; 441 + strcpy(xattr_name, prefix); 442 + strcpy(xattr_name + prefixlen, name); 443 + res = __hfsplus_setxattr(dentry->d_inode, xattr_name, value, size, 444 + flags); 445 + kfree(xattr_name); 446 + return res; 447 + } 448 + 449 static ssize_t hfsplus_getxattr_finder_info(struct inode *inode, 450 void *value, size_t size) 451 { ··· 558 failed_getxattr_init: 559 hfsplus_destroy_attr_entry(entry); 560 return res; 561 + } 562 + 563 + ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, 564 + void *value, size_t size, 565 + const char *prefix, size_t prefixlen) 566 + { 567 + int res; 568 + char *xattr_name; 569 + 570 + if (!strcmp(name, "")) 571 + return -EINVAL; 572 + 573 + xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 574 + GFP_KERNEL); 575 + if (!xattr_name) 576 + return -ENOMEM; 577 + 578 + strcpy(xattr_name, prefix); 579 + strcpy(xattr_name + prefixlen, name); 580 + 581 + res = __hfsplus_getxattr(dentry->d_inode, xattr_name, value, size); 582 + kfree(xattr_name); 583 + return res; 584 + 585 } 586 587 static inline int can_list(const char *xattr_name) ··· 806 static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, 807 void *buffer, size_t size, int type) 808 { 809 if (!strcmp(name, "")) 810 return -EINVAL; 811 ··· 818 */ 819 if (is_known_namespace(name)) 820 return -EOPNOTSUPP; 821 822 + /* 823 + * osx is the namespace we use to indicate an unprefixed 824 + * attribute on the filesystem (like the ones that OS X 825 + * creates), so we pass the name through unmodified (after 826 + * ensuring it doesn't conflict with another namespace). 827 + */ 828 + return __hfsplus_getxattr(dentry->d_inode, name, buffer, size); 829 } 830 831 static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, 832 const void *buffer, size_t size, int flags, int type) 833 { 834 if (!strcmp(name, "")) 835 return -EINVAL; 836 ··· 845 */ 846 if (is_known_namespace(name)) 847 return -EOPNOTSUPP; 848 849 + /* 850 + * osx is the namespace we use to indicate an unprefixed 851 + * attribute on the filesystem (like the ones that OS X 852 + * creates), so we pass the name through unmodified (after 853 + * ensuring it doesn't conflict with another namespace). 854 + */ 855 + return __hfsplus_setxattr(dentry->d_inode, name, buffer, size, flags); 856 } 857 858 static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
+7 -13
fs/hfsplus/xattr.h
··· 21 int __hfsplus_setxattr(struct inode *inode, const char *name, 22 const void *value, size_t size, int flags); 23 24 - static inline int hfsplus_setxattr(struct dentry *dentry, const char *name, 25 - const void *value, size_t size, int flags) 26 - { 27 - return __hfsplus_setxattr(dentry->d_inode, name, value, size, flags); 28 - } 29 30 ssize_t __hfsplus_getxattr(struct inode *inode, const char *name, 31 - void *value, size_t size); 32 33 - static inline ssize_t hfsplus_getxattr(struct dentry *dentry, 34 - const char *name, 35 - void *value, 36 - size_t size) 37 - { 38 - return __hfsplus_getxattr(dentry->d_inode, name, value, size); 39 - } 40 41 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); 42
··· 21 int __hfsplus_setxattr(struct inode *inode, const char *name, 22 const void *value, size_t size, int flags); 23 24 + int hfsplus_setxattr(struct dentry *dentry, const char *name, 25 + const void *value, size_t size, int flags, 26 + const char *prefix, size_t prefixlen); 27 28 ssize_t __hfsplus_getxattr(struct inode *inode, const char *name, 29 + void *value, size_t size); 30 31 + ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, 32 + void *value, size_t size, 33 + const char *prefix, size_t prefixlen); 34 35 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); 36
+6 -32
fs/hfsplus/xattr_security.c
··· 16 static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, 17 void *buffer, size_t size, int type) 18 { 19 - char *xattr_name; 20 - int res; 21 - 22 - if (!strcmp(name, "")) 23 - return -EINVAL; 24 - 25 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 26 - GFP_KERNEL); 27 - if (!xattr_name) 28 - return -ENOMEM; 29 - strcpy(xattr_name, XATTR_SECURITY_PREFIX); 30 - strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); 31 - 32 - res = hfsplus_getxattr(dentry, xattr_name, buffer, size); 33 - kfree(xattr_name); 34 - return res; 35 } 36 37 static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, 38 const void *buffer, size_t size, int flags, int type) 39 { 40 - char *xattr_name; 41 - int res; 42 - 43 - if (!strcmp(name, "")) 44 - return -EINVAL; 45 - 46 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 47 - GFP_KERNEL); 48 - if (!xattr_name) 49 - return -ENOMEM; 50 - strcpy(xattr_name, XATTR_SECURITY_PREFIX); 51 - strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); 52 - 53 - res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); 54 - kfree(xattr_name); 55 - return res; 56 } 57 58 static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
··· 16 static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, 17 void *buffer, size_t size, int type) 18 { 19 + return hfsplus_getxattr(dentry, name, buffer, size, 20 + XATTR_SECURITY_PREFIX, 21 + XATTR_SECURITY_PREFIX_LEN); 22 } 23 24 static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, 25 const void *buffer, size_t size, int flags, int type) 26 { 27 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 28 + XATTR_SECURITY_PREFIX, 29 + XATTR_SECURITY_PREFIX_LEN); 30 } 31 32 static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
+5 -32
fs/hfsplus/xattr_trusted.c
··· 14 static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, 15 void *buffer, size_t size, int type) 16 { 17 - char *xattr_name; 18 - int res; 19 - 20 - if (!strcmp(name, "")) 21 - return -EINVAL; 22 - 23 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 24 - GFP_KERNEL); 25 - if (!xattr_name) 26 - return -ENOMEM; 27 - strcpy(xattr_name, XATTR_TRUSTED_PREFIX); 28 - strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); 29 - 30 - res = hfsplus_getxattr(dentry, xattr_name, buffer, size); 31 - kfree(xattr_name); 32 - return res; 33 } 34 35 static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, 36 const void *buffer, size_t size, int flags, int type) 37 { 38 - char *xattr_name; 39 - int res; 40 - 41 - if (!strcmp(name, "")) 42 - return -EINVAL; 43 - 44 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 45 - GFP_KERNEL); 46 - if (!xattr_name) 47 - return -ENOMEM; 48 - strcpy(xattr_name, XATTR_TRUSTED_PREFIX); 49 - strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); 50 - 51 - res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); 52 - kfree(xattr_name); 53 - return res; 54 } 55 56 static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
··· 14 static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, 15 void *buffer, size_t size, int type) 16 { 17 + return hfsplus_getxattr(dentry, name, buffer, size, 18 + XATTR_TRUSTED_PREFIX, 19 + XATTR_TRUSTED_PREFIX_LEN); 20 } 21 22 static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, 23 const void *buffer, size_t size, int flags, int type) 24 { 25 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 26 + XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN); 27 } 28 29 static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
+4 -31
fs/hfsplus/xattr_user.c
··· 14 static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, 15 void *buffer, size_t size, int type) 16 { 17 - char *xattr_name; 18 - int res; 19 20 - if (!strcmp(name, "")) 21 - return -EINVAL; 22 - 23 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 24 - GFP_KERNEL); 25 - if (!xattr_name) 26 - return -ENOMEM; 27 - strcpy(xattr_name, XATTR_USER_PREFIX); 28 - strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); 29 - 30 - res = hfsplus_getxattr(dentry, xattr_name, buffer, size); 31 - kfree(xattr_name); 32 - return res; 33 } 34 35 static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, 36 const void *buffer, size_t size, int flags, int type) 37 { 38 - char *xattr_name; 39 - int res; 40 - 41 - if (!strcmp(name, "")) 42 - return -EINVAL; 43 - 44 - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, 45 - GFP_KERNEL); 46 - if (!xattr_name) 47 - return -ENOMEM; 48 - strcpy(xattr_name, XATTR_USER_PREFIX); 49 - strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); 50 - 51 - res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); 52 - kfree(xattr_name); 53 - return res; 54 } 55 56 static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
··· 14 static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, 15 void *buffer, size_t size, int type) 16 { 17 18 + return hfsplus_getxattr(dentry, name, buffer, size, 19 + XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 20 } 21 22 static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, 23 const void *buffer, size_t size, int flags, int type) 24 { 25 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 26 + XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 27 } 28 29 static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
+38
fs/locks.c
··· 2590 return 0; 2591 } 2592 2593 static void *locks_start(struct seq_file *f, loff_t *pos) 2594 __acquires(&blocked_lock_lock) 2595 {
··· 2590 return 0; 2591 } 2592 2593 + static void __show_fd_locks(struct seq_file *f, 2594 + struct list_head *head, int *id, 2595 + struct file *filp, struct files_struct *files) 2596 + { 2597 + struct file_lock *fl; 2598 + 2599 + list_for_each_entry(fl, head, fl_list) { 2600 + 2601 + if (filp != fl->fl_file) 2602 + continue; 2603 + if (fl->fl_owner != files && 2604 + fl->fl_owner != filp) 2605 + continue; 2606 + 2607 + (*id)++; 2608 + seq_puts(f, "lock:\t"); 2609 + lock_get_status(f, fl, *id, ""); 2610 + } 2611 + } 2612 + 2613 + void show_fd_locks(struct seq_file *f, 2614 + struct file *filp, struct files_struct *files) 2615 + { 2616 + struct inode *inode = file_inode(filp); 2617 + struct file_lock_context *ctx; 2618 + int id = 0; 2619 + 2620 + ctx = inode->i_flctx; 2621 + if (!ctx) 2622 + return; 2623 + 2624 + spin_lock(&ctx->flc_lock); 2625 + __show_fd_locks(f, &ctx->flc_flock, &id, filp, files); 2626 + __show_fd_locks(f, &ctx->flc_posix, &id, filp, files); 2627 + __show_fd_locks(f, &ctx->flc_lease, &id, filp, files); 2628 + spin_unlock(&ctx->flc_lock); 2629 + } 2630 + 2631 static void *locks_start(struct seq_file *f, loff_t *pos) 2632 __acquires(&blocked_lock_lock) 2633 {
+3 -2
fs/nilfs2/alloc.c
··· 405 static int nilfs_palloc_count_desc_blocks(struct inode *inode, 406 unsigned long *desc_blocks) 407 { 408 - unsigned long blknum; 409 int ret; 410 411 ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); 412 if (likely(!ret)) 413 *desc_blocks = DIV_ROUND_UP( 414 - blknum, NILFS_MDT(inode)->mi_blocks_per_desc_block); 415 return ret; 416 } 417
··· 405 static int nilfs_palloc_count_desc_blocks(struct inode *inode, 406 unsigned long *desc_blocks) 407 { 408 + __u64 blknum; 409 int ret; 410 411 ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); 412 if (likely(!ret)) 413 *desc_blocks = DIV_ROUND_UP( 414 + (unsigned long)blknum, 415 + NILFS_MDT(inode)->mi_blocks_per_desc_block); 416 return ret; 417 } 418
+37 -11
fs/nilfs2/bmap.c
··· 152 * 153 * %-EEXIST - A record associated with @key already exist. 154 */ 155 - int nilfs_bmap_insert(struct nilfs_bmap *bmap, 156 - unsigned long key, 157 - unsigned long rec) 158 { 159 int ret; 160 ··· 189 return bmap->b_ops->bop_delete(bmap, key); 190 } 191 192 - int nilfs_bmap_last_key(struct nilfs_bmap *bmap, unsigned long *key) 193 { 194 - __u64 lastkey; 195 int ret; 196 197 down_read(&bmap->b_sem); 198 - ret = bmap->b_ops->bop_last_key(bmap, &lastkey); 199 up_read(&bmap->b_sem); 200 201 if (ret < 0) 202 ret = nilfs_bmap_convert_error(bmap, __func__, ret); 203 - else 204 - *key = lastkey; 205 return ret; 206 } 207 ··· 250 * 251 * %-ENOENT - A record associated with @key does not exist. 252 */ 253 - int nilfs_bmap_delete(struct nilfs_bmap *bmap, unsigned long key) 254 { 255 int ret; 256 ··· 261 return nilfs_bmap_convert_error(bmap, __func__, ret); 262 } 263 264 - static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, unsigned long key) 265 { 266 __u64 lastkey; 267 int ret; ··· 302 * 303 * %-ENOMEM - Insufficient amount of memory available. 304 */ 305 - int nilfs_bmap_truncate(struct nilfs_bmap *bmap, unsigned long key) 306 { 307 int ret; 308
··· 152 * 153 * %-EEXIST - A record associated with @key already exist. 154 */ 155 + int nilfs_bmap_insert(struct nilfs_bmap *bmap, __u64 key, unsigned long rec) 156 { 157 int ret; 158 ··· 191 return bmap->b_ops->bop_delete(bmap, key); 192 } 193 194 + /** 195 + * nilfs_bmap_seek_key - seek a valid entry and return its key 196 + * @bmap: bmap struct 197 + * @start: start key number 198 + * @keyp: place to store valid key 199 + * 200 + * Description: nilfs_bmap_seek_key() seeks a valid key on @bmap 201 + * starting from @start, and stores it to @keyp if found. 202 + * 203 + * Return Value: On success, 0 is returned. On error, one of the following 204 + * negative error codes is returned. 205 + * 206 + * %-EIO - I/O error. 207 + * 208 + * %-ENOMEM - Insufficient amount of memory available. 209 + * 210 + * %-ENOENT - No valid entry was found 211 + */ 212 + int nilfs_bmap_seek_key(struct nilfs_bmap *bmap, __u64 start, __u64 *keyp) 213 { 214 int ret; 215 216 down_read(&bmap->b_sem); 217 + ret = bmap->b_ops->bop_seek_key(bmap, start, keyp); 218 up_read(&bmap->b_sem); 219 220 if (ret < 0) 221 ret = nilfs_bmap_convert_error(bmap, __func__, ret); 222 + return ret; 223 + } 224 + 225 + int nilfs_bmap_last_key(struct nilfs_bmap *bmap, __u64 *keyp) 226 + { 227 + int ret; 228 + 229 + down_read(&bmap->b_sem); 230 + ret = bmap->b_ops->bop_last_key(bmap, keyp); 231 + up_read(&bmap->b_sem); 232 + 233 + if (ret < 0) 234 + ret = nilfs_bmap_convert_error(bmap, __func__, ret); 235 return ret; 236 } 237 ··· 224 * 225 * %-ENOENT - A record associated with @key does not exist. 226 */ 227 + int nilfs_bmap_delete(struct nilfs_bmap *bmap, __u64 key) 228 { 229 int ret; 230 ··· 235 return nilfs_bmap_convert_error(bmap, __func__, ret); 236 } 237 238 + static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, __u64 key) 239 { 240 __u64 lastkey; 241 int ret; ··· 276 * 277 * %-ENOMEM - Insufficient amount of memory available. 278 */ 279 + int nilfs_bmap_truncate(struct nilfs_bmap *bmap, __u64 key) 280 { 281 int ret; 282
+8 -5
fs/nilfs2/bmap.h
··· 76 union nilfs_binfo *); 77 int (*bop_mark)(struct nilfs_bmap *, __u64, int); 78 79 - /* The following functions are internal use only. */ 80 int (*bop_last_key)(const struct nilfs_bmap *, __u64 *); 81 int (*bop_check_insert)(const struct nilfs_bmap *, __u64); 82 int (*bop_check_delete)(struct nilfs_bmap *, __u64); 83 int (*bop_gather_data)(struct nilfs_bmap *, __u64 *, __u64 *, int); ··· 155 int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *); 156 void nilfs_bmap_write(struct nilfs_bmap *, struct nilfs_inode *); 157 int nilfs_bmap_lookup_contig(struct nilfs_bmap *, __u64, __u64 *, unsigned); 158 - int nilfs_bmap_insert(struct nilfs_bmap *, unsigned long, unsigned long); 159 - int nilfs_bmap_delete(struct nilfs_bmap *, unsigned long); 160 - int nilfs_bmap_last_key(struct nilfs_bmap *, unsigned long *); 161 - int nilfs_bmap_truncate(struct nilfs_bmap *, unsigned long); 162 void nilfs_bmap_clear(struct nilfs_bmap *); 163 int nilfs_bmap_propagate(struct nilfs_bmap *, struct buffer_head *); 164 void nilfs_bmap_lookup_dirty_buffers(struct nilfs_bmap *, struct list_head *);
··· 76 union nilfs_binfo *); 77 int (*bop_mark)(struct nilfs_bmap *, __u64, int); 78 79 + int (*bop_seek_key)(const struct nilfs_bmap *, __u64, __u64 *); 80 int (*bop_last_key)(const struct nilfs_bmap *, __u64 *); 81 + 82 + /* The following functions are internal use only. */ 83 int (*bop_check_insert)(const struct nilfs_bmap *, __u64); 84 int (*bop_check_delete)(struct nilfs_bmap *, __u64); 85 int (*bop_gather_data)(struct nilfs_bmap *, __u64 *, __u64 *, int); ··· 153 int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *); 154 void nilfs_bmap_write(struct nilfs_bmap *, struct nilfs_inode *); 155 int nilfs_bmap_lookup_contig(struct nilfs_bmap *, __u64, __u64 *, unsigned); 156 + int nilfs_bmap_insert(struct nilfs_bmap *bmap, __u64 key, unsigned long rec); 157 + int nilfs_bmap_delete(struct nilfs_bmap *bmap, __u64 key); 158 + int nilfs_bmap_seek_key(struct nilfs_bmap *bmap, __u64 start, __u64 *keyp); 159 + int nilfs_bmap_last_key(struct nilfs_bmap *bmap, __u64 *keyp); 160 + int nilfs_bmap_truncate(struct nilfs_bmap *bmap, __u64 key); 161 void nilfs_bmap_clear(struct nilfs_bmap *); 162 int nilfs_bmap_propagate(struct nilfs_bmap *, struct buffer_head *); 163 void nilfs_bmap_lookup_dirty_buffers(struct nilfs_bmap *, struct list_head *);
+63
fs/nilfs2/btree.c
··· 633 return 0; 634 } 635 636 static int nilfs_btree_lookup(const struct nilfs_bmap *btree, 637 __u64 key, int level, __u64 *ptrp) 638 { ··· 1601 return ret; 1602 } 1603 1604 static int nilfs_btree_last_key(const struct nilfs_bmap *btree, __u64 *keyp) 1605 { 1606 struct nilfs_btree_path *path; ··· 2357 .bop_assign = nilfs_btree_assign, 2358 .bop_mark = nilfs_btree_mark, 2359 2360 .bop_last_key = nilfs_btree_last_key, 2361 .bop_check_insert = NULL, 2362 .bop_check_delete = nilfs_btree_check_delete, 2363 .bop_gather_data = nilfs_btree_gather_data, ··· 2379 .bop_assign = nilfs_btree_assign_gc, 2380 .bop_mark = NULL, 2381 2382 .bop_last_key = NULL, 2383 .bop_check_insert = NULL, 2384 .bop_check_delete = NULL, 2385 .bop_gather_data = NULL,
··· 633 return 0; 634 } 635 636 + /** 637 + * nilfs_btree_get_next_key - get next valid key from btree path array 638 + * @btree: bmap struct of btree 639 + * @path: array of nilfs_btree_path struct 640 + * @minlevel: start level 641 + * @nextkey: place to store the next valid key 642 + * 643 + * Return Value: If a next key was found, 0 is returned. Otherwise, 644 + * -ENOENT is returned. 645 + */ 646 + static int nilfs_btree_get_next_key(const struct nilfs_bmap *btree, 647 + const struct nilfs_btree_path *path, 648 + int minlevel, __u64 *nextkey) 649 + { 650 + struct nilfs_btree_node *node; 651 + int maxlevel = nilfs_btree_height(btree) - 1; 652 + int index, next_adj, level; 653 + 654 + /* Next index is already set to bp_index for leaf nodes. */ 655 + next_adj = 0; 656 + for (level = minlevel; level <= maxlevel; level++) { 657 + if (level == maxlevel) 658 + node = nilfs_btree_get_root(btree); 659 + else 660 + node = nilfs_btree_get_nonroot_node(path, level); 661 + 662 + index = path[level].bp_index + next_adj; 663 + if (index < nilfs_btree_node_get_nchildren(node)) { 664 + /* Next key is in this node */ 665 + *nextkey = nilfs_btree_node_get_key(node, index); 666 + return 0; 667 + } 668 + /* For non-leaf nodes, next index is stored at bp_index + 1. */ 669 + next_adj = 1; 670 + } 671 + return -ENOENT; 672 + } 673 + 674 static int nilfs_btree_lookup(const struct nilfs_bmap *btree, 675 __u64 key, int level, __u64 *ptrp) 676 { ··· 1563 return ret; 1564 } 1565 1566 + static int nilfs_btree_seek_key(const struct nilfs_bmap *btree, __u64 start, 1567 + __u64 *keyp) 1568 + { 1569 + struct nilfs_btree_path *path; 1570 + const int minlevel = NILFS_BTREE_LEVEL_NODE_MIN; 1571 + int ret; 1572 + 1573 + path = nilfs_btree_alloc_path(); 1574 + if (!path) 1575 + return -ENOMEM; 1576 + 1577 + ret = nilfs_btree_do_lookup(btree, path, start, NULL, minlevel, 0); 1578 + if (!ret) 1579 + *keyp = start; 1580 + else if (ret == -ENOENT) 1581 + ret = nilfs_btree_get_next_key(btree, path, minlevel, keyp); 1582 + 1583 + nilfs_btree_free_path(path); 1584 + return ret; 1585 + } 1586 + 1587 static int nilfs_btree_last_key(const struct nilfs_bmap *btree, __u64 *keyp) 1588 { 1589 struct nilfs_btree_path *path; ··· 2298 .bop_assign = nilfs_btree_assign, 2299 .bop_mark = nilfs_btree_mark, 2300 2301 + .bop_seek_key = nilfs_btree_seek_key, 2302 .bop_last_key = nilfs_btree_last_key, 2303 + 2304 .bop_check_insert = NULL, 2305 .bop_check_delete = nilfs_btree_check_delete, 2306 .bop_gather_data = nilfs_btree_gather_data, ··· 2318 .bop_assign = nilfs_btree_assign_gc, 2319 .bop_mark = NULL, 2320 2321 + .bop_seek_key = NULL, 2322 .bop_last_key = NULL, 2323 + 2324 .bop_check_insert = NULL, 2325 .bop_check_delete = NULL, 2326 .bop_gather_data = NULL,
+52 -6
fs/nilfs2/cpfile.c
··· 53 return do_div(tcno, nilfs_cpfile_checkpoints_per_block(cpfile)); 54 } 55 56 static unsigned long 57 nilfs_cpfile_checkpoints_in_block(const struct inode *cpfile, 58 __u64 curr, ··· 151 return nilfs_mdt_get_block(cpfile, 152 nilfs_cpfile_get_blkoff(cpfile, cno), 153 create, nilfs_cpfile_block_init, bhp); 154 } 155 156 static inline int nilfs_cpfile_delete_checkpoint_block(struct inode *cpfile, ··· 448 return -ENOENT; /* checkpoint number 0 is invalid */ 449 down_read(&NILFS_MDT(cpfile)->mi_sem); 450 451 - for (n = 0; cno < cur_cno && n < nci; cno += ncps) { 452 - ncps = nilfs_cpfile_checkpoints_in_block(cpfile, cno, cur_cno); 453 - ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &bh); 454 if (ret < 0) { 455 - if (ret != -ENOENT) 456 - goto out; 457 - continue; /* skip hole */ 458 } 459 460 kaddr = kmap_atomic(bh->b_page); 461 cp = nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr);
··· 53 return do_div(tcno, nilfs_cpfile_checkpoints_per_block(cpfile)); 54 } 55 56 + static __u64 nilfs_cpfile_first_checkpoint_in_block(const struct inode *cpfile, 57 + unsigned long blkoff) 58 + { 59 + return (__u64)nilfs_cpfile_checkpoints_per_block(cpfile) * blkoff 60 + + 1 - NILFS_MDT(cpfile)->mi_first_entry_offset; 61 + } 62 + 63 static unsigned long 64 nilfs_cpfile_checkpoints_in_block(const struct inode *cpfile, 65 __u64 curr, ··· 144 return nilfs_mdt_get_block(cpfile, 145 nilfs_cpfile_get_blkoff(cpfile, cno), 146 create, nilfs_cpfile_block_init, bhp); 147 + } 148 + 149 + /** 150 + * nilfs_cpfile_find_checkpoint_block - find and get a buffer on cpfile 151 + * @cpfile: inode of cpfile 152 + * @start_cno: start checkpoint number (inclusive) 153 + * @end_cno: end checkpoint number (inclusive) 154 + * @cnop: place to store the next checkpoint number 155 + * @bhp: place to store a pointer to buffer_head struct 156 + * 157 + * Return Value: On success, it returns 0. On error, the following negative 158 + * error code is returned. 159 + * 160 + * %-ENOMEM - Insufficient memory available. 161 + * 162 + * %-EIO - I/O error 163 + * 164 + * %-ENOENT - no block exists in the range. 165 + */ 166 + static int nilfs_cpfile_find_checkpoint_block(struct inode *cpfile, 167 + __u64 start_cno, __u64 end_cno, 168 + __u64 *cnop, 169 + struct buffer_head **bhp) 170 + { 171 + unsigned long start, end, blkoff; 172 + int ret; 173 + 174 + if (unlikely(start_cno > end_cno)) 175 + return -ENOENT; 176 + 177 + start = nilfs_cpfile_get_blkoff(cpfile, start_cno); 178 + end = nilfs_cpfile_get_blkoff(cpfile, end_cno); 179 + 180 + ret = nilfs_mdt_find_block(cpfile, start, end, &blkoff, bhp); 181 + if (!ret) 182 + *cnop = (blkoff == start) ? start_cno : 183 + nilfs_cpfile_first_checkpoint_in_block(cpfile, blkoff); 184 + return ret; 185 } 186 187 static inline int nilfs_cpfile_delete_checkpoint_block(struct inode *cpfile, ··· 403 return -ENOENT; /* checkpoint number 0 is invalid */ 404 down_read(&NILFS_MDT(cpfile)->mi_sem); 405 406 + for (n = 0; n < nci; cno += ncps) { 407 + ret = nilfs_cpfile_find_checkpoint_block( 408 + cpfile, cno, cur_cno - 1, &cno, &bh); 409 if (ret < 0) { 410 + if (likely(ret == -ENOENT)) 411 + break; 412 + goto out; 413 } 414 + ncps = nilfs_cpfile_checkpoints_in_block(cpfile, cno, cur_cno); 415 416 kaddr = kmap_atomic(bh->b_page); 417 cp = nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr);
+17
fs/nilfs2/direct.c
··· 173 return ret; 174 } 175 176 static int nilfs_direct_last_key(const struct nilfs_bmap *direct, __u64 *keyp) 177 { 178 __u64 key, lastkey; ··· 370 .bop_assign = nilfs_direct_assign, 371 .bop_mark = NULL, 372 373 .bop_last_key = nilfs_direct_last_key, 374 .bop_check_insert = nilfs_direct_check_insert, 375 .bop_check_delete = NULL, 376 .bop_gather_data = nilfs_direct_gather_data,
··· 173 return ret; 174 } 175 176 + static int nilfs_direct_seek_key(const struct nilfs_bmap *direct, __u64 start, 177 + __u64 *keyp) 178 + { 179 + __u64 key; 180 + 181 + for (key = start; key <= NILFS_DIRECT_KEY_MAX; key++) { 182 + if (nilfs_direct_get_ptr(direct, key) != 183 + NILFS_BMAP_INVALID_PTR) { 184 + *keyp = key; 185 + return 0; 186 + } 187 + } 188 + return -ENOENT; 189 + } 190 + 191 static int nilfs_direct_last_key(const struct nilfs_bmap *direct, __u64 *keyp) 192 { 193 __u64 key, lastkey; ··· 355 .bop_assign = nilfs_direct_assign, 356 .bop_mark = NULL, 357 358 + .bop_seek_key = nilfs_direct_seek_key, 359 .bop_last_key = nilfs_direct_last_key, 360 + 361 .bop_check_insert = nilfs_direct_check_insert, 362 .bop_check_delete = NULL, 363 .bop_gather_data = nilfs_direct_gather_data,
+13 -12
fs/nilfs2/inode.c
··· 106 err = nilfs_transaction_begin(inode->i_sb, &ti, 1); 107 if (unlikely(err)) 108 goto out; 109 - err = nilfs_bmap_insert(ii->i_bmap, (unsigned long)blkoff, 110 (unsigned long)bh_result); 111 if (unlikely(err != 0)) { 112 if (err == -EEXIST) { ··· 441 void nilfs_set_inode_flags(struct inode *inode) 442 { 443 unsigned int flags = NILFS_I(inode)->i_flags; 444 445 - inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | 446 - S_DIRSYNC); 447 if (flags & FS_SYNC_FL) 448 - inode->i_flags |= S_SYNC; 449 if (flags & FS_APPEND_FL) 450 - inode->i_flags |= S_APPEND; 451 if (flags & FS_IMMUTABLE_FL) 452 - inode->i_flags |= S_IMMUTABLE; 453 if (flags & FS_NOATIME_FL) 454 - inode->i_flags |= S_NOATIME; 455 if (flags & FS_DIRSYNC_FL) 456 - inode->i_flags |= S_DIRSYNC; 457 - mapping_set_gfp_mask(inode->i_mapping, 458 - mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 459 } 460 461 int nilfs_read_inode_common(struct inode *inode, ··· 539 brelse(bh); 540 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); 541 nilfs_set_inode_flags(inode); 542 return 0; 543 544 failed_unmap: ··· 713 static void nilfs_truncate_bmap(struct nilfs_inode_info *ii, 714 unsigned long from) 715 { 716 - unsigned long b; 717 int ret; 718 719 if (!test_bit(NILFS_I_BMAP, &ii->i_state)) ··· 728 if (b < from) 729 return; 730 731 - b -= min_t(unsigned long, NILFS_MAX_TRUNCATE_BLOCKS, b - from); 732 ret = nilfs_bmap_truncate(ii->i_bmap, b); 733 nilfs_relax_pressure_in_lock(ii->vfs_inode.i_sb); 734 if (!ret || (ret == -ENOMEM &&
··· 106 err = nilfs_transaction_begin(inode->i_sb, &ti, 1); 107 if (unlikely(err)) 108 goto out; 109 + err = nilfs_bmap_insert(ii->i_bmap, blkoff, 110 (unsigned long)bh_result); 111 if (unlikely(err != 0)) { 112 if (err == -EEXIST) { ··· 441 void nilfs_set_inode_flags(struct inode *inode) 442 { 443 unsigned int flags = NILFS_I(inode)->i_flags; 444 + unsigned int new_fl = 0; 445 446 if (flags & FS_SYNC_FL) 447 + new_fl |= S_SYNC; 448 if (flags & FS_APPEND_FL) 449 + new_fl |= S_APPEND; 450 if (flags & FS_IMMUTABLE_FL) 451 + new_fl |= S_IMMUTABLE; 452 if (flags & FS_NOATIME_FL) 453 + new_fl |= S_NOATIME; 454 if (flags & FS_DIRSYNC_FL) 455 + new_fl |= S_DIRSYNC; 456 + inode_set_flags(inode, new_fl, S_SYNC | S_APPEND | S_IMMUTABLE | 457 + S_NOATIME | S_DIRSYNC); 458 } 459 460 int nilfs_read_inode_common(struct inode *inode, ··· 540 brelse(bh); 541 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); 542 nilfs_set_inode_flags(inode); 543 + mapping_set_gfp_mask(inode->i_mapping, 544 + mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 545 return 0; 546 547 failed_unmap: ··· 712 static void nilfs_truncate_bmap(struct nilfs_inode_info *ii, 713 unsigned long from) 714 { 715 + __u64 b; 716 int ret; 717 718 if (!test_bit(NILFS_I_BMAP, &ii->i_state)) ··· 727 if (b < from) 728 return; 729 730 + b -= min_t(__u64, NILFS_MAX_TRUNCATE_BLOCKS, b - from); 731 ret = nilfs_bmap_truncate(ii->i_bmap, b); 732 nilfs_relax_pressure_in_lock(ii->vfs_inode.i_sb); 733 if (!ret || (ret == -ENOMEM &&
+54
fs/nilfs2/mdt.c
··· 261 } 262 263 /** 264 * nilfs_mdt_delete_block - make a hole on the meta data file. 265 * @inode: inode of the meta data file 266 * @block: block offset
··· 261 } 262 263 /** 264 + * nilfs_mdt_find_block - find and get a buffer on meta data file. 265 + * @inode: inode of the meta data file 266 + * @start: start block offset (inclusive) 267 + * @end: end block offset (inclusive) 268 + * @blkoff: block offset 269 + * @out_bh: place to store a pointer to buffer_head struct 270 + * 271 + * nilfs_mdt_find_block() looks up an existing block in range of 272 + * [@start, @end] and stores pointer to a buffer head of the block to 273 + * @out_bh, and block offset to @blkoff, respectively. @out_bh and 274 + * @blkoff are substituted only when zero is returned. 275 + * 276 + * Return Value: On success, it returns 0. On error, the following negative 277 + * error code is returned. 278 + * 279 + * %-ENOMEM - Insufficient memory available. 280 + * 281 + * %-EIO - I/O error 282 + * 283 + * %-ENOENT - no block was found in the range 284 + */ 285 + int nilfs_mdt_find_block(struct inode *inode, unsigned long start, 286 + unsigned long end, unsigned long *blkoff, 287 + struct buffer_head **out_bh) 288 + { 289 + __u64 next; 290 + int ret; 291 + 292 + if (unlikely(start > end)) 293 + return -ENOENT; 294 + 295 + ret = nilfs_mdt_read_block(inode, start, true, out_bh); 296 + if (!ret) { 297 + *blkoff = start; 298 + goto out; 299 + } 300 + if (unlikely(ret != -ENOENT || start == ULONG_MAX)) 301 + goto out; 302 + 303 + ret = nilfs_bmap_seek_key(NILFS_I(inode)->i_bmap, start + 1, &next); 304 + if (!ret) { 305 + if (next <= end) { 306 + ret = nilfs_mdt_read_block(inode, next, true, out_bh); 307 + if (!ret) 308 + *blkoff = next; 309 + } else { 310 + ret = -ENOENT; 311 + } 312 + } 313 + out: 314 + return ret; 315 + } 316 + 317 + /** 318 * nilfs_mdt_delete_block - make a hole on the meta data file. 319 * @inode: inode of the meta data file 320 * @block: block offset
+8 -2
fs/nilfs2/mdt.h
··· 78 void (*init_block)(struct inode *, 79 struct buffer_head *, void *), 80 struct buffer_head **); 81 int nilfs_mdt_delete_block(struct inode *, unsigned long); 82 int nilfs_mdt_forget_block(struct inode *, unsigned long); 83 int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long); ··· 114 return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno; 115 } 116 117 - #define nilfs_mdt_bgl_lock(inode, bg) \ 118 - (&NILFS_MDT(inode)->mi_bgl->locks[(bg) & (NR_BG_LOCKS-1)].lock) 119 120 #endif /* _NILFS_MDT_H */
··· 78 void (*init_block)(struct inode *, 79 struct buffer_head *, void *), 80 struct buffer_head **); 81 + int nilfs_mdt_find_block(struct inode *inode, unsigned long start, 82 + unsigned long end, unsigned long *blkoff, 83 + struct buffer_head **out_bh); 84 int nilfs_mdt_delete_block(struct inode *, unsigned long); 85 int nilfs_mdt_forget_block(struct inode *, unsigned long); 86 int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long); ··· 111 return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno; 112 } 113 114 + static inline spinlock_t * 115 + nilfs_mdt_bgl_lock(struct inode *inode, unsigned int block_group) 116 + { 117 + return bgl_lock_ptr(NILFS_MDT(inode)->mi_bgl, block_group); 118 + } 119 120 #endif /* _NILFS_MDT_H */
+10 -14
fs/nilfs2/page.c
··· 89 void nilfs_forget_buffer(struct buffer_head *bh) 90 { 91 struct page *page = bh->b_page; 92 93 lock_buffer(bh); 94 - clear_buffer_nilfs_volatile(bh); 95 - clear_buffer_nilfs_checked(bh); 96 - clear_buffer_nilfs_redirected(bh); 97 - clear_buffer_async_write(bh); 98 - clear_buffer_dirty(bh); 99 if (nilfs_page_buffers_clean(page)) 100 __nilfs_clear_page_dirty(page); 101 102 - clear_buffer_uptodate(bh); 103 - clear_buffer_mapped(bh); 104 bh->b_blocknr = -1; 105 ClearPageUptodate(page); 106 ClearPageMappedToDisk(page); ··· 419 420 if (page_has_buffers(page)) { 421 struct buffer_head *bh, *head; 422 423 bh = head = page_buffers(page); 424 do { ··· 432 "discard block %llu, size %zu", 433 (u64)bh->b_blocknr, bh->b_size); 434 } 435 - clear_buffer_async_write(bh); 436 - clear_buffer_dirty(bh); 437 - clear_buffer_nilfs_volatile(bh); 438 - clear_buffer_nilfs_checked(bh); 439 - clear_buffer_nilfs_redirected(bh); 440 - clear_buffer_uptodate(bh); 441 - clear_buffer_mapped(bh); 442 unlock_buffer(bh); 443 } while (bh = bh->b_this_page, bh != head); 444 }
··· 89 void nilfs_forget_buffer(struct buffer_head *bh) 90 { 91 struct page *page = bh->b_page; 92 + const unsigned long clear_bits = 93 + (1 << BH_Uptodate | 1 << BH_Dirty | 1 << BH_Mapped | 94 + 1 << BH_Async_Write | 1 << BH_NILFS_Volatile | 95 + 1 << BH_NILFS_Checked | 1 << BH_NILFS_Redirected); 96 97 lock_buffer(bh); 98 + set_mask_bits(&bh->b_state, clear_bits, 0); 99 if (nilfs_page_buffers_clean(page)) 100 __nilfs_clear_page_dirty(page); 101 102 bh->b_blocknr = -1; 103 ClearPageUptodate(page); 104 ClearPageMappedToDisk(page); ··· 421 422 if (page_has_buffers(page)) { 423 struct buffer_head *bh, *head; 424 + const unsigned long clear_bits = 425 + (1 << BH_Uptodate | 1 << BH_Dirty | 1 << BH_Mapped | 426 + 1 << BH_Async_Write | 1 << BH_NILFS_Volatile | 427 + 1 << BH_NILFS_Checked | 1 << BH_NILFS_Redirected); 428 429 bh = head = page_buffers(page); 430 do { ··· 430 "discard block %llu, size %zu", 431 (u64)bh->b_blocknr, bh->b_size); 432 } 433 + set_mask_bits(&bh->b_state, clear_bits, 0); 434 unlock_buffer(bh); 435 } while (bh = bh->b_this_page, bh != head); 436 }
+8 -9
fs/nilfs2/segment.c
··· 24 #include <linux/pagemap.h> 25 #include <linux/buffer_head.h> 26 #include <linux/writeback.h> 27 #include <linux/bio.h> 28 #include <linux/completion.h> 29 #include <linux/blkdev.h> ··· 1589 1590 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1591 b_assoc_buffers) { 1592 - set_buffer_async_write(bh); 1593 if (bh->b_page != bd_page) { 1594 if (bd_page) { 1595 lock_page(bd_page); ··· 1688 list_for_each_entry(segbuf, logs, sb_list) { 1689 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1690 b_assoc_buffers) { 1691 - clear_buffer_async_write(bh); 1692 if (bh->b_page != bd_page) { 1693 if (bd_page) 1694 end_page_writeback(bd_page); ··· 1767 b_assoc_buffers) { 1768 set_buffer_uptodate(bh); 1769 clear_buffer_dirty(bh); 1770 - clear_buffer_async_write(bh); 1771 if (bh->b_page != bd_page) { 1772 if (bd_page) 1773 end_page_writeback(bd_page); ··· 1786 */ 1787 list_for_each_entry(bh, &segbuf->sb_payload_buffers, 1788 b_assoc_buffers) { 1789 - set_buffer_uptodate(bh); 1790 - clear_buffer_dirty(bh); 1791 - clear_buffer_async_write(bh); 1792 - clear_buffer_delay(bh); 1793 - clear_buffer_nilfs_volatile(bh); 1794 - clear_buffer_nilfs_redirected(bh); 1795 if (bh == segbuf->sb_super_root) { 1796 if (bh->b_page != bd_page) { 1797 end_page_writeback(bd_page);
··· 24 #include <linux/pagemap.h> 25 #include <linux/buffer_head.h> 26 #include <linux/writeback.h> 27 + #include <linux/bitops.h> 28 #include <linux/bio.h> 29 #include <linux/completion.h> 30 #include <linux/blkdev.h> ··· 1588 1589 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1590 b_assoc_buffers) { 1591 if (bh->b_page != bd_page) { 1592 if (bd_page) { 1593 lock_page(bd_page); ··· 1688 list_for_each_entry(segbuf, logs, sb_list) { 1689 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1690 b_assoc_buffers) { 1691 if (bh->b_page != bd_page) { 1692 if (bd_page) 1693 end_page_writeback(bd_page); ··· 1768 b_assoc_buffers) { 1769 set_buffer_uptodate(bh); 1770 clear_buffer_dirty(bh); 1771 if (bh->b_page != bd_page) { 1772 if (bd_page) 1773 end_page_writeback(bd_page); ··· 1788 */ 1789 list_for_each_entry(bh, &segbuf->sb_payload_buffers, 1790 b_assoc_buffers) { 1791 + const unsigned long set_bits = (1 << BH_Uptodate); 1792 + const unsigned long clear_bits = 1793 + (1 << BH_Dirty | 1 << BH_Async_Write | 1794 + 1 << BH_Delay | 1 << BH_NILFS_Volatile | 1795 + 1 << BH_NILFS_Redirected); 1796 + 1797 + set_mask_bits(&bh->b_state, clear_bits, set_bits); 1798 if (bh == segbuf->sb_super_root) { 1799 if (bh->b_page != bd_page) { 1800 end_page_writeback(bd_page);
+1 -1
fs/nilfs2/super.c
··· 1020 struct dentry *dentry; 1021 int ret; 1022 1023 - if (cno < 0 || cno > nilfs->ns_cno) 1024 return false; 1025 1026 if (cno >= nilfs_last_cno(nilfs))
··· 1020 struct dentry *dentry; 1021 int ret; 1022 1023 + if (cno > nilfs->ns_cno) 1024 return false; 1025 1026 if (cno >= nilfs_last_cno(nilfs))
+17 -10
fs/proc/fd.c
··· 8 #include <linux/security.h> 9 #include <linux/file.h> 10 #include <linux/seq_file.h> 11 12 #include <linux/proc_fs.h> 13 ··· 49 put_files_struct(files); 50 } 51 52 - if (!ret) { 53 - seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n", 54 - (long long)file->f_pos, f_flags, 55 - real_mount(file->f_path.mnt)->mnt_id); 56 - if (file->f_op->show_fdinfo) 57 - file->f_op->show_fdinfo(m, file); 58 - ret = seq_has_overflowed(m); 59 - fput(file); 60 - } 61 62 - return ret; 63 } 64 65 static int seq_fdinfo_open(struct inode *inode, struct file *file)
··· 8 #include <linux/security.h> 9 #include <linux/file.h> 10 #include <linux/seq_file.h> 11 + #include <linux/fs.h> 12 13 #include <linux/proc_fs.h> 14 ··· 48 put_files_struct(files); 49 } 50 51 + if (ret) 52 + return ret; 53 54 + seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n", 55 + (long long)file->f_pos, f_flags, 56 + real_mount(file->f_path.mnt)->mnt_id); 57 + 58 + show_fd_locks(m, file, files); 59 + if (seq_has_overflowed(m)) 60 + goto out; 61 + 62 + if (file->f_op->show_fdinfo) 63 + file->f_op->show_fdinfo(m, file); 64 + 65 + out: 66 + fput(file); 67 + return 0; 68 } 69 70 static int seq_fdinfo_open(struct inode *inode, struct file *file)
+2
include/asm-generic/seccomp.h
··· 17 #define __NR_seccomp_read_32 __NR_read 18 #define __NR_seccomp_write_32 __NR_write 19 #define __NR_seccomp_exit_32 __NR_exit 20 #define __NR_seccomp_sigreturn_32 __NR_rt_sigreturn 21 #endif /* CONFIG_COMPAT && ! already defined */ 22 23 #define __NR_seccomp_read __NR_read
··· 17 #define __NR_seccomp_read_32 __NR_read 18 #define __NR_seccomp_write_32 __NR_write 19 #define __NR_seccomp_exit_32 __NR_exit 20 + #ifndef __NR_seccomp_sigreturn_32 21 #define __NR_seccomp_sigreturn_32 __NR_rt_sigreturn 22 + #endif 23 #endif /* CONFIG_COMPAT && ! already defined */ 24 25 #define __NR_seccomp_read __NR_read
+4 -4
include/linux/bitmap.h
··· 283 { 284 if (small_const_nbits(nbits)) 285 return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); 286 - else 287 - return __bitmap_empty(src, nbits); 288 } 289 290 static inline int bitmap_full(const unsigned long *src, unsigned int nbits) 291 { 292 if (small_const_nbits(nbits)) 293 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); 294 - else 295 - return __bitmap_full(src, nbits); 296 } 297 298 static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
··· 283 { 284 if (small_const_nbits(nbits)) 285 return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); 286 + 287 + return find_first_bit(src, nbits) == nbits; 288 } 289 290 static inline int bitmap_full(const unsigned long *src, unsigned int nbits) 291 { 292 if (small_const_nbits(nbits)) 293 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); 294 + 295 + return find_first_zero_bit(src, nbits) == nbits; 296 } 297 298 static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
+2 -2
include/linux/bitops.h
··· 218 /** 219 * find_last_bit - find the last set bit in a memory region 220 * @addr: The address to start the search at 221 - * @size: The maximum size to search 222 * 223 - * Returns the bit number of the first set bit, or size. 224 */ 225 extern unsigned long find_last_bit(const unsigned long *addr, 226 unsigned long size);
··· 218 /** 219 * find_last_bit - find the last set bit in a memory region 220 * @addr: The address to start the search at 221 + * @size: The number of bits to search 222 * 223 + * Returns the bit number of the last set bit, or size. 224 */ 225 extern unsigned long find_last_bit(const unsigned long *addr, 226 unsigned long size);
+8
include/linux/fs.h
··· 875 atomic_long_inc(&f->f_count); 876 return f; 877 } 878 #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) 879 #define file_count(x) atomic_long_read(&(x)->f_count) 880 ··· 1047 extern int generic_setlease(struct file *, long, struct file_lock **, void **priv); 1048 extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 1049 extern int lease_modify(struct file_lock *, int, struct list_head *); 1050 #else /* !CONFIG_FILE_LOCKING */ 1051 static inline int fcntl_getlk(struct file *file, unsigned int cmd, 1052 struct flock __user *user) ··· 1186 { 1187 return -EINVAL; 1188 } 1189 #endif /* !CONFIG_FILE_LOCKING */ 1190 1191
··· 875 atomic_long_inc(&f->f_count); 876 return f; 877 } 878 + #define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count) 879 #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) 880 #define file_count(x) atomic_long_read(&(x)->f_count) 881 ··· 1046 extern int generic_setlease(struct file *, long, struct file_lock **, void **priv); 1047 extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 1048 extern int lease_modify(struct file_lock *, int, struct list_head *); 1049 + struct files_struct; 1050 + extern void show_fd_locks(struct seq_file *f, 1051 + struct file *filp, struct files_struct *files); 1052 #else /* !CONFIG_FILE_LOCKING */ 1053 static inline int fcntl_getlk(struct file *file, unsigned int cmd, 1054 struct flock __user *user) ··· 1182 { 1183 return -EINVAL; 1184 } 1185 + 1186 + struct files_struct; 1187 + static inline void show_fd_locks(struct seq_file *f, 1188 + struct file *filp, struct files_struct *files) {} 1189 #endif /* !CONFIG_FILE_LOCKING */ 1190 1191
+7 -8
include/linux/kconfig.h
··· 23 #define ___config_enabled(__ignored, val, ...) val 24 25 /* 26 - * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm', 27 - * 0 otherwise. 28 - * 29 - */ 30 - #define IS_ENABLED(option) \ 31 - (config_enabled(option) || config_enabled(option##_MODULE)) 32 - 33 - /* 34 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 35 * otherwise. For boolean options, this is equivalent to 36 * IS_ENABLED(CONFIG_FOO). ··· 34 * otherwise. 35 */ 36 #define IS_MODULE(option) config_enabled(option##_MODULE) 37 38 #endif /* __LINUX_KCONFIG_H */
··· 23 #define ___config_enabled(__ignored, val, ...) val 24 25 /* 26 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 27 * otherwise. For boolean options, this is equivalent to 28 * IS_ENABLED(CONFIG_FOO). ··· 42 * otherwise. 43 */ 44 #define IS_MODULE(option) config_enabled(option##_MODULE) 45 + 46 + /* 47 + * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm', 48 + * 0 otherwise. 49 + */ 50 + #define IS_ENABLED(option) \ 51 + (IS_BUILTIN(option) || IS_MODULE(option)) 52 53 #endif /* __LINUX_KCONFIG_H */
+12
include/linux/kernel.h
··· 103 (((__x) - ((__d) / 2)) / (__d)); \ 104 } \ 105 ) 106 107 /* 108 * Multiplies an integer by a fraction, while avoiding unnecessary
··· 103 (((__x) - ((__d) / 2)) / (__d)); \ 104 } \ 105 ) 106 + /* 107 + * Same as above but for u64 dividends. divisor must be a 32-bit 108 + * number. 109 + */ 110 + #define DIV_ROUND_CLOSEST_ULL(x, divisor)( \ 111 + { \ 112 + typeof(divisor) __d = divisor; \ 113 + unsigned long long _tmp = (x) + (__d) / 2; \ 114 + do_div(_tmp, __d); \ 115 + _tmp; \ 116 + } \ 117 + ) 118 119 /* 120 * Multiplies an integer by a fraction, while avoiding unnecessary
+2
include/linux/mfd/samsung/rtc.h
··· 105 #define S5M_RTC_UDR_MASK (1 << S5M_RTC_UDR_SHIFT) 106 #define S2MPS_RTC_WUDR_SHIFT 4 107 #define S2MPS_RTC_WUDR_MASK (1 << S2MPS_RTC_WUDR_SHIFT) 108 #define S2MPS_RTC_RUDR_SHIFT 0 109 #define S2MPS_RTC_RUDR_MASK (1 << S2MPS_RTC_RUDR_SHIFT) 110 #define RTC_TCON_SHIFT 1
··· 105 #define S5M_RTC_UDR_MASK (1 << S5M_RTC_UDR_SHIFT) 106 #define S2MPS_RTC_WUDR_SHIFT 4 107 #define S2MPS_RTC_WUDR_MASK (1 << S2MPS_RTC_WUDR_SHIFT) 108 + #define S2MPS13_RTC_AUDR_SHIFT 1 109 + #define S2MPS13_RTC_AUDR_MASK (1 << S2MPS13_RTC_AUDR_SHIFT) 110 #define S2MPS_RTC_RUDR_SHIFT 0 111 #define S2MPS_RTC_RUDR_MASK (1 << S2MPS_RTC_RUDR_SHIFT) 112 #define RTC_TCON_SHIFT 1
+1 -1
include/linux/mm_types.h
··· 429 #endif 430 431 /* store ref to file /proc/<pid>/exe symlink points to */ 432 - struct file *exe_file; 433 #ifdef CONFIG_MMU_NOTIFIER 434 struct mmu_notifier_mm *mmu_notifier_mm; 435 #endif
··· 429 #endif 430 431 /* store ref to file /proc/<pid>/exe symlink points to */ 432 + struct file __rcu *exe_file; 433 #ifdef CONFIG_MMU_NOTIFIER 434 struct mmu_notifier_mm *mmu_notifier_mm; 435 #endif
+3
include/linux/sysctl.h
··· 212 213 #endif /* CONFIG_SYSCTL */ 214 215 #endif /* _LINUX_SYSCTL_H */
··· 212 213 #endif /* CONFIG_SYSCTL */ 214 215 + int sysctl_max_threads(struct ctl_table *table, int write, 216 + void __user *buffer, size_t *lenp, loff_t *ppos); 217 + 218 #endif /* _LINUX_SYSCTL_H */
+40
include/linux/util_macros.h
···
··· 1 + #ifndef _LINUX_HELPER_MACROS_H_ 2 + #define _LINUX_HELPER_MACROS_H_ 3 + 4 + #define __find_closest(x, a, as, op) \ 5 + ({ \ 6 + typeof(as) __fc_i, __fc_as = (as) - 1; \ 7 + typeof(x) __fc_x = (x); \ 8 + typeof(*a) *__fc_a = (a); \ 9 + for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \ 10 + if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \ 11 + __fc_a[__fc_i + 1], 2)) \ 12 + break; \ 13 + } \ 14 + (__fc_i); \ 15 + }) 16 + 17 + /** 18 + * find_closest - locate the closest element in a sorted array 19 + * @x: The reference value. 20 + * @a: The array in which to look for the closest element. Must be sorted 21 + * in ascending order. 22 + * @as: Size of 'a'. 23 + * 24 + * Returns the index of the element closest to 'x'. 25 + */ 26 + #define find_closest(x, a, as) __find_closest(x, a, as, <=) 27 + 28 + /** 29 + * find_closest_descending - locate the closest element in a sorted array 30 + * @x: The reference value. 31 + * @a: The array in which to look for the closest element. Must be sorted 32 + * in descending order. 33 + * @as: Size of 'a'. 34 + * 35 + * Similar to find_closest() but 'a' is expected to be sorted in descending 36 + * order. 37 + */ 38 + #define find_closest_descending(x, a, as) __find_closest(x, a, as, >=) 39 + 40 + #endif
+10 -1
include/uapi/asm-generic/errno.h
··· 6 #define EDEADLK 35 /* Resource deadlock would occur */ 7 #define ENAMETOOLONG 36 /* File name too long */ 8 #define ENOLCK 37 /* No record locks available */ 9 - #define ENOSYS 38 /* Function not implemented */ 10 #define ENOTEMPTY 39 /* Directory not empty */ 11 #define ELOOP 40 /* Too many symbolic links encountered */ 12 #define EWOULDBLOCK EAGAIN /* Operation would block */
··· 6 #define EDEADLK 35 /* Resource deadlock would occur */ 7 #define ENAMETOOLONG 36 /* File name too long */ 8 #define ENOLCK 37 /* No record locks available */ 9 + 10 + /* 11 + * This error code is special: arch syscall entry code will return 12 + * -ENOSYS if users try to call a syscall that doesn't exist. To keep 13 + * failures of syscalls that really do exist distinguishable from 14 + * failures due to attempts to use a nonexistent syscall, syscall 15 + * implementations should refrain from returning -ENOSYS. 16 + */ 17 + #define ENOSYS 38 /* Invalid system call number */ 18 + 19 #define ENOTEMPTY 39 /* Directory not empty */ 20 #define ELOOP 40 /* Too many symbolic links encountered */ 21 #define EWOULDBLOCK EAGAIN /* Operation would block */
+2 -2
init/main.c
··· 91 static int kernel_init(void *); 92 93 extern void init_IRQ(void); 94 - extern void fork_init(unsigned long); 95 extern void radix_tree_init(void); 96 #ifndef CONFIG_DEBUG_RODATA 97 static inline void mark_rodata_ro(void) { } ··· 645 #endif 646 thread_info_cache_init(); 647 cred_init(); 648 - fork_init(totalram_pages); 649 proc_caches_init(); 650 buffer_init(); 651 key_init();
··· 91 static int kernel_init(void *); 92 93 extern void init_IRQ(void); 94 + extern void fork_init(void); 95 extern void radix_tree_init(void); 96 #ifndef CONFIG_DEBUG_RODATA 97 static inline void mark_rodata_ro(void) { } ··· 645 #endif 646 thread_info_cache_init(); 647 cred_init(); 648 + fork_init(); 649 proc_caches_init(); 650 buffer_init(); 651 key_init();
+107 -34
kernel/fork.c
··· 74 #include <linux/uprobes.h> 75 #include <linux/aio.h> 76 #include <linux/compiler.h> 77 78 #include <asm/pgtable.h> 79 #include <asm/pgalloc.h> ··· 87 88 #define CREATE_TRACE_POINTS 89 #include <trace/events/task.h> 90 91 /* 92 * Protected counters by write_lock_irq(&tasklist_lock) ··· 264 265 void __init __weak arch_task_cache_init(void) { } 266 267 - void __init fork_init(unsigned long mempages) 268 { 269 #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 270 #ifndef ARCH_MIN_TASKALIGN ··· 302 /* do the arch specific task caches init */ 303 arch_task_cache_init(); 304 305 - /* 306 - * The default maximum number of threads is set to a safe 307 - * value: the thread structures can take up at most half 308 - * of memory. 309 - */ 310 - max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE); 311 - 312 - /* 313 - * we need to allow at least 20 threads to boot a system 314 - */ 315 - if (max_threads < 20) 316 - max_threads = 20; 317 318 init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2; 319 init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2; ··· 402 * Not linked in yet - no deadlock potential: 403 */ 404 down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING); 405 406 mm->total_vm = oldmm->total_vm; 407 mm->shared_vm = oldmm->shared_vm; ··· 531 pgd_free(mm, mm->pgd); 532 } 533 #else 534 - #define dup_mmap(mm, oldmm) (0) 535 #define mm_alloc_pgd(mm) (0) 536 #define mm_free_pgd(mm) 537 #endif /* CONFIG_MMU */ ··· 706 } 707 EXPORT_SYMBOL_GPL(mmput); 708 709 void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) 710 { 711 if (new_exe_file) 712 get_file(new_exe_file); 713 - if (mm->exe_file) 714 - fput(mm->exe_file); 715 - mm->exe_file = new_exe_file; 716 } 717 718 struct file *get_mm_exe_file(struct mm_struct *mm) 719 { 720 struct file *exe_file; 721 722 - /* We need mmap_sem to protect against races with removal of exe_file */ 723 - down_read(&mm->mmap_sem); 724 - exe_file = mm->exe_file; 725 - if (exe_file) 726 - get_file(exe_file); 727 - up_read(&mm->mmap_sem); 728 return exe_file; 729 } 730 - 731 - static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm) 732 - { 733 - /* It's safe to write the exe_file pointer without exe_file_lock because 734 - * this is called during fork when the task is not yet in /proc */ 735 - newmm->exe_file = get_mm_exe_file(oldmm); 736 - } 737 738 /** 739 * get_task_mm - acquire a reference to the task's mm ··· 914 915 if (!mm_init(mm, tsk)) 916 goto fail_nomem; 917 - 918 - dup_mm_exe_file(oldmm, mm); 919 920 err = dup_mmap(mm, oldmm); 921 if (err) ··· 1452 goto bad_fork_cleanup_io; 1453 1454 if (pid != &init_struct_pid) { 1455 - retval = -ENOMEM; 1456 pid = alloc_pid(p->nsproxy->pid_ns_for_children); 1457 - if (!pid) 1458 goto bad_fork_cleanup_io; 1459 } 1460 1461 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; ··· 2048 task_lock(task); 2049 task->files = copy; 2050 task_unlock(task); 2051 return 0; 2052 }
··· 74 #include <linux/uprobes.h> 75 #include <linux/aio.h> 76 #include <linux/compiler.h> 77 + #include <linux/sysctl.h> 78 79 #include <asm/pgtable.h> 80 #include <asm/pgalloc.h> ··· 86 87 #define CREATE_TRACE_POINTS 88 #include <trace/events/task.h> 89 + 90 + /* 91 + * Minimum number of threads to boot the kernel 92 + */ 93 + #define MIN_THREADS 20 94 + 95 + /* 96 + * Maximum number of threads 97 + */ 98 + #define MAX_THREADS FUTEX_TID_MASK 99 100 /* 101 * Protected counters by write_lock_irq(&tasklist_lock) ··· 253 254 void __init __weak arch_task_cache_init(void) { } 255 256 + /* 257 + * set_max_threads 258 + */ 259 + static void set_max_threads(unsigned int max_threads_suggested) 260 + { 261 + u64 threads; 262 + 263 + /* 264 + * The number of threads shall be limited such that the thread 265 + * structures may only consume a small part of the available memory. 266 + */ 267 + if (fls64(totalram_pages) + fls64(PAGE_SIZE) > 64) 268 + threads = MAX_THREADS; 269 + else 270 + threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE, 271 + (u64) THREAD_SIZE * 8UL); 272 + 273 + if (threads > max_threads_suggested) 274 + threads = max_threads_suggested; 275 + 276 + max_threads = clamp_t(u64, threads, MIN_THREADS, MAX_THREADS); 277 + } 278 + 279 + void __init fork_init(void) 280 { 281 #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 282 #ifndef ARCH_MIN_TASKALIGN ··· 268 /* do the arch specific task caches init */ 269 arch_task_cache_init(); 270 271 + set_max_threads(MAX_THREADS); 272 273 init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2; 274 init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2; ··· 379 * Not linked in yet - no deadlock potential: 380 */ 381 down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING); 382 + 383 + /* No ordering required: file already has been exposed. */ 384 + RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm)); 385 386 mm->total_vm = oldmm->total_vm; 387 mm->shared_vm = oldmm->shared_vm; ··· 505 pgd_free(mm, mm->pgd); 506 } 507 #else 508 + static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) 509 + { 510 + down_write(&oldmm->mmap_sem); 511 + RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm)); 512 + up_write(&oldmm->mmap_sem); 513 + return 0; 514 + } 515 #define mm_alloc_pgd(mm) (0) 516 #define mm_free_pgd(mm) 517 #endif /* CONFIG_MMU */ ··· 674 } 675 EXPORT_SYMBOL_GPL(mmput); 676 677 + /** 678 + * set_mm_exe_file - change a reference to the mm's executable file 679 + * 680 + * This changes mm's executable file (shown as symlink /proc/[pid]/exe). 681 + * 682 + * Main users are mmput() and sys_execve(). Callers prevent concurrent 683 + * invocations: in mmput() nobody alive left, in execve task is single 684 + * threaded. sys_prctl(PR_SET_MM_MAP/EXE_FILE) also needs to set the 685 + * mm->exe_file, but does so without using set_mm_exe_file() in order 686 + * to do avoid the need for any locks. 687 + */ 688 void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) 689 { 690 + struct file *old_exe_file; 691 + 692 + /* 693 + * It is safe to dereference the exe_file without RCU as 694 + * this function is only called if nobody else can access 695 + * this mm -- see comment above for justification. 696 + */ 697 + old_exe_file = rcu_dereference_raw(mm->exe_file); 698 + 699 if (new_exe_file) 700 get_file(new_exe_file); 701 + rcu_assign_pointer(mm->exe_file, new_exe_file); 702 + if (old_exe_file) 703 + fput(old_exe_file); 704 } 705 706 + /** 707 + * get_mm_exe_file - acquire a reference to the mm's executable file 708 + * 709 + * Returns %NULL if mm has no associated executable file. 710 + * User must release file via fput(). 711 + */ 712 struct file *get_mm_exe_file(struct mm_struct *mm) 713 { 714 struct file *exe_file; 715 716 + rcu_read_lock(); 717 + exe_file = rcu_dereference(mm->exe_file); 718 + if (exe_file && !get_file_rcu(exe_file)) 719 + exe_file = NULL; 720 + rcu_read_unlock(); 721 return exe_file; 722 } 723 + EXPORT_SYMBOL(get_mm_exe_file); 724 725 /** 726 * get_task_mm - acquire a reference to the task's mm ··· 863 864 if (!mm_init(mm, tsk)) 865 goto fail_nomem; 866 867 err = dup_mmap(mm, oldmm); 868 if (err) ··· 1403 goto bad_fork_cleanup_io; 1404 1405 if (pid != &init_struct_pid) { 1406 pid = alloc_pid(p->nsproxy->pid_ns_for_children); 1407 + if (IS_ERR(pid)) { 1408 + retval = PTR_ERR(pid); 1409 goto bad_fork_cleanup_io; 1410 + } 1411 } 1412 1413 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; ··· 1998 task_lock(task); 1999 task->files = copy; 2000 task_unlock(task); 2001 + return 0; 2002 + } 2003 + 2004 + int sysctl_max_threads(struct ctl_table *table, int write, 2005 + void __user *buffer, size_t *lenp, loff_t *ppos) 2006 + { 2007 + struct ctl_table t; 2008 + int ret; 2009 + int threads = max_threads; 2010 + int min = MIN_THREADS; 2011 + int max = MAX_THREADS; 2012 + 2013 + t = *table; 2014 + t.data = &threads; 2015 + t.extra1 = &min; 2016 + t.extra2 = &max; 2017 + 2018 + ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); 2019 + if (ret || !write) 2020 + return ret; 2021 + 2022 + set_max_threads(threads); 2023 + 2024 return 0; 2025 }
+4 -1
kernel/gcov/base.c
··· 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/mutex.h> 21 #include "gcov.h" 22 23 static int gcov_events_enabled; ··· 108 gcov_events_enabled = 1; 109 110 /* Perform event callback for previously registered entries. */ 111 - while ((info = gcov_info_next(info))) 112 gcov_event(GCOV_ADD, info); 113 114 mutex_unlock(&gcov_lock); 115 }
··· 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/mutex.h> 21 + #include <linux/sched.h> 22 #include "gcov.h" 23 24 static int gcov_events_enabled; ··· 107 gcov_events_enabled = 1; 108 109 /* Perform event callback for previously registered entries. */ 110 + while ((info = gcov_info_next(info))) { 111 gcov_event(GCOV_ADD, info); 112 + cond_resched(); 113 + } 114 115 mutex_unlock(&gcov_lock); 116 }
+8 -7
kernel/pid.c
··· 182 spin_unlock_irq(&pidmap_lock); 183 kfree(page); 184 if (unlikely(!map->page)) 185 - break; 186 } 187 if (likely(atomic_read(&map->nr_free))) { 188 for ( ; ; ) { ··· 210 } 211 pid = mk_pid(pid_ns, map, offset); 212 } 213 - return -1; 214 } 215 216 int next_pidmap(struct pid_namespace *pid_ns, unsigned int last) ··· 301 int i, nr; 302 struct pid_namespace *tmp; 303 struct upid *upid; 304 305 pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); 306 if (!pid) 307 - goto out; 308 309 tmp = ns; 310 pid->level = ns->level; 311 for (i = ns->level; i >= 0; i--) { 312 nr = alloc_pidmap(tmp); 313 - if (nr < 0) 314 goto out_free; 315 316 pid->numbers[i].nr = nr; 317 pid->numbers[i].ns = tmp; ··· 342 } 343 spin_unlock_irq(&pidmap_lock); 344 345 - out: 346 return pid; 347 348 out_unlock: ··· 353 free_pidmap(pid->numbers + i); 354 355 kmem_cache_free(ns->pid_cachep, pid); 356 - pid = NULL; 357 - goto out; 358 } 359 360 void disable_pid_allocation(struct pid_namespace *ns)
··· 182 spin_unlock_irq(&pidmap_lock); 183 kfree(page); 184 if (unlikely(!map->page)) 185 + return -ENOMEM; 186 } 187 if (likely(atomic_read(&map->nr_free))) { 188 for ( ; ; ) { ··· 210 } 211 pid = mk_pid(pid_ns, map, offset); 212 } 213 + return -EAGAIN; 214 } 215 216 int next_pidmap(struct pid_namespace *pid_ns, unsigned int last) ··· 301 int i, nr; 302 struct pid_namespace *tmp; 303 struct upid *upid; 304 + int retval = -ENOMEM; 305 306 pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); 307 if (!pid) 308 + return ERR_PTR(retval); 309 310 tmp = ns; 311 pid->level = ns->level; 312 for (i = ns->level; i >= 0; i--) { 313 nr = alloc_pidmap(tmp); 314 + if (IS_ERR_VALUE(nr)) { 315 + retval = nr; 316 goto out_free; 317 + } 318 319 pid->numbers[i].nr = nr; 320 pid->numbers[i].ns = tmp; ··· 339 } 340 spin_unlock_irq(&pidmap_lock); 341 342 return pid; 343 344 out_unlock: ··· 351 free_pidmap(pid->numbers + i); 352 353 kmem_cache_free(ns->pid_cachep, pid); 354 + return ERR_PTR(retval); 355 } 356 357 void disable_pid_allocation(struct pid_namespace *ns)
+29 -10
kernel/ptrace.c
··· 456 457 static int ptrace_detach(struct task_struct *child, unsigned int data) 458 { 459 - bool dead = false; 460 - 461 if (!valid_signal(data)) 462 return -EIO; 463 ··· 465 466 write_lock_irq(&tasklist_lock); 467 /* 468 - * This child can be already killed. Make sure de_thread() or 469 - * our sub-thread doing do_wait() didn't do release_task() yet. 470 */ 471 - if (child->ptrace) { 472 - child->exit_code = data; 473 - dead = __ptrace_detach(current, child); 474 - } 475 write_unlock_irq(&tasklist_lock); 476 477 proc_ptrace_connector(child, PTRACE_DETACH); 478 - if (unlikely(dead)) 479 - release_task(child); 480 481 return 0; 482 } ··· 696 static int ptrace_resume(struct task_struct *child, long request, 697 unsigned long data) 698 { 699 if (!valid_signal(data)) 700 return -EIO; 701 ··· 725 user_disable_single_step(child); 726 } 727 728 child->exit_code = data; 729 wake_up_state(child, __TASK_TRACED); 730 731 return 0; 732 }
··· 456 457 static int ptrace_detach(struct task_struct *child, unsigned int data) 458 { 459 if (!valid_signal(data)) 460 return -EIO; 461 ··· 467 468 write_lock_irq(&tasklist_lock); 469 /* 470 + * We rely on ptrace_freeze_traced(). It can't be killed and 471 + * untraced by another thread, it can't be a zombie. 472 */ 473 + WARN_ON(!child->ptrace || child->exit_state); 474 + /* 475 + * tasklist_lock avoids the race with wait_task_stopped(), see 476 + * the comment in ptrace_resume(). 477 + */ 478 + child->exit_code = data; 479 + __ptrace_detach(current, child); 480 write_unlock_irq(&tasklist_lock); 481 482 proc_ptrace_connector(child, PTRACE_DETACH); 483 484 return 0; 485 } ··· 697 static int ptrace_resume(struct task_struct *child, long request, 698 unsigned long data) 699 { 700 + bool need_siglock; 701 + 702 if (!valid_signal(data)) 703 return -EIO; 704 ··· 724 user_disable_single_step(child); 725 } 726 727 + /* 728 + * Change ->exit_code and ->state under siglock to avoid the race 729 + * with wait_task_stopped() in between; a non-zero ->exit_code will 730 + * wrongly look like another report from tracee. 731 + * 732 + * Note that we need siglock even if ->exit_code == data and/or this 733 + * status was not reported yet, the new status must not be cleared by 734 + * wait_task_stopped() after resume. 735 + * 736 + * If data == 0 we do not care if wait_task_stopped() reports the old 737 + * status and clears the code too; this can't race with the tracee, it 738 + * takes siglock after resume. 739 + */ 740 + need_siglock = data && !thread_group_empty(current); 741 + if (need_siglock) 742 + spin_lock_irq(&child->sighand->siglock); 743 child->exit_code = data; 744 wake_up_state(child, __TASK_TRACED); 745 + if (need_siglock) 746 + spin_unlock_irq(&child->sighand->siglock); 747 748 return 0; 749 }
+5 -9
kernel/signal.c
··· 2992 * Nor can they impersonate a kill()/tgkill(), which adds source info. 2993 */ 2994 if ((info->si_code >= 0 || info->si_code == SI_TKILL) && 2995 - (task_pid_vnr(current) != pid)) { 2996 - /* We used to allow any < 0 si_code */ 2997 - WARN_ON_ONCE(info->si_code < 0); 2998 return -EPERM; 2999 - } 3000 info->si_signo = sig; 3001 3002 /* POSIX.1b doesn't mention process groups. */ ··· 3039 /* Not even root can pretend to send signals from the kernel. 3040 * Nor can they impersonate a kill()/tgkill(), which adds source info. 3041 */ 3042 - if (((info->si_code >= 0 || info->si_code == SI_TKILL)) && 3043 - (task_pid_vnr(current) != pid)) { 3044 - /* We used to allow any < 0 si_code */ 3045 - WARN_ON_ONCE(info->si_code < 0); 3046 return -EPERM; 3047 - } 3048 info->si_signo = sig; 3049 3050 return do_send_specific(tgid, pid, sig, info);
··· 2992 * Nor can they impersonate a kill()/tgkill(), which adds source info. 2993 */ 2994 if ((info->si_code >= 0 || info->si_code == SI_TKILL) && 2995 + (task_pid_vnr(current) != pid)) 2996 return -EPERM; 2997 + 2998 info->si_signo = sig; 2999 3000 /* POSIX.1b doesn't mention process groups. */ ··· 3041 /* Not even root can pretend to send signals from the kernel. 3042 * Nor can they impersonate a kill()/tgkill(), which adds source info. 3043 */ 3044 + if ((info->si_code >= 0 || info->si_code == SI_TKILL) && 3045 + (task_pid_vnr(current) != pid)) 3046 return -EPERM; 3047 + 3048 info->si_signo = sig; 3049 3050 return do_send_specific(tgid, pid, sig, info);
+28 -19
kernel/sys.c
··· 1649 return mask; 1650 } 1651 1652 - static int prctl_set_mm_exe_file_locked(struct mm_struct *mm, unsigned int fd) 1653 { 1654 struct fd exe; 1655 struct inode *inode; 1656 int err; 1657 - 1658 - VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm); 1659 1660 exe = fdget(fd); 1661 if (!exe.file) ··· 1679 /* 1680 * Forbid mm->exe_file change if old file still mapped. 1681 */ 1682 err = -EBUSY; 1683 - if (mm->exe_file) { 1684 struct vm_area_struct *vma; 1685 1686 - for (vma = mm->mmap; vma; vma = vma->vm_next) 1687 - if (vma->vm_file && 1688 - path_equal(&vma->vm_file->f_path, 1689 - &mm->exe_file->f_path)) 1690 - goto exit; 1691 } 1692 1693 /* ··· 1708 goto exit; 1709 1710 err = 0; 1711 - set_mm_exe_file(mm, exe.file); /* this grabs a reference to exe.file */ 1712 exit: 1713 fdput(exe); 1714 return err; 1715 } 1716 1717 #ifdef CONFIG_CHECKPOINT_RESTORE ··· 1854 user_auxv[AT_VECTOR_SIZE - 1] = AT_NULL; 1855 } 1856 1857 - down_write(&mm->mmap_sem); 1858 if (prctl_map.exe_fd != (u32)-1) 1859 - error = prctl_set_mm_exe_file_locked(mm, prctl_map.exe_fd); 1860 - downgrade_write(&mm->mmap_sem); 1861 if (error) 1862 goto out; 1863 ··· 1922 if (!capable(CAP_SYS_RESOURCE)) 1923 return -EPERM; 1924 1925 - if (opt == PR_SET_MM_EXE_FILE) { 1926 - down_write(&mm->mmap_sem); 1927 - error = prctl_set_mm_exe_file_locked(mm, (unsigned int)addr); 1928 - up_write(&mm->mmap_sem); 1929 - return error; 1930 - } 1931 1932 if (addr >= TASK_SIZE || addr < mmap_min_addr) 1933 return -EINVAL;
··· 1649 return mask; 1650 } 1651 1652 + static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) 1653 { 1654 struct fd exe; 1655 + struct file *old_exe, *exe_file; 1656 struct inode *inode; 1657 int err; 1658 1659 exe = fdget(fd); 1660 if (!exe.file) ··· 1680 /* 1681 * Forbid mm->exe_file change if old file still mapped. 1682 */ 1683 + exe_file = get_mm_exe_file(mm); 1684 err = -EBUSY; 1685 + if (exe_file) { 1686 struct vm_area_struct *vma; 1687 1688 + down_read(&mm->mmap_sem); 1689 + for (vma = mm->mmap; vma; vma = vma->vm_next) { 1690 + if (!vma->vm_file) 1691 + continue; 1692 + if (path_equal(&vma->vm_file->f_path, 1693 + &exe_file->f_path)) 1694 + goto exit_err; 1695 + } 1696 + 1697 + up_read(&mm->mmap_sem); 1698 + fput(exe_file); 1699 } 1700 1701 /* ··· 1702 goto exit; 1703 1704 err = 0; 1705 + /* set the new file, lockless */ 1706 + get_file(exe.file); 1707 + old_exe = xchg(&mm->exe_file, exe.file); 1708 + if (old_exe) 1709 + fput(old_exe); 1710 exit: 1711 fdput(exe); 1712 return err; 1713 + exit_err: 1714 + up_read(&mm->mmap_sem); 1715 + fput(exe_file); 1716 + goto exit; 1717 } 1718 1719 #ifdef CONFIG_CHECKPOINT_RESTORE ··· 1840 user_auxv[AT_VECTOR_SIZE - 1] = AT_NULL; 1841 } 1842 1843 if (prctl_map.exe_fd != (u32)-1) 1844 + error = prctl_set_mm_exe_file(mm, prctl_map.exe_fd); 1845 + down_read(&mm->mmap_sem); 1846 if (error) 1847 goto out; 1848 ··· 1909 if (!capable(CAP_SYS_RESOURCE)) 1910 return -EPERM; 1911 1912 + if (opt == PR_SET_MM_EXE_FILE) 1913 + return prctl_set_mm_exe_file(mm, (unsigned int)addr); 1914 1915 if (addr >= TASK_SIZE || addr < mmap_min_addr) 1916 return -EINVAL;
+11 -5
kernel/sysctl.c
··· 93 #include <linux/nmi.h> 94 #endif 95 96 - 97 #if defined(CONFIG_SYSCTL) 98 99 /* External variables not in a header file. */ 100 - extern int max_threads; 101 extern int suid_dumpable; 102 #ifdef CONFIG_COREDUMP 103 extern int core_uses_pid; ··· 708 #endif 709 { 710 .procname = "threads-max", 711 - .data = &max_threads, 712 .maxlen = sizeof(int), 713 .mode = 0644, 714 - .proc_handler = proc_dointvec, 715 }, 716 { 717 .procname = "random", ··· 1981 int write, void *data) 1982 { 1983 if (write) { 1984 - *valp = *negp ? -*lvalp : *lvalp; 1985 } else { 1986 int val = *valp; 1987 if (val < 0) {
··· 93 #include <linux/nmi.h> 94 #endif 95 96 #if defined(CONFIG_SYSCTL) 97 98 /* External variables not in a header file. */ 99 extern int suid_dumpable; 100 #ifdef CONFIG_COREDUMP 101 extern int core_uses_pid; ··· 710 #endif 711 { 712 .procname = "threads-max", 713 + .data = NULL, 714 .maxlen = sizeof(int), 715 .mode = 0644, 716 + .proc_handler = sysctl_max_threads, 717 }, 718 { 719 .procname = "random", ··· 1983 int write, void *data) 1984 { 1985 if (write) { 1986 + if (*negp) { 1987 + if (*lvalp > (unsigned long) INT_MAX + 1) 1988 + return -EINVAL; 1989 + *valp = -*lvalp; 1990 + } else { 1991 + if (*lvalp > (unsigned long) INT_MAX) 1992 + return -EINVAL; 1993 + *valp = *lvalp; 1994 + } 1995 } else { 1996 int val = *valp; 1997 if (val < 0) {
+2 -3
lib/Kconfig
··· 18 default n 19 depends on BITREVERSE 20 help 21 - This option provides an config for the architecture which have instruction 22 - can do bitreverse operation, we use the hardware instruction if the architecture 23 - have this capability. 24 25 config RATIONAL 26 bool
··· 18 default n 19 depends on BITREVERSE 20 help 21 + This option enables the use of hardware bit-reversal instructions on 22 + architectures which support such operations. 23 24 config RATIONAL 25 bool
+1 -1
lib/Makefile
··· 25 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 26 bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ 27 gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ 28 - bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o \ 29 percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o 30 obj-y += string_helpers.o 31 obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
··· 25 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 26 bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ 27 gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ 28 + bsearch.o find_bit.o llist.o memweight.o kfifo.o \ 29 percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o 30 obj-y += string_helpers.o 31 obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
-30
lib/bitmap.c
··· 42 * for the best explanations of this ordering. 43 */ 44 45 - int __bitmap_empty(const unsigned long *bitmap, unsigned int bits) 46 - { 47 - unsigned int k, lim = bits/BITS_PER_LONG; 48 - for (k = 0; k < lim; ++k) 49 - if (bitmap[k]) 50 - return 0; 51 - 52 - if (bits % BITS_PER_LONG) 53 - if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) 54 - return 0; 55 - 56 - return 1; 57 - } 58 - EXPORT_SYMBOL(__bitmap_empty); 59 - 60 - int __bitmap_full(const unsigned long *bitmap, unsigned int bits) 61 - { 62 - unsigned int k, lim = bits/BITS_PER_LONG; 63 - for (k = 0; k < lim; ++k) 64 - if (~bitmap[k]) 65 - return 0; 66 - 67 - if (bits % BITS_PER_LONG) 68 - if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) 69 - return 0; 70 - 71 - return 1; 72 - } 73 - EXPORT_SYMBOL(__bitmap_full); 74 - 75 int __bitmap_equal(const unsigned long *bitmap1, 76 const unsigned long *bitmap2, unsigned int bits) 77 {
··· 42 * for the best explanations of this ordering. 43 */ 44 45 int __bitmap_equal(const unsigned long *bitmap1, 46 const unsigned long *bitmap2, unsigned int bits) 47 {
+5 -4
lib/cpumask.c
··· 37 int cpumask_next_and(int n, const struct cpumask *src1p, 38 const struct cpumask *src2p) 39 { 40 - while ((n = cpumask_next(n, src1p)) < nr_cpu_ids) 41 - if (cpumask_test_cpu(n, src2p)) 42 - break; 43 - return n; 44 } 45 EXPORT_SYMBOL(cpumask_next_and); 46
··· 37 int cpumask_next_and(int n, const struct cpumask *src1p, 38 const struct cpumask *src2p) 39 { 40 + struct cpumask tmp; 41 + 42 + if (cpumask_and(&tmp, src1p, src2p)) 43 + return cpumask_next(n, &tmp); 44 + return nr_cpu_ids; 45 } 46 EXPORT_SYMBOL(cpumask_next_and); 47
+1 -1
lib/dma-debug.c
··· 361 unsigned int range = 0; 362 363 while (range <= max_range) { 364 - entry = __hash_bucket_find(*bucket, &index, containing_match); 365 366 if (entry) 367 return entry;
··· 361 unsigned int range = 0; 362 363 while (range <= max_range) { 364 + entry = __hash_bucket_find(*bucket, ref, containing_match); 365 366 if (entry) 367 return entry;
+193
lib/find_bit.c
···
··· 1 + /* bit search implementation 2 + * 3 + * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. 4 + * Written by David Howells (dhowells@redhat.com) 5 + * 6 + * Copyright (C) 2008 IBM Corporation 7 + * 'find_last_bit' is written by Rusty Russell <rusty@rustcorp.com.au> 8 + * (Inspired by David Howell's find_next_bit implementation) 9 + * 10 + * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease 11 + * size and improve performance, 2015. 12 + * 13 + * This program is free software; you can redistribute it and/or 14 + * modify it under the terms of the GNU General Public License 15 + * as published by the Free Software Foundation; either version 16 + * 2 of the License, or (at your option) any later version. 17 + */ 18 + 19 + #include <linux/bitops.h> 20 + #include <linux/bitmap.h> 21 + #include <linux/export.h> 22 + #include <linux/kernel.h> 23 + 24 + #if !defined(find_next_bit) || !defined(find_next_zero_bit) 25 + 26 + /* 27 + * This is a common helper function for find_next_bit and 28 + * find_next_zero_bit. The difference is the "invert" argument, which 29 + * is XORed with each fetched word before searching it for one bits. 30 + */ 31 + static unsigned long _find_next_bit(const unsigned long *addr, 32 + unsigned long nbits, unsigned long start, unsigned long invert) 33 + { 34 + unsigned long tmp; 35 + 36 + if (!nbits || start >= nbits) 37 + return nbits; 38 + 39 + tmp = addr[start / BITS_PER_LONG] ^ invert; 40 + 41 + /* Handle 1st word. */ 42 + tmp &= BITMAP_FIRST_WORD_MASK(start); 43 + start = round_down(start, BITS_PER_LONG); 44 + 45 + while (!tmp) { 46 + start += BITS_PER_LONG; 47 + if (start >= nbits) 48 + return nbits; 49 + 50 + tmp = addr[start / BITS_PER_LONG] ^ invert; 51 + } 52 + 53 + return min(start + __ffs(tmp), nbits); 54 + } 55 + #endif 56 + 57 + #ifndef find_next_bit 58 + /* 59 + * Find the next set bit in a memory region. 60 + */ 61 + unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 62 + unsigned long offset) 63 + { 64 + return _find_next_bit(addr, size, offset, 0UL); 65 + } 66 + EXPORT_SYMBOL(find_next_bit); 67 + #endif 68 + 69 + #ifndef find_next_zero_bit 70 + unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 71 + unsigned long offset) 72 + { 73 + return _find_next_bit(addr, size, offset, ~0UL); 74 + } 75 + EXPORT_SYMBOL(find_next_zero_bit); 76 + #endif 77 + 78 + #ifndef find_first_bit 79 + /* 80 + * Find the first set bit in a memory region. 81 + */ 82 + unsigned long find_first_bit(const unsigned long *addr, unsigned long size) 83 + { 84 + unsigned long idx; 85 + 86 + for (idx = 0; idx * BITS_PER_LONG < size; idx++) { 87 + if (addr[idx]) 88 + return min(idx * BITS_PER_LONG + __ffs(addr[idx]), size); 89 + } 90 + 91 + return size; 92 + } 93 + EXPORT_SYMBOL(find_first_bit); 94 + #endif 95 + 96 + #ifndef find_first_zero_bit 97 + /* 98 + * Find the first cleared bit in a memory region. 99 + */ 100 + unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) 101 + { 102 + unsigned long idx; 103 + 104 + for (idx = 0; idx * BITS_PER_LONG < size; idx++) { 105 + if (addr[idx] != ~0UL) 106 + return min(idx * BITS_PER_LONG + ffz(addr[idx]), size); 107 + } 108 + 109 + return size; 110 + } 111 + EXPORT_SYMBOL(find_first_zero_bit); 112 + #endif 113 + 114 + #ifndef find_last_bit 115 + unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 116 + { 117 + if (size) { 118 + unsigned long val = BITMAP_LAST_WORD_MASK(size); 119 + unsigned long idx = (size-1) / BITS_PER_LONG; 120 + 121 + do { 122 + val &= addr[idx]; 123 + if (val) 124 + return idx * BITS_PER_LONG + __fls(val); 125 + 126 + val = ~0ul; 127 + } while (idx--); 128 + } 129 + return size; 130 + } 131 + EXPORT_SYMBOL(find_last_bit); 132 + #endif 133 + 134 + #ifdef __BIG_ENDIAN 135 + 136 + /* include/linux/byteorder does not support "unsigned long" type */ 137 + static inline unsigned long ext2_swab(const unsigned long y) 138 + { 139 + #if BITS_PER_LONG == 64 140 + return (unsigned long) __swab64((u64) y); 141 + #elif BITS_PER_LONG == 32 142 + return (unsigned long) __swab32((u32) y); 143 + #else 144 + #error BITS_PER_LONG not defined 145 + #endif 146 + } 147 + 148 + #if !defined(find_next_bit_le) || !defined(find_next_zero_bit_le) 149 + static unsigned long _find_next_bit_le(const unsigned long *addr, 150 + unsigned long nbits, unsigned long start, unsigned long invert) 151 + { 152 + unsigned long tmp; 153 + 154 + if (!nbits || start >= nbits) 155 + return nbits; 156 + 157 + tmp = addr[start / BITS_PER_LONG] ^ invert; 158 + 159 + /* Handle 1st word. */ 160 + tmp &= ext2_swab(BITMAP_FIRST_WORD_MASK(start)); 161 + start = round_down(start, BITS_PER_LONG); 162 + 163 + while (!tmp) { 164 + start += BITS_PER_LONG; 165 + if (start >= nbits) 166 + return nbits; 167 + 168 + tmp = addr[start / BITS_PER_LONG] ^ invert; 169 + } 170 + 171 + return min(start + __ffs(ext2_swab(tmp)), nbits); 172 + } 173 + #endif 174 + 175 + #ifndef find_next_zero_bit_le 176 + unsigned long find_next_zero_bit_le(const void *addr, unsigned 177 + long size, unsigned long offset) 178 + { 179 + return _find_next_bit_le(addr, size, offset, ~0UL); 180 + } 181 + EXPORT_SYMBOL(find_next_zero_bit_le); 182 + #endif 183 + 184 + #ifndef find_next_bit_le 185 + unsigned long find_next_bit_le(const void *addr, unsigned 186 + long size, unsigned long offset) 187 + { 188 + return _find_next_bit_le(addr, size, offset, 0UL); 189 + } 190 + EXPORT_SYMBOL(find_next_bit_le); 191 + #endif 192 + 193 + #endif /* __BIG_ENDIAN */
+14 -22
lib/find_last_bit.c
··· 4 * Written by Rusty Russell <rusty@rustcorp.com.au> 5 * (Inspired by David Howell's find_next_bit implementation) 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version ··· 14 */ 15 16 #include <linux/bitops.h> 17 #include <linux/export.h> 18 - #include <asm/types.h> 19 - #include <asm/byteorder.h> 20 21 #ifndef find_last_bit 22 23 unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 24 { 25 - unsigned long words; 26 - unsigned long tmp; 27 28 - /* Start at final word. */ 29 - words = size / BITS_PER_LONG; 30 31 - /* Partial final word? */ 32 - if (size & (BITS_PER_LONG-1)) { 33 - tmp = (addr[words] & (~0UL >> (BITS_PER_LONG 34 - - (size & (BITS_PER_LONG-1))))); 35 - if (tmp) 36 - goto found; 37 } 38 - 39 - while (words) { 40 - tmp = addr[--words]; 41 - if (tmp) { 42 - found: 43 - return words * BITS_PER_LONG + __fls(tmp); 44 - } 45 - } 46 - 47 - /* Not found */ 48 return size; 49 } 50 EXPORT_SYMBOL(find_last_bit);
··· 4 * Written by Rusty Russell <rusty@rustcorp.com.au> 5 * (Inspired by David Howell's find_next_bit implementation) 6 * 7 + * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease 8 + * size and improve performance, 2015. 9 + * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version ··· 11 */ 12 13 #include <linux/bitops.h> 14 + #include <linux/bitmap.h> 15 #include <linux/export.h> 16 + #include <linux/kernel.h> 17 18 #ifndef find_last_bit 19 20 unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 21 { 22 + if (size) { 23 + unsigned long val = BITMAP_LAST_WORD_MASK(size); 24 + unsigned long idx = (size-1) / BITS_PER_LONG; 25 26 + do { 27 + val &= addr[idx]; 28 + if (val) 29 + return idx * BITS_PER_LONG + __fls(val); 30 31 + val = ~0ul; 32 + } while (idx--); 33 } 34 return size; 35 } 36 EXPORT_SYMBOL(find_last_bit);
-285
lib/find_next_bit.c
··· 1 - /* find_next_bit.c: fallback find next bit implementation 2 - * 3 - * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. 4 - * Written by David Howells (dhowells@redhat.com) 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; either version 9 - * 2 of the License, or (at your option) any later version. 10 - */ 11 - 12 - #include <linux/bitops.h> 13 - #include <linux/export.h> 14 - #include <asm/types.h> 15 - #include <asm/byteorder.h> 16 - 17 - #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 18 - 19 - #ifndef find_next_bit 20 - /* 21 - * Find the next set bit in a memory region. 22 - */ 23 - unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 24 - unsigned long offset) 25 - { 26 - const unsigned long *p = addr + BITOP_WORD(offset); 27 - unsigned long result = offset & ~(BITS_PER_LONG-1); 28 - unsigned long tmp; 29 - 30 - if (offset >= size) 31 - return size; 32 - size -= result; 33 - offset %= BITS_PER_LONG; 34 - if (offset) { 35 - tmp = *(p++); 36 - tmp &= (~0UL << offset); 37 - if (size < BITS_PER_LONG) 38 - goto found_first; 39 - if (tmp) 40 - goto found_middle; 41 - size -= BITS_PER_LONG; 42 - result += BITS_PER_LONG; 43 - } 44 - while (size & ~(BITS_PER_LONG-1)) { 45 - if ((tmp = *(p++))) 46 - goto found_middle; 47 - result += BITS_PER_LONG; 48 - size -= BITS_PER_LONG; 49 - } 50 - if (!size) 51 - return result; 52 - tmp = *p; 53 - 54 - found_first: 55 - tmp &= (~0UL >> (BITS_PER_LONG - size)); 56 - if (tmp == 0UL) /* Are any bits set? */ 57 - return result + size; /* Nope. */ 58 - found_middle: 59 - return result + __ffs(tmp); 60 - } 61 - EXPORT_SYMBOL(find_next_bit); 62 - #endif 63 - 64 - #ifndef find_next_zero_bit 65 - /* 66 - * This implementation of find_{first,next}_zero_bit was stolen from 67 - * Linus' asm-alpha/bitops.h. 68 - */ 69 - unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 70 - unsigned long offset) 71 - { 72 - const unsigned long *p = addr + BITOP_WORD(offset); 73 - unsigned long result = offset & ~(BITS_PER_LONG-1); 74 - unsigned long tmp; 75 - 76 - if (offset >= size) 77 - return size; 78 - size -= result; 79 - offset %= BITS_PER_LONG; 80 - if (offset) { 81 - tmp = *(p++); 82 - tmp |= ~0UL >> (BITS_PER_LONG - offset); 83 - if (size < BITS_PER_LONG) 84 - goto found_first; 85 - if (~tmp) 86 - goto found_middle; 87 - size -= BITS_PER_LONG; 88 - result += BITS_PER_LONG; 89 - } 90 - while (size & ~(BITS_PER_LONG-1)) { 91 - if (~(tmp = *(p++))) 92 - goto found_middle; 93 - result += BITS_PER_LONG; 94 - size -= BITS_PER_LONG; 95 - } 96 - if (!size) 97 - return result; 98 - tmp = *p; 99 - 100 - found_first: 101 - tmp |= ~0UL << size; 102 - if (tmp == ~0UL) /* Are any bits zero? */ 103 - return result + size; /* Nope. */ 104 - found_middle: 105 - return result + ffz(tmp); 106 - } 107 - EXPORT_SYMBOL(find_next_zero_bit); 108 - #endif 109 - 110 - #ifndef find_first_bit 111 - /* 112 - * Find the first set bit in a memory region. 113 - */ 114 - unsigned long find_first_bit(const unsigned long *addr, unsigned long size) 115 - { 116 - const unsigned long *p = addr; 117 - unsigned long result = 0; 118 - unsigned long tmp; 119 - 120 - while (size & ~(BITS_PER_LONG-1)) { 121 - if ((tmp = *(p++))) 122 - goto found; 123 - result += BITS_PER_LONG; 124 - size -= BITS_PER_LONG; 125 - } 126 - if (!size) 127 - return result; 128 - 129 - tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); 130 - if (tmp == 0UL) /* Are any bits set? */ 131 - return result + size; /* Nope. */ 132 - found: 133 - return result + __ffs(tmp); 134 - } 135 - EXPORT_SYMBOL(find_first_bit); 136 - #endif 137 - 138 - #ifndef find_first_zero_bit 139 - /* 140 - * Find the first cleared bit in a memory region. 141 - */ 142 - unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) 143 - { 144 - const unsigned long *p = addr; 145 - unsigned long result = 0; 146 - unsigned long tmp; 147 - 148 - while (size & ~(BITS_PER_LONG-1)) { 149 - if (~(tmp = *(p++))) 150 - goto found; 151 - result += BITS_PER_LONG; 152 - size -= BITS_PER_LONG; 153 - } 154 - if (!size) 155 - return result; 156 - 157 - tmp = (*p) | (~0UL << size); 158 - if (tmp == ~0UL) /* Are any bits zero? */ 159 - return result + size; /* Nope. */ 160 - found: 161 - return result + ffz(tmp); 162 - } 163 - EXPORT_SYMBOL(find_first_zero_bit); 164 - #endif 165 - 166 - #ifdef __BIG_ENDIAN 167 - 168 - /* include/linux/byteorder does not support "unsigned long" type */ 169 - static inline unsigned long ext2_swabp(const unsigned long * x) 170 - { 171 - #if BITS_PER_LONG == 64 172 - return (unsigned long) __swab64p((u64 *) x); 173 - #elif BITS_PER_LONG == 32 174 - return (unsigned long) __swab32p((u32 *) x); 175 - #else 176 - #error BITS_PER_LONG not defined 177 - #endif 178 - } 179 - 180 - /* include/linux/byteorder doesn't support "unsigned long" type */ 181 - static inline unsigned long ext2_swab(const unsigned long y) 182 - { 183 - #if BITS_PER_LONG == 64 184 - return (unsigned long) __swab64((u64) y); 185 - #elif BITS_PER_LONG == 32 186 - return (unsigned long) __swab32((u32) y); 187 - #else 188 - #error BITS_PER_LONG not defined 189 - #endif 190 - } 191 - 192 - #ifndef find_next_zero_bit_le 193 - unsigned long find_next_zero_bit_le(const void *addr, unsigned 194 - long size, unsigned long offset) 195 - { 196 - const unsigned long *p = addr; 197 - unsigned long result = offset & ~(BITS_PER_LONG - 1); 198 - unsigned long tmp; 199 - 200 - if (offset >= size) 201 - return size; 202 - p += BITOP_WORD(offset); 203 - size -= result; 204 - offset &= (BITS_PER_LONG - 1UL); 205 - if (offset) { 206 - tmp = ext2_swabp(p++); 207 - tmp |= (~0UL >> (BITS_PER_LONG - offset)); 208 - if (size < BITS_PER_LONG) 209 - goto found_first; 210 - if (~tmp) 211 - goto found_middle; 212 - size -= BITS_PER_LONG; 213 - result += BITS_PER_LONG; 214 - } 215 - 216 - while (size & ~(BITS_PER_LONG - 1)) { 217 - if (~(tmp = *(p++))) 218 - goto found_middle_swap; 219 - result += BITS_PER_LONG; 220 - size -= BITS_PER_LONG; 221 - } 222 - if (!size) 223 - return result; 224 - tmp = ext2_swabp(p); 225 - found_first: 226 - tmp |= ~0UL << size; 227 - if (tmp == ~0UL) /* Are any bits zero? */ 228 - return result + size; /* Nope. Skip ffz */ 229 - found_middle: 230 - return result + ffz(tmp); 231 - 232 - found_middle_swap: 233 - return result + ffz(ext2_swab(tmp)); 234 - } 235 - EXPORT_SYMBOL(find_next_zero_bit_le); 236 - #endif 237 - 238 - #ifndef find_next_bit_le 239 - unsigned long find_next_bit_le(const void *addr, unsigned 240 - long size, unsigned long offset) 241 - { 242 - const unsigned long *p = addr; 243 - unsigned long result = offset & ~(BITS_PER_LONG - 1); 244 - unsigned long tmp; 245 - 246 - if (offset >= size) 247 - return size; 248 - p += BITOP_WORD(offset); 249 - size -= result; 250 - offset &= (BITS_PER_LONG - 1UL); 251 - if (offset) { 252 - tmp = ext2_swabp(p++); 253 - tmp &= (~0UL << offset); 254 - if (size < BITS_PER_LONG) 255 - goto found_first; 256 - if (tmp) 257 - goto found_middle; 258 - size -= BITS_PER_LONG; 259 - result += BITS_PER_LONG; 260 - } 261 - 262 - while (size & ~(BITS_PER_LONG - 1)) { 263 - tmp = *(p++); 264 - if (tmp) 265 - goto found_middle_swap; 266 - result += BITS_PER_LONG; 267 - size -= BITS_PER_LONG; 268 - } 269 - if (!size) 270 - return result; 271 - tmp = ext2_swabp(p); 272 - found_first: 273 - tmp &= (~0UL >> (BITS_PER_LONG - size)); 274 - if (tmp == 0UL) /* Are any bits set? */ 275 - return result + size; /* Nope. */ 276 - found_middle: 277 - return result + __ffs(tmp); 278 - 279 - found_middle_swap: 280 - return result + __ffs(ext2_swab(tmp)); 281 - } 282 - EXPORT_SYMBOL(find_next_bit_le); 283 - #endif 284 - 285 - #endif /* __BIG_ENDIAN */
···
+127 -119
lib/vsprintf.c
··· 33 34 #include <asm/page.h> /* for PAGE_SIZE */ 35 #include <asm/sections.h> /* for dereference_function_descriptor() */ 36 37 #include <linux/string_helpers.h> 38 #include "kstrtox.h" ··· 123 return i; 124 } 125 126 - /* Decimal conversion is by far the most typical, and is used 127 - * for /proc and /sys data. This directly impacts e.g. top performance 128 - * with many processes running. We optimize it for speed 129 - * using ideas described at <http://www.cs.uiowa.edu/~jones/bcd/divide.html> 130 - * (with permission from the author, Douglas W. Jones). 131 */ 132 133 - #if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64 134 - /* Formats correctly any integer in [0, 999999999] */ 135 - static noinline_for_stack 136 - char *put_dec_full9(char *buf, unsigned q) 137 - { 138 - unsigned r; 139 140 - /* 141 - * Possible ways to approx. divide by 10 142 - * (x * 0x1999999a) >> 32 x < 1073741829 (multiply must be 64-bit) 143 - * (x * 0xcccd) >> 19 x < 81920 (x < 262149 when 64-bit mul) 144 - * (x * 0x6667) >> 18 x < 43699 145 - * (x * 0x3334) >> 17 x < 16389 146 - * (x * 0x199a) >> 16 x < 16389 147 - * (x * 0x0ccd) >> 15 x < 16389 148 - * (x * 0x0667) >> 14 x < 2739 149 - * (x * 0x0334) >> 13 x < 1029 150 - * (x * 0x019a) >> 12 x < 1029 151 - * (x * 0x00cd) >> 11 x < 1029 shorter code than * 0x67 (on i386) 152 - * (x * 0x0067) >> 10 x < 179 153 - * (x * 0x0034) >> 9 x < 69 same 154 - * (x * 0x001a) >> 8 x < 69 same 155 - * (x * 0x000d) >> 7 x < 69 same, shortest code (on i386) 156 - * (x * 0x0007) >> 6 x < 19 157 - * See <http://www.cs.uiowa.edu/~jones/bcd/divide.html> 158 - */ 159 - r = (q * (uint64_t)0x1999999a) >> 32; 160 - *buf++ = (q - 10 * r) + '0'; /* 1 */ 161 - q = (r * (uint64_t)0x1999999a) >> 32; 162 - *buf++ = (r - 10 * q) + '0'; /* 2 */ 163 - r = (q * (uint64_t)0x1999999a) >> 32; 164 - *buf++ = (q - 10 * r) + '0'; /* 3 */ 165 - q = (r * (uint64_t)0x1999999a) >> 32; 166 - *buf++ = (r - 10 * q) + '0'; /* 4 */ 167 - r = (q * (uint64_t)0x1999999a) >> 32; 168 - *buf++ = (q - 10 * r) + '0'; /* 5 */ 169 - /* Now value is under 10000, can avoid 64-bit multiply */ 170 - q = (r * 0x199a) >> 16; 171 - *buf++ = (r - 10 * q) + '0'; /* 6 */ 172 - r = (q * 0xcd) >> 11; 173 - *buf++ = (q - 10 * r) + '0'; /* 7 */ 174 - q = (r * 0xcd) >> 11; 175 - *buf++ = (r - 10 * q) + '0'; /* 8 */ 176 - *buf++ = q + '0'; /* 9 */ 177 - return buf; 178 - } 179 - #endif 180 - 181 - /* Similar to above but do not pad with zeros. 182 - * Code can be easily arranged to print 9 digits too, but our callers 183 - * always call put_dec_full9() instead when the number has 9 decimal digits. 184 - */ 185 static noinline_for_stack 186 char *put_dec_trunc8(char *buf, unsigned r) 187 { 188 unsigned q; 189 190 - /* Copy of previous function's body with added early returns */ 191 - while (r >= 10000) { 192 - q = r + '0'; 193 - r = (r * (uint64_t)0x1999999a) >> 32; 194 - *buf++ = q - 10*r; 195 - } 196 197 - q = (r * 0x199a) >> 16; /* r <= 9999 */ 198 - *buf++ = (r - 10 * q) + '0'; 199 - if (q == 0) 200 - return buf; 201 - r = (q * 0xcd) >> 11; /* q <= 999 */ 202 - *buf++ = (q - 10 * r) + '0'; 203 - if (r == 0) 204 - return buf; 205 - q = (r * 0xcd) >> 11; /* r <= 99 */ 206 - *buf++ = (r - 10 * q) + '0'; 207 - if (q == 0) 208 - return buf; 209 - *buf++ = q + '0'; /* q <= 9 */ 210 return buf; 211 } 212 213 - /* There are two algorithms to print larger numbers. 214 - * One is generic: divide by 1000000000 and repeatedly print 215 - * groups of (up to) 9 digits. It's conceptually simple, 216 - * but requires a (unsigned long long) / 1000000000 division. 217 - * 218 - * Second algorithm splits 64-bit unsigned long long into 16-bit chunks, 219 - * manipulates them cleverly and generates groups of 4 decimal digits. 220 - * It so happens that it does NOT require long long division. 221 - * 222 - * If long is > 32 bits, division of 64-bit values is relatively easy, 223 - * and we will use the first algorithm. 224 - * If long long is > 64 bits (strange architecture with VERY large long long), 225 - * second algorithm can't be used, and we again use the first one. 226 - * 227 - * Else (if long is 32 bits and long long is 64 bits) we use second one. 228 - */ 229 230 - #if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64 231 232 - /* First algorithm: generic */ 233 234 - static 235 char *put_dec(char *buf, unsigned long long n) 236 { 237 - if (n >= 100*1000*1000) { 238 - while (n >= 1000*1000*1000) 239 - buf = put_dec_full9(buf, do_div(n, 1000*1000*1000)); 240 - if (n >= 100*1000*1000) 241 - return put_dec_full9(buf, n); 242 - } 243 return put_dec_trunc8(buf, n); 244 } 245 246 - #else 247 248 - /* Second algorithm: valid only for 64-bit long longs */ 249 - 250 - /* See comment in put_dec_full9 for choice of constants */ 251 - static noinline_for_stack 252 - void put_dec_full4(char *buf, unsigned q) 253 { 254 - unsigned r; 255 - r = (q * 0xccd) >> 15; 256 - buf[0] = (q - 10 * r) + '0'; 257 - q = (r * 0xcd) >> 11; 258 - buf[1] = (r - 10 * q) + '0'; 259 - r = (q * 0xcd) >> 11; 260 - buf[2] = (q - 10 * r) + '0'; 261 - buf[3] = r + '0'; 262 } 263 264 /* ··· 269 * The approximation x/10000 == (x * 0x346DC5D7) >> 43 270 * holds for all x < 1,128,869,999. The largest value this 271 * helper will ever be asked to convert is 1,125,520,955. 272 - * (d1 in the put_dec code, assuming n is all-ones). 273 */ 274 - static 275 unsigned put_dec_helper4(char *buf, unsigned x) 276 { 277 uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43; ··· 298 d2 = (h ) & 0xffff; 299 d3 = (h >> 16); /* implicit "& 0xffff" */ 300 301 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); 302 q = put_dec_helper4(buf, q); 303 ··· 329 */ 330 int num_to_str(char *buf, int size, unsigned long long num) 331 { 332 - char tmp[sizeof(num) * 3]; 333 int idx, len; 334 335 /* put_dec() may work incorrectly for num = 0 (generate "", not "0") */ ··· 391 char *number(char *buf, char *end, unsigned long long num, 392 struct printf_spec spec) 393 { 394 - char tmp[3 * sizeof(num)]; 395 char sign; 396 char locase; 397 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); ··· 952 break; 953 } 954 for (i = 0; i < 4; i++) { 955 - char temp[3]; /* hold each IP quad in reverse order */ 956 int digits = put_dec_trunc8(temp, addr[index]) - temp; 957 if (leading_zeros) { 958 if (digits < 3)
··· 33 34 #include <asm/page.h> /* for PAGE_SIZE */ 35 #include <asm/sections.h> /* for dereference_function_descriptor() */ 36 + #include <asm/byteorder.h> /* cpu_to_le16 */ 37 38 #include <linux/string_helpers.h> 39 #include "kstrtox.h" ··· 122 return i; 123 } 124 125 + /* 126 + * Decimal conversion is by far the most typical, and is used for 127 + * /proc and /sys data. This directly impacts e.g. top performance 128 + * with many processes running. We optimize it for speed by emitting 129 + * two characters at a time, using a 200 byte lookup table. This 130 + * roughly halves the number of multiplications compared to computing 131 + * the digits one at a time. Implementation strongly inspired by the 132 + * previous version, which in turn used ideas described at 133 + * <http://www.cs.uiowa.edu/~jones/bcd/divide.html> (with permission 134 + * from the author, Douglas W. Jones). 135 + * 136 + * It turns out there is precisely one 26 bit fixed-point 137 + * approximation a of 64/100 for which x/100 == (x * (u64)a) >> 32 138 + * holds for all x in [0, 10^8-1], namely a = 0x28f5c29. The actual 139 + * range happens to be somewhat larger (x <= 1073741898), but that's 140 + * irrelevant for our purpose. 141 + * 142 + * For dividing a number in the range [10^4, 10^6-1] by 100, we still 143 + * need a 32x32->64 bit multiply, so we simply use the same constant. 144 + * 145 + * For dividing a number in the range [100, 10^4-1] by 100, there are 146 + * several options. The simplest is (x * 0x147b) >> 19, which is valid 147 + * for all x <= 43698. 148 */ 149 150 + static const u16 decpair[100] = { 151 + #define _(x) (__force u16) cpu_to_le16(((x % 10) | ((x / 10) << 8)) + 0x3030) 152 + _( 0), _( 1), _( 2), _( 3), _( 4), _( 5), _( 6), _( 7), _( 8), _( 9), 153 + _(10), _(11), _(12), _(13), _(14), _(15), _(16), _(17), _(18), _(19), 154 + _(20), _(21), _(22), _(23), _(24), _(25), _(26), _(27), _(28), _(29), 155 + _(30), _(31), _(32), _(33), _(34), _(35), _(36), _(37), _(38), _(39), 156 + _(40), _(41), _(42), _(43), _(44), _(45), _(46), _(47), _(48), _(49), 157 + _(50), _(51), _(52), _(53), _(54), _(55), _(56), _(57), _(58), _(59), 158 + _(60), _(61), _(62), _(63), _(64), _(65), _(66), _(67), _(68), _(69), 159 + _(70), _(71), _(72), _(73), _(74), _(75), _(76), _(77), _(78), _(79), 160 + _(80), _(81), _(82), _(83), _(84), _(85), _(86), _(87), _(88), _(89), 161 + _(90), _(91), _(92), _(93), _(94), _(95), _(96), _(97), _(98), _(99), 162 + #undef _ 163 + }; 164 165 + /* 166 + * This will print a single '0' even if r == 0, since we would 167 + * immediately jump to out_r where two 0s would be written but only 168 + * one of them accounted for in buf. This is needed by ip4_string 169 + * below. All other callers pass a non-zero value of r. 170 + */ 171 static noinline_for_stack 172 char *put_dec_trunc8(char *buf, unsigned r) 173 { 174 unsigned q; 175 176 + /* 1 <= r < 10^8 */ 177 + if (r < 100) 178 + goto out_r; 179 180 + /* 100 <= r < 10^8 */ 181 + q = (r * (u64)0x28f5c29) >> 32; 182 + *((u16 *)buf) = decpair[r - 100*q]; 183 + buf += 2; 184 + 185 + /* 1 <= q < 10^6 */ 186 + if (q < 100) 187 + goto out_q; 188 + 189 + /* 100 <= q < 10^6 */ 190 + r = (q * (u64)0x28f5c29) >> 32; 191 + *((u16 *)buf) = decpair[q - 100*r]; 192 + buf += 2; 193 + 194 + /* 1 <= r < 10^4 */ 195 + if (r < 100) 196 + goto out_r; 197 + 198 + /* 100 <= r < 10^4 */ 199 + q = (r * 0x147b) >> 19; 200 + *((u16 *)buf) = decpair[r - 100*q]; 201 + buf += 2; 202 + out_q: 203 + /* 1 <= q < 100 */ 204 + r = q; 205 + out_r: 206 + /* 1 <= r < 100 */ 207 + *((u16 *)buf) = decpair[r]; 208 + buf += r < 10 ? 1 : 2; 209 return buf; 210 } 211 212 + #if BITS_PER_LONG == 64 && BITS_PER_LONG_LONG == 64 213 + static noinline_for_stack 214 + char *put_dec_full8(char *buf, unsigned r) 215 + { 216 + unsigned q; 217 218 + /* 0 <= r < 10^8 */ 219 + q = (r * (u64)0x28f5c29) >> 32; 220 + *((u16 *)buf) = decpair[r - 100*q]; 221 + buf += 2; 222 223 + /* 0 <= q < 10^6 */ 224 + r = (q * (u64)0x28f5c29) >> 32; 225 + *((u16 *)buf) = decpair[q - 100*r]; 226 + buf += 2; 227 228 + /* 0 <= r < 10^4 */ 229 + q = (r * 0x147b) >> 19; 230 + *((u16 *)buf) = decpair[r - 100*q]; 231 + buf += 2; 232 + 233 + /* 0 <= q < 100 */ 234 + *((u16 *)buf) = decpair[q]; 235 + buf += 2; 236 + return buf; 237 + } 238 + 239 + static noinline_for_stack 240 char *put_dec(char *buf, unsigned long long n) 241 { 242 + if (n >= 100*1000*1000) 243 + buf = put_dec_full8(buf, do_div(n, 100*1000*1000)); 244 + /* 1 <= n <= 1.6e11 */ 245 + if (n >= 100*1000*1000) 246 + buf = put_dec_full8(buf, do_div(n, 100*1000*1000)); 247 + /* 1 <= n < 1e8 */ 248 return put_dec_trunc8(buf, n); 249 } 250 251 + #elif BITS_PER_LONG == 32 && BITS_PER_LONG_LONG == 64 252 253 + static void 254 + put_dec_full4(char *buf, unsigned r) 255 { 256 + unsigned q; 257 + 258 + /* 0 <= r < 10^4 */ 259 + q = (r * 0x147b) >> 19; 260 + *((u16 *)buf) = decpair[r - 100*q]; 261 + buf += 2; 262 + /* 0 <= q < 100 */ 263 + *((u16 *)buf) = decpair[q]; 264 } 265 266 /* ··· 265 * The approximation x/10000 == (x * 0x346DC5D7) >> 43 266 * holds for all x < 1,128,869,999. The largest value this 267 * helper will ever be asked to convert is 1,125,520,955. 268 + * (second call in the put_dec code, assuming n is all-ones). 269 */ 270 + static noinline_for_stack 271 unsigned put_dec_helper4(char *buf, unsigned x) 272 { 273 uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43; ··· 294 d2 = (h ) & 0xffff; 295 d3 = (h >> 16); /* implicit "& 0xffff" */ 296 297 + /* n = 2^48 d3 + 2^32 d2 + 2^16 d1 + d0 298 + = 281_4749_7671_0656 d3 + 42_9496_7296 d2 + 6_5536 d1 + d0 */ 299 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); 300 q = put_dec_helper4(buf, q); 301 ··· 323 */ 324 int num_to_str(char *buf, int size, unsigned long long num) 325 { 326 + /* put_dec requires 2-byte alignment of the buffer. */ 327 + char tmp[sizeof(num) * 3] __aligned(2); 328 int idx, len; 329 330 /* put_dec() may work incorrectly for num = 0 (generate "", not "0") */ ··· 384 char *number(char *buf, char *end, unsigned long long num, 385 struct printf_spec spec) 386 { 387 + /* put_dec requires 2-byte alignment of the buffer. */ 388 + char tmp[3 * sizeof(num)] __aligned(2); 389 char sign; 390 char locase; 391 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); ··· 944 break; 945 } 946 for (i = 0; i < 4; i++) { 947 + char temp[4] __aligned(2); /* hold each IP quad in reverse order */ 948 int digits = put_dec_trunc8(temp, addr[index]) - temp; 949 if (leading_zeros) { 950 if (digits < 3)
+6 -2
scripts/Makefile.kasan
··· 13 --param asan-instrumentation-with-call-threshold=$(call_threshold)) 14 15 ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) 16 $(warning Cannot use CONFIG_KASAN: \ 17 -fsanitize=kernel-address is not supported by compiler) 18 else 19 ifeq ($(CFLAGS_KASAN),) 20 - $(warning CONFIG_KASAN: compiler does not support all options.\ 21 - Trying minimal configuration) 22 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) 23 endif 24 endif
··· 13 --param asan-instrumentation-with-call-threshold=$(call_threshold)) 14 15 ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) 16 + ifneq ($(CONFIG_COMPILE_TEST),y) 17 $(warning Cannot use CONFIG_KASAN: \ 18 -fsanitize=kernel-address is not supported by compiler) 19 + endif 20 else 21 ifeq ($(CFLAGS_KASAN),) 22 + ifneq ($(CONFIG_COMPILE_TEST),y) 23 + $(warning CONFIG_KASAN: compiler does not support all options.\ 24 + Trying minimal configuration) 25 + endif 26 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) 27 endif 28 endif
+141 -23
scripts/checkpatch.pl
··· 47 my $minimum_perl_version = 5.10.0; 48 my $min_conf_desc_length = 4; 49 my $spelling_file = "$D/spelling.txt"; 50 51 sub help { 52 my ($exitcode) = @_; ··· 90 file. It's your fault if there's no backup or git 91 --ignore-perl-version override checking of perl version. expect 92 runtime errors. 93 -h, --help, --version display this help and exit 94 95 When FILE is - read standard input. ··· 151 'ignore-perl-version!' => \$ignore_perl_version, 152 'debug=s' => \%debug, 153 'test-only=s' => \$tst_only, 154 'h|help' => \$help, 155 'version' => \$help 156 ) or help(1); ··· 323 324 our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; 325 326 our $NonptrType; 327 our $NonptrTypeMisordered; 328 our $NonptrTypeWithAttr; ··· 444 $mode_perms_search .= $entry->[0]; 445 } 446 447 our $allowed_asm_includes = qr{(?x: 448 irq| 449 memory| ··· 465 my %spelling_fix; 466 467 if (open(my $spelling, '<', $spelling_file)) { 468 - my @spelling_list; 469 while (<$spelling>) { 470 my $line = $_; 471 ··· 476 477 my ($suspect, $fix) = split(/\|\|/, $line); 478 479 - push(@spelling_list, $suspect); 480 $spelling_fix{$suspect} = $fix; 481 } 482 close($spelling); 483 - $misspellings = join("|", @spelling_list); 484 } else { 485 warn "No typos will be found - file '$spelling_file': $!\n"; 486 } 487 488 sub build_types { 489 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; ··· 515 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; 516 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; 517 $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; 518 $NonptrType = qr{ 519 (?:$Modifier\s+|const\s+)* 520 (?: ··· 1690 foreach my $old_line (@{$linesRef}) { 1691 my $save_line = 1; 1692 my $line = $old_line; #don't modify the array 1693 - if ($line =~ /^(?:\+\+\+\|\-\-\-)\s+\S+/) { #new filename 1694 $delta_offset = 0; 1695 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk 1696 $range_last_linenr = $new_linenr; ··· 1898 1899 my $in_header_lines = $file ? 0 : 1; 1900 my $in_commit_log = 0; #Scanning lines before patch 1901 my $reported_maintainer_file = 0; 1902 my $non_utf8_charset = 0; 1903 ··· 2234 "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); 2235 } 2236 2237 # Check for git id commit length and improperly formed commit descriptions 2238 if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { 2239 my $init_char = $1; ··· 2356 } 2357 2358 # Check for various typo / spelling mistakes 2359 - if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) { 2360 - while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { 2361 my $typo = $1; 2362 my $typo_fix = $spelling_fix{lc($typo)}; 2363 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); ··· 2513 #line length limit 2514 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 2515 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 2516 - !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ || 2517 - $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && 2518 $length > $max_line_length) 2519 { 2520 WARN("LONG_LINE", ··· 2607 } 2608 } 2609 2610 - if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && 2611 - (!defined($1) || $1 !~ /sizeof\s*/)) { 2612 if (CHK("SPACING", 2613 "No space is necessary after a cast\n" . $herecurr) && 2614 $fix) { ··· 3208 $herecurr); 3209 } 3210 3211 # check for non-global char *foo[] = {"bar", ...} declarations. 3212 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { 3213 WARN("STATIC_CONST_CHAR_ARRAY", 3214 "char * array declaration might be better as static const\n" . 3215 $herecurr); 3216 } 3217 3218 # check for function declarations without arguments like "int foo()" 3219 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { ··· 3394 $level = "dbg" if ($level eq "debug"); 3395 WARN("PREFER_DEV_LEVEL", 3396 "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); 3397 } 3398 3399 # function brace can't be on same line, except for #defines of do while, ··· 3660 3661 # Ignore operators passed as parameters. 3662 if ($op_type ne 'V' && 3663 - $ca =~ /\s$/ && $cc =~ /^\s*,/) { 3664 3665 # # Ignore comments 3666 # } elsif ($op =~ /^$;+$/) { ··· 3843 $ca =~ /<\S+\@\S+$/)) 3844 { 3845 $ok = 1; 3846 } 3847 3848 # messages are ERROR, but ?: are CHK ··· 4066 } 4067 } 4068 4069 - # Return of what appears to be an errno should normally be -'ve 4070 - if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { 4071 my $name = $1; 4072 if ($name ne 'EOF' && $name ne 'ERROR') { 4073 WARN("USE_NEGATIVE_ERRNO", 4074 - "return of an errno should typically be -ve (return -$1)\n" . $herecurr); 4075 } 4076 } 4077 ··· 4281 } 4282 } 4283 4284 - #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) 4285 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) { 4286 my $file = "$1.h"; 4287 my $checkfile = "include/linux/$file"; ··· 4290 $realfile ne $checkfile && 4291 $1 !~ /$allowed_asm_includes/) 4292 { 4293 - if ($realfile =~ m{^arch/}) { 4294 - CHK("ARCH_INCLUDE_LINUX", 4295 - "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 4296 - } else { 4297 - WARN("INCLUDE_LINUX", 4298 - "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 4299 } 4300 } 4301 } ··· 4804 $lead = "$lead " if ($lead !~ /^\+$/); 4805 $lead = "${lead}const "; 4806 $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/; 4807 } 4808 } 4809 ··· 5378 stacktrace_ops| 5379 sysfs_ops| 5380 tty_operations| 5381 usb_mon_operations| 5382 wd_ops}x; 5383 if ($line !~ /\bconst\b/ && ··· 5436 } 5437 } 5438 5439 - if ($line =~ /debugfs_create_file.*S_IWUGO/ || 5440 - $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { 5441 WARN("EXPORTED_WORLD_WRITABLE", 5442 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 5443 }
··· 47 my $minimum_perl_version = 5.10.0; 48 my $min_conf_desc_length = 4; 49 my $spelling_file = "$D/spelling.txt"; 50 + my $codespell = 0; 51 + my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; 52 53 sub help { 54 my ($exitcode) = @_; ··· 88 file. It's your fault if there's no backup or git 89 --ignore-perl-version override checking of perl version. expect 90 runtime errors. 91 + --codespell Use the codespell dictionary for spelling/typos 92 + (default:/usr/local/share/codespell/dictionary.txt) 93 + --codespellfile Use this codespell dictionary 94 -h, --help, --version display this help and exit 95 96 When FILE is - read standard input. ··· 146 'ignore-perl-version!' => \$ignore_perl_version, 147 'debug=s' => \%debug, 148 'test-only=s' => \$tst_only, 149 + 'codespell!' => \$codespell, 150 + 'codespellfile=s' => \$codespellfile, 151 'h|help' => \$help, 152 'version' => \$help 153 ) or help(1); ··· 316 317 our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; 318 319 + our $BasicType; 320 our $NonptrType; 321 our $NonptrTypeMisordered; 322 our $NonptrTypeWithAttr; ··· 436 $mode_perms_search .= $entry->[0]; 437 } 438 439 + our $mode_perms_world_writable = qr{ 440 + S_IWUGO | 441 + S_IWOTH | 442 + S_IRWXUGO | 443 + S_IALLUGO | 444 + 0[0-7][0-7][2367] 445 + }x; 446 + 447 our $allowed_asm_includes = qr{(?x: 448 irq| 449 memory| ··· 449 my %spelling_fix; 450 451 if (open(my $spelling, '<', $spelling_file)) { 452 while (<$spelling>) { 453 my $line = $_; 454 ··· 461 462 my ($suspect, $fix) = split(/\|\|/, $line); 463 464 $spelling_fix{$suspect} = $fix; 465 } 466 close($spelling); 467 } else { 468 warn "No typos will be found - file '$spelling_file': $!\n"; 469 } 470 + 471 + if ($codespell) { 472 + if (open(my $spelling, '<', $codespellfile)) { 473 + while (<$spelling>) { 474 + my $line = $_; 475 + 476 + $line =~ s/\s*\n?$//g; 477 + $line =~ s/^\s*//g; 478 + 479 + next if ($line =~ m/^\s*#/); 480 + next if ($line =~ m/^\s*$/); 481 + next if ($line =~ m/, disabled/i); 482 + 483 + $line =~ s/,.*$//; 484 + 485 + my ($suspect, $fix) = split(/->/, $line); 486 + 487 + $spelling_fix{$suspect} = $fix; 488 + } 489 + close($spelling); 490 + } else { 491 + warn "No codespell typos will be found - file '$codespellfile': $!\n"; 492 + } 493 + } 494 + 495 + $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; 496 497 sub build_types { 498 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; ··· 476 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; 477 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; 478 $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; 479 + $BasicType = qr{ 480 + (?:$typeOtherOSTypedefs\b)| 481 + (?:$typeTypedefs\b)| 482 + (?:${all}\b) 483 + }x; 484 $NonptrType = qr{ 485 (?:$Modifier\s+|const\s+)* 486 (?: ··· 1646 foreach my $old_line (@{$linesRef}) { 1647 my $save_line = 1; 1648 my $line = $old_line; #don't modify the array 1649 + if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename 1650 $delta_offset = 0; 1651 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk 1652 $range_last_linenr = $new_linenr; ··· 1854 1855 my $in_header_lines = $file ? 0 : 1; 1856 my $in_commit_log = 0; #Scanning lines before patch 1857 + my $commit_log_long_line = 0; 1858 my $reported_maintainer_file = 0; 1859 my $non_utf8_charset = 0; 1860 ··· 2189 "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); 2190 } 2191 2192 + # Check for line lengths > 75 in commit log, warn once 2193 + if ($in_commit_log && !$commit_log_long_line && 2194 + length($line) > 75) { 2195 + WARN("COMMIT_LOG_LONG_LINE", 2196 + "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr); 2197 + $commit_log_long_line = 1; 2198 + } 2199 + 2200 # Check for git id commit length and improperly formed commit descriptions 2201 if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { 2202 my $init_char = $1; ··· 2303 } 2304 2305 # Check for various typo / spelling mistakes 2306 + if (defined($misspellings) && 2307 + ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { 2308 + while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) { 2309 my $typo = $1; 2310 my $typo_fix = $spelling_fix{lc($typo)}; 2311 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); ··· 2459 #line length limit 2460 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 2461 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 2462 + !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?$String\s*(?:|,|\)\s*;)\s*$/ || 2463 + $line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ || 2464 + $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) && 2465 $length > $max_line_length) 2466 { 2467 WARN("LONG_LINE", ··· 2552 } 2553 } 2554 2555 + # check for space after cast like "(int) foo" or "(struct foo) bar" 2556 + # avoid checking a few false positives: 2557 + # "sizeof(<type>)" or "__alignof__(<type>)" 2558 + # function pointer declarations like "(*foo)(int) = bar;" 2559 + # structure definitions like "(struct foo) { 0 };" 2560 + # multiline macros that define functions 2561 + # known attributes or the __attribute__ keyword 2562 + if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ && 2563 + (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) { 2564 if (CHK("SPACING", 2565 "No space is necessary after a cast\n" . $herecurr) && 2566 $fix) { ··· 3146 $herecurr); 3147 } 3148 3149 + # check for const <foo> const where <foo> is not a pointer or array type 3150 + if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { 3151 + my $found = $1; 3152 + if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { 3153 + WARN("CONST_CONST", 3154 + "'const $found const *' should probably be 'const $found * const'\n" . $herecurr); 3155 + } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { 3156 + WARN("CONST_CONST", 3157 + "'const $found const' should probably be 'const $found'\n" . $herecurr); 3158 + } 3159 + } 3160 + 3161 # check for non-global char *foo[] = {"bar", ...} declarations. 3162 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { 3163 WARN("STATIC_CONST_CHAR_ARRAY", 3164 "char * array declaration might be better as static const\n" . 3165 $herecurr); 3166 } 3167 + 3168 + # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo) 3169 + if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) { 3170 + my $array = $1; 3171 + if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) { 3172 + my $array_div = $1; 3173 + if (WARN("ARRAY_SIZE", 3174 + "Prefer ARRAY_SIZE($array)\n" . $herecurr) && 3175 + $fix) { 3176 + $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/; 3177 + } 3178 + } 3179 + } 3180 3181 # check for function declarations without arguments like "int foo()" 3182 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { ··· 3307 $level = "dbg" if ($level eq "debug"); 3308 WARN("PREFER_DEV_LEVEL", 3309 "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); 3310 + } 3311 + 3312 + # ENOSYS means "bad syscall nr" and nothing else. This will have a small 3313 + # number of false positives, but assembly files are not checked, so at 3314 + # least the arch entry code will not trigger this warning. 3315 + if ($line =~ /\bENOSYS\b/) { 3316 + WARN("ENOSYS", 3317 + "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr); 3318 } 3319 3320 # function brace can't be on same line, except for #defines of do while, ··· 3565 3566 # Ignore operators passed as parameters. 3567 if ($op_type ne 'V' && 3568 + $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) { 3569 3570 # # Ignore comments 3571 # } elsif ($op =~ /^$;+$/) { ··· 3748 $ca =~ /<\S+\@\S+$/)) 3749 { 3750 $ok = 1; 3751 + } 3752 + 3753 + # for asm volatile statements 3754 + # ignore a colon with another 3755 + # colon immediately before or after 3756 + if (($op eq ':') && 3757 + ($ca =~ /:$/ || $cc =~ /^:/)) { 3758 + $ok = 1; 3759 } 3760 3761 # messages are ERROR, but ?: are CHK ··· 3963 } 3964 } 3965 3966 + # Return of what appears to be an errno should normally be negative 3967 + if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { 3968 my $name = $1; 3969 if ($name ne 'EOF' && $name ne 'ERROR') { 3970 WARN("USE_NEGATIVE_ERRNO", 3971 + "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); 3972 } 3973 } 3974 ··· 4178 } 4179 } 4180 4181 + # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes 4182 + # itself <asm/foo.h> (uses RAW line) 4183 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) { 4184 my $file = "$1.h"; 4185 my $checkfile = "include/linux/$file"; ··· 4186 $realfile ne $checkfile && 4187 $1 !~ /$allowed_asm_includes/) 4188 { 4189 + my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`; 4190 + if ($asminclude > 0) { 4191 + if ($realfile =~ m{^arch/}) { 4192 + CHK("ARCH_INCLUDE_LINUX", 4193 + "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 4194 + } else { 4195 + WARN("INCLUDE_LINUX", 4196 + "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 4197 + } 4198 } 4199 } 4200 } ··· 4697 $lead = "$lead " if ($lead !~ /^\+$/); 4698 $lead = "${lead}const "; 4699 $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/; 4700 + } 4701 + } 4702 + 4703 + # check for __read_mostly with const non-pointer (should just be const) 4704 + if ($line =~ /\b__read_mostly\b/ && 4705 + $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) { 4706 + if (ERROR("CONST_READ_MOSTLY", 4707 + "Invalid use of __read_mostly with const type\n" . $herecurr) && 4708 + $fix) { 4709 + $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//; 4710 } 4711 } 4712 ··· 5261 stacktrace_ops| 5262 sysfs_ops| 5263 tty_operations| 5264 + uart_ops| 5265 usb_mon_operations| 5266 wd_ops}x; 5267 if ($line !~ /\bconst\b/ && ··· 5318 } 5319 } 5320 5321 + if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ || 5322 + $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) { 5323 WARN("EXPORTED_WORLD_WRITABLE", 5324 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 5325 }
+1
scripts/spelling.txt
··· 825 retreive||retrieve 826 retrive||retrieve 827 retuned||returned 828 reuest||request 829 reuqest||request 830 reutnred||returned
··· 825 retreive||retrieve 826 retrive||retrieve 827 retuned||returned 828 + reudce||reduce 829 reuest||request 830 reuqest||request 831 reutnred||returned
+8 -5
security/tomoyo/util.c
··· 948 */ 949 const char *tomoyo_get_exe(void) 950 { 951 struct mm_struct *mm = current->mm; 952 - const char *cp = NULL; 953 954 if (!mm) 955 return NULL; 956 - down_read(&mm->mmap_sem); 957 - if (mm->exe_file) 958 - cp = tomoyo_realpath_from_path(&mm->exe_file->f_path); 959 - up_read(&mm->mmap_sem); 960 return cp; 961 } 962
··· 948 */ 949 const char *tomoyo_get_exe(void) 950 { 951 + struct file *exe_file; 952 + const char *cp; 953 struct mm_struct *mm = current->mm; 954 955 if (!mm) 956 return NULL; 957 + exe_file = get_mm_exe_file(mm); 958 + if (!exe_file) 959 + return NULL; 960 + 961 + cp = tomoyo_realpath_from_path(&exe_file->f_path); 962 + fput(exe_file); 963 return cp; 964 } 965
+1 -2
sound/soc/codecs/pcm512x.c
··· 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/clk.h> 21 #include <linux/pm_runtime.h> 22 #include <linux/regmap.h> 23 #include <linux/regulator/consumer.h> ··· 32 33 #define DIV_ROUND_DOWN_ULL(ll, d) \ 34 ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) 35 - #define DIV_ROUND_CLOSEST_ULL(ll, d) \ 36 - ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; }) 37 38 #define PCM512x_NUM_SUPPLIES 3 39 static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
··· 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/clk.h> 21 + #include <linux/kernel.h> 22 #include <linux/pm_runtime.h> 23 #include <linux/regmap.h> 24 #include <linux/regulator/consumer.h> ··· 31 32 #define DIV_ROUND_DOWN_ULL(ll, d) \ 33 ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) 34 35 #define PCM512x_NUM_SUPPLIES 3 36 static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {