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

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
...

+2194 -1555
+1
.gitignore
··· 24 24 *.order 25 25 *.elf 26 26 *.bin 27 + *.tar 27 28 *.gz 28 29 *.bz2 29 30 *.lzma
+13
Documentation/CodingStyle
··· 659 659 #define CONSTANT 0x4000 660 660 #define CONSTEXP (CONSTANT | 3) 661 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 + 662 675 The cpp manual deals with macros exhaustively. The gcc internals manual also 663 676 covers RTL which is used frequently with assembly language in the kernel. 664 677
+2 -2
Documentation/SubmittingPatches
··· 614 614 615 615 - An empty line. 616 616 617 - - The body of the explanation, which will be copied to the 618 - permanent changelog to describe this patch. 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 619 620 620 - The "Signed-off-by:" lines, described above, which will 621 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 7 region. 8 8 - interrupts: rtc alarm interrupt 9 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 + 10 15 Example: 11 16 12 17 rtc@80056000 {
+12 -3
Documentation/filesystems/proc.txt
··· 200 200 explained in Table 1-4. 201 201 202 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 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 205 snapshot of a moment, you can see /proc/<pid>/smaps file and scan page table. 206 206 It's slow but very precise. 207 207 208 - Table 1-2: Contents of the status files (as of 2.6.30-rc7) 208 + Table 1-2: Contents of the status files (as of 3.20.0) 209 209 .............................................................................. 210 210 Field Content 211 211 Name filename of the executable ··· 213 213 in an uninterruptible wait, Z is zombie, 214 214 T is traced or stopped) 215 215 Tgid thread group ID 216 + Ngid NUMA group ID (0 if none) 216 217 Pid process id 217 218 PPid process id of the parent process 218 219 TracerPid PID of process tracing this process (0 if not) ··· 221 220 Gid Real, effective, saved set, and file system GIDs 222 221 FDSize number of file descriptor slots currently allocated 223 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 224 227 VmPeak peak virtual memory size 225 228 VmSize total program size 226 229 VmLck locked memory size ··· 1708 1703 pos: 0 1709 1704 flags: 0100002 1710 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 1711 1710 1712 1711 The files such as eventfd, fsnotify, signalfd, epoll among the regular pos/flags 1713 1712 pair provide additional information particular to the objects they represent.
+2 -2
Documentation/spi/spidev_test.c
··· 80 80 * Unescape - process hexadecimal escape character 81 81 * converts shell input "\x23" -> 0x23 82 82 */ 83 - int unespcape(char *_dst, char *_src, size_t len) 83 + static int unescape(char *_dst, char *_src, size_t len) 84 84 { 85 85 int ret = 0; 86 86 char *src = _src; ··· 304 304 size = strlen(input_tx+1); 305 305 tx = malloc(size); 306 306 rx = malloc(size); 307 - size = unespcape((char *)tx, input_tx, size); 307 + size = unescape((char *)tx, input_tx, size); 308 308 transfer(fd, tx, rx, size); 309 309 free(rx); 310 310 free(tx);
+21
Documentation/sysctl/kernel.txt
··· 872 872 873 873 ============================================================== 874 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 + 875 896 unknown_nmi_panic: 876 897 877 898 The value in this file affects behavior of handling NMI. When the
+2
MAINTAINERS
··· 1215 1215 ARM/Mediatek SoC support 1216 1216 M: Matthias Brugger <matthias.bgg@gmail.com> 1217 1217 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1218 + L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 1218 1219 S: Maintained 1219 1220 F: arch/arm/boot/dts/mt6* 1220 1221 F: arch/arm/boot/dts/mt8* ··· 8184 8183 8185 8184 REAL TIME CLOCK (RTC) SUBSYSTEM 8186 8185 M: Alessandro Zummo <a.zummo@towertech.it> 8186 + M: Alexandre Belloni <alexandre.belloni@free-electrons.com> 8187 8187 L: rtc-linux@googlegroups.com 8188 8188 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 8189 8189 S: Maintained
+1
arch/alpha/include/asm/processor.h
··· 44 44 extern unsigned long thread_saved_pc(struct task_struct *); 45 45 46 46 /* Do necessary setup to start up a newly executed thread. */ 47 + struct pt_regs; 47 48 extern void start_thread(struct pt_regs *, unsigned long, unsigned long); 48 49 49 50 /* Free all resources held by a thread. */
+1 -2
arch/arc/kernel/troubleshoot.c
··· 52 52 print_reg_file(&(cregs->r13), 13); 53 53 } 54 54 55 - void print_task_path_n_nm(struct task_struct *tsk, char *buf) 55 + static void print_task_path_n_nm(struct task_struct *tsk, char *buf) 56 56 { 57 57 struct path path; 58 58 char *path_nm = NULL; ··· 77 77 done: 78 78 pr_info("Path: %s\n", path_nm); 79 79 } 80 - EXPORT_SYMBOL(print_task_path_n_nm); 81 80 82 81 static void show_faulting_vma(unsigned long address, char *buf) 83 82 {
+1
arch/arm/include/asm/Kbuild
··· 21 21 generic-y += resource.h 22 22 generic-y += rwsem.h 23 23 generic-y += scatterlist.h 24 + generic-y += seccomp.h 24 25 generic-y += sections.h 25 26 generic-y += segment.h 26 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 3 4 4 #include <linux/unistd.h> 5 5 6 - #define __NR_seccomp_read __NR_read 7 - #define __NR_seccomp_write __NR_write 8 - #define __NR_seccomp_exit __NR_exit 9 6 #define __NR_seccomp_sigreturn __NR_sigreturn 10 7 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 8 + #include <asm-generic/seccomp.h> 15 9 16 10 #endif /* _ASM_MICROBLAZE_SECCOMP_H */
+2 -1
arch/mips/configs/ip32_defconfig
··· 105 105 # CONFIG_RTC_HCTOSYS is not set 106 106 # CONFIG_RTC_INTF_SYSFS is not set 107 107 # CONFIG_RTC_INTF_PROC is not set 108 - CONFIG_RTC_DRV_CMOS=y 108 + CONFIG_RTC_DRV_DS1685_FAMILY=y 109 + CONFIG_RTC_DRV_DS1685=y 109 110 CONFIG_EXT2_FS=y 110 111 CONFIG_EXT2_FS_XATTR=y 111 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 2 3 3 #include <linux/unistd.h> 4 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 5 /* 11 6 * Kludge alert: 12 7 * ··· 23 28 #define __NR_seccomp_sigreturn_32 6211 /* rt_sigreturn */ 24 29 25 30 #endif /* CONFIG_MIPS32_O32 */ 31 + 32 + #include <asm-generic/seccomp.h> 26 33 27 34 #endif /* __ASM_SECCOMP_H */
+39 -7
arch/mips/sgi-ip32/ip32-platform.c
··· 9 9 #include <linux/init.h> 10 10 #include <linux/platform_device.h> 11 11 #include <linux/serial_8250.h> 12 + #include <linux/rtc/ds1685.h> 12 13 13 14 #include <asm/ip32/mace.h> 14 15 #include <asm/ip32/ip32_ints.h> 16 + 17 + extern void ip32_prepare_poweroff(void); 15 18 16 19 #define MACEISA_SERIAL1_OFFS offsetof(struct sgi_mace, isa.serial1) 17 20 #define MACEISA_SERIAL2_OFFS offsetof(struct sgi_mace, isa.serial2) ··· 93 90 94 91 device_initcall(sgio2btns_devinit); 95 92 96 - static struct resource sgio2_cmos_rsrc[] = { 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 97 { 98 - .start = 0x70, 99 - .end = 0x71, 100 - .flags = IORESOURCE_IO 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, 101 105 } 102 106 }; 103 107 104 - static __init int sgio2_cmos_devinit(void) 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) 105 132 { 106 - return IS_ERR(platform_device_register_simple("rtc_cmos", -1, 107 - sgio2_cmos_rsrc, 1)); 133 + return platform_device_register(&ip32_rtc_device); 108 134 } 109 135 110 136 device_initcall(sgio2_cmos_devinit);
+43 -96
arch/mips/sgi-ip32/ip32-reset.c
··· 11 11 #include <linux/compiler.h> 12 12 #include <linux/init.h> 13 13 #include <linux/kernel.h> 14 + #include <linux/module.h> 14 15 #include <linux/sched.h> 15 16 #include <linux/notifier.h> 16 17 #include <linux/delay.h> 17 - #include <linux/ds17287rtc.h> 18 + #include <linux/rtc/ds1685.h> 18 19 #include <linux/interrupt.h> 19 20 #include <linux/pm.h> 20 21 ··· 34 33 #define POWERDOWN_FREQ (HZ / 4) 35 34 #define PANIC_FREQ (HZ / 8) 36 35 37 - static struct timer_list power_timer, blink_timer, debounce_timer; 38 - static int has_panicked, shuting_down; 36 + extern struct platform_device ip32_rtc_device; 39 37 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; 38 + static struct timer_list power_timer, blink_timer; 39 + static int has_panicked, shutting_down; 43 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; 44 65 static void ip32_machine_restart(char *cmd) 45 66 { 67 + msleep(20); 46 68 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(); 69 + unreachable(); 84 70 } 85 71 86 72 static void blink_timeout(unsigned long data) ··· 77 89 mod_timer(&blink_timer, jiffies + data); 78 90 } 79 91 80 - static void debounce(unsigned long data) 92 + static void ip32_machine_halt(void) 81 93 { 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); 94 + ip32_poweroff(&ip32_rtc_device); 105 95 } 106 96 107 - static inline void ip32_power_button(void) 97 + static void power_timeout(unsigned long data) 98 + { 99 + ip32_poweroff(&ip32_rtc_device); 100 + } 101 + 102 + void ip32_prepare_poweroff(void) 108 103 { 109 104 if (has_panicked) 110 105 return; 111 106 112 - if (shuting_down || kill_cad_pid(SIGINT, 1)) { 107 + if (shutting_down || kill_cad_pid(SIGINT, 1)) { 113 108 /* No init process or button pressed twice. */ 114 - ip32_machine_power_off(); 109 + ip32_poweroff(&ip32_rtc_device); 115 110 } 116 111 117 - shuting_down = 1; 112 + shutting_down = 1; 118 113 blink_timer.data = POWERDOWN_FREQ; 119 114 blink_timeout(POWERDOWN_FREQ); 120 115 ··· 105 134 power_timer.function = power_timeout; 106 135 power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ; 107 136 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 137 } 130 138 131 139 static int panic_event(struct notifier_block *this, unsigned long event, ··· 140 190 141 191 _machine_restart = ip32_machine_restart; 142 192 _machine_halt = ip32_machine_halt; 143 - pm_power_off = ip32_machine_power_off; 193 + pm_power_off = ip32_machine_halt; 144 194 145 195 init_timer(&blink_timer); 146 196 blink_timer.function = blink_timeout; 147 197 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 198 152 199 return 0; 153 200 }
+1
arch/parisc/include/asm/Kbuild
··· 20 20 generic-y += percpu.h 21 21 generic-y += poll.h 22 22 generic-y += preempt.h 23 + generic-y += seccomp.h 23 24 generic-y += segment.h 24 25 generic-y += topology.h 25 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 25 header-y += ps3fb.h 26 26 header-y += ptrace.h 27 27 header-y += resource.h 28 - header-y += seccomp.h 29 28 header-y += sembuf.h 30 29 header-y += setup.h 31 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 22 #include <linux/kref.h> 23 23 #include <linux/mm.h> 24 24 #include <linux/fs.h> 25 + #include <linux/file.h> 25 26 #include <linux/module.h> 26 27 #include <linux/notifier.h> 27 28 #include <linux/numa.h> ··· 323 322 unsigned long app_cookie = 0; 324 323 unsigned int my_offset = 0; 325 324 struct vm_area_struct *vma; 325 + struct file *exe_file; 326 326 struct mm_struct *mm = spu->mm; 327 327 328 328 if (!mm) 329 329 goto out; 330 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); 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 336 } 337 337 338 + down_read(&mm->mmap_sem); 338 339 for (vma = mm->mmap; vma; vma = vma->vm_next) { 339 340 if (vma->vm_start > spu_ref || vma->vm_end <= spu_ref) 340 341 continue;
+3 -8
arch/sparc/include/asm/seccomp.h
··· 1 1 #ifndef _ASM_SECCOMP_H 2 + #define _ASM_SECCOMP_H 2 3 3 4 #include <linux/unistd.h> 4 5 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 6 #define __NR_seccomp_sigreturn_32 __NR_sigreturn 7 + 8 + #include <asm-generic/seccomp.h> 14 9 15 10 #endif /* _ASM_SECCOMP_H */
+18 -3
arch/x86/include/asm/seccomp.h
··· 1 + #ifndef _ASM_X86_SECCOMP_H 2 + #define _ASM_X86_SECCOMP_H 3 + 4 + #include <asm/unistd.h> 5 + 1 6 #ifdef CONFIG_X86_32 2 - # include <asm/seccomp_32.h> 3 - #else 4 - # include <asm/seccomp_64.h> 7 + #define __NR_seccomp_sigreturn __NR_sigreturn 5 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 15 #include "clk-kona.h" 16 16 17 17 #include <linux/delay.h> 18 + #include <linux/kernel.h> 18 19 19 20 /* 20 21 * "Policies" affect the frequencies of bus clocks provided by a ··· 52 51 53 52 /* Divider and scaling helpers */ 54 53 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 54 /* Convert a divider into the scaled divisor value it represents. */ 71 55 static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) 72 56 { ··· 73 87 combined = (u64)div_value * BILLION + billionths; 74 88 combined <<= div->u.s.frac_width; 75 89 76 - return do_div_round_closest(combined, BILLION); 90 + return DIV_ROUND_CLOSEST_ULL(combined, BILLION); 77 91 } 78 92 79 93 /* The scaled minimum divisor representable by a divider */ ··· 717 731 scaled_rate = scale_rate(pre_div, parent_rate); 718 732 scaled_rate = scale_rate(div, scaled_rate); 719 733 scaled_div = divider_read_scaled(ccu, pre_div); 720 - scaled_parent_rate = do_div_round_closest(scaled_rate, 734 + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, 721 735 scaled_div); 722 736 } else { 723 737 scaled_parent_rate = scale_rate(div, parent_rate); ··· 729 743 * rate. 730 744 */ 731 745 scaled_div = divider_read_scaled(ccu, div); 732 - result = do_div_round_closest(scaled_parent_rate, scaled_div); 746 + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div); 733 747 734 748 return (unsigned long)result; 735 749 } ··· 776 790 scaled_rate = scale_rate(pre_div, parent_rate); 777 791 scaled_rate = scale_rate(div, scaled_rate); 778 792 scaled_pre_div = divider_read_scaled(ccu, pre_div); 779 - scaled_parent_rate = do_div_round_closest(scaled_rate, 793 + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, 780 794 scaled_pre_div); 781 795 } else { 782 796 scaled_parent_rate = scale_rate(div, parent_rate); ··· 788 802 * the best we can do. 789 803 */ 790 804 if (!divider_is_fixed(div)) { 791 - best_scaled_div = do_div_round_closest(scaled_parent_rate, 805 + best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, 792 806 rate); 793 807 min_scaled_div = scaled_div_min(div); 794 808 max_scaled_div = scaled_div_max(div); ··· 801 815 } 802 816 803 817 /* OK, figure out the resulting rate */ 804 - result = do_div_round_closest(scaled_parent_rate, best_scaled_div); 818 + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div); 805 819 806 820 if (scaled_div) 807 821 *scaled_div = best_scaled_div;
-1
drivers/clk/bcm/clk-kona.h
··· 503 503 504 504 /* Externally visible functions */ 505 505 506 - extern u64 do_div_round_closest(u64 dividend, unsigned long divisor); 507 506 extern u64 scaled_div_max(struct bcm_clk_div *div); 508 507 extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, 509 508 u32 billionths);
+1 -7
drivers/cpuidle/governors/menu.c
··· 190 190 191 191 static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); 192 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 193 /* 200 194 * Try detecting repeating patterns by keeping track of the last 8 201 195 * intervals, and checking if the standard deviation of that set ··· 311 317 * operands are 32 bits. 312 318 * Make sure to round up for half microseconds. 313 319 */ 314 - data->predicted_us = div_round64((uint64_t)data->next_timer_us * 320 + data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us * 315 321 data->correction_factor[data->bucket], 316 322 RESOLUTION * DECAY); 317 323
-3
drivers/gpu/drm/i915/intel_drv.h
··· 36 36 #include <drm/drm_dp_mst_helper.h> 37 37 #include <drm/drm_rect.h> 38 38 39 - #define DIV_ROUND_CLOSEST_ULL(ll, d) \ 40 - ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; }) 41 - 42 39 /** 43 40 * _wait_for - magic (register) wait macro 44 41 *
+1
drivers/gpu/drm/i915/intel_panel.c
··· 30 30 31 31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 32 33 + #include <linux/kernel.h> 33 34 #include <linux/moduleparam.h> 34 35 #include "intel_drv.h" 35 36
+3 -14
drivers/hwmon/ina2xx.c
··· 36 36 #include <linux/jiffies.h> 37 37 #include <linux/of.h> 38 38 #include <linux/delay.h> 39 + #include <linux/util_macros.h> 39 40 40 41 #include <linux/platform_data/ina2xx.h> 41 42 ··· 142 141 */ 143 142 static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; 144 143 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 144 static int ina226_reg_to_interval(u16 config) 159 145 { 160 146 int avg = ina226_avg_tab[INA226_READ_AVG(config)]; ··· 159 171 160 172 avg = DIV_ROUND_CLOSEST(interval * 1000, 161 173 INA226_TOTAL_CONV_TIME_DEFAULT); 162 - avg_bits = ina226_avg_bits(avg); 174 + avg_bits = find_closest(avg, ina226_avg_tab, 175 + ARRAY_SIZE(ina226_avg_tab)); 163 176 164 177 return (config & ~INA226_AVG_RD_MASK) | INA226_SHIFT_AVG(avg_bits); 165 178 }
+8 -18
drivers/hwmon/lm85.c
··· 34 34 #include <linux/hwmon-sysfs.h> 35 35 #include <linux/err.h> 36 36 #include <linux/mutex.h> 37 + #include <linux/util_macros.h> 37 38 38 39 /* Addresses to scan */ 39 40 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; ··· 191 190 192 191 static int RANGE_TO_REG(long range) 193 192 { 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; 193 + return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map)); 203 194 } 204 195 #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 205 196 ··· 202 209 static const int adm1027_freq_map[8] = { /* 1 Hz */ 203 210 11, 15, 22, 29, 35, 44, 59, 88 204 211 }; 212 + #define FREQ_MAP_LEN 8 205 213 206 - static int FREQ_TO_REG(const int *map, unsigned long freq) 214 + static int FREQ_TO_REG(const int *map, 215 + unsigned int map_size, unsigned long freq) 207 216 { 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; 217 + return find_closest(freq, map, map_size); 215 218 } 216 219 217 220 static int FREQ_FROM_REG(const int *map, u8 reg) ··· 817 828 data->cfg5 &= ~ADT7468_HFPWM; 818 829 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 819 830 } else { /* Low freq. mode */ 820 - data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); 831 + data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, 832 + FREQ_MAP_LEN, val); 821 833 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 822 834 (data->zone[nr].range << 4) 823 835 | data->pwm_freq[nr]);
+3 -5
drivers/hwmon/w83795.c
··· 35 35 #include <linux/err.h> 36 36 #include <linux/mutex.h> 37 37 #include <linux/jiffies.h> 38 + #include <linux/util_macros.h> 38 39 39 40 /* Addresses to scan */ 40 41 static const unsigned short normal_i2c[] = { ··· 309 308 unsigned long best0, best1; 310 309 311 310 /* 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 - } 311 + reg0 = find_closest_descending(val, pwm_freq_cksel0, 312 + ARRAY_SIZE(pwm_freq_cksel0)); 317 313 if (val < 375) /* cksel = 1 can't beat this */ 318 314 return reg0; 319 315 best0 = pwm_freq_cksel0[reg0];
+1 -1
drivers/media/dvb-frontends/cxd2820r_c.c
··· 79 79 80 80 num = if_freq / 1000; /* Hz => kHz */ 81 81 num *= 0x4000; 82 - if_ctl = 0x4000 - cxd2820r_div_u64_round_closest(num, 41000); 82 + if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000); 83 83 buf[0] = (if_ctl >> 8) & 0x3f; 84 84 buf[1] = (if_ctl >> 0) & 0xff; 85 85
-6
drivers/media/dvb-frontends/cxd2820r_core.c
··· 244 244 return ret; 245 245 } 246 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 247 static int cxd2820r_set_frontend(struct dvb_frontend *fe) 254 248 { 255 249 struct cxd2820r_priv *priv = fe->demodulator_priv;
-2
drivers/media/dvb-frontends/cxd2820r_priv.h
··· 64 64 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 65 65 int len); 66 66 67 - u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor); 68 - 69 67 int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 70 68 int len); 71 69
+1 -1
drivers/media/dvb-frontends/cxd2820r_t.c
··· 103 103 104 104 num = if_freq / 1000; /* Hz => kHz */ 105 105 num *= 0x1000000; 106 - if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 106 + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000); 107 107 buf[0] = ((if_ctl >> 16) & 0xff); 108 108 buf[1] = ((if_ctl >> 8) & 0xff); 109 109 buf[2] = ((if_ctl >> 0) & 0xff);
+1 -1
drivers/media/dvb-frontends/cxd2820r_t2.c
··· 120 120 121 121 num = if_freq / 1000; /* Hz => kHz */ 122 122 num *= 0x1000000; 123 - if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 123 + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000); 124 124 buf[0] = ((if_ctl >> 16) & 0xff); 125 125 buf[1] = ((if_ctl >> 8) & 0xff); 126 126 buf[2] = ((if_ctl >> 0) & 0xff);
+2 -1
drivers/memstick/core/mspro_block.c
··· 758 758 759 759 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { 760 760 if (msb->data_dir == READ) { 761 - for (cnt = 0; cnt < msb->current_seg; cnt++) 761 + for (cnt = 0; cnt < msb->current_seg; cnt++) { 762 762 t_len += msb->req_sg[cnt].length 763 763 / msb->page_size; 764 764 ··· 766 766 t_len += msb->current_page - 1; 767 767 768 768 t_len *= msb->page_size; 769 + } 769 770 } 770 771 } else 771 772 t_len = blk_rq_bytes(msb->block_req);
+16 -14
drivers/oprofile/buffer_sync.c
··· 21 21 * objects. 22 22 */ 23 23 24 + #include <linux/file.h> 24 25 #include <linux/mm.h> 25 26 #include <linux/workqueue.h> 26 27 #include <linux/notifier.h> ··· 225 224 static unsigned long get_exec_dcookie(struct mm_struct *mm) 226 225 { 227 226 unsigned long cookie = NO_COOKIE; 227 + struct file *exe_file; 228 228 229 - if (mm && mm->exe_file) 230 - cookie = fast_get_dcookie(&mm->exe_file->f_path); 229 + if (!mm) 230 + goto done; 231 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: 232 239 return cookie; 233 240 } 234 241 ··· 245 236 * pair that can then be added to the global event buffer. We make 246 237 * sure to do this lookup before a mm->mmap modification happens so 247 238 * we don't lose track. 239 + * 240 + * The caller must ensure the mm is not nil (ie: not a kernel thread). 248 241 */ 249 242 static unsigned long 250 243 lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset) ··· 254 243 unsigned long cookie = NO_COOKIE; 255 244 struct vm_area_struct *vma; 256 245 246 + down_read(&mm->mmap_sem); 257 247 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 258 248 259 249 if (addr < vma->vm_start || addr >= vma->vm_end) ··· 274 262 275 263 if (!vma) 276 264 cookie = INVALID_COOKIE; 265 + up_read(&mm->mmap_sem); 277 266 278 267 return cookie; 279 268 } ··· 415 402 { 416 403 if (!mm) 417 404 return; 418 - up_read(&mm->mmap_sem); 419 405 mmput(mm); 420 406 } 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 407 432 408 static inline int is_code(unsigned long val) 433 409 { ··· 534 532 new = (struct task_struct *)val; 535 533 oldmm = mm; 536 534 release_mm(oldmm); 537 - mm = take_tasks_mm(new); 535 + mm = get_task_mm(new); 538 536 if (mm != oldmm) 539 537 cookie = get_exec_dcookie(mm); 540 538 add_user_ctx_switch(new, cookie);
+13 -3
drivers/rtc/Kconfig
··· 1111 1111 This driver can also be built as a module. If so, the module 1112 1112 will be called rtc-davinci. 1113 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 + 1114 1124 config RTC_DRV_IMXDI 1115 1125 tristate "Freescale IMX DryIce Real Time Clock" 1116 1126 depends on ARCH_MXC ··· 1131 1121 will be called "rtc-imxdi". 1132 1122 1133 1123 config RTC_DRV_OMAP 1134 - tristate "TI OMAP1" 1135 - depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX || SOC_AM33XX 1124 + tristate "TI OMAP Real Time Clock" 1125 + depends on ARCH_OMAP || ARCH_DAVINCI 1136 1126 help 1137 1127 Say "yes" here to support the on chip real time clock 1138 - present on TI OMAP1, AM33xx and DA8xx/OMAP-L13x. 1128 + present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx. 1139 1129 1140 1130 This driver can also be built as a module, if so, module 1141 1131 will be called rtc-omap.
+1
drivers/rtc/Makefile
··· 40 40 obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o 41 41 obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o 42 42 obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o 43 + obj-$(CONFIG_RTC_DRV_DIGICOLOR) += rtc-digicolor.o 43 44 obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o 44 45 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 45 46 obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
+3 -3
drivers/rtc/class.c
··· 221 221 rtc->pie_timer.function = rtc_pie_update_irq; 222 222 rtc->pie_enabled = 0; 223 223 224 + strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); 225 + dev_set_name(&rtc->dev, "rtc%d", id); 226 + 224 227 /* Check to see if there is an ALARM already set in hw */ 225 228 err = __rtc_read_alarm(rtc, &alrm); 226 229 227 230 if (!err && !rtc_valid_tm(&alrm.time)) 228 231 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 232 233 233 rtc_dev_prepare(rtc); 234 234
+4 -2
drivers/rtc/hctosys.c
··· 9 9 * published by the Free Software Foundation. 10 10 */ 11 11 12 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 + 12 14 #include <linux/rtc.h> 13 15 14 16 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary ··· 34 32 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 35 33 36 34 if (rtc == NULL) { 37 - pr_err("%s: unable to open rtc device (%s)\n", 38 - __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); 35 + pr_info("unable to open rtc device (%s)\n", 36 + CONFIG_RTC_HCTOSYS_DEVICE); 39 37 goto err_open; 40 38 } 41 39
+3 -2
drivers/rtc/interface.c
··· 31 31 memset(tm, 0, sizeof(struct rtc_time)); 32 32 err = rtc->ops->read_time(rtc->dev.parent, tm); 33 33 if (err < 0) { 34 - dev_err(&rtc->dev, "read_time: fail to read\n"); 34 + dev_dbg(&rtc->dev, "read_time: fail to read: %d\n", 35 + err); 35 36 return err; 36 37 } 37 38 38 39 err = rtc_valid_tm(tm); 39 40 if (err < 0) 40 - dev_err(&rtc->dev, "read_time: rtc_time isn't valid\n"); 41 + dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n"); 41 42 } 42 43 return err; 43 44 }
+1 -1
drivers/rtc/rtc-ab-b5ze-s3.c
··· 881 881 .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, 882 882 }; 883 883 884 - static struct regmap_config abb5zes3_rtc_regmap_config = { 884 + static const struct regmap_config abb5zes3_rtc_regmap_config = { 885 885 .reg_bits = 8, 886 886 .val_bits = 8, 887 887 };
+2 -2
drivers/rtc/rtc-at91rm9200.c
··· 37 37 #include "rtc-at91rm9200.h" 38 38 39 39 #define at91_rtc_read(field) \ 40 - __raw_readl(at91_rtc_regs + field) 40 + readl_relaxed(at91_rtc_regs + field) 41 41 #define at91_rtc_write(field, val) \ 42 - __raw_writel((val), at91_rtc_regs + field) 42 + writel_relaxed((val), at91_rtc_regs + field) 43 43 44 44 #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 45 45
+4 -2
drivers/rtc/rtc-cmos.c
··· 28 28 * interrupts disabled, holding the global rtc_lock, to exclude those 29 29 * other drivers and utilities on correctly configured systems. 30 30 */ 31 + 32 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 33 + 31 34 #include <linux/kernel.h> 32 35 #include <linux/module.h> 33 36 #include <linux/init.h> ··· 388 385 static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) 389 386 { 390 387 alarm_disable_quirk = true; 391 - pr_info("rtc-cmos: BIOS has alarm-disable quirk. "); 392 - pr_info("RTC alarms disabled\n"); 388 + pr_info("BIOS has alarm-disable quirk - RTC alarms disabled\n"); 393 389 return 0; 394 390 } 395 391
+76 -21
drivers/rtc/rtc-da9052.c
··· 16 16 #include <linux/platform_device.h> 17 17 #include <linux/rtc.h> 18 18 #include <linux/err.h> 19 + #include <linux/delay.h> 19 20 20 21 #include <linux/mfd/da9052/da9052.h> 21 22 #include <linux/mfd/da9052/reg.h> 22 23 23 24 #define rtc_err(rtc, fmt, ...) \ 24 25 dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) 26 + 27 + #define DA9052_GET_TIME_RETRIES 5 25 28 26 29 struct da9052_rtc { 27 30 struct rtc_device *rtc; ··· 61 58 static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) 62 59 { 63 60 int ret; 64 - uint8_t v[5]; 61 + uint8_t v[2][5]; 62 + int idx = 1; 63 + int timeout = DA9052_GET_TIME_RETRIES; 65 64 66 - ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, v); 67 - if (ret != 0) { 65 + ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, &v[0][0]); 66 + if (ret) { 68 67 rtc_err(rtc, "Failed to group read ALM: %d\n", ret); 69 68 return ret; 70 69 } 71 70 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; 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 + } 77 78 78 - ret = rtc_valid_tm(rtc_tm); 79 - return ret; 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; 80 98 } 81 99 82 100 static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) ··· 159 135 static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) 160 136 { 161 137 struct da9052_rtc *rtc = dev_get_drvdata(dev); 162 - uint8_t v[6]; 163 138 int ret; 139 + uint8_t v[2][6]; 140 + int idx = 1; 141 + int timeout = DA9052_GET_TIME_RETRIES; 164 142 165 - ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, v); 166 - if (ret < 0) { 143 + ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, &v[0][0]); 144 + if (ret) { 167 145 rtc_err(rtc, "Failed to read RTC time : %d\n", ret); 168 146 return ret; 169 147 } 170 148 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; 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 + } 177 156 178 - ret = rtc_valid_tm(rtc_tm); 179 - return ret; 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; 180 177 } 181 178 182 179 static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 205 160 struct da9052_rtc *rtc; 206 161 uint8_t v[6]; 207 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; 208 167 209 168 rtc = dev_get_drvdata(dev); 210 169 ··· 246 197 int ret; 247 198 struct rtc_time *tm = &alrm->time; 248 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; 249 204 250 205 ret = da9052_rtc_enable_alarm(rtc, 0); 251 206 if (ret < 0) ··· 308 255 rtc_err(rtc, "irq registration failed: %d\n", ret); 309 256 return ret; 310 257 } 258 + 259 + device_init_wakeup(&pdev->dev, true); 311 260 312 261 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 313 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 18 * "Sending and receiving", using SMBus level communication is preferred. 19 19 */ 20 20 21 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 + 21 23 #include <linux/kernel.h> 22 24 #include <linux/module.h> 23 25 #include <linux/interrupt.h> ··· 408 406 /* Set new watchdog time */ 409 407 ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); 410 408 if (ret) { 411 - pr_info("rtc-ds1374 - couldn't set new watchdog time\n"); 409 + pr_info("couldn't set new watchdog time\n"); 412 410 goto out; 413 411 } 414 412 ··· 541 539 return -EFAULT; 542 540 543 541 if (options & WDIOS_DISABLECARD) { 544 - pr_info("rtc-ds1374: disable watchdog\n"); 542 + pr_info("disable watchdog\n"); 545 543 ds1374_wdt_disable(); 546 544 } 547 545 548 546 if (options & WDIOS_ENABLECARD) { 549 - pr_info("rtc-ds1374: enable watchdog\n"); 547 + pr_info("enable watchdog\n"); 550 548 ds1374_wdt_settimeout(wdt_margin); 551 549 ds1374_wdt_ping(); 552 550 }
+5 -4
drivers/rtc/rtc-ds1685.c
··· 16 16 * published by the Free Software Foundation. 17 17 */ 18 18 19 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20 + 19 21 #include <linux/bcd.h> 20 22 #include <linux/delay.h> 21 23 #include <linux/io.h> ··· 801 799 struct platform_device *pdev = to_platform_device(dev); 802 800 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 803 801 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; 804 - char *model = '\0'; 802 + char *model; 805 803 #ifdef CONFIG_RTC_DS1685_PROC_REGS 806 804 char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; 807 805 #endif ··· 2141 2139 static struct platform_driver ds1685_rtc_driver = { 2142 2140 .driver = { 2143 2141 .name = "rtc-ds1685", 2144 - .owner = THIS_MODULE, 2145 2142 }, 2146 2143 .probe = ds1685_rtc_probe, 2147 2144 .remove = ds1685_rtc_remove, ··· 2176 2175 * ds1685_rtc_poweroff - uses the RTC chip to power the system off. 2177 2176 * @pdev: pointer to platform_device structure. 2178 2177 */ 2179 - extern void __noreturn 2178 + void __noreturn 2180 2179 ds1685_rtc_poweroff(struct platform_device *pdev) 2181 2180 { 2182 2181 u8 ctrla, ctrl4a, ctrl4b; ··· 2184 2183 2185 2184 /* Check for valid RTC data, else, spin forever. */ 2186 2185 if (unlikely(!pdev)) { 2187 - pr_emerg("rtc-ds1685: platform device data not available, spinning forever ...\n"); 2186 + pr_emerg("platform device data not available, spinning forever ...\n"); 2188 2187 unreachable(); 2189 2188 } else { 2190 2189 /* Get the rtc data. */
+4 -2
drivers/rtc/rtc-ds3232.c
··· 15 15 * "Sending and receiving", using SMBus level communication is preferred. 16 16 */ 17 17 18 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 19 + 18 20 #include <linux/kernel.h> 19 21 #include <linux/module.h> 20 22 #include <linux/interrupt.h> ··· 375 373 if (stat & DS3232_REG_SR_A1F) { 376 374 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 377 375 if (control < 0) { 378 - pr_warn("Read DS3232 Control Register error." 379 - "Disable IRQ%d.\n", client->irq); 376 + pr_warn("Read Control Register error - Disable IRQ%d\n", 377 + client->irq); 380 378 } else { 381 379 /* disable alarm1 interrupt */ 382 380 control &= ~(DS3232_REG_CR_A1IE);
+3
drivers/rtc/rtc-efi-platform.c
··· 8 8 * Copyright (C) 1999-2000 VA Linux Systems 9 9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> 10 10 */ 11 + 12 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 + 11 14 #include <linux/init.h> 12 15 #include <linux/kernel.h> 13 16 #include <linux/module.h>
+11
drivers/rtc/rtc-em3027.c
··· 15 15 #include <linux/rtc.h> 16 16 #include <linux/bcd.h> 17 17 #include <linux/module.h> 18 + #include <linux/of.h> 18 19 19 20 /* Registers */ 20 21 #define EM3027_REG_ON_OFF_CTRL 0x00 ··· 136 135 { "em3027", 0 }, 137 136 { } 138 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 139 147 140 148 static struct i2c_driver em3027_driver = { 141 149 .driver = { 142 150 .name = "rtc-em3027", 151 + .of_match_table = of_match_ptr(em3027_of_match), 143 152 }, 144 153 .probe = &em3027_probe, 145 154 .id_table = em3027_id,
+6 -6
drivers/rtc/rtc-hym8563.c
··· 66 66 #define HYM8563_ALM_BIT_DISABLE BIT(7) 67 67 68 68 #define HYM8563_CLKOUT 0x0d 69 - #define HYM8563_CLKOUT_DISABLE BIT(7) 69 + #define HYM8563_CLKOUT_ENABLE BIT(7) 70 70 #define HYM8563_CLKOUT_32768 0 71 71 #define HYM8563_CLKOUT_1024 1 72 72 #define HYM8563_CLKOUT_32 2 ··· 309 309 struct i2c_client *client = hym8563->client; 310 310 int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); 311 311 312 - if (ret < 0 || ret & HYM8563_CLKOUT_DISABLE) 312 + if (ret < 0) 313 313 return 0; 314 314 315 315 ret &= HYM8563_CLKOUT_MASK; ··· 360 360 return ret; 361 361 362 362 if (enable) 363 - ret &= ~HYM8563_CLKOUT_DISABLE; 363 + ret |= HYM8563_CLKOUT_ENABLE; 364 364 else 365 - ret |= HYM8563_CLKOUT_DISABLE; 365 + ret &= ~HYM8563_CLKOUT_ENABLE; 366 366 367 367 return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); 368 368 } ··· 386 386 if (ret < 0) 387 387 return ret; 388 388 389 - return !(ret & HYM8563_CLKOUT_DISABLE); 389 + return !!(ret & HYM8563_CLKOUT_ENABLE); 390 390 } 391 391 392 392 static const struct clk_ops hym8563_clkout_ops = { ··· 407 407 int ret; 408 408 409 409 ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, 410 - HYM8563_CLKOUT_DISABLE); 410 + 0); 411 411 if (ret < 0) 412 412 return ERR_PTR(ret); 413 413
+4 -2
drivers/rtc/rtc-m41t80.c
··· 13 13 * 14 14 */ 15 15 16 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 + 16 18 #include <linux/bcd.h> 17 19 #include <linux/i2c.h> 18 20 #include <linux/init.h> ··· 515 513 return -EFAULT; 516 514 517 515 if (rv & WDIOS_DISABLECARD) { 518 - pr_info("rtc-m41t80: disable watchdog\n"); 516 + pr_info("disable watchdog\n"); 519 517 wdt_disable(); 520 518 } 521 519 522 520 if (rv & WDIOS_ENABLECARD) { 523 - pr_info("rtc-m41t80: enable watchdog\n"); 521 + pr_info("enable watchdog\n"); 524 522 wdt_ping(); 525 523 } 526 524
+4 -2
drivers/rtc/rtc-max77686.c
··· 12 12 * 13 13 */ 14 14 15 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16 + 15 17 #include <linux/slab.h> 16 18 #include <linux/rtc.h> 17 19 #include <linux/delay.h> ··· 105 103 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 106 104 107 105 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); 106 + pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", 107 + 1900 + tm->tm_year); 110 108 return -EINVAL; 111 109 } 112 110 return 0;
+5 -3
drivers/rtc/rtc-max8997.c
··· 12 12 * 13 13 */ 14 14 15 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16 + 15 17 #include <linux/slab.h> 16 18 #include <linux/rtc.h> 17 19 #include <linux/delay.h> ··· 109 107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 110 108 111 109 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); 110 + pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", 111 + 1900 + tm->tm_year); 114 112 return -EINVAL; 115 113 } 116 114 return 0; ··· 426 424 427 425 val = 0; 428 426 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); 429 - pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); 427 + pr_info("WTSR_SMPL(0x%02x)\n", val); 430 428 } 431 429 432 430 static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
+3 -1
drivers/rtc/rtc-msm6242.c
··· 7 7 * Copyright (C) 1993 Hamish Macdonald 8 8 */ 9 9 10 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 + 10 12 #include <linux/delay.h> 11 13 #include <linux/io.h> 12 14 #include <linux/kernel.h> ··· 113 111 } 114 112 115 113 if (!cnt) 116 - pr_warn("msm6242: timed out waiting for RTC (0x%x)\n", 114 + pr_warn("timed out waiting for RTC (0x%x)\n", 117 115 msm6242_read(priv, MSM6242_CD)); 118 116 } 119 117
+55 -13
drivers/rtc/rtc-omap.c
··· 118 118 #define KICK0_VALUE 0x83e70b13 119 119 #define KICK1_VALUE 0x95a4f1e0 120 120 121 + struct omap_rtc; 122 + 121 123 struct omap_rtc_device_type { 122 124 bool has_32kclk_en; 123 - bool has_kicker; 124 125 bool has_irqwakeen; 125 126 bool has_pmic_mode; 126 127 bool has_power_up_reset; 128 + void (*lock)(struct omap_rtc *rtc); 129 + void (*unlock)(struct omap_rtc *rtc); 127 130 }; 128 131 129 132 struct omap_rtc { ··· 159 156 writel(val, rtc->base + reg); 160 157 } 161 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 + 162 179 /* 163 180 * We rely on the rtc framework to handle locking (rtc->ops_lock), 164 181 * so the only other requirement is that register accesses which ··· 209 186 210 187 /* alarm irq? */ 211 188 if (irq_data & OMAP_RTC_STATUS_ALARM) { 189 + rtc->type->unlock(rtc); 212 190 rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); 191 + rtc->type->lock(rtc); 213 192 events |= RTC_IRQF | RTC_AF; 214 193 } 215 194 ··· 243 218 irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; 244 219 } 245 220 rtc_wait_not_busy(rtc); 221 + rtc->type->unlock(rtc); 246 222 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 247 223 if (rtc->type->has_irqwakeen) 248 224 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 225 + rtc->type->lock(rtc); 249 226 local_irq_enable(); 250 227 251 228 return 0; ··· 320 293 local_irq_disable(); 321 294 rtc_wait_not_busy(rtc); 322 295 296 + rtc->type->unlock(rtc); 323 297 rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); 324 298 rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); 325 299 rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); 326 300 rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); 327 301 rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); 328 302 rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); 303 + rtc->type->lock(rtc); 329 304 330 305 local_irq_enable(); 331 306 ··· 370 341 local_irq_disable(); 371 342 rtc_wait_not_busy(rtc); 372 343 344 + rtc->type->unlock(rtc); 373 345 rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); 374 346 rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); 375 347 rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); ··· 392 362 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 393 363 if (rtc->type->has_irqwakeen) 394 364 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 365 + rtc->type->lock(rtc); 395 366 396 367 local_irq_enable(); 397 368 ··· 422 391 unsigned long now; 423 392 u32 val; 424 393 394 + rtc->type->unlock(rtc); 425 395 /* enable pmic_power_en control */ 426 396 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); 427 397 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); ··· 455 423 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 456 424 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 457 425 val | OMAP_RTC_INTERRUPTS_IT_ALARM2); 426 + rtc->type->lock(rtc); 458 427 459 428 /* 460 429 * Wait for alarm to trigger (within two seconds) and external PMIC to ··· 475 442 476 443 static const struct omap_rtc_device_type omap_rtc_default_type = { 477 444 .has_power_up_reset = true, 445 + .lock = default_rtc_lock, 446 + .unlock = default_rtc_unlock, 478 447 }; 479 448 480 449 static const struct omap_rtc_device_type omap_rtc_am3352_type = { 481 450 .has_32kclk_en = true, 482 - .has_kicker = true, 483 451 .has_irqwakeen = true, 484 452 .has_pmic_mode = true, 453 + .lock = am3352_rtc_lock, 454 + .unlock = am3352_rtc_unlock, 485 455 }; 486 456 487 457 static const struct omap_rtc_device_type omap_rtc_da830_type = { 488 - .has_kicker = true, 458 + .lock = am3352_rtc_lock, 459 + .unlock = am3352_rtc_unlock, 489 460 }; 490 461 491 462 static const struct platform_device_id omap_rtc_id_table[] = { ··· 521 484 }; 522 485 MODULE_DEVICE_TABLE(of, omap_rtc_of_match); 523 486 524 - static int __init omap_rtc_probe(struct platform_device *pdev) 487 + static int omap_rtc_probe(struct platform_device *pdev) 525 488 { 526 489 struct omap_rtc *rtc; 527 490 struct resource *res; ··· 564 527 pm_runtime_enable(&pdev->dev); 565 528 pm_runtime_get_sync(&pdev->dev); 566 529 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 - } 530 + rtc->type->unlock(rtc); 571 531 572 532 /* 573 533 * disable interrupts ··· 627 593 if (reg != new_ctrl) 628 594 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 629 595 596 + rtc->type->lock(rtc); 597 + 630 598 device_init_wakeup(&pdev->dev, true); 631 599 632 600 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, ··· 662 626 663 627 err: 664 628 device_init_wakeup(&pdev->dev, false); 665 - if (rtc->type->has_kicker) 666 - rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); 629 + rtc->type->lock(rtc); 667 630 pm_runtime_put_sync(&pdev->dev); 668 631 pm_runtime_disable(&pdev->dev); 669 632 ··· 681 646 682 647 device_init_wakeup(&pdev->dev, 0); 683 648 649 + rtc->type->unlock(rtc); 684 650 /* leave rtc running, but disable irqs */ 685 651 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 686 652 687 - if (rtc->type->has_kicker) 688 - rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); 653 + rtc->type->lock(rtc); 689 654 690 655 /* Disable the clock/module */ 691 656 pm_runtime_put_sync(&pdev->dev); ··· 701 666 702 667 rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 703 668 669 + rtc->type->unlock(rtc); 704 670 /* 705 671 * FIXME: the RTC alarm is not currently acting as a wakeup event 706 672 * source on some platforms, and in fact this enable() call is just ··· 711 675 enable_irq_wake(rtc->irq_alarm); 712 676 else 713 677 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 678 + rtc->type->lock(rtc); 714 679 715 680 /* Disable the clock/module */ 716 681 pm_runtime_put_sync(dev); ··· 726 689 /* Enable the clock/module so that we can access the registers */ 727 690 pm_runtime_get_sync(dev); 728 691 692 + rtc->type->unlock(rtc); 729 693 if (device_may_wakeup(dev)) 730 694 disable_irq_wake(rtc->irq_alarm); 731 695 else 732 696 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); 697 + rtc->type->lock(rtc); 733 698 734 699 return 0; 735 700 } ··· 748 709 * Keep the ALARM interrupt enabled to allow the system to power up on 749 710 * alarm events. 750 711 */ 712 + rtc->type->unlock(rtc); 751 713 mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 752 714 mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; 753 715 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); 716 + rtc->type->lock(rtc); 754 717 } 755 718 756 719 static struct platform_driver omap_rtc_driver = { 720 + .probe = omap_rtc_probe, 757 721 .remove = __exit_p(omap_rtc_remove), 758 722 .shutdown = omap_rtc_shutdown, 759 723 .driver = { ··· 767 725 .id_table = omap_rtc_id_table, 768 726 }; 769 727 770 - module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); 728 + module_platform_driver(omap_rtc_driver); 771 729 772 730 MODULE_ALIAS("platform:omap_rtc"); 773 731 MODULE_AUTHOR("George G. Davis (and others)");
+2 -1
drivers/rtc/rtc-opal.c
··· 16 16 * along with this program. 17 17 */ 18 18 19 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20 + 19 21 #define DRVNAME "rtc-opal" 20 - #define pr_fmt(fmt) DRVNAME ": " fmt 21 22 22 23 #include <linux/module.h> 23 24 #include <linux/err.h>
+1 -6
drivers/rtc/rtc-pcf8563.c
··· 246 246 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 247 247 { 248 248 struct pcf8563 *pcf8563 = i2c_get_clientdata(client); 249 - int err; 250 249 unsigned char buf[9]; 251 250 252 251 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " ··· 271 272 272 273 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; 273 274 274 - err = pcf8563_write_block_data(client, PCF8563_REG_SC, 275 + return pcf8563_write_block_data(client, PCF8563_REG_SC, 275 276 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); 276 - if (err) 277 - return err; 278 - 279 - return 0; 280 277 } 281 278 282 279 #ifdef CONFIG_RTC_INTF_DEV
+53 -140
drivers/rtc/rtc-s3c.c
··· 39 39 void __iomem *base; 40 40 struct clk *rtc_clk; 41 41 struct clk *rtc_src_clk; 42 - bool enabled; 43 42 44 43 struct s3c_rtc_data *data; 45 44 ··· 66 67 void (*disable) (struct s3c_rtc *info); 67 68 }; 68 69 69 - static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable) 70 + static void s3c_rtc_enable_clk(struct s3c_rtc *info) 70 71 { 71 72 unsigned long irq_flags; 72 73 73 74 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 - } 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 89 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 90 90 } 91 91 ··· 117 119 118 120 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); 119 121 120 - clk_enable(info->rtc_clk); 121 - if (info->data->needs_src_clk) 122 - clk_enable(info->rtc_src_clk); 122 + s3c_rtc_enable_clk(info); 123 + 123 124 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 124 125 125 126 if (enabled) 126 127 tmp |= S3C2410_RTCALM_ALMEN; 127 128 128 129 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 130 133 - s3c_rtc_alarm_clk_enable(info, enabled); 131 + s3c_rtc_disable_clk(info); 134 132 135 133 return 0; 136 134 } ··· 137 143 if (!is_power_of_2(freq)) 138 144 return -EINVAL; 139 145 140 - clk_enable(info->rtc_clk); 141 - if (info->data->needs_src_clk) 142 - clk_enable(info->rtc_src_clk); 143 146 spin_lock_irq(&info->pie_lock); 144 147 145 148 if (info->data->set_freq) 146 149 info->data->set_freq(info, freq); 147 150 148 151 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 152 153 153 return 0; 154 154 } ··· 153 165 struct s3c_rtc *info = dev_get_drvdata(dev); 154 166 unsigned int have_retried = 0; 155 167 156 - clk_enable(info->rtc_clk); 157 - if (info->data->needs_src_clk) 158 - clk_enable(info->rtc_src_clk); 168 + s3c_rtc_enable_clk(info); 159 169 160 170 retry_get_time: 161 171 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); ··· 180 194 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); 181 195 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); 182 196 197 + s3c_rtc_disable_clk(info); 198 + 183 199 rtc_tm->tm_year += 100; 184 200 185 201 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", ··· 189 201 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 190 202 191 203 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 204 197 205 return rtc_valid_tm(rtc_tm); 198 206 } ··· 209 225 return -EINVAL; 210 226 } 211 227 212 - clk_enable(info->rtc_clk); 213 - if (info->data->needs_src_clk) 214 - clk_enable(info->rtc_src_clk); 228 + s3c_rtc_enable_clk(info); 215 229 216 230 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); 217 231 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); ··· 218 236 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); 219 237 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); 220 238 221 - if (info->data->needs_src_clk) 222 - clk_disable(info->rtc_src_clk); 223 - clk_disable(info->rtc_clk); 239 + s3c_rtc_disable_clk(info); 224 240 225 241 return 0; 226 242 } ··· 229 249 struct rtc_time *alm_tm = &alrm->time; 230 250 unsigned int alm_en; 231 251 232 - clk_enable(info->rtc_clk); 233 - if (info->data->needs_src_clk) 234 - clk_enable(info->rtc_src_clk); 252 + s3c_rtc_enable_clk(info); 235 253 236 254 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); 237 255 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); ··· 240 262 241 263 alm_en = readb(info->base + S3C2410_RTCALM); 242 264 265 + s3c_rtc_disable_clk(info); 266 + 243 267 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 244 268 245 269 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", ··· 249 269 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 250 270 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 251 271 252 - 253 272 /* decode the alarm enable field */ 254 - 255 273 if (alm_en & S3C2410_RTCALM_SECEN) 256 274 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 257 275 else ··· 282 304 else 283 305 alm_tm->tm_year = -1; 284 306 285 - if (info->data->needs_src_clk) 286 - clk_disable(info->rtc_src_clk); 287 - clk_disable(info->rtc_clk); 288 - 289 307 return 0; 290 308 } 291 309 ··· 291 317 struct rtc_time *tm = &alrm->time; 292 318 unsigned int alrm_en; 293 319 294 - clk_enable(info->rtc_clk); 295 - if (info->data->needs_src_clk) 296 - clk_enable(info->rtc_src_clk); 297 - 298 320 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 299 321 alrm->enabled, 300 322 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 301 323 tm->tm_hour, tm->tm_min, tm->tm_sec); 324 + 325 + s3c_rtc_enable_clk(info); 302 326 303 327 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 304 328 writeb(0x00, info->base + S3C2410_RTCALM); ··· 320 348 321 349 writeb(alrm_en, info->base + S3C2410_RTCALM); 322 350 323 - s3c_rtc_setaie(dev, alrm->enabled); 351 + s3c_rtc_disable_clk(info); 324 352 325 - if (info->data->needs_src_clk) 326 - clk_disable(info->rtc_src_clk); 327 - clk_disable(info->rtc_clk); 353 + s3c_rtc_setaie(dev, alrm->enabled); 328 354 329 355 return 0; 330 356 } ··· 331 361 { 332 362 struct s3c_rtc *info = dev_get_drvdata(dev); 333 363 334 - clk_enable(info->rtc_clk); 335 - if (info->data->needs_src_clk) 336 - clk_enable(info->rtc_src_clk); 364 + s3c_rtc_enable_clk(info); 337 365 338 366 if (info->data->enable_tick) 339 367 info->data->enable_tick(info, seq); 340 368 341 - if (info->data->needs_src_clk) 342 - clk_disable(info->rtc_src_clk); 343 - clk_disable(info->rtc_clk); 369 + s3c_rtc_disable_clk(info); 344 370 345 371 return 0; 346 372 } ··· 353 387 static void s3c24xx_rtc_enable(struct s3c_rtc *info) 354 388 { 355 389 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 390 361 391 con = readw(info->base + S3C2410_RTCCON); 362 392 /* re-enable the device, and check it is ok */ ··· 379 417 writew(tmp & ~S3C2410_RTCCON_CLKRST, 380 418 info->base + S3C2410_RTCCON); 381 419 } 382 - 383 - if (info->data->needs_src_clk) 384 - clk_disable(info->rtc_src_clk); 385 - clk_disable(info->rtc_clk); 386 420 } 387 421 388 422 static void s3c24xx_rtc_disable(struct s3c_rtc *info) 389 423 { 390 424 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 425 396 426 con = readw(info->base + S3C2410_RTCCON); 397 427 con &= ~S3C2410_RTCCON_RTCEN; ··· 392 438 con = readb(info->base + S3C2410_TICNT); 393 439 con &= ~S3C2410_TICNT_ENABLE; 394 440 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 441 } 400 442 401 443 static void s3c6410_rtc_disable(struct s3c_rtc *info) 402 444 { 403 445 unsigned int con; 404 446 405 - clk_enable(info->rtc_clk); 406 - if (info->data->needs_src_clk) 407 - clk_enable(info->rtc_src_clk); 408 - 409 447 con = readw(info->base + S3C2410_RTCCON); 410 448 con &= ~S3C64XX_RTCCON_TICEN; 411 449 con &= ~S3C2410_RTCCON_RTCEN; 412 450 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 451 } 418 452 419 453 static int s3c_rtc_remove(struct platform_device *pdev) ··· 496 554 497 555 device_init_wakeup(&pdev->dev, 1); 498 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 + 499 571 /* register RTC and exit */ 500 572 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, 501 573 THIS_MODULE); ··· 533 577 goto err_nortc; 534 578 } 535 579 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 580 if (info->data->select_tick_clk) 553 581 info->data->select_tick_clk(info); 554 582 555 583 s3c_rtc_setfreq(info, 1); 556 584 557 - if (info->data->needs_src_clk) 558 - clk_disable(info->rtc_src_clk); 559 - clk_disable(info->rtc_clk); 585 + s3c_rtc_disable_clk(info); 560 586 561 587 return 0; 562 588 563 589 err_nortc: 564 590 if (info->data->disable) 565 591 info->data->disable(info); 592 + 593 + if (info->data->needs_src_clk) 594 + clk_disable_unprepare(info->rtc_src_clk); 566 595 clk_disable_unprepare(info->rtc_clk); 567 596 568 597 return ret; ··· 559 618 { 560 619 struct s3c_rtc *info = dev_get_drvdata(dev); 561 620 562 - clk_enable(info->rtc_clk); 563 - if (info->data->needs_src_clk) 564 - clk_enable(info->rtc_src_clk); 621 + s3c_rtc_enable_clk(info); 565 622 566 623 /* save TICNT for anyone using periodic interrupts */ 567 624 if (info->data->save_tick_cnt) ··· 575 636 dev_err(dev, "enable_irq_wake failed\n"); 576 637 } 577 638 578 - if (info->data->needs_src_clk) 579 - clk_disable(info->rtc_src_clk); 580 - clk_disable(info->rtc_clk); 581 - 582 639 return 0; 583 640 } 584 641 ··· 582 647 { 583 648 struct s3c_rtc *info = dev_get_drvdata(dev); 584 649 585 - clk_enable(info->rtc_clk); 586 - if (info->data->needs_src_clk) 587 - clk_enable(info->rtc_src_clk); 588 - 589 650 if (info->data->enable) 590 651 info->data->enable(info); 591 652 592 653 if (info->data->restore_tick_cnt) 593 654 info->data->restore_tick_cnt(info); 594 655 656 + s3c_rtc_disable_clk(info); 657 + 595 658 if (device_may_wakeup(dev) && info->wake_en) { 596 659 disable_irq_wake(info->irq_alarm); 597 660 info->wake_en = false; 598 661 } 599 - 600 - if (info->data->needs_src_clk) 601 - clk_disable(info->rtc_src_clk); 602 - clk_disable(info->rtc_clk); 603 662 604 663 return 0; 605 664 } ··· 602 673 603 674 static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) 604 675 { 605 - clk_enable(info->rtc_clk); 606 - if (info->data->needs_src_clk) 607 - clk_enable(info->rtc_src_clk); 608 676 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 677 } 615 678 616 679 static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) 617 680 { 618 - clk_enable(info->rtc_clk); 619 - if (info->data->needs_src_clk) 620 - clk_enable(info->rtc_src_clk); 621 681 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 622 682 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 683 } 629 684 630 685 static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq)
+28 -6
drivers/rtc/rtc-s5m.c
··· 15 15 * GNU General Public License for more details. 16 16 */ 17 17 18 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 19 + 18 20 #include <linux/module.h> 19 21 #include <linux/i2c.h> 20 22 #include <linux/bcd.h> ··· 92 90 struct regmap *regmap; 93 91 struct rtc_device *rtc_dev; 94 92 int irq; 95 - int device_type; 93 + enum sec_device_type device_type; 96 94 int rtc_24hr_mode; 97 95 const struct s5m_rtc_reg_config *regs; 98 96 }; ··· 148 146 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 149 147 150 148 if (tm->tm_year < 100) { 151 - pr_err("s5m8767 RTC cannot handle the year %d.\n", 149 + pr_err("RTC cannot handle the year %d\n", 152 150 1900 + tm->tm_year); 153 151 return -EINVAL; 154 152 } else { ··· 189 187 val &= S5M_ALARM0_STATUS; 190 188 break; 191 189 case S2MPS14X: 190 + case S2MPS13X: 192 191 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, 193 192 &val); 194 193 val &= S2MPS_ALARM0_STATUS; ··· 255 252 case S2MPS14X: 256 253 data |= S2MPS_RTC_RUDR_MASK; 257 254 break; 255 + case S2MPS13X: 256 + data |= S2MPS13_RTC_AUDR_MASK; 257 + break; 258 258 default: 259 259 return -EINVAL; 260 260 } ··· 270 264 } 271 265 272 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); 273 272 274 273 return ret; 275 274 } ··· 317 306 u8 data[info->regs->regs_count]; 318 307 int ret; 319 308 320 - if (info->device_type == S2MPS14X) { 309 + if (info->device_type == S2MPS14X || info->device_type == S2MPS13X) { 321 310 ret = regmap_update_bits(info->regmap, 322 311 info->regs->rtc_udr_update, 323 312 S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); ··· 340 329 341 330 case S5M8767X: 342 331 case S2MPS14X: 332 + case S2MPS13X: 343 333 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); 344 334 break; 345 335 ··· 367 355 break; 368 356 case S5M8767X: 369 357 case S2MPS14X: 358 + case S2MPS13X: 370 359 ret = s5m8767_tm_to_data(tm, data); 371 360 break; 372 361 default: ··· 415 402 416 403 case S5M8767X: 417 404 case S2MPS14X: 405 + case S2MPS13X: 418 406 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 419 407 alrm->enabled = 0; 420 408 for (i = 0; i < info->regs->regs_count; i++) { ··· 464 450 465 451 case S5M8767X: 466 452 case S2MPS14X: 453 + case S2MPS13X: 467 454 for (i = 0; i < info->regs->regs_count; i++) 468 455 data[i] &= ~ALARM_ENABLE_MASK; 469 456 ··· 509 494 510 495 case S5M8767X: 511 496 case S2MPS14X: 497 + case S2MPS13X: 512 498 data[RTC_SEC] |= ALARM_ENABLE_MASK; 513 499 data[RTC_MIN] |= ALARM_ENABLE_MASK; 514 500 data[RTC_HOUR] |= ALARM_ENABLE_MASK; ··· 549 533 550 534 case S5M8767X: 551 535 case S2MPS14X: 536 + case S2MPS13X: 552 537 s5m8767_tm_to_data(&alrm->time, data); 553 538 break; 554 539 ··· 632 615 break; 633 616 634 617 case S2MPS14X: 618 + case S2MPS13X: 635 619 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 636 620 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); 637 621 break; ··· 668 650 if (!info) 669 651 return -ENOMEM; 670 652 671 - switch (pdata->device_type) { 653 + switch (platform_get_device_id(pdev)->driver_data) { 672 654 case S2MPS14X: 655 + case S2MPS13X: 673 656 regmap_cfg = &s2mps14_rtc_regmap_config; 674 657 info->regs = &s2mps_rtc_regs; 675 658 alarm_irq = S2MPS14_IRQ_RTCA0; ··· 686 667 alarm_irq = S5M8767_IRQ_RTCA1; 687 668 break; 688 669 default: 689 - dev_err(&pdev->dev, "Device type is not supported by RTC driver\n"); 670 + dev_err(&pdev->dev, 671 + "Device type %lu is not supported by RTC driver\n", 672 + platform_get_device_id(pdev)->driver_data); 690 673 return -ENODEV; 691 674 } 692 675 ··· 708 687 709 688 info->dev = &pdev->dev; 710 689 info->s5m87xx = s5m87xx; 711 - info->device_type = s5m87xx->device_type; 690 + info->device_type = platform_get_device_id(pdev)->driver_data; 712 691 713 692 if (s5m87xx->irq_data) { 714 693 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); ··· 793 772 794 773 static const struct platform_device_id s5m_rtc_id[] = { 795 774 { "s5m-rtc", S5M8767X }, 775 + { "s2mps13-rtc", S2MPS13X }, 796 776 { "s2mps14-rtc", S2MPS14X }, 797 777 { }, 798 778 };
+60 -6
drivers/rtc/rtc-stmp3xxx.c
··· 42 42 #define STMP3XXX_RTC_STAT 0x10 43 43 #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 44 44 #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 45 + #define STMP3XXX_RTC_STAT_XTAL32000_PRESENT 0x10000000 46 + #define STMP3XXX_RTC_STAT_XTAL32768_PRESENT 0x08000000 45 47 46 48 #define STMP3XXX_RTC_SECONDS 0x30 47 49 ··· 54 52 #define STMP3XXX_RTC_PERSISTENT0 0x60 55 53 #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 56 54 #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 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) 60 62 61 63 #define STMP3XXX_RTC_PERSISTENT1 0x70 62 64 /* missing bitmask in headers */ ··· 254 248 { 255 249 struct stmp3xxx_rtc_data *rtc_data; 256 250 struct resource *r; 251 + u32 rtc_stat; 252 + u32 pers0_set, pers0_clr; 253 + u32 crystalfreq = 0; 257 254 int err; 258 255 259 256 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); ··· 277 268 278 269 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 279 270 280 - if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & 281 - STMP3XXX_RTC_STAT_RTC_PRESENT)) { 271 + rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT); 272 + if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) { 282 273 dev_err(&pdev->dev, "no device onboard\n"); 283 274 return -ENODEV; 284 275 } ··· 291 282 return err; 292 283 } 293 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 + 294 330 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 295 331 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 296 - STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 332 + STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr, 297 333 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 298 334 299 335 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN |
+5 -4
drivers/rtc/rtc-twl.c
··· 18 18 * 2 of the License, or (at your option) any later version. 19 19 */ 20 20 21 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 + 21 23 #include <linux/kernel.h> 22 24 #include <linux/errno.h> 23 25 #include <linux/init.h> ··· 147 145 148 146 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 149 147 if (ret < 0) 150 - pr_err("twl_rtc: Could not read TWL" 151 - "register %X - error %d\n", reg, ret); 148 + pr_err("Could not read TWL register %X - error %d\n", reg, ret); 152 149 return ret; 153 150 } 154 151 ··· 160 159 161 160 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 162 161 if (ret < 0) 163 - pr_err("twl_rtc: Could not write TWL" 164 - "register %X - error %d\n", reg, ret); 162 + pr_err("Could not write TWL register %X - error %d\n", 163 + reg, ret); 165 164 return ret; 166 165 } 167 166
+2 -2
drivers/rtc/rtc-x1205.c
··· 22 22 #include <linux/rtc.h> 23 23 #include <linux/delay.h> 24 24 #include <linux/module.h> 25 + #include <linux/bitops.h> 25 26 26 27 #define DRV_VERSION "1.0.8" 27 28 ··· 367 366 * perform sign extension. The formula is 368 367 * Catr = (atr * 0.25pF) + 11.00pF. 369 368 */ 370 - if (atr & 0x20) 371 - atr |= 0xC0; 369 + atr = sign_extend32(atr, 5); 372 370 373 371 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); 374 372
+9 -13
drivers/scsi/bfa/bfad.c
··· 1079 1079 int 1080 1080 bfad_worker(void *ptr) 1081 1081 { 1082 - struct bfad_s *bfad; 1083 - unsigned long flags; 1082 + struct bfad_s *bfad = ptr; 1083 + unsigned long flags; 1084 1084 1085 - bfad = (struct bfad_s *)ptr; 1085 + if (kthread_should_stop()) 1086 + return 0; 1086 1087 1087 - while (!kthread_should_stop()) { 1088 + /* Send event BFAD_E_INIT_SUCCESS */ 1089 + bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); 1088 1090 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 - } 1091 + spin_lock_irqsave(&bfad->bfad_lock, flags); 1092 + bfad->bfad_tsk = NULL; 1093 + spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1098 1094 1099 1095 return 0; 1100 1096 }
+1
firmware/ihex2fw.c
··· 86 86 case 'j': 87 87 include_jump = 1; 88 88 break; 89 + default: 89 90 return usage(); 90 91 } 91 92 }
+1
fs/adfs/dir_fplus.c
··· 61 61 kcalloc(size, sizeof(struct buffer_head *), 62 62 GFP_KERNEL); 63 63 if (!bh_fplus) { 64 + ret = -ENOMEM; 64 65 adfs_error(sb, "not enough memory for" 65 66 " dir object %X (%d blocks)", id, size); 66 67 goto out;
+15 -5
fs/adfs/super.c
··· 316 316 dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL); 317 317 if (dm == NULL) { 318 318 adfs_error(sb, "not enough memory"); 319 - return NULL; 319 + return ERR_PTR(-ENOMEM); 320 320 } 321 321 322 322 for (zone = 0; zone < nzones; zone++, map_addr++) { ··· 349 349 brelse(dm[zone].dm_bh); 350 350 351 351 kfree(dm); 352 - return NULL; 352 + return ERR_PTR(-EIO); 353 353 } 354 354 355 355 static inline unsigned long adfs_discsize(struct adfs_discrecord *dr, int block_bits) ··· 370 370 unsigned char *b_data; 371 371 struct adfs_sb_info *asb; 372 372 struct inode *root; 373 + int ret = -EINVAL; 373 374 374 375 sb->s_flags |= MS_NODIRATIME; 375 376 ··· 392 391 sb_set_blocksize(sb, BLOCK_SIZE); 393 392 if (!(bh = sb_bread(sb, ADFS_DISCRECORD / BLOCK_SIZE))) { 394 393 adfs_error(sb, "unable to read superblock"); 394 + ret = -EIO; 395 395 goto error; 396 396 } 397 397 ··· 402 400 if (!silent) 403 401 printk("VFS: Can't find an adfs filesystem on dev " 404 402 "%s.\n", sb->s_id); 403 + ret = -EINVAL; 405 404 goto error_free_bh; 406 405 } 407 406 ··· 415 412 if (!silent) 416 413 printk("VPS: Can't find an adfs filesystem on dev " 417 414 "%s.\n", sb->s_id); 415 + ret = -EINVAL; 418 416 goto error_free_bh; 419 417 } 420 418 ··· 425 421 if (!bh) { 426 422 adfs_error(sb, "couldn't read superblock on " 427 423 "2nd try."); 424 + ret = -EIO; 428 425 goto error; 429 426 } 430 427 b_data = bh->b_data + (ADFS_DISCRECORD % sb->s_blocksize); 431 428 if (adfs_checkbblk(b_data)) { 432 429 adfs_error(sb, "disc record mismatch, very weird!"); 430 + ret = -EINVAL; 433 431 goto error_free_bh; 434 432 } 435 433 dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET); ··· 439 433 if (!silent) 440 434 printk(KERN_ERR "VFS: Unsupported blocksize on dev " 441 435 "%s.\n", sb->s_id); 436 + ret = -EINVAL; 442 437 goto error; 443 438 } 444 439 ··· 454 447 asb->s_size = adfs_discsize(dr, sb->s_blocksize_bits); 455 448 asb->s_version = dr->format_version; 456 449 asb->s_log2sharesize = dr->log2sharesize; 457 - 450 + 458 451 asb->s_map = adfs_read_map(sb, dr); 459 - if (!asb->s_map) 452 + if (IS_ERR(asb->s_map)) { 453 + ret = PTR_ERR(asb->s_map); 460 454 goto error_free_bh; 455 + } 461 456 462 457 brelse(bh); 463 458 ··· 508 499 brelse(asb->s_map[i].dm_bh); 509 500 kfree(asb->s_map); 510 501 adfs_error(sb, "get root inode failed\n"); 502 + ret = -EIO; 511 503 goto error; 512 504 } 513 505 return 0; ··· 518 508 error: 519 509 sb->s_fs_info = NULL; 520 510 kfree(asb); 521 - return -EINVAL; 511 + return ret; 522 512 } 523 513 524 514 static struct dentry *adfs_mount(struct file_system_type *fs_type,
+16 -12
fs/affs/affs.h
··· 106 106 spinlock_t work_lock; /* protects sb_work and work_queued */ 107 107 }; 108 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 */ 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) 121 125 122 126 /* short cut to get to the affs specific sb data */ 123 127 static inline struct affs_sb_info *AFFS_SB(struct super_block *sb)
+2 -1
fs/affs/amigaffs.c
··· 472 472 affs_nofilenametruncate(const struct dentry *dentry) 473 473 { 474 474 struct inode *inode = dentry->d_inode; 475 - return AFFS_SB(inode->i_sb)->s_flags & SF_NO_TRUNCATE; 475 + 476 + return affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_NO_TRUNCATE); 476 477 477 478 } 478 479
+1 -1
fs/affs/file.c
··· 914 914 if (inode->i_size) { 915 915 AFFS_I(inode)->i_blkcnt = last_blk + 1; 916 916 AFFS_I(inode)->i_extcnt = ext + 1; 917 - if (AFFS_SB(sb)->s_flags & SF_OFS) { 917 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS)) { 918 918 struct buffer_head *bh = affs_bread_ino(inode, last_blk, 0); 919 919 u32 tmp; 920 920 if (IS_ERR(bh)) {
+18 -14
fs/affs/inode.c
··· 66 66 AFFS_I(inode)->i_lastalloc = 0; 67 67 AFFS_I(inode)->i_pa_cnt = 0; 68 68 69 - if (sbi->s_flags & SF_SETMODE) 69 + if (affs_test_opt(sbi->s_flags, SF_SETMODE)) 70 70 inode->i_mode = sbi->s_mode; 71 71 else 72 72 inode->i_mode = prot_to_mode(prot); 73 73 74 74 id = be16_to_cpu(tail->uid); 75 - if (id == 0 || sbi->s_flags & SF_SETUID) 75 + if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETUID)) 76 76 inode->i_uid = sbi->s_uid; 77 - else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) 77 + else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS)) 78 78 i_uid_write(inode, 0); 79 79 else 80 80 i_uid_write(inode, id); 81 81 82 82 id = be16_to_cpu(tail->gid); 83 - if (id == 0 || sbi->s_flags & SF_SETGID) 83 + if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETGID)) 84 84 inode->i_gid = sbi->s_gid; 85 - else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) 85 + else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS)) 86 86 i_gid_write(inode, 0); 87 87 else 88 88 i_gid_write(inode, id); ··· 94 94 /* fall through */ 95 95 case ST_USERDIR: 96 96 if (be32_to_cpu(tail->stype) == ST_USERDIR || 97 - sbi->s_flags & SF_SETMODE) { 97 + affs_test_opt(sbi->s_flags, SF_SETMODE)) { 98 98 if (inode->i_mode & S_IRUSR) 99 99 inode->i_mode |= S_IXUSR; 100 100 if (inode->i_mode & S_IRGRP) ··· 133 133 } 134 134 if (tail->link_chain) 135 135 set_nlink(inode, 2); 136 - inode->i_mapping->a_ops = (sbi->s_flags & SF_OFS) ? &affs_aops_ofs : &affs_aops; 136 + inode->i_mapping->a_ops = affs_test_opt(sbi->s_flags, SF_OFS) ? 137 + &affs_aops_ofs : &affs_aops; 137 138 inode->i_op = &affs_file_inode_operations; 138 139 inode->i_fop = &affs_file_operations; 139 140 break; ··· 191 190 if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) { 192 191 uid = i_uid_read(inode); 193 192 gid = i_gid_read(inode); 194 - if (AFFS_SB(sb)->s_flags & SF_MUFS) { 193 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_MUFS)) { 195 194 if (uid == 0 || uid == 0xFFFF) 196 195 uid = uid ^ ~0; 197 196 if (gid == 0 || gid == 0xFFFF) 198 197 gid = gid ^ ~0; 199 198 } 200 - if (!(AFFS_SB(sb)->s_flags & SF_SETUID)) 199 + if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETUID)) 201 200 tail->uid = cpu_to_be16(uid); 202 - if (!(AFFS_SB(sb)->s_flags & SF_SETGID)) 201 + if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETGID)) 203 202 tail->gid = cpu_to_be16(gid); 204 203 } 205 204 } ··· 222 221 if (error) 223 222 goto out; 224 223 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)) || 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)) || 227 228 ((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)) 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)) 230 232 error = -EPERM; 231 233 goto out; 232 234 }
+4 -2
fs/affs/namei.c
··· 53 53 static inline toupper_t 54 54 affs_get_toupper(struct super_block *sb) 55 55 { 56 - return AFFS_SB(sb)->s_flags & SF_INTL ? affs_intl_toupper : affs_toupper; 56 + return affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL) ? 57 + affs_intl_toupper : affs_toupper; 57 58 } 58 59 59 60 /* ··· 276 275 277 276 inode->i_op = &affs_file_inode_operations; 278 277 inode->i_fop = &affs_file_operations; 279 - inode->i_mapping->a_ops = (AFFS_SB(sb)->s_flags & SF_OFS) ? &affs_aops_ofs : &affs_aops; 278 + inode->i_mapping->a_ops = affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS) ? 279 + &affs_aops_ofs : &affs_aops; 280 280 error = affs_add_entry(dir, inode, dentry, ST_FILE); 281 281 if (error) { 282 282 clear_nlink(inode);
+24 -19
fs/affs/super.c
··· 227 227 if (match_octal(&args[0], &option)) 228 228 return 0; 229 229 *mode = option & 0777; 230 - *mount_opts |= SF_SETMODE; 230 + affs_set_opt(*mount_opts, SF_SETMODE); 231 231 break; 232 232 case Opt_mufs: 233 - *mount_opts |= SF_MUFS; 233 + affs_set_opt(*mount_opts, SF_MUFS); 234 234 break; 235 235 case Opt_notruncate: 236 - *mount_opts |= SF_NO_TRUNCATE; 236 + affs_set_opt(*mount_opts, SF_NO_TRUNCATE); 237 237 break; 238 238 case Opt_prefix: 239 239 *prefix = match_strdup(&args[0]); 240 240 if (!*prefix) 241 241 return 0; 242 - *mount_opts |= SF_PREFIX; 242 + affs_set_opt(*mount_opts, SF_PREFIX); 243 243 break; 244 244 case Opt_protect: 245 - *mount_opts |= SF_IMMUTABLE; 245 + affs_set_opt(*mount_opts, SF_IMMUTABLE); 246 246 break; 247 247 case Opt_reserved: 248 248 if (match_int(&args[0], reserved)) ··· 258 258 *gid = make_kgid(current_user_ns(), option); 259 259 if (!gid_valid(*gid)) 260 260 return 0; 261 - *mount_opts |= SF_SETGID; 261 + affs_set_opt(*mount_opts, SF_SETGID); 262 262 break; 263 263 case Opt_setuid: 264 264 if (match_int(&args[0], &option)) ··· 266 266 *uid = make_kuid(current_user_ns(), option); 267 267 if (!uid_valid(*uid)) 268 268 return 0; 269 - *mount_opts |= SF_SETUID; 269 + affs_set_opt(*mount_opts, SF_SETUID); 270 270 break; 271 271 case Opt_verbose: 272 - *mount_opts |= SF_VERBOSE; 272 + affs_set_opt(*mount_opts, SF_VERBOSE); 273 273 break; 274 274 case Opt_volume: { 275 275 char *vol = match_strdup(&args[0]); ··· 435 435 case MUFS_FS: 436 436 case MUFS_INTLFFS: 437 437 case MUFS_DCFFS: 438 - sbi->s_flags |= SF_MUFS; 438 + affs_set_opt(sbi->s_flags, SF_MUFS); 439 439 /* fall thru */ 440 440 case FS_INTLFFS: 441 441 case FS_DCFFS: 442 - sbi->s_flags |= SF_INTL; 442 + affs_set_opt(sbi->s_flags, SF_INTL); 443 443 break; 444 444 case MUFS_FFS: 445 - sbi->s_flags |= SF_MUFS; 445 + affs_set_opt(sbi->s_flags, SF_MUFS); 446 446 break; 447 447 case FS_FFS: 448 448 break; 449 449 case MUFS_OFS: 450 - sbi->s_flags |= SF_MUFS; 450 + affs_set_opt(sbi->s_flags, SF_MUFS); 451 451 /* fall thru */ 452 452 case FS_OFS: 453 - sbi->s_flags |= SF_OFS; 453 + affs_set_opt(sbi->s_flags, SF_OFS); 454 454 sb->s_flags |= MS_NOEXEC; 455 455 break; 456 456 case MUFS_DCOFS: 457 457 case MUFS_INTLOFS: 458 - sbi->s_flags |= SF_MUFS; 458 + affs_set_opt(sbi->s_flags, SF_MUFS); 459 459 case FS_DCOFS: 460 460 case FS_INTLOFS: 461 - sbi->s_flags |= SF_INTL | SF_OFS; 461 + affs_set_opt(sbi->s_flags, SF_INTL); 462 + affs_set_opt(sbi->s_flags, SF_OFS); 462 463 sb->s_flags |= MS_NOEXEC; 463 464 break; 464 465 default: ··· 468 467 return -EINVAL; 469 468 } 470 469 471 - if (mount_flags & SF_VERBOSE) { 470 + if (affs_test_opt(mount_flags, SF_VERBOSE)) { 472 471 u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; 473 472 pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", 474 473 len > 31 ? 31 : len, ··· 479 478 sb->s_flags |= MS_NODEV | MS_NOSUID; 480 479 481 480 sbi->s_data_blksize = sb->s_blocksize; 482 - if (sbi->s_flags & SF_OFS) 481 + if (affs_test_opt(sbi->s_flags, SF_OFS)) 483 482 sbi->s_data_blksize -= 24; 484 483 485 484 tmp_flags = sb->s_flags; ··· 494 493 if (IS_ERR(root_inode)) 495 494 return PTR_ERR(root_inode); 496 495 497 - if (AFFS_SB(sb)->s_flags & SF_INTL) 496 + if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL)) 498 497 sb->s_d_op = &affs_intl_dentry_operations; 499 498 else 500 499 sb->s_d_op = &affs_dentry_operations; ··· 521 520 int root_block; 522 521 unsigned long mount_flags; 523 522 int res = 0; 524 - char *new_opts = kstrdup(data, GFP_KERNEL); 523 + char *new_opts; 525 524 char volume[32]; 526 525 char *prefix = NULL; 526 + 527 + new_opts = kstrdup(data, GFP_KERNEL); 528 + if (!new_opts) 529 + return -ENOMEM; 527 530 528 531 pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data); 529 532
+10 -12
fs/befs/befs.h
··· 19 19 * BeFS in memory structures 20 20 */ 21 21 22 - typedef struct befs_mount_options { 22 + struct befs_mount_options { 23 23 kgid_t gid; 24 24 kuid_t uid; 25 25 int use_gid; 26 26 int use_uid; 27 27 int debug; 28 28 char *iocharset; 29 - } befs_mount_options; 29 + }; 30 30 31 - typedef struct befs_sb_info { 31 + struct befs_sb_info { 32 32 u32 magic1; 33 33 u32 block_size; 34 34 u32 block_shift; ··· 52 52 befs_inode_addr indices; 53 53 u32 magic3; 54 54 55 - befs_mount_options mount_opts; 55 + struct befs_mount_options mount_opts; 56 56 struct nls_table *nls; 57 + }; 57 58 58 - } befs_sb_info; 59 - 60 - typedef struct befs_inode_info { 59 + struct befs_inode_info { 61 60 u32 i_flags; 62 61 u32 i_type; 63 62 ··· 70 71 } i_data; 71 72 72 73 struct inode vfs_inode; 73 - 74 - } befs_inode_info; 74 + }; 75 75 76 76 enum befs_err { 77 77 BEFS_OK, ··· 103 105 /* Gets a pointer to the private portion of the super_block 104 106 * structure from the public part 105 107 */ 106 - static inline befs_sb_info * 108 + static inline struct befs_sb_info * 107 109 BEFS_SB(const struct super_block *super) 108 110 { 109 - return (befs_sb_info *) super->s_fs_info; 111 + return (struct befs_sb_info *) super->s_fs_info; 110 112 } 111 113 112 - static inline befs_inode_info * 114 + static inline struct befs_inode_info * 113 115 BEFS_I(const struct inode *inode) 114 116 { 115 117 return list_entry(inode, struct befs_inode_info, vfs_inode);
+2 -2
fs/befs/datastream.c
··· 168 168 befs_blocknr_t blocks; 169 169 befs_blocknr_t datablocks; /* File data blocks */ 170 170 befs_blocknr_t metablocks; /* FS metadata blocks */ 171 - befs_sb_info *befs_sb = BEFS_SB(sb); 171 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 172 172 173 173 befs_debug(sb, "---> %s", __func__); 174 174 ··· 428 428 struct buffer_head *indir_block; 429 429 befs_block_run indir_run; 430 430 befs_disk_inode_addr *iaddr_array = NULL; 431 - befs_sb_info *befs_sb = BEFS_SB(sb); 431 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 432 432 433 433 befs_blocknr_t indir_start_blk = 434 434 data->max_indirect_range >> befs_sb->block_shift;
+1 -1
fs/befs/io.c
··· 28 28 { 29 29 struct buffer_head *bh = NULL; 30 30 befs_blocknr_t block = 0; 31 - befs_sb_info *befs_sb = BEFS_SB(sb); 31 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 32 32 33 33 befs_debug(sb, "---> Enter %s " 34 34 "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
+8 -8
fs/befs/linuxvfs.c
··· 51 51 static void befs_put_super(struct super_block *); 52 52 static int befs_remount(struct super_block *, int *, char *); 53 53 static int befs_statfs(struct dentry *, struct kstatfs *); 54 - static int parse_options(char *, befs_mount_options *); 54 + static int parse_options(char *, struct befs_mount_options *); 55 55 56 56 static const struct super_operations befs_sops = { 57 57 .alloc_inode = befs_alloc_inode, /* allocate a new inode */ ··· 304 304 { 305 305 struct buffer_head *bh = NULL; 306 306 befs_inode *raw_inode = NULL; 307 - 308 - befs_sb_info *befs_sb = BEFS_SB(sb); 309 - befs_inode_info *befs_ino = NULL; 307 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 308 + struct befs_inode_info *befs_ino = NULL; 310 309 struct inode *inode; 311 310 long ret = -EIO; 312 311 ··· 471 472 befs_follow_link(struct dentry *dentry, struct nameidata *nd) 472 473 { 473 474 struct super_block *sb = dentry->d_sb; 474 - befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 475 + struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 475 476 befs_data_stream *data = &befs_ino->i_data.ds; 476 477 befs_off_t len = data->size; 477 478 char *link; ··· 501 502 static void * 502 503 befs_fast_follow_link(struct dentry *dentry, struct nameidata *nd) 503 504 { 504 - befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 505 + struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 506 + 505 507 nd_set_link(nd, befs_ino->i_data.symlink); 506 508 return NULL; 507 509 } ··· 669 669 }; 670 670 671 671 static int 672 - parse_options(char *options, befs_mount_options * opts) 672 + parse_options(char *options, struct befs_mount_options *opts) 673 673 { 674 674 char *p; 675 675 substring_t args[MAX_OPT_ARGS]; ··· 769 769 befs_fill_super(struct super_block *sb, void *data, int silent) 770 770 { 771 771 struct buffer_head *bh; 772 - befs_sb_info *befs_sb; 772 + struct befs_sb_info *befs_sb; 773 773 befs_super_block *disk_sb; 774 774 struct inode *root; 775 775 long ret = -EINVAL;
+2 -2
fs/befs/super.c
··· 24 24 int 25 25 befs_load_sb(struct super_block *sb, befs_super_block * disk_sb) 26 26 { 27 - befs_sb_info *befs_sb = BEFS_SB(sb); 27 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 28 28 29 29 /* Check the byte order of the filesystem */ 30 30 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE) ··· 59 59 int 60 60 befs_check_sb(struct super_block *sb) 61 61 { 62 - befs_sb_info *befs_sb = BEFS_SB(sb); 62 + struct befs_sb_info *befs_sb = BEFS_SB(sb); 63 63 64 64 /* Check magic headers of super block */ 65 65 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
+2 -2
fs/bfs/dir.c
··· 86 86 87 87 inode = new_inode(s); 88 88 if (!inode) 89 - return -ENOSPC; 89 + return -ENOMEM; 90 90 mutex_lock(&info->bfs_lock); 91 91 ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1); 92 92 if (ino > info->si_lasti) { ··· 293 293 for (block = sblock; block <= eblock; block++) { 294 294 bh = sb_bread(dir->i_sb, block); 295 295 if (!bh) 296 - return -ENOSPC; 296 + return -EIO; 297 297 for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) { 298 298 de = (struct bfs_dirent *)(bh->b_data + off); 299 299 if (!de->ino) {
+9 -21
fs/binfmt_misc.c
··· 9 9 10 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 11 12 + #include <linux/kernel.h> 12 13 #include <linux/module.h> 13 14 #include <linux/init.h> 14 15 #include <linux/sched.h> ··· 522 521 523 522 static void entry_status(Node *e, char *page) 524 523 { 525 - char *dp; 526 - char *status = "disabled"; 527 - const char *flags = "flags: "; 524 + char *dp = page; 525 + const char *status = "disabled"; 528 526 529 527 if (test_bit(Enabled, &e->flags)) 530 528 status = "enabled"; ··· 533 533 return; 534 534 } 535 535 536 - sprintf(page, "%s\ninterpreter %s\n", status, e->interpreter); 537 - dp = page + strlen(page); 536 + dp += sprintf(dp, "%s\ninterpreter %s\n", status, e->interpreter); 538 537 539 538 /* print the special flags */ 540 - sprintf(dp, "%s", flags); 541 - dp += strlen(flags); 539 + dp += sprintf(dp, "flags: "); 542 540 if (e->flags & MISC_FMT_PRESERVE_ARGV0) 543 541 *dp++ = 'P'; 544 542 if (e->flags & MISC_FMT_OPEN_BINARY) ··· 548 550 if (!test_bit(Magic, &e->flags)) { 549 551 sprintf(dp, "extension .%s\n", e->magic); 550 552 } 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 - } 553 + dp += sprintf(dp, "offset %i\nmagic ", e->offset); 554 + dp = bin2hex(dp, e->magic, e->size); 559 555 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 - } 556 + dp += sprintf(dp, "\nmask "); 557 + dp = bin2hex(dp, e->mask, e->size); 566 558 } 567 559 *dp++ = '\n'; 568 560 *dp = '\0';
+11 -1
fs/exec.c
··· 926 926 if (!thread_group_leader(tsk)) { 927 927 struct task_struct *leader = tsk->group_leader; 928 928 929 - sig->notify_count = -1; /* for exit_notify() */ 930 929 for (;;) { 931 930 threadgroup_change_begin(tsk); 932 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; 933 937 if (likely(leader->exit_state)) 934 938 break; 935 939 __set_current_state(TASK_KILLABLE); ··· 1082 1078 if (retval) 1083 1079 goto out; 1084 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 + */ 1085 1086 set_mm_exe_file(bprm->mm, bprm->file); 1087 + 1086 1088 /* 1087 1089 * Release all of the old mmap stuff 1088 1090 */
-2
fs/fat/cache.c
··· 8 8 * May 1999. AV. Fixed the bogosity with FAT32 (read "FAT28"). Fscking lusers. 9 9 */ 10 10 11 - #include <linux/fs.h> 12 11 #include <linux/slab.h> 13 - #include <linux/buffer_head.h> 14 12 #include "fat.h" 15 13 16 14 /* this must be > 0. */
-4
fs/fat/dir.c
··· 13 13 * Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de> 14 14 */ 15 15 16 - #include <linux/module.h> 17 16 #include <linux/slab.h> 18 - #include <linux/time.h> 19 - #include <linux/buffer_head.h> 20 17 #include <linux/compat.h> 21 18 #include <linux/uaccess.h> 22 - #include <linux/kernel.h> 23 19 #include "fat.h" 24 20 25 21 /*
+1 -4
fs/fat/fat.h
··· 2 2 #define _FAT_H 3 3 4 4 #include <linux/buffer_head.h> 5 - #include <linux/string.h> 6 5 #include <linux/nls.h> 7 - #include <linux/fs.h> 8 6 #include <linux/hash.h> 9 - #include <linux/mutex.h> 10 7 #include <linux/ratelimit.h> 11 8 #include <linux/msdos_fs.h> 12 9 ··· 63 66 unsigned short sec_per_clus; /* sectors/cluster */ 64 67 unsigned short cluster_bits; /* log2(cluster_size) */ 65 68 unsigned int cluster_size; /* cluster size */ 66 - unsigned char fats, fat_bits; /* number of FATs, FAT bits (12 or 16) */ 69 + unsigned char fats, fat_bits; /* number of FATs, FAT bits (12,16 or 32) */ 67 70 unsigned short fat_start; 68 71 unsigned long fat_length; /* FAT start & length (sec.) */ 69 72 unsigned long dir_start;
-3
fs/fat/fatent.c
··· 3 3 * Released under GPL v2. 4 4 */ 5 5 6 - #include <linux/module.h> 7 - #include <linux/fs.h> 8 - #include <linux/msdos_fs.h> 9 6 #include <linux/blkdev.h> 10 7 #include "fat.h" 11 8
-4
fs/fat/file.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/compat.h> 12 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 13 #include <linux/blkdev.h> 18 14 #include <linux/fsnotify.h> 19 15 #include <linux/security.h>
+2 -11
fs/fat/inode.c
··· 11 11 */ 12 12 13 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 14 #include <linux/pagemap.h> 19 15 #include <linux/mpage.h> 20 - #include <linux/buffer_head.h> 21 - #include <linux/mount.h> 22 16 #include <linux/vfs.h> 17 + #include <linux/seq_file.h> 23 18 #include <linux/parser.h> 24 19 #include <linux/uio.h> 25 - #include <linux/writeback.h> 26 - #include <linux/log2.h> 27 - #include <linux/hash.h> 28 20 #include <linux/blkdev.h> 29 21 #include <asm/unaligned.h> 30 22 #include "fat.h" ··· 1270 1278 1271 1279 static int fat_read_root(struct inode *inode) 1272 1280 { 1273 - struct super_block *sb = inode->i_sb; 1274 - struct msdos_sb_info *sbi = MSDOS_SB(sb); 1281 + struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); 1275 1282 int error; 1276 1283 1277 1284 MSDOS_I(inode)->i_pos = MSDOS_ROOT_INO;
-4
fs/fat/misc.c
··· 6 6 * and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru) 7 7 */ 8 8 9 - #include <linux/module.h> 10 - #include <linux/fs.h> 11 - #include <linux/buffer_head.h> 12 - #include <linux/time.h> 13 9 #include "fat.h" 14 10 15 11 /*
-2
fs/fat/namei_msdos.c
··· 7 7 */ 8 8 9 9 #include <linux/module.h> 10 - #include <linux/time.h> 11 - #include <linux/buffer_head.h> 12 10 #include "fat.h" 13 11 14 12 /* Characters that are undesirable in an MS-DOS file name */
-2
fs/fat/namei_vfat.c
··· 16 16 */ 17 17 18 18 #include <linux/module.h> 19 - #include <linux/jiffies.h> 20 19 #include <linux/ctype.h> 21 20 #include <linux/slab.h> 22 - #include <linux/buffer_head.h> 23 21 #include <linux/namei.h> 24 22 #include "fat.h" 25 23
+1 -2
fs/file.c
··· 638 638 file = fcheck_files(files, fd); 639 639 if (file) { 640 640 /* File object ref couldn't be taken */ 641 - if ((file->f_mode & mask) || 642 - !atomic_long_inc_not_zero(&file->f_count)) 641 + if ((file->f_mode & mask) || !get_file_rcu(file)) 643 642 file = NULL; 644 643 } 645 644 rcu_read_unlock();
+2 -2
fs/hfs/dir.c
··· 197 197 198 198 inode = hfs_new_inode(dir, &dentry->d_name, mode); 199 199 if (!inode) 200 - return -ENOSPC; 200 + return -ENOMEM; 201 201 202 202 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 203 203 if (res) { ··· 226 226 227 227 inode = hfs_new_inode(dir, &dentry->d_name, S_IFDIR | mode); 228 228 if (!inode) 229 - return -ENOSPC; 229 + return -ENOMEM; 230 230 231 231 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 232 232 if (res) {
+1 -3
fs/hfsplus/bfind.c
··· 118 118 int b, e; 119 119 int res; 120 120 121 - if (!rec_found) 122 - BUG(); 123 - 121 + BUG_ON(!rec_found); 124 122 b = 0; 125 123 e = bnode->num_recs - 1; 126 124 res = -ENOENT;
+2 -1
fs/hfsplus/catalog.c
··· 350 350 &fd.search_key->cat.name.unicode, 351 351 off + 2, len); 352 352 fd.search_key->key_len = cpu_to_be16(6 + len); 353 - } else 353 + } else { 354 354 err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str); 355 355 if (unlikely(err)) 356 356 goto out; 357 + } 357 358 358 359 err = hfs_brec_find(&fd, hfs_find_rec_by_key); 359 360 if (err)
+2 -2
fs/hfsplus/dir.c
··· 434 434 { 435 435 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 436 436 struct inode *inode; 437 - int res = -ENOSPC; 437 + int res = -ENOMEM; 438 438 439 439 mutex_lock(&sbi->vh_mutex); 440 440 inode = hfsplus_new_inode(dir->i_sb, S_IFLNK | S_IRWXUGO); ··· 476 476 { 477 477 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 478 478 struct inode *inode; 479 - int res = -ENOSPC; 479 + int res = -ENOMEM; 480 480 481 481 mutex_lock(&sbi->vh_mutex); 482 482 inode = hfsplus_new_inode(dir->i_sb, mode);
+6
fs/hfsplus/inode.c
··· 253 253 if ((attr->ia_valid & ATTR_SIZE) && 254 254 attr->ia_size != i_size_read(inode)) { 255 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 + } 256 262 truncate_setsize(inode, attr->ia_size); 257 263 hfsplus_file_truncate(inode); 258 264 }
+5 -7
fs/hfsplus/ioctl.c
··· 76 76 { 77 77 struct inode *inode = file_inode(file); 78 78 struct hfsplus_inode_info *hip = HFSPLUS_I(inode); 79 - unsigned int flags; 79 + unsigned int flags, new_fl = 0; 80 80 int err = 0; 81 81 82 82 err = mnt_want_write_file(file); ··· 110 110 } 111 111 112 112 if (flags & FS_IMMUTABLE_FL) 113 - inode->i_flags |= S_IMMUTABLE; 114 - else 115 - inode->i_flags &= ~S_IMMUTABLE; 113 + new_fl |= S_IMMUTABLE; 116 114 117 115 if (flags & FS_APPEND_FL) 118 - inode->i_flags |= S_APPEND; 119 - else 120 - inode->i_flags &= ~S_APPEND; 116 + new_fl |= S_APPEND; 117 + 118 + inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND); 121 119 122 120 if (flags & FS_NODUMP_FL) 123 121 hip->userflags |= HFSPLUS_FLG_NODUMP;
+61 -25
fs/hfsplus/xattr.c
··· 44 44 return -1; 45 45 } 46 46 47 - static inline int is_known_namespace(const char *name) 47 + static bool is_known_namespace(const char *name) 48 48 { 49 49 if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) && 50 50 strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && ··· 424 424 return len; 425 425 } 426 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 + 427 449 static ssize_t hfsplus_getxattr_finder_info(struct inode *inode, 428 450 void *value, size_t size) 429 451 { ··· 580 558 failed_getxattr_init: 581 559 hfsplus_destroy_attr_entry(entry); 582 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 + 583 585 } 584 586 585 587 static inline int can_list(const char *xattr_name) ··· 852 806 static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, 853 807 void *buffer, size_t size, int type) 854 808 { 855 - char *xattr_name; 856 - int res; 857 - 858 809 if (!strcmp(name, "")) 859 810 return -EINVAL; 860 811 ··· 861 818 */ 862 819 if (is_known_namespace(name)) 863 820 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 821 871 - res = hfsplus_getxattr(dentry, xattr_name, buffer, size); 872 - kfree(xattr_name); 873 - return res; 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); 874 829 } 875 830 876 831 static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, 877 832 const void *buffer, size_t size, int flags, int type) 878 833 { 879 - char *xattr_name; 880 - int res; 881 - 882 834 if (!strcmp(name, "")) 883 835 return -EINVAL; 884 836 ··· 883 845 */ 884 846 if (is_known_namespace(name)) 885 847 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 848 893 - res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); 894 - kfree(xattr_name); 895 - return res; 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); 896 856 } 897 857 898 858 static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
+7 -13
fs/hfsplus/xattr.h
··· 21 21 int __hfsplus_setxattr(struct inode *inode, const char *name, 22 22 const void *value, size_t size, int flags); 23 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 - } 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); 29 27 30 28 ssize_t __hfsplus_getxattr(struct inode *inode, const char *name, 31 - void *value, size_t size); 29 + void *value, size_t size); 32 30 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 - } 31 + ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, 32 + void *value, size_t size, 33 + const char *prefix, size_t prefixlen); 40 34 41 35 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); 42 36
+6 -32
fs/hfsplus/xattr_security.c
··· 16 16 static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, 17 17 void *buffer, size_t size, int type) 18 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; 19 + return hfsplus_getxattr(dentry, name, buffer, size, 20 + XATTR_SECURITY_PREFIX, 21 + XATTR_SECURITY_PREFIX_LEN); 35 22 } 36 23 37 24 static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, 38 25 const void *buffer, size_t size, int flags, int type) 39 26 { 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; 27 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 28 + XATTR_SECURITY_PREFIX, 29 + XATTR_SECURITY_PREFIX_LEN); 56 30 } 57 31 58 32 static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
+5 -32
fs/hfsplus/xattr_trusted.c
··· 14 14 static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, 15 15 void *buffer, size_t size, int type) 16 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; 17 + return hfsplus_getxattr(dentry, name, buffer, size, 18 + XATTR_TRUSTED_PREFIX, 19 + XATTR_TRUSTED_PREFIX_LEN); 33 20 } 34 21 35 22 static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, 36 23 const void *buffer, size_t size, int flags, int type) 37 24 { 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; 25 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 26 + XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN); 54 27 } 55 28 56 29 static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
+4 -31
fs/hfsplus/xattr_user.c
··· 14 14 static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, 15 15 void *buffer, size_t size, int type) 16 16 { 17 - char *xattr_name; 18 - int res; 19 17 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; 18 + return hfsplus_getxattr(dentry, name, buffer, size, 19 + XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 33 20 } 34 21 35 22 static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, 36 23 const void *buffer, size_t size, int flags, int type) 37 24 { 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; 25 + return hfsplus_setxattr(dentry, name, buffer, size, flags, 26 + XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 54 27 } 55 28 56 29 static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
+38
fs/locks.c
··· 2590 2590 return 0; 2591 2591 } 2592 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 + 2593 2631 static void *locks_start(struct seq_file *f, loff_t *pos) 2594 2632 __acquires(&blocked_lock_lock) 2595 2633 {
+3 -2
fs/nilfs2/alloc.c
··· 405 405 static int nilfs_palloc_count_desc_blocks(struct inode *inode, 406 406 unsigned long *desc_blocks) 407 407 { 408 - unsigned long blknum; 408 + __u64 blknum; 409 409 int ret; 410 410 411 411 ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); 412 412 if (likely(!ret)) 413 413 *desc_blocks = DIV_ROUND_UP( 414 - blknum, NILFS_MDT(inode)->mi_blocks_per_desc_block); 414 + (unsigned long)blknum, 415 + NILFS_MDT(inode)->mi_blocks_per_desc_block); 415 416 return ret; 416 417 } 417 418
+37 -11
fs/nilfs2/bmap.c
··· 152 152 * 153 153 * %-EEXIST - A record associated with @key already exist. 154 154 */ 155 - int nilfs_bmap_insert(struct nilfs_bmap *bmap, 156 - unsigned long key, 157 - unsigned long rec) 155 + int nilfs_bmap_insert(struct nilfs_bmap *bmap, __u64 key, unsigned long rec) 158 156 { 159 157 int ret; 160 158 ··· 189 191 return bmap->b_ops->bop_delete(bmap, key); 190 192 } 191 193 192 - int nilfs_bmap_last_key(struct nilfs_bmap *bmap, unsigned long *key) 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) 193 213 { 194 - __u64 lastkey; 195 214 int ret; 196 215 197 216 down_read(&bmap->b_sem); 198 - ret = bmap->b_ops->bop_last_key(bmap, &lastkey); 217 + ret = bmap->b_ops->bop_seek_key(bmap, start, keyp); 199 218 up_read(&bmap->b_sem); 200 219 201 220 if (ret < 0) 202 221 ret = nilfs_bmap_convert_error(bmap, __func__, ret); 203 - else 204 - *key = lastkey; 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); 205 235 return ret; 206 236 } 207 237 ··· 250 224 * 251 225 * %-ENOENT - A record associated with @key does not exist. 252 226 */ 253 - int nilfs_bmap_delete(struct nilfs_bmap *bmap, unsigned long key) 227 + int nilfs_bmap_delete(struct nilfs_bmap *bmap, __u64 key) 254 228 { 255 229 int ret; 256 230 ··· 261 235 return nilfs_bmap_convert_error(bmap, __func__, ret); 262 236 } 263 237 264 - static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, unsigned long key) 238 + static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, __u64 key) 265 239 { 266 240 __u64 lastkey; 267 241 int ret; ··· 302 276 * 303 277 * %-ENOMEM - Insufficient amount of memory available. 304 278 */ 305 - int nilfs_bmap_truncate(struct nilfs_bmap *bmap, unsigned long key) 279 + int nilfs_bmap_truncate(struct nilfs_bmap *bmap, __u64 key) 306 280 { 307 281 int ret; 308 282
+8 -5
fs/nilfs2/bmap.h
··· 76 76 union nilfs_binfo *); 77 77 int (*bop_mark)(struct nilfs_bmap *, __u64, int); 78 78 79 - /* The following functions are internal use only. */ 79 + int (*bop_seek_key)(const struct nilfs_bmap *, __u64, __u64 *); 80 80 int (*bop_last_key)(const struct nilfs_bmap *, __u64 *); 81 + 82 + /* The following functions are internal use only. */ 81 83 int (*bop_check_insert)(const struct nilfs_bmap *, __u64); 82 84 int (*bop_check_delete)(struct nilfs_bmap *, __u64); 83 85 int (*bop_gather_data)(struct nilfs_bmap *, __u64 *, __u64 *, int); ··· 155 153 int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *); 156 154 void nilfs_bmap_write(struct nilfs_bmap *, struct nilfs_inode *); 157 155 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); 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); 162 161 void nilfs_bmap_clear(struct nilfs_bmap *); 163 162 int nilfs_bmap_propagate(struct nilfs_bmap *, struct buffer_head *); 164 163 void nilfs_bmap_lookup_dirty_buffers(struct nilfs_bmap *, struct list_head *);
+63
fs/nilfs2/btree.c
··· 633 633 return 0; 634 634 } 635 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 + 636 674 static int nilfs_btree_lookup(const struct nilfs_bmap *btree, 637 675 __u64 key, int level, __u64 *ptrp) 638 676 { ··· 1601 1563 return ret; 1602 1564 } 1603 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 + 1604 1587 static int nilfs_btree_last_key(const struct nilfs_bmap *btree, __u64 *keyp) 1605 1588 { 1606 1589 struct nilfs_btree_path *path; ··· 2357 2298 .bop_assign = nilfs_btree_assign, 2358 2299 .bop_mark = nilfs_btree_mark, 2359 2300 2301 + .bop_seek_key = nilfs_btree_seek_key, 2360 2302 .bop_last_key = nilfs_btree_last_key, 2303 + 2361 2304 .bop_check_insert = NULL, 2362 2305 .bop_check_delete = nilfs_btree_check_delete, 2363 2306 .bop_gather_data = nilfs_btree_gather_data, ··· 2379 2318 .bop_assign = nilfs_btree_assign_gc, 2380 2319 .bop_mark = NULL, 2381 2320 2321 + .bop_seek_key = NULL, 2382 2322 .bop_last_key = NULL, 2323 + 2383 2324 .bop_check_insert = NULL, 2384 2325 .bop_check_delete = NULL, 2385 2326 .bop_gather_data = NULL,
+52 -6
fs/nilfs2/cpfile.c
··· 53 53 return do_div(tcno, nilfs_cpfile_checkpoints_per_block(cpfile)); 54 54 } 55 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 + 56 63 static unsigned long 57 64 nilfs_cpfile_checkpoints_in_block(const struct inode *cpfile, 58 65 __u64 curr, ··· 151 144 return nilfs_mdt_get_block(cpfile, 152 145 nilfs_cpfile_get_blkoff(cpfile, cno), 153 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; 154 185 } 155 186 156 187 static inline int nilfs_cpfile_delete_checkpoint_block(struct inode *cpfile, ··· 448 403 return -ENOENT; /* checkpoint number 0 is invalid */ 449 404 down_read(&NILFS_MDT(cpfile)->mi_sem); 450 405 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); 406 + for (n = 0; n < nci; cno += ncps) { 407 + ret = nilfs_cpfile_find_checkpoint_block( 408 + cpfile, cno, cur_cno - 1, &cno, &bh); 454 409 if (ret < 0) { 455 - if (ret != -ENOENT) 456 - goto out; 457 - continue; /* skip hole */ 410 + if (likely(ret == -ENOENT)) 411 + break; 412 + goto out; 458 413 } 414 + ncps = nilfs_cpfile_checkpoints_in_block(cpfile, cno, cur_cno); 459 415 460 416 kaddr = kmap_atomic(bh->b_page); 461 417 cp = nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr);
+17
fs/nilfs2/direct.c
··· 173 173 return ret; 174 174 } 175 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 + 176 191 static int nilfs_direct_last_key(const struct nilfs_bmap *direct, __u64 *keyp) 177 192 { 178 193 __u64 key, lastkey; ··· 370 355 .bop_assign = nilfs_direct_assign, 371 356 .bop_mark = NULL, 372 357 358 + .bop_seek_key = nilfs_direct_seek_key, 373 359 .bop_last_key = nilfs_direct_last_key, 360 + 374 361 .bop_check_insert = nilfs_direct_check_insert, 375 362 .bop_check_delete = NULL, 376 363 .bop_gather_data = nilfs_direct_gather_data,
+13 -12
fs/nilfs2/inode.c
··· 106 106 err = nilfs_transaction_begin(inode->i_sb, &ti, 1); 107 107 if (unlikely(err)) 108 108 goto out; 109 - err = nilfs_bmap_insert(ii->i_bmap, (unsigned long)blkoff, 109 + err = nilfs_bmap_insert(ii->i_bmap, blkoff, 110 110 (unsigned long)bh_result); 111 111 if (unlikely(err != 0)) { 112 112 if (err == -EEXIST) { ··· 441 441 void nilfs_set_inode_flags(struct inode *inode) 442 442 { 443 443 unsigned int flags = NILFS_I(inode)->i_flags; 444 + unsigned int new_fl = 0; 444 445 445 - inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | 446 - S_DIRSYNC); 447 446 if (flags & FS_SYNC_FL) 448 - inode->i_flags |= S_SYNC; 447 + new_fl |= S_SYNC; 449 448 if (flags & FS_APPEND_FL) 450 - inode->i_flags |= S_APPEND; 449 + new_fl |= S_APPEND; 451 450 if (flags & FS_IMMUTABLE_FL) 452 - inode->i_flags |= S_IMMUTABLE; 451 + new_fl |= S_IMMUTABLE; 453 452 if (flags & FS_NOATIME_FL) 454 - inode->i_flags |= S_NOATIME; 453 + new_fl |= S_NOATIME; 455 454 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); 455 + new_fl |= S_DIRSYNC; 456 + inode_set_flags(inode, new_fl, S_SYNC | S_APPEND | S_IMMUTABLE | 457 + S_NOATIME | S_DIRSYNC); 459 458 } 460 459 461 460 int nilfs_read_inode_common(struct inode *inode, ··· 539 540 brelse(bh); 540 541 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); 541 542 nilfs_set_inode_flags(inode); 543 + mapping_set_gfp_mask(inode->i_mapping, 544 + mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 542 545 return 0; 543 546 544 547 failed_unmap: ··· 713 712 static void nilfs_truncate_bmap(struct nilfs_inode_info *ii, 714 713 unsigned long from) 715 714 { 716 - unsigned long b; 715 + __u64 b; 717 716 int ret; 718 717 719 718 if (!test_bit(NILFS_I_BMAP, &ii->i_state)) ··· 728 727 if (b < from) 729 728 return; 730 729 731 - b -= min_t(unsigned long, NILFS_MAX_TRUNCATE_BLOCKS, b - from); 730 + b -= min_t(__u64, NILFS_MAX_TRUNCATE_BLOCKS, b - from); 732 731 ret = nilfs_bmap_truncate(ii->i_bmap, b); 733 732 nilfs_relax_pressure_in_lock(ii->vfs_inode.i_sb); 734 733 if (!ret || (ret == -ENOMEM &&
+54
fs/nilfs2/mdt.c
··· 261 261 } 262 262 263 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 + /** 264 318 * nilfs_mdt_delete_block - make a hole on the meta data file. 265 319 * @inode: inode of the meta data file 266 320 * @block: block offset
+8 -2
fs/nilfs2/mdt.h
··· 78 78 void (*init_block)(struct inode *, 79 79 struct buffer_head *, void *), 80 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); 81 84 int nilfs_mdt_delete_block(struct inode *, unsigned long); 82 85 int nilfs_mdt_forget_block(struct inode *, unsigned long); 83 86 int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long); ··· 114 111 return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno; 115 112 } 116 113 117 - #define nilfs_mdt_bgl_lock(inode, bg) \ 118 - (&NILFS_MDT(inode)->mi_bgl->locks[(bg) & (NR_BG_LOCKS-1)].lock) 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 119 120 120 #endif /* _NILFS_MDT_H */
+10 -14
fs/nilfs2/page.c
··· 89 89 void nilfs_forget_buffer(struct buffer_head *bh) 90 90 { 91 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); 92 96 93 97 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); 98 + set_mask_bits(&bh->b_state, clear_bits, 0); 99 99 if (nilfs_page_buffers_clean(page)) 100 100 __nilfs_clear_page_dirty(page); 101 101 102 - clear_buffer_uptodate(bh); 103 - clear_buffer_mapped(bh); 104 102 bh->b_blocknr = -1; 105 103 ClearPageUptodate(page); 106 104 ClearPageMappedToDisk(page); ··· 419 421 420 422 if (page_has_buffers(page)) { 421 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); 422 428 423 429 bh = head = page_buffers(page); 424 430 do { ··· 432 430 "discard block %llu, size %zu", 433 431 (u64)bh->b_blocknr, bh->b_size); 434 432 } 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); 433 + set_mask_bits(&bh->b_state, clear_bits, 0); 442 434 unlock_buffer(bh); 443 435 } while (bh = bh->b_this_page, bh != head); 444 436 }
+8 -9
fs/nilfs2/segment.c
··· 24 24 #include <linux/pagemap.h> 25 25 #include <linux/buffer_head.h> 26 26 #include <linux/writeback.h> 27 + #include <linux/bitops.h> 27 28 #include <linux/bio.h> 28 29 #include <linux/completion.h> 29 30 #include <linux/blkdev.h> ··· 1589 1588 1590 1589 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1591 1590 b_assoc_buffers) { 1592 - set_buffer_async_write(bh); 1593 1591 if (bh->b_page != bd_page) { 1594 1592 if (bd_page) { 1595 1593 lock_page(bd_page); ··· 1688 1688 list_for_each_entry(segbuf, logs, sb_list) { 1689 1689 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, 1690 1690 b_assoc_buffers) { 1691 - clear_buffer_async_write(bh); 1692 1691 if (bh->b_page != bd_page) { 1693 1692 if (bd_page) 1694 1693 end_page_writeback(bd_page); ··· 1767 1768 b_assoc_buffers) { 1768 1769 set_buffer_uptodate(bh); 1769 1770 clear_buffer_dirty(bh); 1770 - clear_buffer_async_write(bh); 1771 1771 if (bh->b_page != bd_page) { 1772 1772 if (bd_page) 1773 1773 end_page_writeback(bd_page); ··· 1786 1788 */ 1787 1789 list_for_each_entry(bh, &segbuf->sb_payload_buffers, 1788 1790 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); 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); 1795 1798 if (bh == segbuf->sb_super_root) { 1796 1799 if (bh->b_page != bd_page) { 1797 1800 end_page_writeback(bd_page);
+1 -1
fs/nilfs2/super.c
··· 1020 1020 struct dentry *dentry; 1021 1021 int ret; 1022 1022 1023 - if (cno < 0 || cno > nilfs->ns_cno) 1023 + if (cno > nilfs->ns_cno) 1024 1024 return false; 1025 1025 1026 1026 if (cno >= nilfs_last_cno(nilfs))
+17 -10
fs/proc/fd.c
··· 8 8 #include <linux/security.h> 9 9 #include <linux/file.h> 10 10 #include <linux/seq_file.h> 11 + #include <linux/fs.h> 11 12 12 13 #include <linux/proc_fs.h> 13 14 ··· 49 48 put_files_struct(files); 50 49 } 51 50 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 - } 51 + if (ret) 52 + return ret; 61 53 62 - return ret; 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; 63 68 } 64 69 65 70 static int seq_fdinfo_open(struct inode *inode, struct file *file)
+2
include/asm-generic/seccomp.h
··· 17 17 #define __NR_seccomp_read_32 __NR_read 18 18 #define __NR_seccomp_write_32 __NR_write 19 19 #define __NR_seccomp_exit_32 __NR_exit 20 + #ifndef __NR_seccomp_sigreturn_32 20 21 #define __NR_seccomp_sigreturn_32 __NR_rt_sigreturn 22 + #endif 21 23 #endif /* CONFIG_COMPAT && ! already defined */ 22 24 23 25 #define __NR_seccomp_read __NR_read
+4 -4
include/linux/bitmap.h
··· 283 283 { 284 284 if (small_const_nbits(nbits)) 285 285 return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); 286 - else 287 - return __bitmap_empty(src, nbits); 286 + 287 + return find_first_bit(src, nbits) == nbits; 288 288 } 289 289 290 290 static inline int bitmap_full(const unsigned long *src, unsigned int nbits) 291 291 { 292 292 if (small_const_nbits(nbits)) 293 293 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); 294 - else 295 - return __bitmap_full(src, nbits); 294 + 295 + return find_first_zero_bit(src, nbits) == nbits; 296 296 } 297 297 298 298 static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
+2 -2
include/linux/bitops.h
··· 218 218 /** 219 219 * find_last_bit - find the last set bit in a memory region 220 220 * @addr: The address to start the search at 221 - * @size: The maximum size to search 221 + * @size: The number of bits to search 222 222 * 223 - * Returns the bit number of the first set bit, or size. 223 + * Returns the bit number of the last set bit, or size. 224 224 */ 225 225 extern unsigned long find_last_bit(const unsigned long *addr, 226 226 unsigned long size);
+8
include/linux/fs.h
··· 875 875 atomic_long_inc(&f->f_count); 876 876 return f; 877 877 } 878 + #define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count) 878 879 #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) 879 880 #define file_count(x) atomic_long_read(&(x)->f_count) 880 881 ··· 1047 1046 extern int generic_setlease(struct file *, long, struct file_lock **, void **priv); 1048 1047 extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 1049 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); 1050 1052 #else /* !CONFIG_FILE_LOCKING */ 1051 1053 static inline int fcntl_getlk(struct file *file, unsigned int cmd, 1052 1054 struct flock __user *user) ··· 1186 1182 { 1187 1183 return -EINVAL; 1188 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 1189 #endif /* !CONFIG_FILE_LOCKING */ 1190 1190 1191 1191
+7 -8
include/linux/kconfig.h
··· 23 23 #define ___config_enabled(__ignored, val, ...) val 24 24 25 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 26 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 35 27 * otherwise. For boolean options, this is equivalent to 36 28 * IS_ENABLED(CONFIG_FOO). ··· 34 42 * otherwise. 35 43 */ 36 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)) 37 52 38 53 #endif /* __LINUX_KCONFIG_H */
+12
include/linux/kernel.h
··· 103 103 (((__x) - ((__d) / 2)) / (__d)); \ 104 104 } \ 105 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 + ) 106 118 107 119 /* 108 120 * Multiplies an integer by a fraction, while avoiding unnecessary
+2
include/linux/mfd/samsung/rtc.h
··· 105 105 #define S5M_RTC_UDR_MASK (1 << S5M_RTC_UDR_SHIFT) 106 106 #define S2MPS_RTC_WUDR_SHIFT 4 107 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) 108 110 #define S2MPS_RTC_RUDR_SHIFT 0 109 111 #define S2MPS_RTC_RUDR_MASK (1 << S2MPS_RTC_RUDR_SHIFT) 110 112 #define RTC_TCON_SHIFT 1
+1 -1
include/linux/mm_types.h
··· 429 429 #endif 430 430 431 431 /* store ref to file /proc/<pid>/exe symlink points to */ 432 - struct file *exe_file; 432 + struct file __rcu *exe_file; 433 433 #ifdef CONFIG_MMU_NOTIFIER 434 434 struct mmu_notifier_mm *mmu_notifier_mm; 435 435 #endif
+3
include/linux/sysctl.h
··· 212 212 213 213 #endif /* CONFIG_SYSCTL */ 214 214 215 + int sysctl_max_threads(struct ctl_table *table, int write, 216 + void __user *buffer, size_t *lenp, loff_t *ppos); 217 + 215 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 6 #define EDEADLK 35 /* Resource deadlock would occur */ 7 7 #define ENAMETOOLONG 36 /* File name too long */ 8 8 #define ENOLCK 37 /* No record locks available */ 9 - #define ENOSYS 38 /* Function not implemented */ 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 + 10 19 #define ENOTEMPTY 39 /* Directory not empty */ 11 20 #define ELOOP 40 /* Too many symbolic links encountered */ 12 21 #define EWOULDBLOCK EAGAIN /* Operation would block */
+2 -2
init/main.c
··· 91 91 static int kernel_init(void *); 92 92 93 93 extern void init_IRQ(void); 94 - extern void fork_init(unsigned long); 94 + extern void fork_init(void); 95 95 extern void radix_tree_init(void); 96 96 #ifndef CONFIG_DEBUG_RODATA 97 97 static inline void mark_rodata_ro(void) { } ··· 645 645 #endif 646 646 thread_info_cache_init(); 647 647 cred_init(); 648 - fork_init(totalram_pages); 648 + fork_init(); 649 649 proc_caches_init(); 650 650 buffer_init(); 651 651 key_init();
+107 -34
kernel/fork.c
··· 74 74 #include <linux/uprobes.h> 75 75 #include <linux/aio.h> 76 76 #include <linux/compiler.h> 77 + #include <linux/sysctl.h> 77 78 78 79 #include <asm/pgtable.h> 79 80 #include <asm/pgalloc.h> ··· 87 86 88 87 #define CREATE_TRACE_POINTS 89 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 90 99 91 100 /* 92 101 * Protected counters by write_lock_irq(&tasklist_lock) ··· 264 253 265 254 void __init __weak arch_task_cache_init(void) { } 266 255 267 - void __init fork_init(unsigned long mempages) 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) 268 280 { 269 281 #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 270 282 #ifndef ARCH_MIN_TASKALIGN ··· 302 268 /* do the arch specific task caches init */ 303 269 arch_task_cache_init(); 304 270 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; 271 + set_max_threads(MAX_THREADS); 317 272 318 273 init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2; 319 274 init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2; ··· 402 379 * Not linked in yet - no deadlock potential: 403 380 */ 404 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)); 405 385 406 386 mm->total_vm = oldmm->total_vm; 407 387 mm->shared_vm = oldmm->shared_vm; ··· 531 505 pgd_free(mm, mm->pgd); 532 506 } 533 507 #else 534 - #define dup_mmap(mm, oldmm) (0) 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 + } 535 515 #define mm_alloc_pgd(mm) (0) 536 516 #define mm_free_pgd(mm) 537 517 #endif /* CONFIG_MMU */ ··· 706 674 } 707 675 EXPORT_SYMBOL_GPL(mmput); 708 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 + */ 709 688 void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) 710 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 + 711 699 if (new_exe_file) 712 700 get_file(new_exe_file); 713 - if (mm->exe_file) 714 - fput(mm->exe_file); 715 - mm->exe_file = new_exe_file; 701 + rcu_assign_pointer(mm->exe_file, new_exe_file); 702 + if (old_exe_file) 703 + fput(old_exe_file); 716 704 } 717 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 + */ 718 712 struct file *get_mm_exe_file(struct mm_struct *mm) 719 713 { 720 714 struct file *exe_file; 721 715 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); 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(); 728 721 return exe_file; 729 722 } 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 - } 723 + EXPORT_SYMBOL(get_mm_exe_file); 737 724 738 725 /** 739 726 * get_task_mm - acquire a reference to the task's mm ··· 914 863 915 864 if (!mm_init(mm, tsk)) 916 865 goto fail_nomem; 917 - 918 - dup_mm_exe_file(oldmm, mm); 919 866 920 867 err = dup_mmap(mm, oldmm); 921 868 if (err) ··· 1452 1403 goto bad_fork_cleanup_io; 1453 1404 1454 1405 if (pid != &init_struct_pid) { 1455 - retval = -ENOMEM; 1456 1406 pid = alloc_pid(p->nsproxy->pid_ns_for_children); 1457 - if (!pid) 1407 + if (IS_ERR(pid)) { 1408 + retval = PTR_ERR(pid); 1458 1409 goto bad_fork_cleanup_io; 1410 + } 1459 1411 } 1460 1412 1461 1413 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; ··· 2048 1998 task_lock(task); 2049 1999 task->files = copy; 2050 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 + 2051 2024 return 0; 2052 2025 }
+4 -1
kernel/gcov/base.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/module.h> 20 20 #include <linux/mutex.h> 21 + #include <linux/sched.h> 21 22 #include "gcov.h" 22 23 23 24 static int gcov_events_enabled; ··· 108 107 gcov_events_enabled = 1; 109 108 110 109 /* Perform event callback for previously registered entries. */ 111 - while ((info = gcov_info_next(info))) 110 + while ((info = gcov_info_next(info))) { 112 111 gcov_event(GCOV_ADD, info); 112 + cond_resched(); 113 + } 113 114 114 115 mutex_unlock(&gcov_lock); 115 116 }
+8 -7
kernel/pid.c
··· 182 182 spin_unlock_irq(&pidmap_lock); 183 183 kfree(page); 184 184 if (unlikely(!map->page)) 185 - break; 185 + return -ENOMEM; 186 186 } 187 187 if (likely(atomic_read(&map->nr_free))) { 188 188 for ( ; ; ) { ··· 210 210 } 211 211 pid = mk_pid(pid_ns, map, offset); 212 212 } 213 - return -1; 213 + return -EAGAIN; 214 214 } 215 215 216 216 int next_pidmap(struct pid_namespace *pid_ns, unsigned int last) ··· 301 301 int i, nr; 302 302 struct pid_namespace *tmp; 303 303 struct upid *upid; 304 + int retval = -ENOMEM; 304 305 305 306 pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); 306 307 if (!pid) 307 - goto out; 308 + return ERR_PTR(retval); 308 309 309 310 tmp = ns; 310 311 pid->level = ns->level; 311 312 for (i = ns->level; i >= 0; i--) { 312 313 nr = alloc_pidmap(tmp); 313 - if (nr < 0) 314 + if (IS_ERR_VALUE(nr)) { 315 + retval = nr; 314 316 goto out_free; 317 + } 315 318 316 319 pid->numbers[i].nr = nr; 317 320 pid->numbers[i].ns = tmp; ··· 342 339 } 343 340 spin_unlock_irq(&pidmap_lock); 344 341 345 - out: 346 342 return pid; 347 343 348 344 out_unlock: ··· 353 351 free_pidmap(pid->numbers + i); 354 352 355 353 kmem_cache_free(ns->pid_cachep, pid); 356 - pid = NULL; 357 - goto out; 354 + return ERR_PTR(retval); 358 355 } 359 356 360 357 void disable_pid_allocation(struct pid_namespace *ns)
+29 -10
kernel/ptrace.c
··· 456 456 457 457 static int ptrace_detach(struct task_struct *child, unsigned int data) 458 458 { 459 - bool dead = false; 460 - 461 459 if (!valid_signal(data)) 462 460 return -EIO; 463 461 ··· 465 467 466 468 write_lock_irq(&tasklist_lock); 467 469 /* 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 + * We rely on ptrace_freeze_traced(). It can't be killed and 471 + * untraced by another thread, it can't be a zombie. 470 472 */ 471 - if (child->ptrace) { 472 - child->exit_code = data; 473 - dead = __ptrace_detach(current, child); 474 - } 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); 475 480 write_unlock_irq(&tasklist_lock); 476 481 477 482 proc_ptrace_connector(child, PTRACE_DETACH); 478 - if (unlikely(dead)) 479 - release_task(child); 480 483 481 484 return 0; 482 485 } ··· 696 697 static int ptrace_resume(struct task_struct *child, long request, 697 698 unsigned long data) 698 699 { 700 + bool need_siglock; 701 + 699 702 if (!valid_signal(data)) 700 703 return -EIO; 701 704 ··· 725 724 user_disable_single_step(child); 726 725 } 727 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); 728 743 child->exit_code = data; 729 744 wake_up_state(child, __TASK_TRACED); 745 + if (need_siglock) 746 + spin_unlock_irq(&child->sighand->siglock); 730 747 731 748 return 0; 732 749 }
+5 -9
kernel/signal.c
··· 2992 2992 * Nor can they impersonate a kill()/tgkill(), which adds source info. 2993 2993 */ 2994 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); 2995 + (task_pid_vnr(current) != pid)) 2998 2996 return -EPERM; 2999 - } 2997 + 3000 2998 info->si_signo = sig; 3001 2999 3002 3000 /* POSIX.1b doesn't mention process groups. */ ··· 3039 3041 /* Not even root can pretend to send signals from the kernel. 3040 3042 * Nor can they impersonate a kill()/tgkill(), which adds source info. 3041 3043 */ 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); 3044 + if ((info->si_code >= 0 || info->si_code == SI_TKILL) && 3045 + (task_pid_vnr(current) != pid)) 3046 3046 return -EPERM; 3047 - } 3047 + 3048 3048 info->si_signo = sig; 3049 3049 3050 3050 return do_send_specific(tgid, pid, sig, info);
+28 -19
kernel/sys.c
··· 1649 1649 return mask; 1650 1650 } 1651 1651 1652 - static int prctl_set_mm_exe_file_locked(struct mm_struct *mm, unsigned int fd) 1652 + static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) 1653 1653 { 1654 1654 struct fd exe; 1655 + struct file *old_exe, *exe_file; 1655 1656 struct inode *inode; 1656 1657 int err; 1657 - 1658 - VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm); 1659 1658 1660 1659 exe = fdget(fd); 1661 1660 if (!exe.file) ··· 1679 1680 /* 1680 1681 * Forbid mm->exe_file change if old file still mapped. 1681 1682 */ 1683 + exe_file = get_mm_exe_file(mm); 1682 1684 err = -EBUSY; 1683 - if (mm->exe_file) { 1685 + if (exe_file) { 1684 1686 struct vm_area_struct *vma; 1685 1687 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; 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); 1691 1699 } 1692 1700 1693 1701 /* ··· 1708 1702 goto exit; 1709 1703 1710 1704 err = 0; 1711 - set_mm_exe_file(mm, exe.file); /* this grabs a reference to exe.file */ 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); 1712 1710 exit: 1713 1711 fdput(exe); 1714 1712 return err; 1713 + exit_err: 1714 + up_read(&mm->mmap_sem); 1715 + fput(exe_file); 1716 + goto exit; 1715 1717 } 1716 1718 1717 1719 #ifdef CONFIG_CHECKPOINT_RESTORE ··· 1854 1840 user_auxv[AT_VECTOR_SIZE - 1] = AT_NULL; 1855 1841 } 1856 1842 1857 - down_write(&mm->mmap_sem); 1858 1843 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); 1844 + error = prctl_set_mm_exe_file(mm, prctl_map.exe_fd); 1845 + down_read(&mm->mmap_sem); 1861 1846 if (error) 1862 1847 goto out; 1863 1848 ··· 1922 1909 if (!capable(CAP_SYS_RESOURCE)) 1923 1910 return -EPERM; 1924 1911 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 - } 1912 + if (opt == PR_SET_MM_EXE_FILE) 1913 + return prctl_set_mm_exe_file(mm, (unsigned int)addr); 1931 1914 1932 1915 if (addr >= TASK_SIZE || addr < mmap_min_addr) 1933 1916 return -EINVAL;
+11 -5
kernel/sysctl.c
··· 93 93 #include <linux/nmi.h> 94 94 #endif 95 95 96 - 97 96 #if defined(CONFIG_SYSCTL) 98 97 99 98 /* External variables not in a header file. */ 100 - extern int max_threads; 101 99 extern int suid_dumpable; 102 100 #ifdef CONFIG_COREDUMP 103 101 extern int core_uses_pid; ··· 708 710 #endif 709 711 { 710 712 .procname = "threads-max", 711 - .data = &max_threads, 713 + .data = NULL, 712 714 .maxlen = sizeof(int), 713 715 .mode = 0644, 714 - .proc_handler = proc_dointvec, 716 + .proc_handler = sysctl_max_threads, 715 717 }, 716 718 { 717 719 .procname = "random", ··· 1981 1983 int write, void *data) 1982 1984 { 1983 1985 if (write) { 1984 - *valp = *negp ? -*lvalp : *lvalp; 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 + } 1985 1995 } else { 1986 1996 int val = *valp; 1987 1997 if (val < 0) {
+2 -3
lib/Kconfig
··· 18 18 default n 19 19 depends on BITREVERSE 20 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. 21 + This option enables the use of hardware bit-reversal instructions on 22 + architectures which support such operations. 24 23 25 24 config RATIONAL 26 25 bool
+1 -1
lib/Makefile
··· 25 25 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 26 26 bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ 27 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 \ 28 + bsearch.o find_bit.o llist.o memweight.o kfifo.o \ 29 29 percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o 30 30 obj-y += string_helpers.o 31 31 obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
-30
lib/bitmap.c
··· 42 42 * for the best explanations of this ordering. 43 43 */ 44 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 45 int __bitmap_equal(const unsigned long *bitmap1, 76 46 const unsigned long *bitmap2, unsigned int bits) 77 47 {
+5 -4
lib/cpumask.c
··· 37 37 int cpumask_next_and(int n, const struct cpumask *src1p, 38 38 const struct cpumask *src2p) 39 39 { 40 - while ((n = cpumask_next(n, src1p)) < nr_cpu_ids) 41 - if (cpumask_test_cpu(n, src2p)) 42 - break; 43 - return n; 40 + struct cpumask tmp; 41 + 42 + if (cpumask_and(&tmp, src1p, src2p)) 43 + return cpumask_next(n, &tmp); 44 + return nr_cpu_ids; 44 45 } 45 46 EXPORT_SYMBOL(cpumask_next_and); 46 47
+1 -1
lib/dma-debug.c
··· 361 361 unsigned int range = 0; 362 362 363 363 while (range <= max_range) { 364 - entry = __hash_bucket_find(*bucket, &index, containing_match); 364 + entry = __hash_bucket_find(*bucket, ref, containing_match); 365 365 366 366 if (entry) 367 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 4 * Written by Rusty Russell <rusty@rustcorp.com.au> 5 5 * (Inspired by David Howell's find_next_bit implementation) 6 6 * 7 + * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease 8 + * size and improve performance, 2015. 9 + * 7 10 * This program is free software; you can redistribute it and/or 8 11 * modify it under the terms of the GNU General Public License 9 12 * as published by the Free Software Foundation; either version ··· 14 11 */ 15 12 16 13 #include <linux/bitops.h> 14 + #include <linux/bitmap.h> 17 15 #include <linux/export.h> 18 - #include <asm/types.h> 19 - #include <asm/byteorder.h> 16 + #include <linux/kernel.h> 20 17 21 18 #ifndef find_last_bit 22 19 23 20 unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 24 21 { 25 - unsigned long words; 26 - unsigned long tmp; 22 + if (size) { 23 + unsigned long val = BITMAP_LAST_WORD_MASK(size); 24 + unsigned long idx = (size-1) / BITS_PER_LONG; 27 25 28 - /* Start at final word. */ 29 - words = size / BITS_PER_LONG; 26 + do { 27 + val &= addr[idx]; 28 + if (val) 29 + return idx * BITS_PER_LONG + __fls(val); 30 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; 31 + val = ~0ul; 32 + } while (idx--); 37 33 } 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 34 return size; 49 35 } 50 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 33 34 34 #include <asm/page.h> /* for PAGE_SIZE */ 35 35 #include <asm/sections.h> /* for dereference_function_descriptor() */ 36 + #include <asm/byteorder.h> /* cpu_to_le16 */ 36 37 37 38 #include <linux/string_helpers.h> 38 39 #include "kstrtox.h" ··· 123 122 return i; 124 123 } 125 124 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). 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. 131 148 */ 132 149 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; 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 + }; 139 164 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 - */ 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 + */ 185 171 static noinline_for_stack 186 172 char *put_dec_trunc8(char *buf, unsigned r) 187 173 { 188 174 unsigned q; 189 175 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 - } 176 + /* 1 <= r < 10^8 */ 177 + if (r < 100) 178 + goto out_r; 196 179 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 */ 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; 210 209 return buf; 211 210 } 212 211 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 - */ 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; 229 217 230 - #if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64 218 + /* 0 <= r < 10^8 */ 219 + q = (r * (u64)0x28f5c29) >> 32; 220 + *((u16 *)buf) = decpair[r - 100*q]; 221 + buf += 2; 231 222 232 - /* First algorithm: generic */ 223 + /* 0 <= q < 10^6 */ 224 + r = (q * (u64)0x28f5c29) >> 32; 225 + *((u16 *)buf) = decpair[q - 100*r]; 226 + buf += 2; 233 227 234 - static 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 235 240 char *put_dec(char *buf, unsigned long long n) 236 241 { 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 - } 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 */ 243 248 return put_dec_trunc8(buf, n); 244 249 } 245 250 246 - #else 251 + #elif BITS_PER_LONG == 32 && BITS_PER_LONG_LONG == 64 247 252 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 + static void 254 + put_dec_full4(char *buf, unsigned r) 253 255 { 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'; 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]; 262 264 } 263 265 264 266 /* ··· 269 265 * The approximation x/10000 == (x * 0x346DC5D7) >> 43 270 266 * holds for all x < 1,128,869,999. The largest value this 271 267 * helper will ever be asked to convert is 1,125,520,955. 272 - * (d1 in the put_dec code, assuming n is all-ones). 268 + * (second call in the put_dec code, assuming n is all-ones). 273 269 */ 274 - static 270 + static noinline_for_stack 275 271 unsigned put_dec_helper4(char *buf, unsigned x) 276 272 { 277 273 uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43; ··· 298 294 d2 = (h ) & 0xffff; 299 295 d3 = (h >> 16); /* implicit "& 0xffff" */ 300 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 */ 301 299 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); 302 300 q = put_dec_helper4(buf, q); 303 301 ··· 329 323 */ 330 324 int num_to_str(char *buf, int size, unsigned long long num) 331 325 { 332 - char tmp[sizeof(num) * 3]; 326 + /* put_dec requires 2-byte alignment of the buffer. */ 327 + char tmp[sizeof(num) * 3] __aligned(2); 333 328 int idx, len; 334 329 335 330 /* put_dec() may work incorrectly for num = 0 (generate "", not "0") */ ··· 391 384 char *number(char *buf, char *end, unsigned long long num, 392 385 struct printf_spec spec) 393 386 { 394 - char tmp[3 * sizeof(num)]; 387 + /* put_dec requires 2-byte alignment of the buffer. */ 388 + char tmp[3 * sizeof(num)] __aligned(2); 395 389 char sign; 396 390 char locase; 397 391 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); ··· 952 944 break; 953 945 } 954 946 for (i = 0; i < 4; i++) { 955 - char temp[3]; /* hold each IP quad in reverse order */ 947 + char temp[4] __aligned(2); /* hold each IP quad in reverse order */ 956 948 int digits = put_dec_trunc8(temp, addr[index]) - temp; 957 949 if (leading_zeros) { 958 950 if (digits < 3)
+6 -2
scripts/Makefile.kasan
··· 13 13 --param asan-instrumentation-with-call-threshold=$(call_threshold)) 14 14 15 15 ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) 16 + ifneq ($(CONFIG_COMPILE_TEST),y) 16 17 $(warning Cannot use CONFIG_KASAN: \ 17 18 -fsanitize=kernel-address is not supported by compiler) 19 + endif 18 20 else 19 21 ifeq ($(CFLAGS_KASAN),) 20 - $(warning CONFIG_KASAN: compiler does not support all options.\ 21 - Trying minimal configuration) 22 + ifneq ($(CONFIG_COMPILE_TEST),y) 23 + $(warning CONFIG_KASAN: compiler does not support all options.\ 24 + Trying minimal configuration) 25 + endif 22 26 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) 23 27 endif 24 28 endif
+141 -23
scripts/checkpatch.pl
··· 47 47 my $minimum_perl_version = 5.10.0; 48 48 my $min_conf_desc_length = 4; 49 49 my $spelling_file = "$D/spelling.txt"; 50 + my $codespell = 0; 51 + my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; 50 52 51 53 sub help { 52 54 my ($exitcode) = @_; ··· 90 88 file. It's your fault if there's no backup or git 91 89 --ignore-perl-version override checking of perl version. expect 92 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 93 94 -h, --help, --version display this help and exit 94 95 95 96 When FILE is - read standard input. ··· 151 146 'ignore-perl-version!' => \$ignore_perl_version, 152 147 'debug=s' => \%debug, 153 148 'test-only=s' => \$tst_only, 149 + 'codespell!' => \$codespell, 150 + 'codespellfile=s' => \$codespellfile, 154 151 'h|help' => \$help, 155 152 'version' => \$help 156 153 ) or help(1); ··· 323 316 324 317 our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; 325 318 319 + our $BasicType; 326 320 our $NonptrType; 327 321 our $NonptrTypeMisordered; 328 322 our $NonptrTypeWithAttr; ··· 444 436 $mode_perms_search .= $entry->[0]; 445 437 } 446 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 447 our $allowed_asm_includes = qr{(?x: 448 448 irq| 449 449 memory| ··· 465 449 my %spelling_fix; 466 450 467 451 if (open(my $spelling, '<', $spelling_file)) { 468 - my @spelling_list; 469 452 while (<$spelling>) { 470 453 my $line = $_; 471 454 ··· 476 461 477 462 my ($suspect, $fix) = split(/\|\|/, $line); 478 463 479 - push(@spelling_list, $suspect); 480 464 $spelling_fix{$suspect} = $fix; 481 465 } 482 466 close($spelling); 483 - $misspellings = join("|", @spelling_list); 484 467 } else { 485 468 warn "No typos will be found - file '$spelling_file': $!\n"; 486 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; 487 496 488 497 sub build_types { 489 498 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; ··· 515 476 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; 516 477 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; 517 478 $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; 479 + $BasicType = qr{ 480 + (?:$typeOtherOSTypedefs\b)| 481 + (?:$typeTypedefs\b)| 482 + (?:${all}\b) 483 + }x; 518 484 $NonptrType = qr{ 519 485 (?:$Modifier\s+|const\s+)* 520 486 (?: ··· 1690 1646 foreach my $old_line (@{$linesRef}) { 1691 1647 my $save_line = 1; 1692 1648 my $line = $old_line; #don't modify the array 1693 - if ($line =~ /^(?:\+\+\+\|\-\-\-)\s+\S+/) { #new filename 1649 + if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename 1694 1650 $delta_offset = 0; 1695 1651 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk 1696 1652 $range_last_linenr = $new_linenr; ··· 1898 1854 1899 1855 my $in_header_lines = $file ? 0 : 1; 1900 1856 my $in_commit_log = 0; #Scanning lines before patch 1857 + my $commit_log_long_line = 0; 1901 1858 my $reported_maintainer_file = 0; 1902 1859 my $non_utf8_charset = 0; 1903 1860 ··· 2234 2189 "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); 2235 2190 } 2236 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 + 2237 2200 # Check for git id commit length and improperly formed commit descriptions 2238 2201 if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { 2239 2202 my $init_char = $1; ··· 2356 2303 } 2357 2304 2358 2305 # Check for various typo / spelling mistakes 2359 - if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) { 2360 - while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { 2306 + if (defined($misspellings) && 2307 + ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { 2308 + while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) { 2361 2309 my $typo = $1; 2362 2310 my $typo_fix = $spelling_fix{lc($typo)}; 2363 2311 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); ··· 2513 2459 #line length limit 2514 2460 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 2515 2461 $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*$/) && 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$/) && 2518 2465 $length > $max_line_length) 2519 2466 { 2520 2467 WARN("LONG_LINE", ··· 2607 2552 } 2608 2553 } 2609 2554 2610 - if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && 2611 - (!defined($1) || $1 !~ /sizeof\s*/)) { 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*$/)) { 2612 2564 if (CHK("SPACING", 2613 2565 "No space is necessary after a cast\n" . $herecurr) && 2614 2566 $fix) { ··· 3208 3146 $herecurr); 3209 3147 } 3210 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 + 3211 3161 # check for non-global char *foo[] = {"bar", ...} declarations. 3212 3162 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { 3213 3163 WARN("STATIC_CONST_CHAR_ARRAY", 3214 3164 "char * array declaration might be better as static const\n" . 3215 3165 $herecurr); 3216 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 + } 3217 3180 3218 3181 # check for function declarations without arguments like "int foo()" 3219 3182 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { ··· 3394 3307 $level = "dbg" if ($level eq "debug"); 3395 3308 WARN("PREFER_DEV_LEVEL", 3396 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); 3397 3318 } 3398 3319 3399 3320 # function brace can't be on same line, except for #defines of do while, ··· 3660 3565 3661 3566 # Ignore operators passed as parameters. 3662 3567 if ($op_type ne 'V' && 3663 - $ca =~ /\s$/ && $cc =~ /^\s*,/) { 3568 + $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) { 3664 3569 3665 3570 # # Ignore comments 3666 3571 # } elsif ($op =~ /^$;+$/) { ··· 3843 3748 $ca =~ /<\S+\@\S+$/)) 3844 3749 { 3845 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; 3846 3759 } 3847 3760 3848 3761 # messages are ERROR, but ?: are CHK ··· 4066 3963 } 4067 3964 } 4068 3965 4069 - # Return of what appears to be an errno should normally be -'ve 4070 - if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { 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*)[;:,]/) { 4071 3968 my $name = $1; 4072 3969 if ($name ne 'EOF' && $name ne 'ERROR') { 4073 3970 WARN("USE_NEGATIVE_ERRNO", 4074 - "return of an errno should typically be -ve (return -$1)\n" . $herecurr); 3971 + "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); 4075 3972 } 4076 3973 } 4077 3974 ··· 4281 4178 } 4282 4179 } 4283 4180 4284 - #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) 4181 + # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes 4182 + # itself <asm/foo.h> (uses RAW line) 4285 4183 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) { 4286 4184 my $file = "$1.h"; 4287 4185 my $checkfile = "include/linux/$file"; ··· 4290 4186 $realfile ne $checkfile && 4291 4187 $1 !~ /$allowed_asm_includes/) 4292 4188 { 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); 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 + } 4299 4198 } 4300 4199 } 4301 4200 } ··· 4804 4697 $lead = "$lead " if ($lead !~ /^\+$/); 4805 4698 $lead = "${lead}const "; 4806 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//; 4807 4710 } 4808 4711 } 4809 4712 ··· 5378 5261 stacktrace_ops| 5379 5262 sysfs_ops| 5380 5263 tty_operations| 5264 + uart_ops| 5381 5265 usb_mon_operations| 5382 5266 wd_ops}x; 5383 5267 if ($line !~ /\bconst\b/ && ··· 5436 5318 } 5437 5319 } 5438 5320 5439 - if ($line =~ /debugfs_create_file.*S_IWUGO/ || 5440 - $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { 5321 + if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ || 5322 + $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) { 5441 5323 WARN("EXPORTED_WORLD_WRITABLE", 5442 5324 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 5443 5325 }
+1
scripts/spelling.txt
··· 825 825 retreive||retrieve 826 826 retrive||retrieve 827 827 retuned||returned 828 + reudce||reduce 828 829 reuest||request 829 830 reuqest||request 830 831 reutnred||returned
+8 -5
security/tomoyo/util.c
··· 948 948 */ 949 949 const char *tomoyo_get_exe(void) 950 950 { 951 + struct file *exe_file; 952 + const char *cp; 951 953 struct mm_struct *mm = current->mm; 952 - const char *cp = NULL; 953 954 954 955 if (!mm) 955 956 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); 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); 960 963 return cp; 961 964 } 962 965
+1 -2
sound/soc/codecs/pcm512x.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/module.h> 20 20 #include <linux/clk.h> 21 + #include <linux/kernel.h> 21 22 #include <linux/pm_runtime.h> 22 23 #include <linux/regmap.h> 23 24 #include <linux/regulator/consumer.h> ··· 32 31 33 32 #define DIV_ROUND_DOWN_ULL(ll, d) \ 34 33 ({ 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 34 38 35 #define PCM512x_NUM_SUPPLIES 3 39 36 static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {