diff options
36 files changed, 992 insertions, 418 deletions
diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches index d91125ab6f49..0958e97d4bf4 100644 --- a/Documentation/SubmittingPatches +++ b/Documentation/SubmittingPatches | |||
@@ -340,8 +340,32 @@ now, but you can do this to mark internal company procedures or just | |||
340 | point out some special detail about the sign-off. | 340 | point out some special detail about the sign-off. |
341 | 341 | ||
342 | 342 | ||
343 | 13) When to use Acked-by: | ||
343 | 344 | ||
344 | 13) The canonical patch format | 345 | The Signed-off-by: tag indicates that the signer was involved in the |
346 | development of the patch, or that he/she was in the patch's delivery path. | ||
347 | |||
348 | If a person was not directly involved in the preparation or handling of a | ||
349 | patch but wishes to signify and record their approval of it then they can | ||
350 | arrange to have an Acked-by: line added to the patch's changelog. | ||
351 | |||
352 | Acked-by: is often used by the maintainer of the affected code when that | ||
353 | maintainer neither contributed to nor forwarded the patch. | ||
354 | |||
355 | Acked-by: is not as formal as Signed-off-by:. It is a record that the acker | ||
356 | has at least reviewed the patch and has indicated acceptance. Hence patch | ||
357 | mergers will sometimes manually convert an acker's "yep, looks good to me" | ||
358 | into an Acked-by:. | ||
359 | |||
360 | Acked-by: does not necessarily indicate acknowledgement of the entire patch. | ||
361 | For example, if a patch affects multiple subsystems and has an Acked-by: from | ||
362 | one subsystem maintainer then this usually indicates acknowledgement of just | ||
363 | the part which affects that maintainer's code. Judgement should be used here. | ||
364 | When in doubt people should refer to the original discussion in the mailing | ||
365 | list archives. | ||
366 | |||
367 | |||
368 | 14) The canonical patch format | ||
345 | 369 | ||
346 | The canonical patch subject line is: | 370 | The canonical patch subject line is: |
347 | 371 | ||
diff --git a/Documentation/atomic_ops.txt b/Documentation/atomic_ops.txt index 2a63d5662a93..05851e9982ed 100644 --- a/Documentation/atomic_ops.txt +++ b/Documentation/atomic_ops.txt | |||
@@ -149,7 +149,7 @@ defined which accomplish this: | |||
149 | void smp_mb__before_atomic_dec(void); | 149 | void smp_mb__before_atomic_dec(void); |
150 | void smp_mb__after_atomic_dec(void); | 150 | void smp_mb__after_atomic_dec(void); |
151 | void smp_mb__before_atomic_inc(void); | 151 | void smp_mb__before_atomic_inc(void); |
152 | void smp_mb__after_atomic_dec(void); | 152 | void smp_mb__after_atomic_inc(void); |
153 | 153 | ||
154 | For example, smp_mb__before_atomic_dec() can be used like so: | 154 | For example, smp_mb__before_atomic_dec() can be used like so: |
155 | 155 | ||
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index 49ae1ea9e868..7d3f205b0ba5 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt | |||
@@ -104,6 +104,7 @@ Who: Dominik Brodowski <linux@brodo.de> | |||
104 | What: remove EXPORT_SYMBOL(kernel_thread) | 104 | What: remove EXPORT_SYMBOL(kernel_thread) |
105 | When: August 2006 | 105 | When: August 2006 |
106 | Files: arch/*/kernel/*_ksyms.c | 106 | Files: arch/*/kernel/*_ksyms.c |
107 | Funcs: kernel_thread | ||
107 | Why: kernel_thread is a low-level implementation detail. Drivers should | 108 | Why: kernel_thread is a low-level implementation detail. Drivers should |
108 | use the <linux/kthread.h> API instead which shields them from | 109 | use the <linux/kthread.h> API instead which shields them from |
109 | implementation details and provides a higherlevel interface that | 110 | implementation details and provides a higherlevel interface that |
diff --git a/Documentation/filesystems/tmpfs.txt b/Documentation/filesystems/tmpfs.txt index 6dd050878a20..145e44086358 100644 --- a/Documentation/filesystems/tmpfs.txt +++ b/Documentation/filesystems/tmpfs.txt | |||
@@ -94,10 +94,10 @@ largest node numbers in the range. For example, mpol=bind:0-3,5,7,9-15 | |||
94 | 94 | ||
95 | Note that trying to mount a tmpfs with an mpol option will fail if the | 95 | Note that trying to mount a tmpfs with an mpol option will fail if the |
96 | running kernel does not support NUMA; and will fail if its nodelist | 96 | running kernel does not support NUMA; and will fail if its nodelist |
97 | specifies a node >= MAX_NUMNODES. If your system relies on that tmpfs | 97 | specifies a node which is not online. If your system relies on that |
98 | being mounted, but from time to time runs a kernel built without NUMA | 98 | tmpfs being mounted, but from time to time runs a kernel built without |
99 | capability (perhaps a safe recovery kernel), or configured to support | 99 | NUMA capability (perhaps a safe recovery kernel), or with fewer nodes |
100 | fewer nodes, then it is advisable to omit the mpol option from automatic | 100 | online, then it is advisable to omit the mpol option from automatic |
101 | mount options. It can be added later, when the tmpfs is already mounted | 101 | mount options. It can be added later, when the tmpfs is already mounted |
102 | on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'. | 102 | on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'. |
103 | 103 | ||
@@ -121,4 +121,4 @@ RAM/SWAP in 10240 inodes and it is only accessible by root. | |||
121 | Author: | 121 | Author: |
122 | Christoph Rohland <cr@sap.com>, 1.12.01 | 122 | Christoph Rohland <cr@sap.com>, 1.12.01 |
123 | Updated: | 123 | Updated: |
124 | Hugh Dickins <hugh@veritas.com>, 19 February 2006 | 124 | Hugh Dickins <hugh@veritas.com>, 4 June 2007 |
diff --git a/MAINTAINERS b/MAINTAINERS index f3b5a391e074..4c715a7e059a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -782,11 +782,6 @@ M: rathamahata@php4.ru | |||
782 | L: linux-kernel@vger.kernel.org | 782 | L: linux-kernel@vger.kernel.org |
783 | S: Maintained | 783 | S: Maintained |
784 | 784 | ||
785 | BERKSHIRE PRODUCTS PC WATCHDOG DRIVER | ||
786 | P: Kenji Hollis | ||
787 | W: http://ftp.bitgate.com/pcwd/ | ||
788 | S: Maintained | ||
789 | |||
790 | BFS FILE SYSTEM | 785 | BFS FILE SYSTEM |
791 | P: Tigran A. Aivazian | 786 | P: Tigran A. Aivazian |
792 | M: tigran@aivazian.fsnet.co.uk | 787 | M: tigran@aivazian.fsnet.co.uk |
@@ -3025,7 +3020,7 @@ S: Maintained | |||
3025 | REISERFS FILE SYSTEM | 3020 | REISERFS FILE SYSTEM |
3026 | P: Hans Reiser | 3021 | P: Hans Reiser |
3027 | M: reiserfs-dev@namesys.com | 3022 | M: reiserfs-dev@namesys.com |
3028 | L: reiserfs-list@namesys.com | 3023 | L: reiserfs-devel@vger.kernel.org |
3029 | W: http://www.namesys.com | 3024 | W: http://www.namesys.com |
3030 | S: Supported | 3025 | S: Supported |
3031 | 3026 | ||
@@ -3904,10 +3899,6 @@ S: Maintained | |||
3904 | 3899 | ||
3905 | UCLINUX FOR NEC V850 | 3900 | UCLINUX FOR NEC V850 |
3906 | P: Miles Bader | 3901 | P: Miles Bader |
3907 | M: uclinux-v850@lsi.nec.co.jp | ||
3908 | W: http://www.ic.nec.co.jp/micro/uclinux/eng/ | ||
3909 | W: http://www.ee.nec.de/uclinux/ | ||
3910 | S: Supported | ||
3911 | 3902 | ||
3912 | UCLINUX FOR RENESAS H8/300 | 3903 | UCLINUX FOR RENESAS H8/300 |
3913 | P: Yoshinori Sato | 3904 | P: Yoshinori Sato |
@@ -3916,10 +3907,10 @@ W: http://uclinux-h8.sourceforge.jp/ | |||
3916 | S: Supported | 3907 | S: Supported |
3917 | 3908 | ||
3918 | UFS FILESYSTEM | 3909 | UFS FILESYSTEM |
3919 | P: Evgeniy Dushistov | 3910 | P: Evgeniy Dushistov |
3920 | M: dushistov@mail.ru | 3911 | M: dushistov@mail.ru |
3921 | L: linux-kernel@vger.kernel.org | 3912 | L: linux-kernel@vger.kernel.org |
3922 | S: Maintained | 3913 | S: Maintained |
3923 | 3914 | ||
3924 | USB DIAMOND RIO500 DRIVER | 3915 | USB DIAMOND RIO500 DRIVER |
3925 | P: Cesar Miquel | 3916 | P: Cesar Miquel |
diff --git a/arch/i386/math-emu/fpu_entry.c b/arch/i386/math-emu/fpu_entry.c index ddf8fa3bbd01..1853524c8b57 100644 --- a/arch/i386/math-emu/fpu_entry.c +++ b/arch/i386/math-emu/fpu_entry.c | |||
@@ -754,7 +754,7 @@ int save_i387_soft(void *s387, struct _fpstate __user * buf) | |||
754 | return -1; | 754 | return -1; |
755 | if ( offset ) | 755 | if ( offset ) |
756 | if (__copy_to_user(d+other, (u_char *)&S387->st_space, offset)) | 756 | if (__copy_to_user(d+other, (u_char *)&S387->st_space, offset)) |
757 | return -1 | 757 | return -1; |
758 | RE_ENTRANT_CHECK_ON; | 758 | RE_ENTRANT_CHECK_ON; |
759 | 759 | ||
760 | return 1; | 760 | return 1; |
diff --git a/arch/m68knommu/platform/5307/timers.c b/arch/m68knommu/platform/5307/timers.c index 92e58070b016..fb66eadd5896 100644 --- a/arch/m68knommu/platform/5307/timers.c +++ b/arch/m68knommu/platform/5307/timers.c | |||
@@ -62,10 +62,13 @@ void coldfire_tick(void) | |||
62 | 62 | ||
63 | /***************************************************************************/ | 63 | /***************************************************************************/ |
64 | 64 | ||
65 | static int ticks_per_intr; | ||
66 | |||
65 | void coldfire_timer_init(irq_handler_t handler) | 67 | void coldfire_timer_init(irq_handler_t handler) |
66 | { | 68 | { |
67 | __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR)); | 69 | __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR)); |
68 | __raw_writetrr(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR)); | 70 | ticks_per_intr = (MCF_BUSCLK / 16) / HZ; |
71 | __raw_writetrr(ticks_per_intr - 1, TA(MCFTIMER_TRR)); | ||
69 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | | 72 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | |
70 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR)); | 73 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR)); |
71 | 74 | ||
@@ -81,11 +84,10 @@ void coldfire_timer_init(irq_handler_t handler) | |||
81 | 84 | ||
82 | unsigned long coldfire_timer_offset(void) | 85 | unsigned long coldfire_timer_offset(void) |
83 | { | 86 | { |
84 | unsigned long trr, tcn, offset; | 87 | unsigned long tcn, offset; |
85 | 88 | ||
86 | tcn = __raw_readw(TA(MCFTIMER_TCN)); | 89 | tcn = __raw_readw(TA(MCFTIMER_TCN)); |
87 | trr = __raw_readtrr(TA(MCFTIMER_TRR)); | 90 | offset = ((tcn + 1) * (1000000 / HZ)) / ticks_per_intr; |
88 | offset = (tcn * (1000000 / HZ)) / trr; | ||
89 | 91 | ||
90 | /* Check if we just wrapped the counters and maybe missed a tick */ | 92 | /* Check if we just wrapped the counters and maybe missed a tick */ |
91 | if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1)) | 93 | if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1)) |
diff --git a/arch/ppc/syslib/qspan_pci.c b/arch/ppc/syslib/qspan_pci.c index 85053b2816a9..7a97c7440b30 100644 --- a/arch/ppc/syslib/qspan_pci.c +++ b/arch/ppc/syslib/qspan_pci.c | |||
@@ -365,13 +365,13 @@ int qspan_pcibios_find_class(unsigned int class_code, unsigned short index, | |||
365 | } | 365 | } |
366 | 366 | ||
367 | void __init | 367 | void __init |
368 | m8xx_pcibios_fixup(void)) | 368 | m8xx_pcibios_fixup(void) |
369 | { | 369 | { |
370 | /* Lots to do here, all board and configuration specific. */ | 370 | /* Lots to do here, all board and configuration specific. */ |
371 | } | 371 | } |
372 | 372 | ||
373 | void __init | 373 | void __init |
374 | m8xx_setup_pci_ptrs(void)) | 374 | m8xx_setup_pci_ptrs(void) |
375 | { | 375 | { |
376 | set_config_access_method(qspan); | 376 | set_config_access_method(qspan); |
377 | 377 | ||
diff --git a/arch/sh64/kernel/pci_sh5.c b/arch/sh64/kernel/pci_sh5.c index fb51660847c8..3334f99b5835 100644 --- a/arch/sh64/kernel/pci_sh5.c +++ b/arch/sh64/kernel/pci_sh5.c | |||
@@ -521,10 +521,10 @@ void __init pcibios_fixup_bus(struct pci_bus *bus) | |||
521 | bus->resource[0]->start = PCIBIOS_MIN_IO; | 521 | bus->resource[0]->start = PCIBIOS_MIN_IO; |
522 | bus->resource[1]->start = PCIBIOS_MIN_MEM; | 522 | bus->resource[1]->start = PCIBIOS_MIN_MEM; |
523 | #else | 523 | #else |
524 | bus->resource[0]->end = 0 | 524 | bus->resource[0]->end = 0; |
525 | bus->resource[1]->end = 0 | 525 | bus->resource[1]->end = 0; |
526 | bus->resource[0]->start =0 | 526 | bus->resource[0]->start =0; |
527 | bus->resource[1]->start = 0; | 527 | bus->resource[1]->start = 0; |
528 | #endif | 528 | #endif |
529 | /* Turn off downstream PF memory address range by default */ | 529 | /* Turn off downstream PF memory address range by default */ |
530 | bus->resource[2]->start = 1024*1024; | 530 | bus->resource[2]->start = 1024*1024; |
diff --git a/arch/um/Kconfig b/arch/um/Kconfig index c504312219b4..e6ff30266542 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig | |||
@@ -278,6 +278,7 @@ config HIGHMEM | |||
278 | config KERNEL_STACK_ORDER | 278 | config KERNEL_STACK_ORDER |
279 | int "Kernel stack size order" | 279 | int "Kernel stack size order" |
280 | default 1 if 64BIT | 280 | default 1 if 64BIT |
281 | range 1 10 if 64BIT | ||
281 | default 0 if !64BIT | 282 | default 0 if !64BIT |
282 | help | 283 | help |
283 | This option determines the size of UML kernel stacks. They will | 284 | This option determines the size of UML kernel stacks. They will |
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c index ced99106f798..4bd40bb43ec2 100644 --- a/arch/um/drivers/line.c +++ b/arch/um/drivers/line.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "linux/kernel.h" | ||
6 | #include "linux/sched.h" | 7 | #include "linux/sched.h" |
7 | #include "linux/slab.h" | 8 | #include "linux/slab.h" |
8 | #include "linux/list.h" | 9 | #include "linux/list.h" |
diff --git a/arch/um/drivers/stderr_console.c b/arch/um/drivers/stderr_console.c index 911539293871..4739dd527b43 100644 --- a/arch/um/drivers/stderr_console.c +++ b/arch/um/drivers/stderr_console.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <linux/kernel.h> | ||
1 | #include <linux/init.h> | 2 | #include <linux/init.h> |
2 | #include <linux/console.h> | 3 | #include <linux/console.h> |
3 | 4 | ||
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 70509ddaac03..2e09f162c42f 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #define MAJOR_NR UBD_MAJOR | 20 | #define MAJOR_NR UBD_MAJOR |
21 | #define UBD_SHIFT 4 | 21 | #define UBD_SHIFT 4 |
22 | 22 | ||
23 | #include "linux/kernel.h" | ||
23 | #include "linux/module.h" | 24 | #include "linux/module.h" |
24 | #include "linux/blkdev.h" | 25 | #include "linux/blkdev.h" |
25 | #include "linux/hdreg.h" | 26 | #include "linux/hdreg.h" |
diff --git a/arch/um/kernel/exitcode.c b/arch/um/kernel/exitcode.c index 8b7f2cdedf94..c716b5a6db13 100644 --- a/arch/um/kernel/exitcode.c +++ b/arch/um/kernel/exitcode.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "linux/kernel.h" | ||
6 | #include "linux/init.h" | 7 | #include "linux/init.h" |
7 | #include "linux/ctype.h" | 8 | #include "linux/ctype.h" |
8 | #include "linux/proc_fs.h" | 9 | #include "linux/proc_fs.h" |
@@ -24,11 +25,14 @@ static int read_proc_exitcode(char *page, char **start, off_t off, | |||
24 | val = uml_exitcode; | 25 | val = uml_exitcode; |
25 | len = sprintf(page, "%d\n", val); | 26 | len = sprintf(page, "%d\n", val); |
26 | len -= off; | 27 | len -= off; |
27 | if(len <= off+count) *eof = 1; | 28 | if(len <= off+count) |
29 | *eof = 1; | ||
28 | *start = page + off; | 30 | *start = page + off; |
29 | if(len > count) len = count; | 31 | if(len > count) |
30 | if(len < 0) len = 0; | 32 | len = count; |
31 | return(len); | 33 | if(len < 0) |
34 | len = 0; | ||
35 | return len; | ||
32 | } | 36 | } |
33 | 37 | ||
34 | static int write_proc_exitcode(struct file *file, const char __user *buffer, | 38 | static int write_proc_exitcode(struct file *file, const char __user *buffer, |
@@ -38,12 +42,14 @@ static int write_proc_exitcode(struct file *file, const char __user *buffer, | |||
38 | int tmp; | 42 | int tmp; |
39 | 43 | ||
40 | if(copy_from_user(buf, buffer, count)) | 44 | if(copy_from_user(buf, buffer, count)) |
41 | return(-EFAULT); | 45 | return -EFAULT; |
46 | |||
42 | tmp = simple_strtol(buf, &end, 0); | 47 | tmp = simple_strtol(buf, &end, 0); |
43 | if((*end != '\0') && !isspace(*end)) | 48 | if((*end != '\0') && !isspace(*end)) |
44 | return(-EINVAL); | 49 | return -EINVAL; |
50 | |||
45 | uml_exitcode = tmp; | 51 | uml_exitcode = tmp; |
46 | return(count); | 52 | return count; |
47 | } | 53 | } |
48 | 54 | ||
49 | static int make_proc_exitcode(void) | 55 | static int make_proc_exitcode(void) |
@@ -54,24 +60,13 @@ static int make_proc_exitcode(void) | |||
54 | if(ent == NULL){ | 60 | if(ent == NULL){ |
55 | printk(KERN_WARNING "make_proc_exitcode : Failed to register " | 61 | printk(KERN_WARNING "make_proc_exitcode : Failed to register " |
56 | "/proc/exitcode\n"); | 62 | "/proc/exitcode\n"); |
57 | return(0); | 63 | return 0; |
58 | } | 64 | } |
59 | 65 | ||
60 | ent->read_proc = read_proc_exitcode; | 66 | ent->read_proc = read_proc_exitcode; |
61 | ent->write_proc = write_proc_exitcode; | 67 | ent->write_proc = write_proc_exitcode; |
62 | 68 | ||
63 | return(0); | 69 | return 0; |
64 | } | 70 | } |
65 | 71 | ||
66 | __initcall(make_proc_exitcode); | 72 | __initcall(make_proc_exitcode); |
67 | |||
68 | /* | ||
69 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
70 | * Emacs will notice this stuff at the end of the file and automatically | ||
71 | * adjust the settings for this buffer only. This must remain at the end | ||
72 | * of the file. | ||
73 | * --------------------------------------------------------------------------- | ||
74 | * Local variables: | ||
75 | * c-file-style: "linux" | ||
76 | * End: | ||
77 | */ | ||
diff --git a/arch/x86_64/kernel/traps.c b/arch/x86_64/kernel/traps.c index cb29fb96948d..aac1c0be54c6 100644 --- a/arch/x86_64/kernel/traps.c +++ b/arch/x86_64/kernel/traps.c | |||
@@ -465,13 +465,14 @@ static unsigned int die_nest_count; | |||
465 | 465 | ||
466 | unsigned __kprobes long oops_begin(void) | 466 | unsigned __kprobes long oops_begin(void) |
467 | { | 467 | { |
468 | int cpu = smp_processor_id(); | 468 | int cpu; |
469 | unsigned long flags; | 469 | unsigned long flags; |
470 | 470 | ||
471 | oops_enter(); | 471 | oops_enter(); |
472 | 472 | ||
473 | /* racy, but better than risking deadlock. */ | 473 | /* racy, but better than risking deadlock. */ |
474 | local_irq_save(flags); | 474 | local_irq_save(flags); |
475 | cpu = smp_processor_id(); | ||
475 | if (!spin_trylock(&die_lock)) { | 476 | if (!spin_trylock(&die_lock)) { |
476 | if (cpu == die_owner) | 477 | if (cpu == die_owner) |
477 | /* nested oops. should stop eventually */; | 478 | /* nested oops. should stop eventually */; |
diff --git a/arch/x86_64/mm/init.c b/arch/x86_64/mm/init.c index 1ad5111aec38..efb6e845114e 100644 --- a/arch/x86_64/mm/init.c +++ b/arch/x86_64/mm/init.c | |||
@@ -79,6 +79,8 @@ void show_mem(void) | |||
79 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) { | 79 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) { |
80 | touch_nmi_watchdog(); | 80 | touch_nmi_watchdog(); |
81 | } | 81 | } |
82 | if (!pfn_valid(pgdat->node_start_pfn + i)) | ||
83 | continue; | ||
82 | page = pfn_to_page(pgdat->node_start_pfn + i); | 84 | page = pfn_to_page(pgdat->node_start_pfn + i); |
83 | total++; | 85 | total++; |
84 | if (PageReserved(page)) | 86 | if (PageReserved(page)) |
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index 2b924a69b365..6dc0b011a6b7 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c | |||
@@ -784,9 +784,12 @@ static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) | |||
784 | if (qc->dev->flags & ATA_DFLAG_CDB_INTR) | 784 | if (qc->dev->flags & ATA_DFLAG_CDB_INTR) |
785 | break; | 785 | break; |
786 | /*FALLTHROUGH*/ | 786 | /*FALLTHROUGH*/ |
787 | case ATA_PROT_NODATA: | ||
788 | if (qc->tf.flags & ATA_TFLAG_POLLING) | ||
789 | break; | ||
790 | /*FALLTHROUGH*/ | ||
787 | case ATA_PROT_ATAPI_DMA: | 791 | case ATA_PROT_ATAPI_DMA: |
788 | case ATA_PROT_DMA: | 792 | case ATA_PROT_DMA: |
789 | case ATA_PROT_NODATA: | ||
790 | pdc_packet_start(qc); | 793 | pdc_packet_start(qc); |
791 | return 0; | 794 | return 0; |
792 | 795 | ||
@@ -800,7 +803,7 @@ static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) | |||
800 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) | 803 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) |
801 | { | 804 | { |
802 | WARN_ON (tf->protocol == ATA_PROT_DMA || | 805 | WARN_ON (tf->protocol == ATA_PROT_DMA || |
803 | tf->protocol == ATA_PROT_NODATA); | 806 | tf->protocol == ATA_PROT_ATAPI_DMA); |
804 | ata_tf_load(ap, tf); | 807 | ata_tf_load(ap, tf); |
805 | } | 808 | } |
806 | 809 | ||
@@ -808,7 +811,7 @@ static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) | |||
808 | static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf) | 811 | static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf) |
809 | { | 812 | { |
810 | WARN_ON (tf->protocol == ATA_PROT_DMA || | 813 | WARN_ON (tf->protocol == ATA_PROT_DMA || |
811 | tf->protocol == ATA_PROT_NODATA); | 814 | tf->protocol == ATA_PROT_ATAPI_DMA); |
812 | ata_exec_command(ap, tf); | 815 | ata_exec_command(ap, tf); |
813 | } | 816 | } |
814 | 817 | ||
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 5526eadb6592..0ed5470d2533 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -1354,7 +1354,7 @@ static struct block_device_operations lo_fops = { | |||
1354 | */ | 1354 | */ |
1355 | static int max_loop; | 1355 | static int max_loop; |
1356 | module_param(max_loop, int, 0); | 1356 | module_param(max_loop, int, 0); |
1357 | MODULE_PARM_DESC(max_loop, "obsolete, loop device is created on-demand"); | 1357 | MODULE_PARM_DESC(max_loop, "Maximum number of loop devices"); |
1358 | MODULE_LICENSE("GPL"); | 1358 | MODULE_LICENSE("GPL"); |
1359 | MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); | 1359 | MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); |
1360 | 1360 | ||
@@ -1394,16 +1394,11 @@ int loop_unregister_transfer(int number) | |||
1394 | EXPORT_SYMBOL(loop_register_transfer); | 1394 | EXPORT_SYMBOL(loop_register_transfer); |
1395 | EXPORT_SYMBOL(loop_unregister_transfer); | 1395 | EXPORT_SYMBOL(loop_unregister_transfer); |
1396 | 1396 | ||
1397 | static struct loop_device *loop_init_one(int i) | 1397 | static struct loop_device *loop_alloc(int i) |
1398 | { | 1398 | { |
1399 | struct loop_device *lo; | 1399 | struct loop_device *lo; |
1400 | struct gendisk *disk; | 1400 | struct gendisk *disk; |
1401 | 1401 | ||
1402 | list_for_each_entry(lo, &loop_devices, lo_list) { | ||
1403 | if (lo->lo_number == i) | ||
1404 | return lo; | ||
1405 | } | ||
1406 | |||
1407 | lo = kzalloc(sizeof(*lo), GFP_KERNEL); | 1402 | lo = kzalloc(sizeof(*lo), GFP_KERNEL); |
1408 | if (!lo) | 1403 | if (!lo) |
1409 | goto out; | 1404 | goto out; |
@@ -1427,8 +1422,6 @@ static struct loop_device *loop_init_one(int i) | |||
1427 | disk->private_data = lo; | 1422 | disk->private_data = lo; |
1428 | disk->queue = lo->lo_queue; | 1423 | disk->queue = lo->lo_queue; |
1429 | sprintf(disk->disk_name, "loop%d", i); | 1424 | sprintf(disk->disk_name, "loop%d", i); |
1430 | add_disk(disk); | ||
1431 | list_add_tail(&lo->lo_list, &loop_devices); | ||
1432 | return lo; | 1425 | return lo; |
1433 | 1426 | ||
1434 | out_free_queue: | 1427 | out_free_queue: |
@@ -1439,15 +1432,37 @@ out: | |||
1439 | return NULL; | 1432 | return NULL; |
1440 | } | 1433 | } |
1441 | 1434 | ||
1442 | static void loop_del_one(struct loop_device *lo) | 1435 | static void loop_free(struct loop_device *lo) |
1443 | { | 1436 | { |
1444 | del_gendisk(lo->lo_disk); | ||
1445 | blk_cleanup_queue(lo->lo_queue); | 1437 | blk_cleanup_queue(lo->lo_queue); |
1446 | put_disk(lo->lo_disk); | 1438 | put_disk(lo->lo_disk); |
1447 | list_del(&lo->lo_list); | 1439 | list_del(&lo->lo_list); |
1448 | kfree(lo); | 1440 | kfree(lo); |
1449 | } | 1441 | } |
1450 | 1442 | ||
1443 | static struct loop_device *loop_init_one(int i) | ||
1444 | { | ||
1445 | struct loop_device *lo; | ||
1446 | |||
1447 | list_for_each_entry(lo, &loop_devices, lo_list) { | ||
1448 | if (lo->lo_number == i) | ||
1449 | return lo; | ||
1450 | } | ||
1451 | |||
1452 | lo = loop_alloc(i); | ||
1453 | if (lo) { | ||
1454 | add_disk(lo->lo_disk); | ||
1455 | list_add_tail(&lo->lo_list, &loop_devices); | ||
1456 | } | ||
1457 | return lo; | ||
1458 | } | ||
1459 | |||
1460 | static void loop_del_one(struct loop_device *lo) | ||
1461 | { | ||
1462 | del_gendisk(lo->lo_disk); | ||
1463 | loop_free(lo); | ||
1464 | } | ||
1465 | |||
1451 | static struct kobject *loop_probe(dev_t dev, int *part, void *data) | 1466 | static struct kobject *loop_probe(dev_t dev, int *part, void *data) |
1452 | { | 1467 | { |
1453 | struct loop_device *lo; | 1468 | struct loop_device *lo; |
@@ -1464,28 +1479,77 @@ static struct kobject *loop_probe(dev_t dev, int *part, void *data) | |||
1464 | 1479 | ||
1465 | static int __init loop_init(void) | 1480 | static int __init loop_init(void) |
1466 | { | 1481 | { |
1467 | if (register_blkdev(LOOP_MAJOR, "loop")) | 1482 | int i, nr; |
1468 | return -EIO; | 1483 | unsigned long range; |
1469 | blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS, | 1484 | struct loop_device *lo, *next; |
1470 | THIS_MODULE, loop_probe, NULL, NULL); | 1485 | |
1486 | /* | ||
1487 | * loop module now has a feature to instantiate underlying device | ||
1488 | * structure on-demand, provided that there is an access dev node. | ||
1489 | * However, this will not work well with user space tool that doesn't | ||
1490 | * know about such "feature". In order to not break any existing | ||
1491 | * tool, we do the following: | ||
1492 | * | ||
1493 | * (1) if max_loop is specified, create that many upfront, and this | ||
1494 | * also becomes a hard limit. | ||
1495 | * (2) if max_loop is not specified, create 8 loop device on module | ||
1496 | * load, user can further extend loop device by create dev node | ||
1497 | * themselves and have kernel automatically instantiate actual | ||
1498 | * device on-demand. | ||
1499 | */ | ||
1500 | if (max_loop > 1UL << MINORBITS) | ||
1501 | return -EINVAL; | ||
1471 | 1502 | ||
1472 | if (max_loop) { | 1503 | if (max_loop) { |
1473 | printk(KERN_INFO "loop: the max_loop option is obsolete " | 1504 | nr = max_loop; |
1474 | "and will be removed in March 2008\n"); | 1505 | range = max_loop; |
1506 | } else { | ||
1507 | nr = 8; | ||
1508 | range = 1UL << MINORBITS; | ||
1509 | } | ||
1510 | |||
1511 | if (register_blkdev(LOOP_MAJOR, "loop")) | ||
1512 | return -EIO; | ||
1475 | 1513 | ||
1514 | for (i = 0; i < nr; i++) { | ||
1515 | lo = loop_alloc(i); | ||
1516 | if (!lo) | ||
1517 | goto Enomem; | ||
1518 | list_add_tail(&lo->lo_list, &loop_devices); | ||
1476 | } | 1519 | } |
1520 | |||
1521 | /* point of no return */ | ||
1522 | |||
1523 | list_for_each_entry(lo, &loop_devices, lo_list) | ||
1524 | add_disk(lo->lo_disk); | ||
1525 | |||
1526 | blk_register_region(MKDEV(LOOP_MAJOR, 0), range, | ||
1527 | THIS_MODULE, loop_probe, NULL, NULL); | ||
1528 | |||
1477 | printk(KERN_INFO "loop: module loaded\n"); | 1529 | printk(KERN_INFO "loop: module loaded\n"); |
1478 | return 0; | 1530 | return 0; |
1531 | |||
1532 | Enomem: | ||
1533 | printk(KERN_INFO "loop: out of memory\n"); | ||
1534 | |||
1535 | list_for_each_entry_safe(lo, next, &loop_devices, lo_list) | ||
1536 | loop_free(lo); | ||
1537 | |||
1538 | unregister_blkdev(LOOP_MAJOR, "loop"); | ||
1539 | return -ENOMEM; | ||
1479 | } | 1540 | } |
1480 | 1541 | ||
1481 | static void __exit loop_exit(void) | 1542 | static void __exit loop_exit(void) |
1482 | { | 1543 | { |
1544 | unsigned long range; | ||
1483 | struct loop_device *lo, *next; | 1545 | struct loop_device *lo, *next; |
1484 | 1546 | ||
1547 | range = max_loop ? max_loop : 1UL << MINORBITS; | ||
1548 | |||
1485 | list_for_each_entry_safe(lo, next, &loop_devices, lo_list) | 1549 | list_for_each_entry_safe(lo, next, &loop_devices, lo_list) |
1486 | loop_del_one(lo); | 1550 | loop_del_one(lo); |
1487 | 1551 | ||
1488 | blk_unregister_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS); | 1552 | blk_unregister_region(MKDEV(LOOP_MAJOR, 0), range); |
1489 | if (unregister_blkdev(LOOP_MAJOR, "loop")) | 1553 | if (unregister_blkdev(LOOP_MAJOR, "loop")) |
1490 | printk(KERN_WARNING "loop: cannot unregister blkdev\n"); | 1554 | printk(KERN_WARNING "loop: cannot unregister blkdev\n"); |
1491 | } | 1555 | } |
diff --git a/drivers/cdrom/mcdx.c b/drivers/cdrom/mcdx.c index f574962f4288..4310cc84dfed 100644 --- a/drivers/cdrom/mcdx.c +++ b/drivers/cdrom/mcdx.c | |||
@@ -1053,11 +1053,11 @@ static void __exit mcdx_exit(void) | |||
1053 | if (unregister_blkdev(MAJOR_NR, "mcdx") != 0) { | 1053 | if (unregister_blkdev(MAJOR_NR, "mcdx") != 0) { |
1054 | xwarn("cleanup() unregister_blkdev() failed\n"); | 1054 | xwarn("cleanup() unregister_blkdev() failed\n"); |
1055 | } | 1055 | } |
1056 | blk_cleanup_queue(mcdx_queue); | ||
1057 | #if !MCDX_QUIET | 1056 | #if !MCDX_QUIET |
1058 | else | 1057 | else |
1059 | xinfo("cleanup() succeeded\n"); | 1058 | xinfo("cleanup() succeeded\n"); |
1060 | #endif | 1059 | #endif |
1060 | blk_cleanup_queue(mcdx_queue); | ||
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | #ifdef MODULE | 1063 | #ifdef MODULE |
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index e45113a7a472..45bf2a262a85 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c | |||
@@ -2172,11 +2172,12 @@ static int __devinit stl_initech(struct stlbrd *brdp) | |||
2172 | } | 2172 | } |
2173 | status = inb(ioaddr + ECH_PNLSTATUS); | 2173 | status = inb(ioaddr + ECH_PNLSTATUS); |
2174 | if ((status & ECH_PNLIDMASK) != nxtid) | 2174 | if ((status & ECH_PNLIDMASK) != nxtid) |
2175 | goto err_fr; | 2175 | break; |
2176 | panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL); | 2176 | panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL); |
2177 | if (!panelp) { | 2177 | if (!panelp) { |
2178 | printk("STALLION: failed to allocate memory " | 2178 | printk("STALLION: failed to allocate memory " |
2179 | "(size=%Zd)\n", sizeof(struct stlpanel)); | 2179 | "(size=%Zd)\n", sizeof(struct stlpanel)); |
2180 | retval = -ENOMEM; | ||
2180 | goto err_fr; | 2181 | goto err_fr; |
2181 | } | 2182 | } |
2182 | panelp->magic = STL_PANELMAGIC; | 2183 | panelp->magic = STL_PANELMAGIC; |
@@ -2223,8 +2224,10 @@ static int __devinit stl_initech(struct stlbrd *brdp) | |||
2223 | brdp->nrports += panelp->nrports; | 2224 | brdp->nrports += panelp->nrports; |
2224 | brdp->panels[panelnr++] = panelp; | 2225 | brdp->panels[panelnr++] = panelp; |
2225 | if ((brdp->brdtype != BRD_ECHPCI) && | 2226 | if ((brdp->brdtype != BRD_ECHPCI) && |
2226 | (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) | 2227 | (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) { |
2228 | retval = -EINVAL; | ||
2227 | goto err_fr; | 2229 | goto err_fr; |
2230 | } | ||
2228 | } | 2231 | } |
2229 | 2232 | ||
2230 | brdp->nrpanels = panelnr; | 2233 | brdp->nrpanels = panelnr; |
@@ -2371,6 +2374,7 @@ static int __devinit stl_pciprobe(struct pci_dev *pdev, | |||
2371 | dev_err(&pdev->dev, "too many boards found, " | 2374 | dev_err(&pdev->dev, "too many boards found, " |
2372 | "maximum supported %d\n", STL_MAXBRDS); | 2375 | "maximum supported %d\n", STL_MAXBRDS); |
2373 | mutex_unlock(&stl_brdslock); | 2376 | mutex_unlock(&stl_brdslock); |
2377 | retval = -ENODEV; | ||
2374 | goto err_fr; | 2378 | goto err_fr; |
2375 | } | 2379 | } |
2376 | brdp->brdnr = (unsigned int)brdnr; | 2380 | brdp->brdnr = (unsigned int)brdnr; |
@@ -4710,6 +4714,29 @@ static int __init stallion_module_init(void) | |||
4710 | spin_lock_init(&stallion_lock); | 4714 | spin_lock_init(&stallion_lock); |
4711 | spin_lock_init(&brd_lock); | 4715 | spin_lock_init(&brd_lock); |
4712 | 4716 | ||
4717 | stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); | ||
4718 | if (!stl_serial) { | ||
4719 | retval = -ENOMEM; | ||
4720 | goto err; | ||
4721 | } | ||
4722 | |||
4723 | stl_serial->owner = THIS_MODULE; | ||
4724 | stl_serial->driver_name = stl_drvname; | ||
4725 | stl_serial->name = "ttyE"; | ||
4726 | stl_serial->major = STL_SERIALMAJOR; | ||
4727 | stl_serial->minor_start = 0; | ||
4728 | stl_serial->type = TTY_DRIVER_TYPE_SERIAL; | ||
4729 | stl_serial->subtype = SERIAL_TYPE_NORMAL; | ||
4730 | stl_serial->init_termios = stl_deftermios; | ||
4731 | stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | ||
4732 | tty_set_operations(stl_serial, &stl_ops); | ||
4733 | |||
4734 | retval = tty_register_driver(stl_serial); | ||
4735 | if (retval) { | ||
4736 | printk("STALLION: failed to register serial driver\n"); | ||
4737 | goto err_frtty; | ||
4738 | } | ||
4739 | |||
4713 | /* | 4740 | /* |
4714 | * Find any dynamically supported boards. That is via module load | 4741 | * Find any dynamically supported boards. That is via module load |
4715 | * line options. | 4742 | * line options. |
@@ -4739,13 +4766,9 @@ static int __init stallion_module_init(void) | |||
4739 | 4766 | ||
4740 | /* this has to be _after_ isa finding because of locking */ | 4767 | /* this has to be _after_ isa finding because of locking */ |
4741 | retval = pci_register_driver(&stl_pcidriver); | 4768 | retval = pci_register_driver(&stl_pcidriver); |
4742 | if (retval && stl_nrbrds == 0) | 4769 | if (retval && stl_nrbrds == 0) { |
4743 | goto err; | 4770 | printk(KERN_ERR "STALLION: can't register pci driver\n"); |
4744 | 4771 | goto err_unrtty; | |
4745 | stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); | ||
4746 | if (!stl_serial) { | ||
4747 | retval = -ENOMEM; | ||
4748 | goto err_pcidr; | ||
4749 | } | 4772 | } |
4750 | 4773 | ||
4751 | /* | 4774 | /* |
@@ -4756,43 +4779,18 @@ static int __init stallion_module_init(void) | |||
4756 | printk("STALLION: failed to register serial board device\n"); | 4779 | printk("STALLION: failed to register serial board device\n"); |
4757 | 4780 | ||
4758 | stallion_class = class_create(THIS_MODULE, "staliomem"); | 4781 | stallion_class = class_create(THIS_MODULE, "staliomem"); |
4759 | if (IS_ERR(stallion_class)) { | 4782 | if (IS_ERR(stallion_class)) |
4760 | retval = PTR_ERR(stallion_class); | 4783 | printk("STALLION: failed to create class\n"); |
4761 | goto err_reg; | ||
4762 | } | ||
4763 | for (i = 0; i < 4; i++) | 4784 | for (i = 0; i < 4; i++) |
4764 | class_device_create(stallion_class, NULL, | 4785 | class_device_create(stallion_class, NULL, |
4765 | MKDEV(STL_SIOMEMMAJOR, i), NULL, | 4786 | MKDEV(STL_SIOMEMMAJOR, i), NULL, |
4766 | "staliomem%d", i); | 4787 | "staliomem%d", i); |
4767 | 4788 | ||
4768 | stl_serial->owner = THIS_MODULE; | ||
4769 | stl_serial->driver_name = stl_drvname; | ||
4770 | stl_serial->name = "ttyE"; | ||
4771 | stl_serial->major = STL_SERIALMAJOR; | ||
4772 | stl_serial->minor_start = 0; | ||
4773 | stl_serial->type = TTY_DRIVER_TYPE_SERIAL; | ||
4774 | stl_serial->subtype = SERIAL_TYPE_NORMAL; | ||
4775 | stl_serial->init_termios = stl_deftermios; | ||
4776 | stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | ||
4777 | tty_set_operations(stl_serial, &stl_ops); | ||
4778 | |||
4779 | retval = tty_register_driver(stl_serial); | ||
4780 | if (retval) { | ||
4781 | printk("STALLION: failed to register serial driver\n"); | ||
4782 | goto err_clsdev; | ||
4783 | } | ||
4784 | |||
4785 | return 0; | 4789 | return 0; |
4786 | err_clsdev: | 4790 | err_unrtty: |
4787 | for (i = 0; i < 4; i++) | 4791 | tty_unregister_driver(stl_serial); |
4788 | class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); | 4792 | err_frtty: |
4789 | class_destroy(stallion_class); | ||
4790 | err_reg: | ||
4791 | unregister_chrdev(STL_SIOMEMMAJOR, "staliomem"); | ||
4792 | put_tty_driver(stl_serial); | 4793 | put_tty_driver(stl_serial); |
4793 | err_pcidr: | ||
4794 | pci_unregister_driver(&stl_pcidriver); | ||
4795 | stl_free_isabrds(); | ||
4796 | err: | 4794 | err: |
4797 | return retval; | 4795 | return retval; |
4798 | } | 4796 | } |
@@ -4821,8 +4819,6 @@ static void __exit stallion_module_exit(void) | |||
4821 | tty_unregister_device(stl_serial, | 4819 | tty_unregister_device(stl_serial, |
4822 | brdp->brdnr * STL_MAXPORTS + j); | 4820 | brdp->brdnr * STL_MAXPORTS + j); |
4823 | } | 4821 | } |
4824 | tty_unregister_driver(stl_serial); | ||
4825 | put_tty_driver(stl_serial); | ||
4826 | 4822 | ||
4827 | for (i = 0; i < 4; i++) | 4823 | for (i = 0; i < 4; i++) |
4828 | class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); | 4824 | class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); |
@@ -4834,6 +4830,9 @@ static void __exit stallion_module_exit(void) | |||
4834 | pci_unregister_driver(&stl_pcidriver); | 4830 | pci_unregister_driver(&stl_pcidriver); |
4835 | 4831 | ||
4836 | stl_free_isabrds(); | 4832 | stl_free_isabrds(); |
4833 | |||
4834 | tty_unregister_driver(stl_serial); | ||
4835 | put_tty_driver(stl_serial); | ||
4837 | } | 4836 | } |
4838 | 4837 | ||
4839 | module_init(stallion_module_init); | 4838 | module_init(stallion_module_init); |
diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c index 46fc21a3f8ff..d36a4c09e25d 100644 --- a/drivers/isdn/hardware/eicon/divasfunc.c +++ b/drivers/isdn/hardware/eicon/divasfunc.c | |||
@@ -195,7 +195,7 @@ static int DIVA_INIT_FUNCTION connect_didd(void) | |||
195 | /* | 195 | /* |
196 | * disconnect from didd | 196 | * disconnect from didd |
197 | */ | 197 | */ |
198 | static void DIVA_EXIT_FUNCTION disconnect_didd(void) | 198 | static void disconnect_didd(void) |
199 | { | 199 | { |
200 | IDI_SYNC_REQ req; | 200 | IDI_SYNC_REQ req; |
201 | 201 | ||
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c index 3524e3fc08b9..61de78a9f6ee 100644 --- a/drivers/tc/zs.c +++ b/drivers/tc/zs.c | |||
@@ -2182,7 +2182,7 @@ struct dec_serial_hook zs_kgdbhook = { | |||
2182 | .init_info = kgdbhook_init_info, | 2182 | .init_info = kgdbhook_init_info, |
2183 | .rx_char = kgdbhook_rx_char, | 2183 | .rx_char = kgdbhook_rx_char, |
2184 | .cflags = B38400 | CS8 | CLOCAL, | 2184 | .cflags = B38400 | CS8 | CLOCAL, |
2185 | } | 2185 | }; |
2186 | 2186 | ||
2187 | void __init zs_kgdb_hook(int tty_num) | 2187 | void __init zs_kgdb_hook(int tty_num) |
2188 | { | 2188 | { |
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 7b0265d7f3a8..861141b4f6d6 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c | |||
@@ -558,7 +558,7 @@ static int load_flat_file(struct linux_binprm * bprm, | |||
558 | if (!realdatastart) | 558 | if (!realdatastart) |
559 | realdatastart = (unsigned long) -ENOMEM; | 559 | realdatastart = (unsigned long) -ENOMEM; |
560 | printk("Unable to allocate RAM for process data, errno %d\n", | 560 | printk("Unable to allocate RAM for process data, errno %d\n", |
561 | (int)-datapos); | 561 | (int)-realdatastart); |
562 | do_munmap(current->mm, textpos, text_len); | 562 | do_munmap(current->mm, textpos, text_len); |
563 | ret = realdatastart; | 563 | ret = realdatastart; |
564 | goto err; | 564 | goto err; |
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h index a461f76fb004..dc77fed7b285 100644 --- a/include/linux/console_struct.h +++ b/include/linux/console_struct.h | |||
@@ -9,6 +9,9 @@ | |||
9 | * to achieve effects such as fast scrolling by changing the origin. | 9 | * to achieve effects such as fast scrolling by changing the origin. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #ifndef _LINUX_CONSOLE_STRUCT_H | ||
13 | #define _LINUX_CONSOLE_STRUCT_H | ||
14 | |||
12 | #include <linux/wait.h> | 15 | #include <linux/wait.h> |
13 | #include <linux/vt.h> | 16 | #include <linux/vt.h> |
14 | #include <linux/workqueue.h> | 17 | #include <linux/workqueue.h> |
@@ -130,3 +133,5 @@ extern void vc_SAK(struct work_struct *work); | |||
130 | #define CUR_DEFAULT CUR_UNDERLINE | 133 | #define CUR_DEFAULT CUR_UNDERLINE |
131 | 134 | ||
132 | #define CON_IS_VISIBLE(conp) (*conp->vc_display_fg == conp) | 135 | #define CON_IS_VISIBLE(conp) (*conp->vc_display_fg == conp) |
136 | |||
137 | #endif /* _LINUX_CONSOLE_STRUCT_H */ | ||
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 45353d757cd0..7a4852505914 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -218,10 +218,14 @@ enum { | |||
218 | DUMP_PREFIX_ADDRESS, | 218 | DUMP_PREFIX_ADDRESS, |
219 | DUMP_PREFIX_OFFSET | 219 | DUMP_PREFIX_OFFSET |
220 | }; | 220 | }; |
221 | extern void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf, | 221 | extern void hex_dump_to_buffer(const void *buf, size_t len, |
222 | size_t linebuflen); | 222 | int rowsize, int groupsize, |
223 | extern void print_hex_dump(const char *level, int prefix_type, | 223 | char *linebuf, size_t linebuflen, bool ascii); |
224 | void *buf, size_t len); | 224 | extern void print_hex_dump(const char *level, const char *prefix_str, |
225 | int prefix_type, int rowsize, int groupsize, | ||
226 | void *buf, size_t len, bool ascii); | ||
227 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | ||
228 | void *buf, size_t len); | ||
225 | #define hex_asc(x) "0123456789abcdef"[x] | 229 | #define hex_asc(x) "0123456789abcdef"[x] |
226 | 230 | ||
227 | #ifdef DEBUG | 231 | #ifdef DEBUG |
diff --git a/include/linux/sched.h b/include/linux/sched.h index d58e74b98367..693f0e6c54d4 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1162,6 +1162,7 @@ static inline void put_task_struct(struct task_struct *t) | |||
1162 | /* Not implemented yet, only for 486*/ | 1162 | /* Not implemented yet, only for 486*/ |
1163 | #define PF_STARTING 0x00000002 /* being created */ | 1163 | #define PF_STARTING 0x00000002 /* being created */ |
1164 | #define PF_EXITING 0x00000004 /* getting shut down */ | 1164 | #define PF_EXITING 0x00000004 /* getting shut down */ |
1165 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ | ||
1165 | #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ | 1166 | #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ |
1166 | #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ | 1167 | #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ |
1167 | #define PF_DUMPCORE 0x00000200 /* dumped core */ | 1168 | #define PF_DUMPCORE 0x00000200 /* dumped core */ |
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index 0764c829d967..a0ad37463d62 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h | |||
@@ -70,11 +70,8 @@ extern struct kmem_cache kmalloc_caches[KMALLOC_SHIFT_HIGH + 1]; | |||
70 | */ | 70 | */ |
71 | static inline int kmalloc_index(size_t size) | 71 | static inline int kmalloc_index(size_t size) |
72 | { | 72 | { |
73 | /* | 73 | if (!size) |
74 | * We should return 0 if size == 0 but we use the smallest object | 74 | return 0; |
75 | * here for SLAB legacy reasons. | ||
76 | */ | ||
77 | WARN_ON_ONCE(size == 0); | ||
78 | 75 | ||
79 | if (size > KMALLOC_MAX_SIZE) | 76 | if (size > KMALLOC_MAX_SIZE) |
80 | return -1; | 77 | return -1; |
@@ -153,13 +150,25 @@ static inline struct kmem_cache *kmalloc_slab(size_t size) | |||
153 | #define SLUB_DMA 0 | 150 | #define SLUB_DMA 0 |
154 | #endif | 151 | #endif |
155 | 152 | ||
153 | |||
154 | /* | ||
155 | * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. | ||
156 | * | ||
157 | * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault. | ||
158 | * | ||
159 | * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can. | ||
160 | * Both make kfree a no-op. | ||
161 | */ | ||
162 | #define ZERO_SIZE_PTR ((void *)16) | ||
163 | |||
164 | |||
156 | static inline void *kmalloc(size_t size, gfp_t flags) | 165 | static inline void *kmalloc(size_t size, gfp_t flags) |
157 | { | 166 | { |
158 | if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) { | 167 | if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) { |
159 | struct kmem_cache *s = kmalloc_slab(size); | 168 | struct kmem_cache *s = kmalloc_slab(size); |
160 | 169 | ||
161 | if (!s) | 170 | if (!s) |
162 | return NULL; | 171 | return ZERO_SIZE_PTR; |
163 | 172 | ||
164 | return kmem_cache_alloc(s, flags); | 173 | return kmem_cache_alloc(s, flags); |
165 | } else | 174 | } else |
@@ -172,7 +181,7 @@ static inline void *kzalloc(size_t size, gfp_t flags) | |||
172 | struct kmem_cache *s = kmalloc_slab(size); | 181 | struct kmem_cache *s = kmalloc_slab(size); |
173 | 182 | ||
174 | if (!s) | 183 | if (!s) |
175 | return NULL; | 184 | return ZERO_SIZE_PTR; |
176 | 185 | ||
177 | return kmem_cache_zalloc(s, flags); | 186 | return kmem_cache_zalloc(s, flags); |
178 | } else | 187 | } else |
@@ -188,7 +197,7 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node) | |||
188 | struct kmem_cache *s = kmalloc_slab(size); | 197 | struct kmem_cache *s = kmalloc_slab(size); |
189 | 198 | ||
190 | if (!s) | 199 | if (!s) |
191 | return NULL; | 200 | return ZERO_SIZE_PTR; |
192 | 201 | ||
193 | return kmem_cache_alloc_node(s, flags, node); | 202 | return kmem_cache_alloc_node(s, flags, node); |
194 | } else | 203 | } else |
diff --git a/kernel/exit.c b/kernel/exit.c index 5b888c24e43e..5c8ecbaa19a5 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -892,13 +892,29 @@ fastcall NORET_TYPE void do_exit(long code) | |||
892 | if (unlikely(tsk->flags & PF_EXITING)) { | 892 | if (unlikely(tsk->flags & PF_EXITING)) { |
893 | printk(KERN_ALERT | 893 | printk(KERN_ALERT |
894 | "Fixing recursive fault but reboot is needed!\n"); | 894 | "Fixing recursive fault but reboot is needed!\n"); |
895 | /* | ||
896 | * We can do this unlocked here. The futex code uses | ||
897 | * this flag just to verify whether the pi state | ||
898 | * cleanup has been done or not. In the worst case it | ||
899 | * loops once more. We pretend that the cleanup was | ||
900 | * done as there is no way to return. Either the | ||
901 | * OWNER_DIED bit is set by now or we push the blocked | ||
902 | * task into the wait for ever nirwana as well. | ||
903 | */ | ||
904 | tsk->flags |= PF_EXITPIDONE; | ||
895 | if (tsk->io_context) | 905 | if (tsk->io_context) |
896 | exit_io_context(); | 906 | exit_io_context(); |
897 | set_current_state(TASK_UNINTERRUPTIBLE); | 907 | set_current_state(TASK_UNINTERRUPTIBLE); |
898 | schedule(); | 908 | schedule(); |
899 | } | 909 | } |
900 | 910 | ||
911 | /* | ||
912 | * tsk->flags are checked in the futex code to protect against | ||
913 | * an exiting task cleaning up the robust pi futexes. | ||
914 | */ | ||
915 | spin_lock_irq(&tsk->pi_lock); | ||
901 | tsk->flags |= PF_EXITING; | 916 | tsk->flags |= PF_EXITING; |
917 | spin_unlock_irq(&tsk->pi_lock); | ||
902 | 918 | ||
903 | if (unlikely(in_atomic())) | 919 | if (unlikely(in_atomic())) |
904 | printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", | 920 | printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", |
@@ -912,7 +928,7 @@ fastcall NORET_TYPE void do_exit(long code) | |||
912 | } | 928 | } |
913 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 929 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
914 | if (group_dead) { | 930 | if (group_dead) { |
915 | hrtimer_cancel(&tsk->signal->real_timer); | 931 | hrtimer_cancel(&tsk->signal->real_timer); |
916 | exit_itimers(tsk->signal); | 932 | exit_itimers(tsk->signal); |
917 | } | 933 | } |
918 | acct_collect(code, group_dead); | 934 | acct_collect(code, group_dead); |
@@ -965,6 +981,12 @@ fastcall NORET_TYPE void do_exit(long code) | |||
965 | * Make sure we are holding no locks: | 981 | * Make sure we are holding no locks: |
966 | */ | 982 | */ |
967 | debug_check_no_locks_held(tsk); | 983 | debug_check_no_locks_held(tsk); |
984 | /* | ||
985 | * We can do this unlocked here. The futex code uses this flag | ||
986 | * just to verify whether the pi state cleanup has been done | ||
987 | * or not. In the worst case it loops once more. | ||
988 | */ | ||
989 | tsk->flags |= PF_EXITPIDONE; | ||
968 | 990 | ||
969 | if (tsk->io_context) | 991 | if (tsk->io_context) |
970 | exit_io_context(); | 992 | exit_io_context(); |
diff --git a/kernel/futex.c b/kernel/futex.c index b7ce15c67e32..3b7f7713d9a4 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
@@ -430,10 +430,6 @@ static struct task_struct * futex_find_get_task(pid_t pid) | |||
430 | p = NULL; | 430 | p = NULL; |
431 | goto out_unlock; | 431 | goto out_unlock; |
432 | } | 432 | } |
433 | if (p->exit_state != 0) { | ||
434 | p = NULL; | ||
435 | goto out_unlock; | ||
436 | } | ||
437 | get_task_struct(p); | 433 | get_task_struct(p); |
438 | out_unlock: | 434 | out_unlock: |
439 | rcu_read_unlock(); | 435 | rcu_read_unlock(); |
@@ -502,7 +498,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, | |||
502 | struct futex_q *this, *next; | 498 | struct futex_q *this, *next; |
503 | struct plist_head *head; | 499 | struct plist_head *head; |
504 | struct task_struct *p; | 500 | struct task_struct *p; |
505 | pid_t pid; | 501 | pid_t pid = uval & FUTEX_TID_MASK; |
506 | 502 | ||
507 | head = &hb->chain; | 503 | head = &hb->chain; |
508 | 504 | ||
@@ -520,6 +516,8 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, | |||
520 | return -EINVAL; | 516 | return -EINVAL; |
521 | 517 | ||
522 | WARN_ON(!atomic_read(&pi_state->refcount)); | 518 | WARN_ON(!atomic_read(&pi_state->refcount)); |
519 | WARN_ON(pid && pi_state->owner && | ||
520 | pi_state->owner->pid != pid); | ||
523 | 521 | ||
524 | atomic_inc(&pi_state->refcount); | 522 | atomic_inc(&pi_state->refcount); |
525 | *ps = pi_state; | 523 | *ps = pi_state; |
@@ -530,15 +528,33 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, | |||
530 | 528 | ||
531 | /* | 529 | /* |
532 | * We are the first waiter - try to look up the real owner and attach | 530 | * We are the first waiter - try to look up the real owner and attach |
533 | * the new pi_state to it, but bail out when the owner died bit is set | 531 | * the new pi_state to it, but bail out when TID = 0 |
534 | * and TID = 0: | ||
535 | */ | 532 | */ |
536 | pid = uval & FUTEX_TID_MASK; | 533 | if (!pid) |
537 | if (!pid && (uval & FUTEX_OWNER_DIED)) | ||
538 | return -ESRCH; | 534 | return -ESRCH; |
539 | p = futex_find_get_task(pid); | 535 | p = futex_find_get_task(pid); |
540 | if (!p) | 536 | if (IS_ERR(p)) |
541 | return -ESRCH; | 537 | return PTR_ERR(p); |
538 | |||
539 | /* | ||
540 | * We need to look at the task state flags to figure out, | ||
541 | * whether the task is exiting. To protect against the do_exit | ||
542 | * change of the task flags, we do this protected by | ||
543 | * p->pi_lock: | ||
544 | */ | ||
545 | spin_lock_irq(&p->pi_lock); | ||
546 | if (unlikely(p->flags & PF_EXITING)) { | ||
547 | /* | ||
548 | * The task is on the way out. When PF_EXITPIDONE is | ||
549 | * set, we know that the task has finished the | ||
550 | * cleanup: | ||
551 | */ | ||
552 | int ret = (p->flags & PF_EXITPIDONE) ? -ESRCH : -EAGAIN; | ||
553 | |||
554 | spin_unlock_irq(&p->pi_lock); | ||
555 | put_task_struct(p); | ||
556 | return ret; | ||
557 | } | ||
542 | 558 | ||
543 | pi_state = alloc_pi_state(); | 559 | pi_state = alloc_pi_state(); |
544 | 560 | ||
@@ -551,7 +567,6 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, | |||
551 | /* Store the key for possible exit cleanups: */ | 567 | /* Store the key for possible exit cleanups: */ |
552 | pi_state->key = *key; | 568 | pi_state->key = *key; |
553 | 569 | ||
554 | spin_lock_irq(&p->pi_lock); | ||
555 | WARN_ON(!list_empty(&pi_state->list)); | 570 | WARN_ON(!list_empty(&pi_state->list)); |
556 | list_add(&pi_state->list, &p->pi_state_list); | 571 | list_add(&pi_state->list, &p->pi_state_list); |
557 | pi_state->owner = p; | 572 | pi_state->owner = p; |
@@ -618,6 +633,8 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this) | |||
618 | * preserve the owner died bit.) | 633 | * preserve the owner died bit.) |
619 | */ | 634 | */ |
620 | if (!(uval & FUTEX_OWNER_DIED)) { | 635 | if (!(uval & FUTEX_OWNER_DIED)) { |
636 | int ret = 0; | ||
637 | |||
621 | newval = FUTEX_WAITERS | new_owner->pid; | 638 | newval = FUTEX_WAITERS | new_owner->pid; |
622 | /* Keep the FUTEX_WAITER_REQUEUED flag if it was set */ | 639 | /* Keep the FUTEX_WAITER_REQUEUED flag if it was set */ |
623 | newval |= (uval & FUTEX_WAITER_REQUEUED); | 640 | newval |= (uval & FUTEX_WAITER_REQUEUED); |
@@ -625,10 +642,15 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this) | |||
625 | pagefault_disable(); | 642 | pagefault_disable(); |
626 | curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); | 643 | curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); |
627 | pagefault_enable(); | 644 | pagefault_enable(); |
645 | |||
628 | if (curval == -EFAULT) | 646 | if (curval == -EFAULT) |
629 | return -EFAULT; | 647 | ret = -EFAULT; |
630 | if (curval != uval) | 648 | if (curval != uval) |
631 | return -EINVAL; | 649 | ret = -EINVAL; |
650 | if (ret) { | ||
651 | spin_unlock(&pi_state->pi_mutex.wait_lock); | ||
652 | return ret; | ||
653 | } | ||
632 | } | 654 | } |
633 | 655 | ||
634 | spin_lock_irq(&pi_state->owner->pi_lock); | 656 | spin_lock_irq(&pi_state->owner->pi_lock); |
@@ -1174,7 +1196,7 @@ static int futex_requeue(u32 __user *uaddr1, struct rw_semaphore *fshared, | |||
1174 | #ifdef CONFIG_DEBUG_PI_LIST | 1196 | #ifdef CONFIG_DEBUG_PI_LIST |
1175 | this->list.plist.lock = &hb2->lock; | 1197 | this->list.plist.lock = &hb2->lock; |
1176 | #endif | 1198 | #endif |
1177 | } | 1199 | } |
1178 | this->key = key2; | 1200 | this->key = key2; |
1179 | get_futex_key_refs(&key2); | 1201 | get_futex_key_refs(&key2); |
1180 | drop_count++; | 1202 | drop_count++; |
@@ -1326,12 +1348,10 @@ static void unqueue_me_pi(struct futex_q *q) | |||
1326 | /* | 1348 | /* |
1327 | * Fixup the pi_state owner with current. | 1349 | * Fixup the pi_state owner with current. |
1328 | * | 1350 | * |
1329 | * The cur->mm semaphore must be held, it is released at return of this | 1351 | * Must be called with hash bucket lock held and mm->sem held for non |
1330 | * function. | 1352 | * private futexes. |
1331 | */ | 1353 | */ |
1332 | static int fixup_pi_state_owner(u32 __user *uaddr, struct rw_semaphore *fshared, | 1354 | static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, |
1333 | struct futex_q *q, | ||
1334 | struct futex_hash_bucket *hb, | ||
1335 | struct task_struct *curr) | 1355 | struct task_struct *curr) |
1336 | { | 1356 | { |
1337 | u32 newtid = curr->pid | FUTEX_WAITERS; | 1357 | u32 newtid = curr->pid | FUTEX_WAITERS; |
@@ -1355,23 +1375,24 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1355 | list_add(&pi_state->list, &curr->pi_state_list); | 1375 | list_add(&pi_state->list, &curr->pi_state_list); |
1356 | spin_unlock_irq(&curr->pi_lock); | 1376 | spin_unlock_irq(&curr->pi_lock); |
1357 | 1377 | ||
1358 | /* Unqueue and drop the lock */ | ||
1359 | unqueue_me_pi(q); | ||
1360 | if (fshared) | ||
1361 | up_read(fshared); | ||
1362 | /* | 1378 | /* |
1363 | * We own it, so we have to replace the pending owner | 1379 | * We own it, so we have to replace the pending owner |
1364 | * TID. This must be atomic as we have preserve the | 1380 | * TID. This must be atomic as we have preserve the |
1365 | * owner died bit here. | 1381 | * owner died bit here. |
1366 | */ | 1382 | */ |
1367 | ret = get_user(uval, uaddr); | 1383 | ret = get_futex_value_locked(&uval, uaddr); |
1384 | |||
1368 | while (!ret) { | 1385 | while (!ret) { |
1369 | newval = (uval & FUTEX_OWNER_DIED) | newtid; | 1386 | newval = (uval & FUTEX_OWNER_DIED) | newtid; |
1370 | newval |= (uval & FUTEX_WAITER_REQUEUED); | 1387 | newval |= (uval & FUTEX_WAITER_REQUEUED); |
1388 | |||
1389 | pagefault_disable(); | ||
1371 | curval = futex_atomic_cmpxchg_inatomic(uaddr, | 1390 | curval = futex_atomic_cmpxchg_inatomic(uaddr, |
1372 | uval, newval); | 1391 | uval, newval); |
1392 | pagefault_enable(); | ||
1393 | |||
1373 | if (curval == -EFAULT) | 1394 | if (curval == -EFAULT) |
1374 | ret = -EFAULT; | 1395 | ret = -EFAULT; |
1375 | if (curval == uval) | 1396 | if (curval == uval) |
1376 | break; | 1397 | break; |
1377 | uval = curval; | 1398 | uval = curval; |
@@ -1553,10 +1574,7 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1553 | */ | 1574 | */ |
1554 | uaddr = q.pi_state->key.uaddr; | 1575 | uaddr = q.pi_state->key.uaddr; |
1555 | 1576 | ||
1556 | /* mmap_sem and hash_bucket lock are unlocked at | 1577 | ret = fixup_pi_state_owner(uaddr, &q, curr); |
1557 | return of this function */ | ||
1558 | ret = fixup_pi_state_owner(uaddr, fshared, | ||
1559 | &q, hb, curr); | ||
1560 | } else { | 1578 | } else { |
1561 | /* | 1579 | /* |
1562 | * Catch the rare case, where the lock was released | 1580 | * Catch the rare case, where the lock was released |
@@ -1567,12 +1585,13 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1567 | if (rt_mutex_trylock(&q.pi_state->pi_mutex)) | 1585 | if (rt_mutex_trylock(&q.pi_state->pi_mutex)) |
1568 | ret = 0; | 1586 | ret = 0; |
1569 | } | 1587 | } |
1570 | /* Unqueue and drop the lock */ | ||
1571 | unqueue_me_pi(&q); | ||
1572 | if (fshared) | ||
1573 | up_read(fshared); | ||
1574 | } | 1588 | } |
1575 | 1589 | ||
1590 | /* Unqueue and drop the lock */ | ||
1591 | unqueue_me_pi(&q); | ||
1592 | if (fshared) | ||
1593 | up_read(fshared); | ||
1594 | |||
1576 | debug_rt_mutex_free_waiter(&q.waiter); | 1595 | debug_rt_mutex_free_waiter(&q.waiter); |
1577 | 1596 | ||
1578 | return ret; | 1597 | return ret; |
@@ -1688,7 +1707,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1688 | struct futex_hash_bucket *hb; | 1707 | struct futex_hash_bucket *hb; |
1689 | u32 uval, newval, curval; | 1708 | u32 uval, newval, curval; |
1690 | struct futex_q q; | 1709 | struct futex_q q; |
1691 | int ret, lock_held, attempt = 0; | 1710 | int ret, lock_taken, ownerdied = 0, attempt = 0; |
1692 | 1711 | ||
1693 | if (refill_pi_state_cache()) | 1712 | if (refill_pi_state_cache()) |
1694 | return -ENOMEM; | 1713 | return -ENOMEM; |
@@ -1709,10 +1728,11 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1709 | if (unlikely(ret != 0)) | 1728 | if (unlikely(ret != 0)) |
1710 | goto out_release_sem; | 1729 | goto out_release_sem; |
1711 | 1730 | ||
1731 | retry_unlocked: | ||
1712 | hb = queue_lock(&q, -1, NULL); | 1732 | hb = queue_lock(&q, -1, NULL); |
1713 | 1733 | ||
1714 | retry_locked: | 1734 | retry_locked: |
1715 | lock_held = 0; | 1735 | ret = lock_taken = 0; |
1716 | 1736 | ||
1717 | /* | 1737 | /* |
1718 | * To avoid races, we attempt to take the lock here again | 1738 | * To avoid races, we attempt to take the lock here again |
@@ -1728,43 +1748,44 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1728 | if (unlikely(curval == -EFAULT)) | 1748 | if (unlikely(curval == -EFAULT)) |
1729 | goto uaddr_faulted; | 1749 | goto uaddr_faulted; |
1730 | 1750 | ||
1731 | /* We own the lock already */ | 1751 | /* |
1752 | * Detect deadlocks. In case of REQUEUE_PI this is a valid | ||
1753 | * situation and we return success to user space. | ||
1754 | */ | ||
1732 | if (unlikely((curval & FUTEX_TID_MASK) == current->pid)) { | 1755 | if (unlikely((curval & FUTEX_TID_MASK) == current->pid)) { |
1733 | if (!detect && 0) | ||
1734 | force_sig(SIGKILL, current); | ||
1735 | /* | ||
1736 | * Normally, this check is done in user space. | ||
1737 | * In case of requeue, the owner may attempt to lock this futex, | ||
1738 | * even if the ownership has already been given by the previous | ||
1739 | * waker. | ||
1740 | * In the usual case, this is a case of deadlock, but not in case | ||
1741 | * of REQUEUE_PI. | ||
1742 | */ | ||
1743 | if (!(curval & FUTEX_WAITER_REQUEUED)) | 1756 | if (!(curval & FUTEX_WAITER_REQUEUED)) |
1744 | ret = -EDEADLK; | 1757 | ret = -EDEADLK; |
1745 | goto out_unlock_release_sem; | 1758 | goto out_unlock_release_sem; |
1746 | } | 1759 | } |
1747 | 1760 | ||
1748 | /* | 1761 | /* |
1749 | * Surprise - we got the lock. Just return | 1762 | * Surprise - we got the lock. Just return to userspace: |
1750 | * to userspace: | ||
1751 | */ | 1763 | */ |
1752 | if (unlikely(!curval)) | 1764 | if (unlikely(!curval)) |
1753 | goto out_unlock_release_sem; | 1765 | goto out_unlock_release_sem; |
1754 | 1766 | ||
1755 | uval = curval; | 1767 | uval = curval; |
1768 | |||
1756 | /* | 1769 | /* |
1757 | * In case of a requeue, check if there already is an owner | 1770 | * Set the WAITERS flag, so the owner will know it has someone |
1758 | * If not, just take the futex. | 1771 | * to wake at next unlock |
1759 | */ | 1772 | */ |
1760 | if ((curval & FUTEX_WAITER_REQUEUED) && !(curval & FUTEX_TID_MASK)) { | 1773 | newval = curval | FUTEX_WAITERS; |
1761 | /* set current as futex owner */ | 1774 | |
1762 | newval = curval | current->pid; | 1775 | /* |
1763 | lock_held = 1; | 1776 | * There are two cases, where a futex might have no owner (the |
1764 | } else | 1777 | * owner TID is 0): OWNER_DIED or REQUEUE. We take over the |
1765 | /* Set the WAITERS flag, so the owner will know it has someone | 1778 | * futex in this case. We also do an unconditional take over, |
1766 | to wake at next unlock */ | 1779 | * when the owner of the futex died. |
1767 | newval = curval | FUTEX_WAITERS; | 1780 | * |
1781 | * This is safe as we are protected by the hash bucket lock ! | ||
1782 | */ | ||
1783 | if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) { | ||
1784 | /* Keep the OWNER_DIED and REQUEUE bits */ | ||
1785 | newval = (curval & ~FUTEX_TID_MASK) | current->pid; | ||
1786 | ownerdied = 0; | ||
1787 | lock_taken = 1; | ||
1788 | } | ||
1768 | 1789 | ||
1769 | pagefault_disable(); | 1790 | pagefault_disable(); |
1770 | curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); | 1791 | curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); |
@@ -1775,8 +1796,13 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1775 | if (unlikely(curval != uval)) | 1796 | if (unlikely(curval != uval)) |
1776 | goto retry_locked; | 1797 | goto retry_locked; |
1777 | 1798 | ||
1778 | if (lock_held) { | 1799 | /* |
1779 | set_pi_futex_owner(hb, &q.key, curr); | 1800 | * We took the lock due to requeue or owner died take over. |
1801 | */ | ||
1802 | if (unlikely(lock_taken)) { | ||
1803 | /* For requeue we need to fixup the pi_futex */ | ||
1804 | if (curval & FUTEX_WAITER_REQUEUED) | ||
1805 | set_pi_futex_owner(hb, &q.key, curr); | ||
1780 | goto out_unlock_release_sem; | 1806 | goto out_unlock_release_sem; |
1781 | } | 1807 | } |
1782 | 1808 | ||
@@ -1787,34 +1813,40 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1787 | ret = lookup_pi_state(uval, hb, &q.key, &q.pi_state); | 1813 | ret = lookup_pi_state(uval, hb, &q.key, &q.pi_state); |
1788 | 1814 | ||
1789 | if (unlikely(ret)) { | 1815 | if (unlikely(ret)) { |
1790 | /* | 1816 | switch (ret) { |
1791 | * There were no waiters and the owner task lookup | ||
1792 | * failed. When the OWNER_DIED bit is set, then we | ||
1793 | * know that this is a robust futex and we actually | ||
1794 | * take the lock. This is safe as we are protected by | ||
1795 | * the hash bucket lock. We also set the waiters bit | ||
1796 | * unconditionally here, to simplify glibc handling of | ||
1797 | * multiple tasks racing to acquire the lock and | ||
1798 | * cleanup the problems which were left by the dead | ||
1799 | * owner. | ||
1800 | */ | ||
1801 | if (curval & FUTEX_OWNER_DIED) { | ||
1802 | uval = newval; | ||
1803 | newval = current->pid | | ||
1804 | FUTEX_OWNER_DIED | FUTEX_WAITERS; | ||
1805 | 1817 | ||
1806 | pagefault_disable(); | 1818 | case -EAGAIN: |
1807 | curval = futex_atomic_cmpxchg_inatomic(uaddr, | 1819 | /* |
1808 | uval, newval); | 1820 | * Task is exiting and we just wait for the |
1809 | pagefault_enable(); | 1821 | * exit to complete. |
1822 | */ | ||
1823 | queue_unlock(&q, hb); | ||
1824 | if (fshared) | ||
1825 | up_read(fshared); | ||
1826 | cond_resched(); | ||
1827 | goto retry; | ||
1810 | 1828 | ||
1811 | if (unlikely(curval == -EFAULT)) | 1829 | case -ESRCH: |
1830 | /* | ||
1831 | * No owner found for this futex. Check if the | ||
1832 | * OWNER_DIED bit is set to figure out whether | ||
1833 | * this is a robust futex or not. | ||
1834 | */ | ||
1835 | if (get_futex_value_locked(&curval, uaddr)) | ||
1812 | goto uaddr_faulted; | 1836 | goto uaddr_faulted; |
1813 | if (unlikely(curval != uval)) | 1837 | |
1838 | /* | ||
1839 | * We simply start over in case of a robust | ||
1840 | * futex. The code above will take the futex | ||
1841 | * and return happy. | ||
1842 | */ | ||
1843 | if (curval & FUTEX_OWNER_DIED) { | ||
1844 | ownerdied = 1; | ||
1814 | goto retry_locked; | 1845 | goto retry_locked; |
1815 | ret = 0; | 1846 | } |
1847 | default: | ||
1848 | goto out_unlock_release_sem; | ||
1816 | } | 1849 | } |
1817 | goto out_unlock_release_sem; | ||
1818 | } | 1850 | } |
1819 | 1851 | ||
1820 | /* | 1852 | /* |
@@ -1845,31 +1877,42 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1845 | down_read(fshared); | 1877 | down_read(fshared); |
1846 | spin_lock(q.lock_ptr); | 1878 | spin_lock(q.lock_ptr); |
1847 | 1879 | ||
1848 | /* | 1880 | if (!ret) { |
1849 | * Got the lock. We might not be the anticipated owner if we | 1881 | /* |
1850 | * did a lock-steal - fix up the PI-state in that case. | 1882 | * Got the lock. We might not be the anticipated owner |
1851 | */ | 1883 | * if we did a lock-steal - fix up the PI-state in |
1852 | if (!ret && q.pi_state->owner != curr) | 1884 | * that case: |
1853 | /* mmap_sem is unlocked at return of this function */ | 1885 | */ |
1854 | ret = fixup_pi_state_owner(uaddr, fshared, &q, hb, curr); | 1886 | if (q.pi_state->owner != curr) |
1855 | else { | 1887 | ret = fixup_pi_state_owner(uaddr, &q, curr); |
1888 | } else { | ||
1856 | /* | 1889 | /* |
1857 | * Catch the rare case, where the lock was released | 1890 | * Catch the rare case, where the lock was released |
1858 | * when we were on the way back before we locked | 1891 | * when we were on the way back before we locked the |
1859 | * the hash bucket. | 1892 | * hash bucket. |
1860 | */ | 1893 | */ |
1861 | if (ret && q.pi_state->owner == curr) { | 1894 | if (q.pi_state->owner == curr && |
1862 | if (rt_mutex_trylock(&q.pi_state->pi_mutex)) | 1895 | rt_mutex_trylock(&q.pi_state->pi_mutex)) { |
1863 | ret = 0; | 1896 | ret = 0; |
1897 | } else { | ||
1898 | /* | ||
1899 | * Paranoia check. If we did not take the lock | ||
1900 | * in the trylock above, then we should not be | ||
1901 | * the owner of the rtmutex, neither the real | ||
1902 | * nor the pending one: | ||
1903 | */ | ||
1904 | if (rt_mutex_owner(&q.pi_state->pi_mutex) == curr) | ||
1905 | printk(KERN_ERR "futex_lock_pi: ret = %d " | ||
1906 | "pi-mutex: %p pi-state %p\n", ret, | ||
1907 | q.pi_state->pi_mutex.owner, | ||
1908 | q.pi_state->owner); | ||
1864 | } | 1909 | } |
1865 | /* Unqueue and drop the lock */ | ||
1866 | unqueue_me_pi(&q); | ||
1867 | if (fshared) | ||
1868 | up_read(fshared); | ||
1869 | } | 1910 | } |
1870 | 1911 | ||
1871 | if (!detect && ret == -EDEADLK && 0) | 1912 | /* Unqueue and drop the lock */ |
1872 | force_sig(SIGKILL, current); | 1913 | unqueue_me_pi(&q); |
1914 | if (fshared) | ||
1915 | up_read(fshared); | ||
1873 | 1916 | ||
1874 | return ret != -EINTR ? ret : -ERESTARTNOINTR; | 1917 | return ret != -EINTR ? ret : -ERESTARTNOINTR; |
1875 | 1918 | ||
@@ -1887,16 +1930,19 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, | |||
1887 | * non-atomically. Therefore, if get_user below is not | 1930 | * non-atomically. Therefore, if get_user below is not |
1888 | * enough, we need to handle the fault ourselves, while | 1931 | * enough, we need to handle the fault ourselves, while |
1889 | * still holding the mmap_sem. | 1932 | * still holding the mmap_sem. |
1933 | * | ||
1934 | * ... and hb->lock. :-) --ANK | ||
1890 | */ | 1935 | */ |
1936 | queue_unlock(&q, hb); | ||
1937 | |||
1891 | if (attempt++) { | 1938 | if (attempt++) { |
1892 | ret = futex_handle_fault((unsigned long)uaddr, fshared, | 1939 | ret = futex_handle_fault((unsigned long)uaddr, fshared, |
1893 | attempt); | 1940 | attempt); |
1894 | if (ret) | 1941 | if (ret) |
1895 | goto out_unlock_release_sem; | 1942 | goto out_release_sem; |
1896 | goto retry_locked; | 1943 | goto retry_unlocked; |
1897 | } | 1944 | } |
1898 | 1945 | ||
1899 | queue_unlock(&q, hb); | ||
1900 | if (fshared) | 1946 | if (fshared) |
1901 | up_read(fshared); | 1947 | up_read(fshared); |
1902 | 1948 | ||
@@ -1940,9 +1986,9 @@ retry: | |||
1940 | goto out; | 1986 | goto out; |
1941 | 1987 | ||
1942 | hb = hash_futex(&key); | 1988 | hb = hash_futex(&key); |
1989 | retry_unlocked: | ||
1943 | spin_lock(&hb->lock); | 1990 | spin_lock(&hb->lock); |
1944 | 1991 | ||
1945 | retry_locked: | ||
1946 | /* | 1992 | /* |
1947 | * To avoid races, try to do the TID -> 0 atomic transition | 1993 | * To avoid races, try to do the TID -> 0 atomic transition |
1948 | * again. If it succeeds then we can return without waking | 1994 | * again. If it succeeds then we can return without waking |
@@ -2005,16 +2051,19 @@ pi_faulted: | |||
2005 | * non-atomically. Therefore, if get_user below is not | 2051 | * non-atomically. Therefore, if get_user below is not |
2006 | * enough, we need to handle the fault ourselves, while | 2052 | * enough, we need to handle the fault ourselves, while |
2007 | * still holding the mmap_sem. | 2053 | * still holding the mmap_sem. |
2054 | * | ||
2055 | * ... and hb->lock. --ANK | ||
2008 | */ | 2056 | */ |
2057 | spin_unlock(&hb->lock); | ||
2058 | |||
2009 | if (attempt++) { | 2059 | if (attempt++) { |
2010 | ret = futex_handle_fault((unsigned long)uaddr, fshared, | 2060 | ret = futex_handle_fault((unsigned long)uaddr, fshared, |
2011 | attempt); | 2061 | attempt); |
2012 | if (ret) | 2062 | if (ret) |
2013 | goto out_unlock; | 2063 | goto out; |
2014 | goto retry_locked; | 2064 | goto retry_unlocked; |
2015 | } | 2065 | } |
2016 | 2066 | ||
2017 | spin_unlock(&hb->lock); | ||
2018 | if (fshared) | 2067 | if (fshared) |
2019 | up_read(fshared); | 2068 | up_read(fshared); |
2020 | 2069 | ||
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c index 12879f6c1ec3..a6fbb4130521 100644 --- a/kernel/rtmutex.c +++ b/kernel/rtmutex.c | |||
@@ -189,6 +189,19 @@ int rt_mutex_adjust_prio_chain(struct task_struct *task, | |||
189 | if (!waiter || !waiter->task) | 189 | if (!waiter || !waiter->task) |
190 | goto out_unlock_pi; | 190 | goto out_unlock_pi; |
191 | 191 | ||
192 | /* | ||
193 | * Check the orig_waiter state. After we dropped the locks, | ||
194 | * the previous owner of the lock might have released the lock | ||
195 | * and made us the pending owner: | ||
196 | */ | ||
197 | if (orig_waiter && !orig_waiter->task) | ||
198 | goto out_unlock_pi; | ||
199 | |||
200 | /* | ||
201 | * Drop out, when the task has no waiters. Note, | ||
202 | * top_waiter can be NULL, when we are in the deboosting | ||
203 | * mode! | ||
204 | */ | ||
192 | if (top_waiter && (!task_has_pi_waiters(task) || | 205 | if (top_waiter && (!task_has_pi_waiters(task) || |
193 | top_waiter != task_top_pi_waiter(task))) | 206 | top_waiter != task_top_pi_waiter(task))) |
194 | goto out_unlock_pi; | 207 | goto out_unlock_pi; |
@@ -636,9 +649,16 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state, | |||
636 | * all over without going into schedule to try | 649 | * all over without going into schedule to try |
637 | * to get the lock now: | 650 | * to get the lock now: |
638 | */ | 651 | */ |
639 | if (unlikely(!waiter.task)) | 652 | if (unlikely(!waiter.task)) { |
653 | /* | ||
654 | * Reset the return value. We might | ||
655 | * have returned with -EDEADLK and the | ||
656 | * owner released the lock while we | ||
657 | * were walking the pi chain. | ||
658 | */ | ||
659 | ret = 0; | ||
640 | continue; | 660 | continue; |
641 | 661 | } | |
642 | if (unlikely(ret)) | 662 | if (unlikely(ret)) |
643 | break; | 663 | break; |
644 | } | 664 | } |
diff --git a/lib/hexdump.c b/lib/hexdump.c index e6da5b7fc29a..473f5aed6cae 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -16,42 +16,98 @@ | |||
16 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory | 16 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
17 | * @buf: data blob to dump | 17 | * @buf: data blob to dump |
18 | * @len: number of bytes in the @buf | 18 | * @len: number of bytes in the @buf |
19 | * @rowsize: number of bytes to print per line; must be 16 or 32 | ||
20 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) | ||
19 | * @linebuf: where to put the converted data | 21 | * @linebuf: where to put the converted data |
20 | * @linebuflen: total size of @linebuf, including space for terminating NUL | 22 | * @linebuflen: total size of @linebuf, including space for terminating NUL |
23 | * @ascii: include ASCII after the hex output | ||
21 | * | 24 | * |
22 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., | 25 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., |
23 | * 16 bytes of input data converted to hex + ASCII output. | 26 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
24 | * | 27 | * |
25 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data | 28 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data |
26 | * to a hex + ASCII dump at the supplied memory location. | 29 | * to a hex + ASCII dump at the supplied memory location. |
27 | * The converted output is always NUL-terminated. | 30 | * The converted output is always NUL-terminated. |
28 | * | 31 | * |
29 | * E.g.: | 32 | * E.g.: |
30 | * hex_dump_to_buffer(frame->data, frame->len, linebuf, sizeof(linebuf)); | 33 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
34 | * linebuf, sizeof(linebuf), 1); | ||
31 | * | 35 | * |
32 | * example output buffer: | 36 | * example output buffer: |
33 | * 40414243 44454647 48494a4b 4c4d4e4f @ABCDEFGHIJKLMNO | 37 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
34 | */ | 38 | */ |
35 | void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf, | 39 | void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, |
36 | size_t linebuflen) | 40 | int groupsize, char *linebuf, size_t linebuflen, |
41 | bool ascii) | ||
37 | { | 42 | { |
38 | const u8 *ptr = buf; | 43 | const u8 *ptr = buf; |
39 | u8 ch; | 44 | u8 ch; |
40 | int j, lx = 0; | 45 | int j, lx = 0; |
46 | int ascii_column; | ||
41 | 47 | ||
42 | for (j = 0; (j < 16) && (j < len) && (lx + 3) < linebuflen; j++) { | 48 | if (rowsize != 16 && rowsize != 32) |
43 | if (j && !(j % 4)) | 49 | rowsize = 16; |
50 | |||
51 | if (!len) | ||
52 | goto nil; | ||
53 | if (len > rowsize) /* limit to one line at a time */ | ||
54 | len = rowsize; | ||
55 | if ((len % groupsize) != 0) /* no mixed size output */ | ||
56 | groupsize = 1; | ||
57 | |||
58 | switch (groupsize) { | ||
59 | case 8: { | ||
60 | const u64 *ptr8 = buf; | ||
61 | int ngroups = len / groupsize; | ||
62 | |||
63 | for (j = 0; j < ngroups; j++) | ||
64 | lx += scnprintf(linebuf + lx, linebuflen - lx, | ||
65 | "%16.16llx ", (unsigned long long)*(ptr8 + j)); | ||
66 | ascii_column = 17 * ngroups + 2; | ||
67 | break; | ||
68 | } | ||
69 | |||
70 | case 4: { | ||
71 | const u32 *ptr4 = buf; | ||
72 | int ngroups = len / groupsize; | ||
73 | |||
74 | for (j = 0; j < ngroups; j++) | ||
75 | lx += scnprintf(linebuf + lx, linebuflen - lx, | ||
76 | "%8.8x ", *(ptr4 + j)); | ||
77 | ascii_column = 9 * ngroups + 2; | ||
78 | break; | ||
79 | } | ||
80 | |||
81 | case 2: { | ||
82 | const u16 *ptr2 = buf; | ||
83 | int ngroups = len / groupsize; | ||
84 | |||
85 | for (j = 0; j < ngroups; j++) | ||
86 | lx += scnprintf(linebuf + lx, linebuflen - lx, | ||
87 | "%4.4x ", *(ptr2 + j)); | ||
88 | ascii_column = 5 * ngroups + 2; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | default: | ||
93 | for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen; | ||
94 | j++) { | ||
95 | ch = ptr[j]; | ||
96 | linebuf[lx++] = hex_asc(ch >> 4); | ||
97 | linebuf[lx++] = hex_asc(ch & 0x0f); | ||
44 | linebuf[lx++] = ' '; | 98 | linebuf[lx++] = ' '; |
45 | ch = ptr[j]; | 99 | } |
46 | linebuf[lx++] = hex_asc(ch >> 4); | 100 | ascii_column = 3 * rowsize + 2; |
47 | linebuf[lx++] = hex_asc(ch & 0x0f); | 101 | break; |
48 | } | 102 | } |
49 | if ((lx + 2) < linebuflen) { | 103 | if (!ascii) |
50 | linebuf[lx++] = ' '; | 104 | goto nil; |
105 | |||
106 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) | ||
51 | linebuf[lx++] = ' '; | 107 | linebuf[lx++] = ' '; |
52 | } | 108 | for (j = 0; (j < rowsize) && (j < len) && (lx + 2) < linebuflen; j++) |
53 | for (j = 0; (j < 16) && (j < len) && (lx + 2) < linebuflen; j++) | ||
54 | linebuf[lx++] = isprint(ptr[j]) ? ptr[j] : '.'; | 109 | linebuf[lx++] = isprint(ptr[j]) ? ptr[j] : '.'; |
110 | nil: | ||
55 | linebuf[lx++] = '\0'; | 111 | linebuf[lx++] = '\0'; |
56 | } | 112 | } |
57 | EXPORT_SYMBOL(hex_dump_to_buffer); | 113 | EXPORT_SYMBOL(hex_dump_to_buffer); |
@@ -59,46 +115,83 @@ EXPORT_SYMBOL(hex_dump_to_buffer); | |||
59 | /** | 115 | /** |
60 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data | 116 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data |
61 | * @level: kernel log level (e.g. KERN_DEBUG) | 117 | * @level: kernel log level (e.g. KERN_DEBUG) |
118 | * @prefix_str: string to prefix each line with; | ||
119 | * caller supplies trailing spaces for alignment if desired | ||
62 | * @prefix_type: controls whether prefix of an offset, address, or none | 120 | * @prefix_type: controls whether prefix of an offset, address, or none |
63 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) | 121 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
122 | * @rowsize: number of bytes to print per line; must be 16 or 32 | ||
123 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) | ||
64 | * @buf: data blob to dump | 124 | * @buf: data blob to dump |
65 | * @len: number of bytes in the @buf | 125 | * @len: number of bytes in the @buf |
126 | * @ascii: include ASCII after the hex output | ||
66 | * | 127 | * |
67 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump | 128 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump |
68 | * to the kernel log at the specified kernel log level, with an optional | 129 | * to the kernel log at the specified kernel log level, with an optional |
69 | * leading prefix. | 130 | * leading prefix. |
70 | * | 131 | * |
132 | * print_hex_dump() works on one "line" of output at a time, i.e., | ||
133 | * 16 or 32 bytes of input data converted to hex + ASCII output. | ||
134 | * print_hex_dump() iterates over the entire input @buf, breaking it into | ||
135 | * "line size" chunks to format and print. | ||
136 | * | ||
71 | * E.g.: | 137 | * E.g.: |
72 | * print_hex_dump(KERN_DEBUG, DUMP_PREFIX_ADDRESS, frame->data, frame->len); | 138 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
139 | * 16, 1, frame->data, frame->len, 1); | ||
73 | * | 140 | * |
74 | * Example output using %DUMP_PREFIX_OFFSET: | 141 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
75 | * 0009ab42: 40414243 44454647 48494a4b 4c4d4e4f @ABCDEFGHIJKLMNO | 142 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
76 | * Example output using %DUMP_PREFIX_ADDRESS: | 143 | * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: |
77 | * ffffffff88089af0: 70717273 74757677 78797a7b 7c7d7e7f pqrstuvwxyz{|}~. | 144 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
78 | */ | 145 | */ |
79 | void print_hex_dump(const char *level, int prefix_type, void *buf, size_t len) | 146 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
147 | int rowsize, int groupsize, | ||
148 | void *buf, size_t len, bool ascii) | ||
80 | { | 149 | { |
81 | u8 *ptr = buf; | 150 | u8 *ptr = buf; |
82 | int i, linelen, remaining = len; | 151 | int i, linelen, remaining = len; |
83 | unsigned char linebuf[100]; | 152 | unsigned char linebuf[200]; |
84 | 153 | ||
85 | for (i = 0; i < len; i += 16) { | 154 | if (rowsize != 16 && rowsize != 32) |
86 | linelen = min(remaining, 16); | 155 | rowsize = 16; |
87 | remaining -= 16; | 156 | |
88 | hex_dump_to_buffer(ptr + i, linelen, linebuf, sizeof(linebuf)); | 157 | for (i = 0; i < len; i += rowsize) { |
158 | linelen = min(remaining, rowsize); | ||
159 | remaining -= rowsize; | ||
160 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, | ||
161 | linebuf, sizeof(linebuf), ascii); | ||
89 | 162 | ||
90 | switch (prefix_type) { | 163 | switch (prefix_type) { |
91 | case DUMP_PREFIX_ADDRESS: | 164 | case DUMP_PREFIX_ADDRESS: |
92 | printk("%s%*p: %s\n", level, | 165 | printk("%s%s%*p: %s\n", level, prefix_str, |
93 | (int)(2 * sizeof(void *)), ptr + i, linebuf); | 166 | (int)(2 * sizeof(void *)), ptr + i, linebuf); |
94 | break; | 167 | break; |
95 | case DUMP_PREFIX_OFFSET: | 168 | case DUMP_PREFIX_OFFSET: |
96 | printk("%s%.8x: %s\n", level, i, linebuf); | 169 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
97 | break; | 170 | break; |
98 | default: | 171 | default: |
99 | printk("%s%s\n", level, linebuf); | 172 | printk("%s%s%s\n", level, prefix_str, linebuf); |
100 | break; | 173 | break; |
101 | } | 174 | } |
102 | } | 175 | } |
103 | } | 176 | } |
104 | EXPORT_SYMBOL(print_hex_dump); | 177 | EXPORT_SYMBOL(print_hex_dump); |
178 | |||
179 | /** | ||
180 | * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params | ||
181 | * @prefix_str: string to prefix each line with; | ||
182 | * caller supplies trailing spaces for alignment if desired | ||
183 | * @prefix_type: controls whether prefix of an offset, address, or none | ||
184 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) | ||
185 | * @buf: data blob to dump | ||
186 | * @len: number of bytes in the @buf | ||
187 | * | ||
188 | * Calls print_hex_dump(), with log level of KERN_DEBUG, | ||
189 | * rowsize of 16, groupsize of 1, and ASCII output included. | ||
190 | */ | ||
191 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | ||
192 | void *buf, size_t len) | ||
193 | { | ||
194 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, | ||
195 | buf, len, 1); | ||
196 | } | ||
197 | EXPORT_SYMBOL(print_hex_dump_bytes); | ||
diff --git a/mm/shmem.c b/mm/shmem.c index e537317bec4d..b6aae2b33393 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -967,6 +967,8 @@ static inline int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_ | |||
967 | *nodelist++ = '\0'; | 967 | *nodelist++ = '\0'; |
968 | if (nodelist_parse(nodelist, *policy_nodes)) | 968 | if (nodelist_parse(nodelist, *policy_nodes)) |
969 | goto out; | 969 | goto out; |
970 | if (!nodes_subset(*policy_nodes, node_online_map)) | ||
971 | goto out; | ||
970 | } | 972 | } |
971 | if (!strcmp(value, "default")) { | 973 | if (!strcmp(value, "default")) { |
972 | *policy = MPOL_DEFAULT; | 974 | *policy = MPOL_DEFAULT; |
@@ -3539,7 +3539,7 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) | |||
3539 | check_irq_off(); | 3539 | check_irq_off(); |
3540 | objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); | 3540 | objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); |
3541 | 3541 | ||
3542 | if (use_alien_caches && cache_free_alien(cachep, objp)) | 3542 | if (cache_free_alien(cachep, objp)) |
3543 | return; | 3543 | return; |
3544 | 3544 | ||
3545 | if (likely(ac->avail < ac->limit)) { | 3545 | if (likely(ac->avail < ac->limit)) { |
@@ -2241,7 +2241,7 @@ void *__kmalloc(size_t size, gfp_t flags) | |||
2241 | 2241 | ||
2242 | if (s) | 2242 | if (s) |
2243 | return slab_alloc(s, flags, -1, __builtin_return_address(0)); | 2243 | return slab_alloc(s, flags, -1, __builtin_return_address(0)); |
2244 | return NULL; | 2244 | return ZERO_SIZE_PTR; |
2245 | } | 2245 | } |
2246 | EXPORT_SYMBOL(__kmalloc); | 2246 | EXPORT_SYMBOL(__kmalloc); |
2247 | 2247 | ||
@@ -2252,16 +2252,20 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) | |||
2252 | 2252 | ||
2253 | if (s) | 2253 | if (s) |
2254 | return slab_alloc(s, flags, node, __builtin_return_address(0)); | 2254 | return slab_alloc(s, flags, node, __builtin_return_address(0)); |
2255 | return NULL; | 2255 | return ZERO_SIZE_PTR; |
2256 | } | 2256 | } |
2257 | EXPORT_SYMBOL(__kmalloc_node); | 2257 | EXPORT_SYMBOL(__kmalloc_node); |
2258 | #endif | 2258 | #endif |
2259 | 2259 | ||
2260 | size_t ksize(const void *object) | 2260 | size_t ksize(const void *object) |
2261 | { | 2261 | { |
2262 | struct page *page = get_object_page(object); | 2262 | struct page *page; |
2263 | struct kmem_cache *s; | 2263 | struct kmem_cache *s; |
2264 | 2264 | ||
2265 | if (object == ZERO_SIZE_PTR) | ||
2266 | return 0; | ||
2267 | |||
2268 | page = get_object_page(object); | ||
2265 | BUG_ON(!page); | 2269 | BUG_ON(!page); |
2266 | s = page->slab; | 2270 | s = page->slab; |
2267 | BUG_ON(!s); | 2271 | BUG_ON(!s); |
@@ -2293,7 +2297,13 @@ void kfree(const void *x) | |||
2293 | struct kmem_cache *s; | 2297 | struct kmem_cache *s; |
2294 | struct page *page; | 2298 | struct page *page; |
2295 | 2299 | ||
2296 | if (!x) | 2300 | /* |
2301 | * This has to be an unsigned comparison. According to Linus | ||
2302 | * some gcc version treat a pointer as a signed entity. Then | ||
2303 | * this comparison would be true for all "negative" pointers | ||
2304 | * (which would cover the whole upper half of the address space). | ||
2305 | */ | ||
2306 | if ((unsigned long)x <= (unsigned long)ZERO_SIZE_PTR) | ||
2297 | return; | 2307 | return; |
2298 | 2308 | ||
2299 | page = virt_to_head_page(x); | 2309 | page = virt_to_head_page(x); |
@@ -2398,12 +2408,12 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) | |||
2398 | void *ret; | 2408 | void *ret; |
2399 | size_t ks; | 2409 | size_t ks; |
2400 | 2410 | ||
2401 | if (unlikely(!p)) | 2411 | if (unlikely(!p || p == ZERO_SIZE_PTR)) |
2402 | return kmalloc(new_size, flags); | 2412 | return kmalloc(new_size, flags); |
2403 | 2413 | ||
2404 | if (unlikely(!new_size)) { | 2414 | if (unlikely(!new_size)) { |
2405 | kfree(p); | 2415 | kfree(p); |
2406 | return NULL; | 2416 | return ZERO_SIZE_PTR; |
2407 | } | 2417 | } |
2408 | 2418 | ||
2409 | ks = ksize(p); | 2419 | ks = ksize(p); |
@@ -2652,7 +2662,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, void *caller) | |||
2652 | struct kmem_cache *s = get_slab(size, gfpflags); | 2662 | struct kmem_cache *s = get_slab(size, gfpflags); |
2653 | 2663 | ||
2654 | if (!s) | 2664 | if (!s) |
2655 | return NULL; | 2665 | return ZERO_SIZE_PTR; |
2656 | 2666 | ||
2657 | return slab_alloc(s, gfpflags, -1, caller); | 2667 | return slab_alloc(s, gfpflags, -1, caller); |
2658 | } | 2668 | } |
@@ -2663,7 +2673,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags, | |||
2663 | struct kmem_cache *s = get_slab(size, gfpflags); | 2673 | struct kmem_cache *s = get_slab(size, gfpflags); |
2664 | 2674 | ||
2665 | if (!s) | 2675 | if (!s) |
2666 | return NULL; | 2676 | return ZERO_SIZE_PTR; |
2667 | 2677 | ||
2668 | return slab_alloc(s, gfpflags, node, caller); | 2678 | return slab_alloc(s, gfpflags, node, caller); |
2669 | } | 2679 | } |
diff --git a/mm/sparse.c b/mm/sparse.c index 545e4d3afcdf..e03b39f3540f 100644 --- a/mm/sparse.c +++ b/mm/sparse.c | |||
@@ -240,6 +240,27 @@ static struct page __init *sparse_early_mem_map_alloc(unsigned long pnum) | |||
240 | return NULL; | 240 | return NULL; |
241 | } | 241 | } |
242 | 242 | ||
243 | /* | ||
244 | * Allocate the accumulated non-linear sections, allocate a mem_map | ||
245 | * for each and record the physical to section mapping. | ||
246 | */ | ||
247 | void __init sparse_init(void) | ||
248 | { | ||
249 | unsigned long pnum; | ||
250 | struct page *map; | ||
251 | |||
252 | for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) { | ||
253 | if (!valid_section_nr(pnum)) | ||
254 | continue; | ||
255 | |||
256 | map = sparse_early_mem_map_alloc(pnum); | ||
257 | if (!map) | ||
258 | continue; | ||
259 | sparse_init_one_section(__nr_to_section(pnum), pnum, map); | ||
260 | } | ||
261 | } | ||
262 | |||
263 | #ifdef CONFIG_MEMORY_HOTPLUG | ||
243 | static struct page *__kmalloc_section_memmap(unsigned long nr_pages) | 264 | static struct page *__kmalloc_section_memmap(unsigned long nr_pages) |
244 | { | 265 | { |
245 | struct page *page, *ret; | 266 | struct page *page, *ret; |
@@ -280,27 +301,6 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) | |||
280 | } | 301 | } |
281 | 302 | ||
282 | /* | 303 | /* |
283 | * Allocate the accumulated non-linear sections, allocate a mem_map | ||
284 | * for each and record the physical to section mapping. | ||
285 | */ | ||
286 | void __init sparse_init(void) | ||
287 | { | ||
288 | unsigned long pnum; | ||
289 | struct page *map; | ||
290 | |||
291 | for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) { | ||
292 | if (!valid_section_nr(pnum)) | ||
293 | continue; | ||
294 | |||
295 | map = sparse_early_mem_map_alloc(pnum); | ||
296 | if (!map) | ||
297 | continue; | ||
298 | sparse_init_one_section(__nr_to_section(pnum), pnum, map); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | #ifdef CONFIG_MEMORY_HOTPLUG | ||
303 | /* | ||
304 | * returns the number of sections whose mem_maps were properly | 304 | * returns the number of sections whose mem_maps were properly |
305 | * set. If this is <=0, then that means that the passed-in | 305 | * set. If this is <=0, then that means that the passed-in |
306 | * map was not consumed and must be freed. | 306 | * map was not consumed and must be freed. |
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e216d49624b7..aea90d30d229 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -1,14 +1,15 @@ | |||
1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) | 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) |
3 | # (c) 2005, Joel Scohpp <jschopp@austin.ibm.com> (the ugly bit) | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) | 4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) |
5 | # Licensed under the terms of the GNU GPL License version 2 | 5 | # Licensed under the terms of the GNU GPL License version 2 |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | 8 | ||
9 | my $P = $0; | 9 | my $P = $0; |
10 | $P =~ s@.*/@@g; | ||
10 | 11 | ||
11 | my $V = '0.01'; | 12 | my $V = '0.04'; |
12 | 13 | ||
13 | use Getopt::Long qw(:config no_auto_abbrev); | 14 | use Getopt::Long qw(:config no_auto_abbrev); |
14 | 15 | ||
@@ -26,7 +27,7 @@ GetOptions( | |||
26 | my $exit = 0; | 27 | my $exit = 0; |
27 | 28 | ||
28 | if ($#ARGV < 0) { | 29 | if ($#ARGV < 0) { |
29 | print "usage: patchstylecheckemail.pl [options] patchfile\n"; | 30 | print "usage: $P [options] patchfile\n"; |
30 | print "version: $V\n"; | 31 | print "version: $V\n"; |
31 | print "options: -q => quiet\n"; | 32 | print "options: -q => quiet\n"; |
32 | print " --no-tree => run without a kernel tree\n"; | 33 | print " --no-tree => run without a kernel tree\n"; |
@@ -38,7 +39,8 @@ if ($tree && !top_of_kernel_tree()) { | |||
38 | exit(2); | 39 | exit(2); |
39 | } | 40 | } |
40 | 41 | ||
41 | my @deprecated = (); | 42 | my @dep_includes = (); |
43 | my @dep_functions = (); | ||
42 | my $removal = 'Documentation/feature-removal-schedule.txt'; | 44 | my $removal = 'Documentation/feature-removal-schedule.txt'; |
43 | if ($tree && -f $removal) { | 45 | if ($tree && -f $removal) { |
44 | open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n"; | 46 | open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n"; |
@@ -46,22 +48,27 @@ if ($tree && -f $removal) { | |||
46 | if (/^Files:\s+(.*\S)/) { | 48 | if (/^Files:\s+(.*\S)/) { |
47 | for my $file (split(/[, ]+/, $1)) { | 49 | for my $file (split(/[, ]+/, $1)) { |
48 | if ($file =~ m@include/(.*)@) { | 50 | if ($file =~ m@include/(.*)@) { |
49 | push(@deprecated, $1); | 51 | push(@dep_includes, $1); |
50 | } | 52 | } |
51 | } | 53 | } |
54 | |||
55 | } elsif (/^Funcs:\s+(.*\S)/) { | ||
56 | for my $func (split(/[, ]+/, $1)) { | ||
57 | push(@dep_functions, $func); | ||
58 | } | ||
52 | } | 59 | } |
53 | } | 60 | } |
54 | } | 61 | } |
55 | 62 | ||
56 | my @lines = (); | 63 | my @rawlines = (); |
57 | while (<>) { | 64 | while (<>) { |
58 | chomp; | 65 | chomp; |
59 | push(@lines, $_); | 66 | push(@rawlines, $_); |
60 | if (eof(ARGV)) { | 67 | if (eof(ARGV)) { |
61 | if (!process($ARGV, @lines)) { | 68 | if (!process($ARGV, @rawlines)) { |
62 | $exit = 1; | 69 | $exit = 1; |
63 | } | 70 | } |
64 | @lines = (); | 71 | @rawlines = (); |
65 | } | 72 | } |
66 | } | 73 | } |
67 | 74 | ||
@@ -99,6 +106,130 @@ sub expand_tabs { | |||
99 | return $res; | 106 | return $res; |
100 | } | 107 | } |
101 | 108 | ||
109 | sub line_stats { | ||
110 | my ($line) = @_; | ||
111 | |||
112 | # Drop the diff line leader and expand tabs | ||
113 | $line =~ s/^.//; | ||
114 | $line = expand_tabs($line); | ||
115 | |||
116 | # Pick the indent from the front of the line. | ||
117 | my ($white) = ($line =~ /^(\s*)/); | ||
118 | |||
119 | return (length($line), length($white)); | ||
120 | } | ||
121 | |||
122 | sub sanitise_line { | ||
123 | my ($line) = @_; | ||
124 | |||
125 | my $res = ''; | ||
126 | my $l = ''; | ||
127 | |||
128 | my $quote = ''; | ||
129 | |||
130 | foreach my $c (split(//, $line)) { | ||
131 | if ($l ne "\\" && ($c eq "'" || $c eq '"')) { | ||
132 | if ($quote eq '') { | ||
133 | $quote = $c; | ||
134 | $res .= $c; | ||
135 | $l = $c; | ||
136 | next; | ||
137 | } elsif ($quote eq $c) { | ||
138 | $quote = ''; | ||
139 | } | ||
140 | } | ||
141 | if ($quote && $c ne "\t") { | ||
142 | $res .= "X"; | ||
143 | } else { | ||
144 | $res .= $c; | ||
145 | } | ||
146 | |||
147 | $l = $c; | ||
148 | } | ||
149 | |||
150 | return $res; | ||
151 | } | ||
152 | |||
153 | sub ctx_block_get { | ||
154 | my ($linenr, $remain, $outer) = @_; | ||
155 | my $line; | ||
156 | my $start = $linenr - 1; | ||
157 | my $blk = ''; | ||
158 | my @o; | ||
159 | my @c; | ||
160 | my @res = (); | ||
161 | |||
162 | for ($line = $start; $remain > 0; $line++) { | ||
163 | next if ($rawlines[$line] =~ /^-/); | ||
164 | $remain--; | ||
165 | |||
166 | $blk .= $rawlines[$line]; | ||
167 | |||
168 | @o = ($blk =~ /\{/g); | ||
169 | @c = ($blk =~ /\}/g); | ||
170 | |||
171 | if (!$outer || (scalar(@o) - scalar(@c)) == 1) { | ||
172 | push(@res, $rawlines[$line]); | ||
173 | } | ||
174 | |||
175 | last if (scalar(@o) == scalar(@c)); | ||
176 | } | ||
177 | |||
178 | return @res; | ||
179 | } | ||
180 | sub ctx_block_outer { | ||
181 | my ($linenr, $remain) = @_; | ||
182 | |||
183 | return ctx_block_get($linenr, $remain, 1); | ||
184 | } | ||
185 | sub ctx_block { | ||
186 | my ($linenr, $remain) = @_; | ||
187 | |||
188 | return ctx_block_get($linenr, $remain, 0); | ||
189 | } | ||
190 | |||
191 | sub ctx_locate_comment { | ||
192 | my ($first_line, $end_line) = @_; | ||
193 | |||
194 | # Catch a comment on the end of the line itself. | ||
195 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); | ||
196 | return $current_comment if (defined $current_comment); | ||
197 | |||
198 | # Look through the context and try and figure out if there is a | ||
199 | # comment. | ||
200 | my $in_comment = 0; | ||
201 | $current_comment = ''; | ||
202 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { | ||
203 | my $line = $rawlines[$linenr - 1]; | ||
204 | #warn " $line\n"; | ||
205 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { | ||
206 | $in_comment = 1; | ||
207 | } | ||
208 | if ($line =~ m@/\*@) { | ||
209 | $in_comment = 1; | ||
210 | } | ||
211 | if (!$in_comment && $current_comment ne '') { | ||
212 | $current_comment = ''; | ||
213 | } | ||
214 | $current_comment .= $line . "\n" if ($in_comment); | ||
215 | if ($line =~ m@\*/@) { | ||
216 | $in_comment = 0; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | chomp($current_comment); | ||
221 | return($current_comment); | ||
222 | } | ||
223 | sub ctx_has_comment { | ||
224 | my ($first_line, $end_line) = @_; | ||
225 | my $cmt = ctx_locate_comment($first_line, $end_line); | ||
226 | |||
227 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; | ||
228 | ##print "CMMT: $cmt\n"; | ||
229 | |||
230 | return ($cmt ne ''); | ||
231 | } | ||
232 | |||
102 | sub cat_vet { | 233 | sub cat_vet { |
103 | my ($vet) = @_; | 234 | my ($vet) = @_; |
104 | 235 | ||
@@ -116,7 +247,7 @@ sub process { | |||
116 | my $prevline=""; | 247 | my $prevline=""; |
117 | my $stashline=""; | 248 | my $stashline=""; |
118 | 249 | ||
119 | my $lineforcounting=''; | 250 | my $length; |
120 | my $indent; | 251 | my $indent; |
121 | my $previndent=0; | 252 | my $previndent=0; |
122 | my $stashindent=0; | 253 | my $stashindent=0; |
@@ -139,13 +270,14 @@ sub process { | |||
139 | #extract the filename as it passes | 270 | #extract the filename as it passes |
140 | if ($line=~/^\+\+\+\s+(\S+)/) { | 271 | if ($line=~/^\+\+\+\s+(\S+)/) { |
141 | $realfile=$1; | 272 | $realfile=$1; |
273 | $realfile =~ s@^[^/]*/@@; | ||
142 | $in_comment = 0; | 274 | $in_comment = 0; |
143 | next; | 275 | next; |
144 | } | 276 | } |
145 | #extract the line range in the file after the patch is applied | 277 | #extract the line range in the file after the patch is applied |
146 | if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) { | 278 | if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) { |
147 | $is_patch = 1; | 279 | $is_patch = 1; |
148 | $first_line = 1; | 280 | $first_line = $linenr + 1; |
149 | $in_comment = 0; | 281 | $in_comment = 0; |
150 | $realline=$1-1; | 282 | $realline=$1-1; |
151 | if (defined $2) { | 283 | if (defined $2) { |
@@ -156,10 +288,11 @@ sub process { | |||
156 | next; | 288 | next; |
157 | } | 289 | } |
158 | 290 | ||
159 | #track the line number as we move through the hunk | 291 | # track the line number as we move through the hunk, note that |
160 | if ($line=~/^[ \+]/) { | 292 | # new versions of GNU diff omit the leading space on completely |
293 | # blank context lines so we need to count that too. | ||
294 | if ($line =~ /^( |\+|$)/) { | ||
161 | $realline++; | 295 | $realline++; |
162 | $realcnt-- if ($realcnt != 0); | ||
163 | 296 | ||
164 | # track any sort of multi-line comment. Obviously if | 297 | # track any sort of multi-line comment. Obviously if |
165 | # the added text or context do not include the whole | 298 | # the added text or context do not include the whole |
@@ -168,7 +301,7 @@ sub process { | |||
168 | # Guestimate if this is a continuing comment. If this | 301 | # Guestimate if this is a continuing comment. If this |
169 | # is the start of a diff block and this line starts | 302 | # is the start of a diff block and this line starts |
170 | # ' *' then it is very likely a comment. | 303 | # ' *' then it is very likely a comment. |
171 | if ($first_line and $line =~ m@^.\s*\*@) { | 304 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
172 | $in_comment = 1; | 305 | $in_comment = 1; |
173 | } | 306 | } |
174 | if ($line =~ m@/\*@) { | 307 | if ($line =~ m@/\*@) { |
@@ -178,23 +311,20 @@ sub process { | |||
178 | $in_comment = 0; | 311 | $in_comment = 0; |
179 | } | 312 | } |
180 | 313 | ||
181 | $lineforcounting = $line; | 314 | # Measure the line length and indent. |
182 | $lineforcounting =~ s/^\+//; | 315 | ($length, $indent) = line_stats($line); |
183 | $lineforcounting = expand_tabs($lineforcounting); | ||
184 | |||
185 | my ($white) = ($lineforcounting =~ /^(\s*)/); | ||
186 | $indent = length($white); | ||
187 | 316 | ||
188 | # Track the previous line. | 317 | # Track the previous line. |
189 | ($prevline, $stashline) = ($stashline, $line); | 318 | ($prevline, $stashline) = ($stashline, $line); |
190 | ($previndent, $stashindent) = ($stashindent, $indent); | 319 | ($previndent, $stashindent) = ($stashindent, $indent); |
191 | $first_line = 0; | ||
192 | } | 320 | } |
321 | $realcnt-- if ($realcnt != 0); | ||
193 | 322 | ||
194 | #make up the handle for any error we report on this line | 323 | #make up the handle for any error we report on this line |
195 | $here = "PATCH: $ARGV:$linenr:"; | 324 | $here = "#$linenr: "; |
196 | $here .= "\nFILE: $realfile:$realline:" if ($realcnt != 0); | 325 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); |
197 | 326 | ||
327 | my $hereline = "$here\n$line\n"; | ||
198 | my $herecurr = "$here\n$line\n\n"; | 328 | my $herecurr = "$here\n$line\n\n"; |
199 | my $hereprev = "$here\n$prevline\n$line\n\n"; | 329 | my $hereprev = "$here\n$prevline\n$line\n\n"; |
200 | 330 | ||
@@ -203,6 +333,8 @@ sub process { | |||
203 | $signoff++; | 333 | $signoff++; |
204 | 334 | ||
205 | } elsif ($line =~ /^\s*signed-off-by:/i) { | 335 | } elsif ($line =~ /^\s*signed-off-by:/i) { |
336 | # This is a signoff, if ugly, so do not double report. | ||
337 | $signoff++; | ||
206 | if (!($line =~ /^\s*Signed-off-by:/)) { | 338 | if (!($line =~ /^\s*Signed-off-by:/)) { |
207 | print "use Signed-off-by:\n"; | 339 | print "use Signed-off-by:\n"; |
208 | print "$herecurr"; | 340 | print "$herecurr"; |
@@ -215,21 +347,28 @@ sub process { | |||
215 | } | 347 | } |
216 | } | 348 | } |
217 | 349 | ||
218 | #ignore lines not being added | 350 | # Check for wrappage within a valid hunk of the file |
219 | if ($line=~/^[^\+]/) {next;} | 351 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) { |
352 | print "patch seems to be corrupt (line wrapped?) [$realcnt]\n"; | ||
353 | print "$herecurr"; | ||
354 | $clean = 0; | ||
355 | } | ||
356 | |||
357 | #ignore lines being removed | ||
358 | if ($line=~/^-/) {next;} | ||
220 | 359 | ||
221 | # check we are in a valid source file *.[hcsS] if not then ignore this hunk | 360 | # check we are in a valid source file if not then ignore this hunk |
222 | next if ($realfile !~ /\.[hcsS]$/); | 361 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
223 | 362 | ||
224 | #trailing whitespace | 363 | #trailing whitespace |
225 | if ($line=~/\S\s+$/) { | 364 | if ($line=~/\+.*\S\s+$/) { |
226 | my $herevet = "$here\n" . cat_vet($line) . "\n\n"; | 365 | my $herevet = "$here\n" . cat_vet($line) . "\n\n"; |
227 | print "trailing whitespace\n"; | 366 | print "trailing whitespace\n"; |
228 | print "$herevet"; | 367 | print "$herevet"; |
229 | $clean = 0; | 368 | $clean = 0; |
230 | } | 369 | } |
231 | #80 column limit | 370 | #80 column limit |
232 | if (!($prevline=~/\/\*\*/) && length($lineforcounting) > 80) { | 371 | if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { |
233 | print "line over 80 characters\n"; | 372 | print "line over 80 characters\n"; |
234 | print "$herecurr"; | 373 | print "$herecurr"; |
235 | $clean = 0; | 374 | $clean = 0; |
@@ -253,19 +392,59 @@ sub process { | |||
253 | # | 392 | # |
254 | next if ($in_comment); | 393 | next if ($in_comment); |
255 | 394 | ||
395 | # Remove comments from the line before processing. | ||
396 | $line =~ s@/\*.*\*/@@g; | ||
397 | $line =~ s@/\*.*@@; | ||
398 | $line =~ s@.*\*/@@; | ||
399 | |||
400 | # | ||
401 | # Checks which may be anchored in the context. | ||
402 | # | ||
403 | |||
404 | # Check for switch () and associated case and default | ||
405 | # statements should be at the same indent. | ||
406 | if ($line=~/\bswitch\s*\(.*\)/) { | ||
407 | my $err = ''; | ||
408 | my $sep = ''; | ||
409 | my @ctx = ctx_block_outer($linenr, $realcnt); | ||
410 | shift(@ctx); | ||
411 | for my $ctx (@ctx) { | ||
412 | my ($clen, $cindent) = line_stats($ctx); | ||
413 | if ($ctx =~ /^\+\s*(case\s+|default:)/ && | ||
414 | $indent != $cindent) { | ||
415 | $err .= "$sep$ctx\n"; | ||
416 | $sep = ''; | ||
417 | } else { | ||
418 | $sep = "[...]\n"; | ||
419 | } | ||
420 | } | ||
421 | if ($err ne '') { | ||
422 | print "switch and case should be at the same indent\n"; | ||
423 | print "$here\n$line\n$err\n"; | ||
424 | $clean = 0; | ||
425 | } | ||
426 | } | ||
427 | |||
428 | #ignore lines not being added | ||
429 | if ($line=~/^[^\+]/) {next;} | ||
430 | |||
431 | # | ||
432 | # Checks which are anchored on the added line. | ||
433 | # | ||
434 | |||
256 | # no C99 // comments | 435 | # no C99 // comments |
257 | if ($line =~ m@//@ and !($line =~ m@\".*//.*\"@)) { | 436 | if ($line =~ m{//}) { |
258 | print "do not use C99 // comments\n"; | 437 | print "do not use C99 // comments\n"; |
259 | print "$herecurr"; | 438 | print "$herecurr"; |
260 | $clean = 0; | 439 | $clean = 0; |
261 | } | 440 | } |
262 | 441 | # Remove C99 comments. | |
263 | # Remove comments from the line before processing. | ||
264 | $line =~ s@/\*.*\*/@@g; | ||
265 | $line =~ s@/\*.*@@; | ||
266 | $line =~ s@.*\*/@@; | ||
267 | $line =~ s@//.*@@; | 442 | $line =~ s@//.*@@; |
268 | 443 | ||
444 | # Standardise the strings and chars within the input | ||
445 | # to simplify matching. | ||
446 | $line = sanitise_line($line); | ||
447 | |||
269 | #EXPORT_SYMBOL should immediately follow its function closing }. | 448 | #EXPORT_SYMBOL should immediately follow its function closing }. |
270 | if (($line =~ /EXPORT_SYMBOL.*\(.*\)/) || | 449 | if (($line =~ /EXPORT_SYMBOL.*\(.*\)/) || |
271 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\(.*\)/)) { | 450 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\(.*\)/)) { |
@@ -293,8 +472,28 @@ sub process { | |||
293 | } | 472 | } |
294 | 473 | ||
295 | # * goes on variable not on type | 474 | # * goes on variable not on type |
296 | if ($line=~/[A-Za-z\d_]+\* [A-Za-z\d_]+/) { | 475 | my $type = '(?:char|short|int|long|unsigned|float|double|' . |
297 | print "\"foo* bar\" should be \"foo *bar\"\n"; | 476 | 'struct\s+[A-Za-z\d_]+|' . |
477 | 'union\s+[A-Za-z\d_]+)'; | ||
478 | |||
479 | if ($line =~ m{[A-Za-z\d_]+(\*+) [A-Za-z\d_]+}) { | ||
480 | print "\"foo$1 bar\" should be \"foo $1bar\"\n"; | ||
481 | print "$herecurr"; | ||
482 | $clean = 0; | ||
483 | } | ||
484 | if ($line =~ m{$type (\*) [A-Za-z\d_]+} || | ||
485 | $line =~ m{[A-Za-z\d_]+ (\*\*+) [A-Za-z\d_]+}) { | ||
486 | print "\"foo $1 bar\" should be \"foo $1bar\"\n"; | ||
487 | print "$herecurr"; | ||
488 | $clean = 0; | ||
489 | } | ||
490 | if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_](\*+)\)}) { | ||
491 | print "\"(foo$1)\" should be \"(foo $1)\"\n"; | ||
492 | print "$herecurr"; | ||
493 | $clean = 0; | ||
494 | } | ||
495 | if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_]\s+(\*+)\s+\)}) { | ||
496 | print "\"(foo $1 )\" should be \"(foo $1)\"\n"; | ||
298 | print "$herecurr"; | 497 | print "$herecurr"; |
299 | $clean = 0; | 498 | $clean = 0; |
300 | } | 499 | } |
@@ -306,11 +505,29 @@ sub process { | |||
306 | # $clean = 0; | 505 | # $clean = 0; |
307 | # } | 506 | # } |
308 | 507 | ||
309 | # printk should use KERN_* levels | 508 | # printk should use KERN_* levels. Note that follow on printk's on the |
509 | # same line do not need a level, so we use the current block context | ||
510 | # to try and find and validate the current printk. In summary the current | ||
511 | # printk includes all preceeding printk's which have no newline on the end. | ||
512 | # we assume the first bad printk is the one to report. | ||
310 | if ($line =~ /\bprintk\((?!KERN_)/) { | 513 | if ($line =~ /\bprintk\((?!KERN_)/) { |
311 | print "printk() should include KERN_ facility level\n"; | 514 | my $ok = 0; |
312 | print "$herecurr"; | 515 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { |
313 | $clean = 0; | 516 | #print "CHECK<$lines[$ln - 1]\n"; |
517 | # we have a preceeding printk if it ends | ||
518 | # with "\n" ignore it, else it is to blame | ||
519 | if ($lines[$ln - 1] =~ m{\bprintk\(}) { | ||
520 | if ($rawlines[$ln - 1] !~ m{\\n"}) { | ||
521 | $ok = 1; | ||
522 | } | ||
523 | last; | ||
524 | } | ||
525 | } | ||
526 | if ($ok == 0) { | ||
527 | print "printk() should include KERN_ facility level\n"; | ||
528 | print "$herecurr"; | ||
529 | $clean = 0; | ||
530 | } | ||
314 | } | 531 | } |
315 | 532 | ||
316 | #function brace can't be on same line, except for #defines of do while, or if closed on same line | 533 | #function brace can't be on same line, except for #defines of do while, or if closed on same line |
@@ -320,86 +537,91 @@ sub process { | |||
320 | print "$herecurr"; | 537 | print "$herecurr"; |
321 | $clean = 0; | 538 | $clean = 0; |
322 | } | 539 | } |
540 | # Note we expand the line with the leading + as the real | ||
541 | # line will be displayed with the leading + and the tabs | ||
542 | # will therefore also expand that way. | ||
323 | my $opline = $line; | 543 | my $opline = $line; |
324 | $opline =~ s/^.//; | 544 | $opline = expand_tabs($opline); |
545 | $opline =~ s/^./ /; | ||
325 | if (!($line=~/\#\s*include/)) { | 546 | if (!($line=~/\#\s*include/)) { |
326 | # Check operator spacing. | 547 | # Check operator spacing. |
327 | my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); | 548 | my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); |
549 | my $off = 0; | ||
328 | for (my $n = 0; $n < $#elements; $n += 2) { | 550 | for (my $n = 0; $n < $#elements; $n += 2) { |
329 | # $wN says we have white-space before or after | 551 | $off += length($elements[$n]); |
330 | # $sN says we have a separator before or after | 552 | |
331 | # $oN says we have another operator before or after | 553 | my $a = ''; |
332 | my $w1 = $elements[$n] =~ /\s$/; | 554 | $a = 'V' if ($elements[$n] ne ''); |
333 | my $s1 = $elements[$n] =~ /(\[|\(|\s)$/; | 555 | $a = 'W' if ($elements[$n] =~ /\s$/); |
334 | my $o1 = $elements[$n] eq ''; | 556 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/); |
557 | $a = 'O' if ($elements[$n] eq ''); | ||
558 | $a = 'E' if ($elements[$n] eq '' && $n == 0); | ||
559 | |||
335 | my $op = $elements[$n + 1]; | 560 | my $op = $elements[$n + 1]; |
336 | my $w2 = 1; | 561 | |
337 | my $s2 = 1; | 562 | my $c = ''; |
338 | my $o2 = 0; | ||
339 | # If we have something after the operator handle it. | ||
340 | if (defined $elements[$n + 2]) { | 563 | if (defined $elements[$n + 2]) { |
341 | $w2 = $elements[$n + 2] =~ /^\s/; | 564 | $c = 'V' if ($elements[$n + 2] ne ''); |
342 | $s2 = $elements[$n + 2] =~ /^(\s|\)|\]|;)/; | 565 | $c = 'W' if ($elements[$n + 2] =~ /^\s/); |
343 | $o2 = $elements[$n + 2] eq ''; | 566 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
567 | $c = 'O' if ($elements[$n + 2] eq ''); | ||
568 | } else { | ||
569 | $c = 'E'; | ||
344 | } | 570 | } |
345 | 571 | ||
346 | # Generate the context. | 572 | # Pick up the preceeding and succeeding characters. |
347 | my $at = "here: "; | 573 | my $ca = substr($opline, $off - 1, 1); |
348 | for (my $m = $n; $m >= 0; $m--) { | 574 | my $cc = ''; |
349 | if ($elements[$m] ne '') { | 575 | if (length($opline) > ($off + length($elements[$n]))) { |
350 | $at .= $elements[$m]; | 576 | $cc = substr($opline, $off + 1 + length($elements[$n]), 1); |
351 | last; | ||
352 | } | ||
353 | } | ||
354 | $at .= $op; | ||
355 | for (my $m = $n + 2; defined $elements[$m]; $m++) { | ||
356 | if ($elements[$m] ne '') { | ||
357 | $at .= $elements[$m]; | ||
358 | last; | ||
359 | } | ||
360 | } | 577 | } |
361 | 578 | ||
579 | my $ctx = "${a}x${c}"; | ||
580 | |||
581 | my $at = "(ctx:$ctx)"; | ||
582 | |||
583 | my $ptr = (" " x $off) . "^"; | ||
584 | my $hereptr = "$hereline$ptr\n\n"; | ||
585 | |||
362 | ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; | 586 | ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; |
363 | # Skip things apparently in quotes. | ||
364 | next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); | ||
365 | 587 | ||
366 | # We need ; as an operator. // is a comment. | 588 | # We need ; as an operator. // is a comment. |
367 | if ($op eq ';' or $op eq '//') { | 589 | if ($op eq ';' or $op eq '//') { |
368 | 590 | ||
369 | # -> should have no spaces | 591 | # -> should have no spaces |
370 | } elsif ($op eq '->') { | 592 | } elsif ($op eq '->') { |
371 | if ($s1 or $s2) { | 593 | if ($ctx =~ /Wx.|.xW/) { |
372 | print "no spaces around that '$op' $at\n"; | 594 | print "no spaces around that '$op' $at\n"; |
373 | print "$herecurr"; | 595 | print "$hereptr"; |
374 | $clean = 0; | 596 | $clean = 0; |
375 | } | 597 | } |
376 | 598 | ||
377 | # , must have a space on the right. | 599 | # , must have a space on the right. |
378 | } elsif ($op eq ',') { | 600 | } elsif ($op eq ',') { |
379 | if (!$s2) { | 601 | if ($ctx !~ /.xW|.xE/) { |
380 | print "need space after that '$op' $at\n"; | 602 | print "need space after that '$op' $at\n"; |
381 | print "$herecurr"; | 603 | print "$hereptr"; |
382 | $clean = 0; | 604 | $clean = 0; |
383 | } | 605 | } |
384 | 606 | ||
385 | # unary ! and unary ~ are allowed no space on the right | 607 | # unary ! and unary ~ are allowed no space on the right |
386 | } elsif ($op eq '!' or $op eq '~') { | 608 | } elsif ($op eq '!' or $op eq '~') { |
387 | if (!$s1 && !$o1) { | 609 | if ($ctx !~ /[WOEB]x./) { |
388 | print "need space before that '$op' $at\n"; | 610 | print "need space before that '$op' $at\n"; |
389 | print "$herecurr"; | 611 | print "$hereptr"; |
390 | $clean = 0; | 612 | $clean = 0; |
391 | } | 613 | } |
392 | if ($s2) { | 614 | if ($ctx =~ /.xW/) { |
393 | print "no space after that '$op' $at\n"; | 615 | print "no space after that '$op' $at\n"; |
394 | print "$herecurr"; | 616 | print "$hereptr"; |
395 | $clean = 0; | 617 | $clean = 0; |
396 | } | 618 | } |
397 | 619 | ||
398 | # unary ++ and unary -- are allowed no space on one side. | 620 | # unary ++ and unary -- are allowed no space on one side. |
399 | } elsif ($op eq '++' or $op eq '--') { | 621 | } elsif ($op eq '++' or $op eq '--') { |
400 | if (($s1 && $s2) || ((!$s1 && !$o1) && (!$s2 && !$o2))) { | 622 | if ($ctx !~ /[WOB]x[^W]|[^W]x[WOB]/) { |
401 | print "need space one side of that '$op' $at\n"; | 623 | print "need space one side of that '$op' $at\n"; |
402 | print "$herecurr"; | 624 | print "$hereptr"; |
403 | $clean = 0; | 625 | $clean = 0; |
404 | } | 626 | } |
405 | 627 | ||
@@ -415,15 +637,28 @@ sub process { | |||
415 | # | 637 | # |
416 | # - is the same | 638 | # - is the same |
417 | # | 639 | # |
418 | # * is the same only adding: | 640 | } elsif ($op eq '&' or $op eq '-') { |
641 | if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) { | ||
642 | print "need space before that '$op' $at\n"; | ||
643 | print "$hereptr"; | ||
644 | $clean = 0; | ||
645 | } | ||
646 | |||
647 | # * is the same as & only adding: | ||
419 | # type: | 648 | # type: |
420 | # (foo *) | 649 | # (foo *) |
421 | # (foo **) | 650 | # (foo **) |
422 | # | 651 | # |
423 | } elsif ($op eq '&' or $op eq '-' or $op eq '*') { | 652 | } elsif ($op eq '*') { |
424 | if ($w2 and !$w1) { | 653 | if ($ca eq '*') { |
654 | if ($cc =~ /\s/) { | ||
655 | print "no space after that '$op' $at\n"; | ||
656 | print "$hereptr"; | ||
657 | $clean = 0; | ||
658 | } | ||
659 | } elsif ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB/) { | ||
425 | print "need space before that '$op' $at\n"; | 660 | print "need space before that '$op' $at\n"; |
426 | print "$herecurr"; | 661 | print "$hereptr"; |
427 | $clean = 0; | 662 | $clean = 0; |
428 | } | 663 | } |
429 | 664 | ||
@@ -431,18 +666,19 @@ sub process { | |||
431 | } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or | 666 | } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or |
432 | $op eq '^' or $op eq '|') | 667 | $op eq '^' or $op eq '|') |
433 | { | 668 | { |
434 | if ($s1 != $s2) { | 669 | if ($ctx !~ /VxV|WxW|VxE|WxE/) { |
435 | print "need consistent spacing around '$op' $at\n"; | 670 | print "need consistent spacing around '$op' $at\n"; |
436 | print "$herecurr"; | 671 | print "$hereptr"; |
437 | $clean = 0; | 672 | $clean = 0; |
438 | } | 673 | } |
439 | 674 | ||
440 | # All the others need spaces both sides. | 675 | # All the others need spaces both sides. |
441 | } elsif (!$s1 or !$s2) { | 676 | } elsif ($ctx !~ /[EW]x[WE]/) { |
442 | print "need spaces around that '$op' $at\n"; | 677 | print "need spaces around that '$op' $at\n"; |
443 | print "$herecurr"; | 678 | print "$hereptr"; |
444 | $clean = 0; | 679 | $clean = 0; |
445 | } | 680 | } |
681 | $off += length($elements[$n + 1]); | ||
446 | } | 682 | } |
447 | } | 683 | } |
448 | 684 | ||
@@ -454,7 +690,7 @@ sub process { | |||
454 | } | 690 | } |
455 | 691 | ||
456 | #goto labels aren't indented, allow a single space however | 692 | #goto labels aren't indented, allow a single space however |
457 | if ($line=~/^.\s+[A-Za-z\d_]+:/ and | 693 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
458 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { | 694 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
459 | print "labels should not be indented\n"; | 695 | print "labels should not be indented\n"; |
460 | print "$herecurr"; | 696 | print "$herecurr"; |
@@ -462,15 +698,16 @@ sub process { | |||
462 | } | 698 | } |
463 | 699 | ||
464 | # Need a space before open parenthesis after if, while etc | 700 | # Need a space before open parenthesis after if, while etc |
465 | if ($line=~/(if|while|for|switch)\(/) { | 701 | if ($line=~/\b(if|while|for|switch)\(/) { |
466 | print "need a space before the open parenthesis\n"; | 702 | print "need a space before the open parenthesis\n"; |
467 | print "$herecurr"; | 703 | print "$herecurr"; |
468 | $clean = 0; | 704 | $clean = 0; |
469 | } | 705 | } |
470 | 706 | ||
471 | # Check for illegal assignment in if conditional. | 707 | # Check for illegal assignment in if conditional. |
472 | if ($line=~/(if|while)\s*\(.*[^<>!=]=[^=].*\)/) { | 708 | if ($line=~/\b(if|while)\s*\(.*[^<>!=]=[^=].*\)/) { |
473 | print "do not use assignment in if condition\n"; | 709 | #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); |
710 | print "do not use assignment in condition\n"; | ||
474 | print "$herecurr"; | 711 | print "$herecurr"; |
475 | $clean = 0; | 712 | $clean = 0; |
476 | } | 713 | } |
@@ -484,17 +721,6 @@ sub process { | |||
484 | $clean = 0; | 721 | $clean = 0; |
485 | } | 722 | } |
486 | 723 | ||
487 | # Check for switch () {<nl>case, these must be at the | ||
488 | # same indent. We will only catch the first one, as our | ||
489 | # context is very small but people tend to be consistent | ||
490 | # so we will catch them out more often than not. | ||
491 | if ($prevline=~/\s*switch\s*\(.*\)/ and $line=~/\s*case\s+/ | ||
492 | and $previndent != $indent) { | ||
493 | print "switch and case should be at the same indent\n"; | ||
494 | print "$hereprev"; | ||
495 | $clean = 0; | ||
496 | } | ||
497 | |||
498 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new | 724 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new |
499 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { | 725 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { |
500 | # print "No studly caps, use _\n"; | 726 | # print "No studly caps, use _\n"; |
@@ -520,11 +746,11 @@ sub process { | |||
520 | } | 746 | } |
521 | 747 | ||
522 | #if/while/etc brace do not go on next line, unless #defining a do while loop, or if that brace on the next line is for something else | 748 | #if/while/etc brace do not go on next line, unless #defining a do while loop, or if that brace on the next line is for something else |
523 | if ($prevline=~/(if|while|for|switch)\s*\(/) { | 749 | if ($prevline=~/\b(if|while|for|switch)\s*\(/) { |
524 | my @opened = $prevline=~/\(/g; | 750 | my @opened = $prevline=~/\(/g; |
525 | my @closed = $prevline=~/\)/g; | 751 | my @closed = $prevline=~/\)/g; |
526 | my $nr_line = $linenr; | 752 | my $nr_line = $linenr; |
527 | my $remaining = $realcnt; | 753 | my $remaining = $realcnt - 1; |
528 | my $next_line = $line; | 754 | my $next_line = $line; |
529 | my $extra_lines = 0; | 755 | my $extra_lines = 0; |
530 | my $display_segment = $prevline; | 756 | my $display_segment = $prevline; |
@@ -540,10 +766,10 @@ sub process { | |||
540 | @closed = $prevline=~/\)/g; | 766 | @closed = $prevline=~/\)/g; |
541 | } | 767 | } |
542 | 768 | ||
543 | if (($prevline=~/(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and | 769 | if (($prevline=~/\b(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and |
544 | !($next_line=~/(if|while|for)/) and !($next_line=~/\#define.*do.*while/)) { | 770 | !($next_line=~/\b(if|while|for)/) and !($next_line=~/\#define.*do.*while/)) { |
545 | print "That { should be on the previous line\n"; | 771 | print "That { should be on the previous line\n"; |
546 | print "$display_segment\n$next_line\n\n"; | 772 | print "$here\n$display_segment\n$next_line\n\n"; |
547 | $clean = 0; | 773 | $clean = 0; |
548 | } | 774 | } |
549 | } | 775 | } |
@@ -558,7 +784,7 @@ sub process { | |||
558 | } | 784 | } |
559 | 785 | ||
560 | # don't include deprecated include files | 786 | # don't include deprecated include files |
561 | for my $inc (@deprecated) { | 787 | for my $inc (@dep_includes) { |
562 | if ($line =~ m@\#\s*include\s*\<$inc>@) { | 788 | if ($line =~ m@\#\s*include\s*\<$inc>@) { |
563 | print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n"; | 789 | print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n"; |
564 | print "$herecurr"; | 790 | print "$herecurr"; |
@@ -566,9 +792,56 @@ sub process { | |||
566 | } | 792 | } |
567 | } | 793 | } |
568 | 794 | ||
569 | # don't use kernel_thread() | 795 | # don't use deprecated functions |
570 | if ($line =~ /\bkernel_thread\b/) { | 796 | for my $func (@dep_functions) { |
571 | print "Don't use kernel_thread(), use kthread(): see Documentation/feature-removal-schedule.txt\n"; | 797 | if ($line =~ /\b$func\b/) { |
798 | print "Don't use $func(): see Documentation/feature-removal-schedule.txt\n"; | ||
799 | print "$herecurr"; | ||
800 | $clean = 0; | ||
801 | } | ||
802 | } | ||
803 | |||
804 | # no volatiles please | ||
805 | if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) { | ||
806 | print "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n"; | ||
807 | print "$herecurr"; | ||
808 | $clean = 0; | ||
809 | } | ||
810 | |||
811 | # warn about #if 0 | ||
812 | if ($line =~ /^.#\s*if\s+0\b/) { | ||
813 | print "#if 0 -- if this code redundant remove it\n"; | ||
814 | print "$herecurr"; | ||
815 | $clean = 0; | ||
816 | } | ||
817 | |||
818 | # warn about #ifdefs in C files | ||
819 | # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { | ||
820 | # print "#ifdef in C files should be avoided\n"; | ||
821 | # print "$herecurr"; | ||
822 | # $clean = 0; | ||
823 | # } | ||
824 | |||
825 | # check for spinlock_t definitions without a comment. | ||
826 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { | ||
827 | my $which = $1; | ||
828 | if (!ctx_has_comment($first_line, $linenr)) { | ||
829 | print "$1 definition without comment\n"; | ||
830 | print "$herecurr"; | ||
831 | $clean = 0; | ||
832 | } | ||
833 | } | ||
834 | # check for memory barriers without a comment. | ||
835 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { | ||
836 | if (!ctx_has_comment($first_line, $linenr)) { | ||
837 | print "memory barrier without comment\n"; | ||
838 | print "$herecurr"; | ||
839 | $clean = 0; | ||
840 | } | ||
841 | } | ||
842 | # check of hardware specific defines | ||
843 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) { | ||
844 | print "architecture specific defines should be avoided\n"; | ||
572 | print "$herecurr"; | 845 | print "$herecurr"; |
573 | $clean = 0; | 846 | $clean = 0; |
574 | } | 847 | } |