From 1d4ae0ee010773281df2ea9d6f676654356d0a9f Mon Sep 17 00:00:00 2001 From: David Brownell Date: Thu, 10 May 2007 22:36:14 -0700 Subject: [PATCH] --- yaml --- r: 57486 b: refs/heads/master c: adfdebceaca988515ecdb557d600fd5ab9da913a h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/Documentation/SubmittingPatches | 26 +- trunk/Documentation/atomic_ops.txt | 2 +- trunk/Documentation/driver-model/platform.txt | 40 ++ .../feature-removal-schedule.txt | 1 - trunk/Documentation/filesystems/tmpfs.txt | 10 +- trunk/MAINTAINERS | 19 +- trunk/arch/i386/math-emu/fpu_entry.c | 2 +- trunk/arch/m68knommu/platform/5307/timers.c | 10 +- trunk/arch/ppc/syslib/qspan_pci.c | 4 +- trunk/arch/sh64/kernel/pci_sh5.c | 8 +- trunk/arch/um/Kconfig | 1 - trunk/arch/um/drivers/line.c | 1 - trunk/arch/um/drivers/stderr_console.c | 1 - trunk/arch/um/drivers/ubd_kern.c | 1 - trunk/arch/um/kernel/exitcode.c | 39 +- trunk/arch/x86_64/kernel/traps.c | 3 +- trunk/arch/x86_64/mm/init.c | 2 - trunk/drivers/ata/sata_promise.c | 9 +- trunk/drivers/block/loop.c | 100 +--- trunk/drivers/cdrom/mcdx.c | 2 +- trunk/drivers/char/stallion.c | 81 +-- trunk/drivers/isdn/hardware/eicon/divasfunc.c | 2 +- trunk/drivers/tc/zs.c | 2 +- trunk/fs/binfmt_flat.c | 2 +- trunk/include/linux/console_struct.h | 5 - trunk/include/linux/kernel.h | 12 +- trunk/include/linux/sched.h | 1 - trunk/include/linux/slub_def.h | 25 +- trunk/kernel/exit.c | 24 +- trunk/kernel/futex.c | 269 ++++------ trunk/kernel/rtmutex.c | 24 +- trunk/lib/hexdump.c | 149 +----- trunk/mm/shmem.c | 2 - trunk/mm/slab.c | 2 +- trunk/mm/slub.c | 26 +- trunk/mm/sparse.c | 42 +- trunk/scripts/checkpatch.pl | 501 ++++-------------- 38 files changed, 459 insertions(+), 993 deletions(-) diff --git a/[refs] b/[refs] index f51509aafd0f..cd9c685f076e 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 217397d7d267f832081169016e1ab66691a13e08 +refs/heads/master: adfdebceaca988515ecdb557d600fd5ab9da913a diff --git a/trunk/Documentation/SubmittingPatches b/trunk/Documentation/SubmittingPatches index 0958e97d4bf4..d91125ab6f49 100644 --- a/trunk/Documentation/SubmittingPatches +++ b/trunk/Documentation/SubmittingPatches @@ -340,32 +340,8 @@ now, but you can do this to mark internal company procedures or just point out some special detail about the sign-off. -13) When to use Acked-by: -The Signed-off-by: tag indicates that the signer was involved in the -development of the patch, or that he/she was in the patch's delivery path. - -If a person was not directly involved in the preparation or handling of a -patch but wishes to signify and record their approval of it then they can -arrange to have an Acked-by: line added to the patch's changelog. - -Acked-by: is often used by the maintainer of the affected code when that -maintainer neither contributed to nor forwarded the patch. - -Acked-by: is not as formal as Signed-off-by:. It is a record that the acker -has at least reviewed the patch and has indicated acceptance. Hence patch -mergers will sometimes manually convert an acker's "yep, looks good to me" -into an Acked-by:. - -Acked-by: does not necessarily indicate acknowledgement of the entire patch. -For example, if a patch affects multiple subsystems and has an Acked-by: from -one subsystem maintainer then this usually indicates acknowledgement of just -the part which affects that maintainer's code. Judgement should be used here. - When in doubt people should refer to the original discussion in the mailing -list archives. - - -14) The canonical patch format +13) The canonical patch format The canonical patch subject line is: diff --git a/trunk/Documentation/atomic_ops.txt b/trunk/Documentation/atomic_ops.txt index 05851e9982ed..2a63d5662a93 100644 --- a/trunk/Documentation/atomic_ops.txt +++ b/trunk/Documentation/atomic_ops.txt @@ -149,7 +149,7 @@ defined which accomplish this: void smp_mb__before_atomic_dec(void); void smp_mb__after_atomic_dec(void); void smp_mb__before_atomic_inc(void); - void smp_mb__after_atomic_inc(void); + void smp_mb__after_atomic_dec(void); For example, smp_mb__before_atomic_dec() can be used like so: diff --git a/trunk/Documentation/driver-model/platform.txt b/trunk/Documentation/driver-model/platform.txt index 19c4a6e13676..2a97320ee17f 100644 --- a/trunk/Documentation/driver-model/platform.txt +++ b/trunk/Documentation/driver-model/platform.txt @@ -96,6 +96,46 @@ System setup also associates those clocks with the device, so that that calls to clk_get(&pdev->dev, clock_name) return them as needed. +Legacy Drivers: Device Probing +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Some drivers are not fully converted to the driver model, because they take +on a non-driver role: the driver registers its platform device, rather than +leaving that for system infrastructure. Such drivers can't be hotplugged +or coldplugged, since those mechanisms require device creation to be in a +different system component than the driver. + +The only "good" reason for this is to handle older system designs which, like +original IBM PCs, rely on error-prone "probe-the-hardware" models for hardware +configuration. Newer systems have largely abandoned that model, in favor of +bus-level support for dynamic configuration (PCI, USB), or device tables +provided by the boot firmware (e.g. PNPACPI on x86). There are too many +conflicting options about what might be where, and even educated guesses by +an operating system will be wrong often enough to make trouble. + +This style of driver is discouraged. If you're updating such a driver, +please try to move the device enumeration to a more appropriate location, +outside the driver. This will usually be cleanup, since such drivers +tend to already have "normal" modes, such as ones using device nodes that +were created by PNP or by platform device setup. + +None the less, there are some APIs to support such legacy drivers. Avoid +using these calls except with such hotplug-deficient drivers. + + struct platform_device *platform_device_alloc( + char *name, unsigned id); + +You can use platform_device_alloc() to dynamically allocate a device, which +you will then initialize with resources and platform_device_register(). +A better solution is usually: + + struct platform_device *platform_device_register_simple( + char *name, unsigned id, + struct resource *res, unsigned nres); + +You can use platform_device_register_simple() as a one-step call to allocate +and register a device. + + Device Naming and Driver Binding ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The platform_device.dev.bus_id is the canonical name for the devices. diff --git a/trunk/Documentation/feature-removal-schedule.txt b/trunk/Documentation/feature-removal-schedule.txt index 7d3f205b0ba5..49ae1ea9e868 100644 --- a/trunk/Documentation/feature-removal-schedule.txt +++ b/trunk/Documentation/feature-removal-schedule.txt @@ -104,7 +104,6 @@ Who: Dominik Brodowski What: remove EXPORT_SYMBOL(kernel_thread) When: August 2006 Files: arch/*/kernel/*_ksyms.c -Funcs: kernel_thread Why: kernel_thread is a low-level implementation detail. Drivers should use the API instead which shields them from implementation details and provides a higherlevel interface that diff --git a/trunk/Documentation/filesystems/tmpfs.txt b/trunk/Documentation/filesystems/tmpfs.txt index 145e44086358..6dd050878a20 100644 --- a/trunk/Documentation/filesystems/tmpfs.txt +++ b/trunk/Documentation/filesystems/tmpfs.txt @@ -94,10 +94,10 @@ largest node numbers in the range. For example, mpol=bind:0-3,5,7,9-15 Note that trying to mount a tmpfs with an mpol option will fail if the running kernel does not support NUMA; and will fail if its nodelist -specifies a node which is not online. If your system relies on that -tmpfs being mounted, but from time to time runs a kernel built without -NUMA capability (perhaps a safe recovery kernel), or with fewer nodes -online, then it is advisable to omit the mpol option from automatic +specifies a node >= MAX_NUMNODES. If your system relies on that tmpfs +being mounted, but from time to time runs a kernel built without NUMA +capability (perhaps a safe recovery kernel), or configured to support +fewer nodes, then it is advisable to omit the mpol option from automatic mount options. It can be added later, when the tmpfs is already mounted on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'. @@ -121,4 +121,4 @@ RAM/SWAP in 10240 inodes and it is only accessible by root. Author: Christoph Rohland , 1.12.01 Updated: - Hugh Dickins , 4 June 2007 + Hugh Dickins , 19 February 2006 diff --git a/trunk/MAINTAINERS b/trunk/MAINTAINERS index 4c715a7e059a..f3b5a391e074 100644 --- a/trunk/MAINTAINERS +++ b/trunk/MAINTAINERS @@ -782,6 +782,11 @@ M: rathamahata@php4.ru L: linux-kernel@vger.kernel.org S: Maintained +BERKSHIRE PRODUCTS PC WATCHDOG DRIVER +P: Kenji Hollis +W: http://ftp.bitgate.com/pcwd/ +S: Maintained + BFS FILE SYSTEM P: Tigran A. Aivazian M: tigran@aivazian.fsnet.co.uk @@ -3020,7 +3025,7 @@ S: Maintained REISERFS FILE SYSTEM P: Hans Reiser M: reiserfs-dev@namesys.com -L: reiserfs-devel@vger.kernel.org +L: reiserfs-list@namesys.com W: http://www.namesys.com S: Supported @@ -3899,6 +3904,10 @@ S: Maintained UCLINUX FOR NEC V850 P: Miles Bader +M: uclinux-v850@lsi.nec.co.jp +W: http://www.ic.nec.co.jp/micro/uclinux/eng/ +W: http://www.ee.nec.de/uclinux/ +S: Supported UCLINUX FOR RENESAS H8/300 P: Yoshinori Sato @@ -3907,10 +3916,10 @@ W: http://uclinux-h8.sourceforge.jp/ S: Supported UFS FILESYSTEM -P: Evgeniy Dushistov -M: dushistov@mail.ru -L: linux-kernel@vger.kernel.org -S: Maintained +P: Evgeniy Dushistov +M: dushistov@mail.ru +L: linux-kernel@vger.kernel.org +S: Maintained USB DIAMOND RIO500 DRIVER P: Cesar Miquel diff --git a/trunk/arch/i386/math-emu/fpu_entry.c b/trunk/arch/i386/math-emu/fpu_entry.c index 1853524c8b57..ddf8fa3bbd01 100644 --- a/trunk/arch/i386/math-emu/fpu_entry.c +++ b/trunk/arch/i386/math-emu/fpu_entry.c @@ -754,7 +754,7 @@ int save_i387_soft(void *s387, struct _fpstate __user * buf) return -1; if ( offset ) if (__copy_to_user(d+other, (u_char *)&S387->st_space, offset)) - return -1; + return -1 RE_ENTRANT_CHECK_ON; return 1; diff --git a/trunk/arch/m68knommu/platform/5307/timers.c b/trunk/arch/m68knommu/platform/5307/timers.c index fb66eadd5896..92e58070b016 100644 --- a/trunk/arch/m68knommu/platform/5307/timers.c +++ b/trunk/arch/m68knommu/platform/5307/timers.c @@ -62,13 +62,10 @@ void coldfire_tick(void) /***************************************************************************/ -static int ticks_per_intr; - void coldfire_timer_init(irq_handler_t handler) { __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR)); - ticks_per_intr = (MCF_BUSCLK / 16) / HZ; - __raw_writetrr(ticks_per_intr - 1, TA(MCFTIMER_TRR)); + __raw_writetrr(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR)); __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR)); @@ -84,10 +81,11 @@ void coldfire_timer_init(irq_handler_t handler) unsigned long coldfire_timer_offset(void) { - unsigned long tcn, offset; + unsigned long trr, tcn, offset; tcn = __raw_readw(TA(MCFTIMER_TCN)); - offset = ((tcn + 1) * (1000000 / HZ)) / ticks_per_intr; + trr = __raw_readtrr(TA(MCFTIMER_TRR)); + offset = (tcn * (1000000 / HZ)) / trr; /* Check if we just wrapped the counters and maybe missed a tick */ if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1)) diff --git a/trunk/arch/ppc/syslib/qspan_pci.c b/trunk/arch/ppc/syslib/qspan_pci.c index 7a97c7440b30..85053b2816a9 100644 --- a/trunk/arch/ppc/syslib/qspan_pci.c +++ b/trunk/arch/ppc/syslib/qspan_pci.c @@ -365,13 +365,13 @@ int qspan_pcibios_find_class(unsigned int class_code, unsigned short index, } void __init -m8xx_pcibios_fixup(void) +m8xx_pcibios_fixup(void)) { /* Lots to do here, all board and configuration specific. */ } void __init -m8xx_setup_pci_ptrs(void) +m8xx_setup_pci_ptrs(void)) { set_config_access_method(qspan); diff --git a/trunk/arch/sh64/kernel/pci_sh5.c b/trunk/arch/sh64/kernel/pci_sh5.c index 3334f99b5835..fb51660847c8 100644 --- a/trunk/arch/sh64/kernel/pci_sh5.c +++ b/trunk/arch/sh64/kernel/pci_sh5.c @@ -521,10 +521,10 @@ void __init pcibios_fixup_bus(struct pci_bus *bus) bus->resource[0]->start = PCIBIOS_MIN_IO; bus->resource[1]->start = PCIBIOS_MIN_MEM; #else - bus->resource[0]->end = 0; - bus->resource[1]->end = 0; - bus->resource[0]->start =0; - bus->resource[1]->start = 0; + bus->resource[0]->end = 0 + bus->resource[1]->end = 0 + bus->resource[0]->start =0 + bus->resource[1]->start = 0; #endif /* Turn off downstream PF memory address range by default */ bus->resource[2]->start = 1024*1024; diff --git a/trunk/arch/um/Kconfig b/trunk/arch/um/Kconfig index e6ff30266542..c504312219b4 100644 --- a/trunk/arch/um/Kconfig +++ b/trunk/arch/um/Kconfig @@ -278,7 +278,6 @@ config HIGHMEM config KERNEL_STACK_ORDER int "Kernel stack size order" default 1 if 64BIT - range 1 10 if 64BIT default 0 if !64BIT help This option determines the size of UML kernel stacks. They will diff --git a/trunk/arch/um/drivers/line.c b/trunk/arch/um/drivers/line.c index 4bd40bb43ec2..ced99106f798 100644 --- a/trunk/arch/um/drivers/line.c +++ b/trunk/arch/um/drivers/line.c @@ -3,7 +3,6 @@ * Licensed under the GPL */ -#include "linux/kernel.h" #include "linux/sched.h" #include "linux/slab.h" #include "linux/list.h" diff --git a/trunk/arch/um/drivers/stderr_console.c b/trunk/arch/um/drivers/stderr_console.c index 4739dd527b43..911539293871 100644 --- a/trunk/arch/um/drivers/stderr_console.c +++ b/trunk/arch/um/drivers/stderr_console.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/trunk/arch/um/drivers/ubd_kern.c b/trunk/arch/um/drivers/ubd_kern.c index 2e09f162c42f..70509ddaac03 100644 --- a/trunk/arch/um/drivers/ubd_kern.c +++ b/trunk/arch/um/drivers/ubd_kern.c @@ -20,7 +20,6 @@ #define MAJOR_NR UBD_MAJOR #define UBD_SHIFT 4 -#include "linux/kernel.h" #include "linux/module.h" #include "linux/blkdev.h" #include "linux/hdreg.h" diff --git a/trunk/arch/um/kernel/exitcode.c b/trunk/arch/um/kernel/exitcode.c index c716b5a6db13..8b7f2cdedf94 100644 --- a/trunk/arch/um/kernel/exitcode.c +++ b/trunk/arch/um/kernel/exitcode.c @@ -1,9 +1,8 @@ -/* +/* * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) * Licensed under the GPL */ -#include "linux/kernel.h" #include "linux/init.h" #include "linux/ctype.h" #include "linux/proc_fs.h" @@ -25,14 +24,11 @@ static int read_proc_exitcode(char *page, char **start, off_t off, val = uml_exitcode; len = sprintf(page, "%d\n", val); len -= off; - if(len <= off+count) - *eof = 1; + if(len <= off+count) *eof = 1; *start = page + off; - if(len > count) - len = count; - if(len < 0) - len = 0; - return len; + if(len > count) len = count; + if(len < 0) len = 0; + return(len); } static int write_proc_exitcode(struct file *file, const char __user *buffer, @@ -42,14 +38,12 @@ static int write_proc_exitcode(struct file *file, const char __user *buffer, int tmp; if(copy_from_user(buf, buffer, count)) - return -EFAULT; - + return(-EFAULT); tmp = simple_strtol(buf, &end, 0); if((*end != '\0') && !isspace(*end)) - return -EINVAL; - + return(-EINVAL); uml_exitcode = tmp; - return count; + return(count); } static int make_proc_exitcode(void) @@ -60,13 +54,24 @@ static int make_proc_exitcode(void) if(ent == NULL){ printk(KERN_WARNING "make_proc_exitcode : Failed to register " "/proc/exitcode\n"); - return 0; + return(0); } ent->read_proc = read_proc_exitcode; ent->write_proc = write_proc_exitcode; - - return 0; + + return(0); } __initcall(make_proc_exitcode); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff --git a/trunk/arch/x86_64/kernel/traps.c b/trunk/arch/x86_64/kernel/traps.c index aac1c0be54c6..cb29fb96948d 100644 --- a/trunk/arch/x86_64/kernel/traps.c +++ b/trunk/arch/x86_64/kernel/traps.c @@ -465,14 +465,13 @@ static unsigned int die_nest_count; unsigned __kprobes long oops_begin(void) { - int cpu; + int cpu = smp_processor_id(); unsigned long flags; oops_enter(); /* racy, but better than risking deadlock. */ local_irq_save(flags); - cpu = smp_processor_id(); if (!spin_trylock(&die_lock)) { if (cpu == die_owner) /* nested oops. should stop eventually */; diff --git a/trunk/arch/x86_64/mm/init.c b/trunk/arch/x86_64/mm/init.c index efb6e845114e..1ad5111aec38 100644 --- a/trunk/arch/x86_64/mm/init.c +++ b/trunk/arch/x86_64/mm/init.c @@ -79,8 +79,6 @@ void show_mem(void) if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) { touch_nmi_watchdog(); } - if (!pfn_valid(pgdat->node_start_pfn + i)) - continue; page = pfn_to_page(pgdat->node_start_pfn + i); total++; if (PageReserved(page)) diff --git a/trunk/drivers/ata/sata_promise.c b/trunk/drivers/ata/sata_promise.c index 6dc0b011a6b7..2b924a69b365 100644 --- a/trunk/drivers/ata/sata_promise.c +++ b/trunk/drivers/ata/sata_promise.c @@ -784,12 +784,9 @@ static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) if (qc->dev->flags & ATA_DFLAG_CDB_INTR) break; /*FALLTHROUGH*/ - case ATA_PROT_NODATA: - if (qc->tf.flags & ATA_TFLAG_POLLING) - break; - /*FALLTHROUGH*/ case ATA_PROT_ATAPI_DMA: case ATA_PROT_DMA: + case ATA_PROT_NODATA: pdc_packet_start(qc); return 0; @@ -803,7 +800,7 @@ static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) { WARN_ON (tf->protocol == ATA_PROT_DMA || - tf->protocol == ATA_PROT_ATAPI_DMA); + tf->protocol == ATA_PROT_NODATA); ata_tf_load(ap, tf); } @@ -811,7 +808,7 @@ static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf) { WARN_ON (tf->protocol == ATA_PROT_DMA || - tf->protocol == ATA_PROT_ATAPI_DMA); + tf->protocol == ATA_PROT_NODATA); ata_exec_command(ap, tf); } diff --git a/trunk/drivers/block/loop.c b/trunk/drivers/block/loop.c index 0ed5470d2533..5526eadb6592 100644 --- a/trunk/drivers/block/loop.c +++ b/trunk/drivers/block/loop.c @@ -1354,7 +1354,7 @@ static struct block_device_operations lo_fops = { */ static int max_loop; module_param(max_loop, int, 0); -MODULE_PARM_DESC(max_loop, "Maximum number of loop devices"); +MODULE_PARM_DESC(max_loop, "obsolete, loop device is created on-demand"); MODULE_LICENSE("GPL"); MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); @@ -1394,11 +1394,16 @@ int loop_unregister_transfer(int number) EXPORT_SYMBOL(loop_register_transfer); EXPORT_SYMBOL(loop_unregister_transfer); -static struct loop_device *loop_alloc(int i) +static struct loop_device *loop_init_one(int i) { struct loop_device *lo; struct gendisk *disk; + list_for_each_entry(lo, &loop_devices, lo_list) { + if (lo->lo_number == i) + return lo; + } + lo = kzalloc(sizeof(*lo), GFP_KERNEL); if (!lo) goto out; @@ -1422,6 +1427,8 @@ static struct loop_device *loop_alloc(int i) disk->private_data = lo; disk->queue = lo->lo_queue; sprintf(disk->disk_name, "loop%d", i); + add_disk(disk); + list_add_tail(&lo->lo_list, &loop_devices); return lo; out_free_queue: @@ -1432,37 +1439,15 @@ static struct loop_device *loop_alloc(int i) return NULL; } -static void loop_free(struct loop_device *lo) +static void loop_del_one(struct loop_device *lo) { + del_gendisk(lo->lo_disk); blk_cleanup_queue(lo->lo_queue); put_disk(lo->lo_disk); list_del(&lo->lo_list); kfree(lo); } -static struct loop_device *loop_init_one(int i) -{ - struct loop_device *lo; - - list_for_each_entry(lo, &loop_devices, lo_list) { - if (lo->lo_number == i) - return lo; - } - - lo = loop_alloc(i); - if (lo) { - add_disk(lo->lo_disk); - list_add_tail(&lo->lo_list, &loop_devices); - } - return lo; -} - -static void loop_del_one(struct loop_device *lo) -{ - del_gendisk(lo->lo_disk); - loop_free(lo); -} - static struct kobject *loop_probe(dev_t dev, int *part, void *data) { struct loop_device *lo; @@ -1479,77 +1464,28 @@ static struct kobject *loop_probe(dev_t dev, int *part, void *data) static int __init loop_init(void) { - int i, nr; - unsigned long range; - struct loop_device *lo, *next; - - /* - * loop module now has a feature to instantiate underlying device - * structure on-demand, provided that there is an access dev node. - * However, this will not work well with user space tool that doesn't - * know about such "feature". In order to not break any existing - * tool, we do the following: - * - * (1) if max_loop is specified, create that many upfront, and this - * also becomes a hard limit. - * (2) if max_loop is not specified, create 8 loop device on module - * load, user can further extend loop device by create dev node - * themselves and have kernel automatically instantiate actual - * device on-demand. - */ - if (max_loop > 1UL << MINORBITS) - return -EINVAL; - - if (max_loop) { - nr = max_loop; - range = max_loop; - } else { - nr = 8; - range = 1UL << MINORBITS; - } - if (register_blkdev(LOOP_MAJOR, "loop")) return -EIO; - - for (i = 0; i < nr; i++) { - lo = loop_alloc(i); - if (!lo) - goto Enomem; - list_add_tail(&lo->lo_list, &loop_devices); - } - - /* point of no return */ - - list_for_each_entry(lo, &loop_devices, lo_list) - add_disk(lo->lo_disk); - - blk_register_region(MKDEV(LOOP_MAJOR, 0), range, + blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS, THIS_MODULE, loop_probe, NULL, NULL); + if (max_loop) { + printk(KERN_INFO "loop: the max_loop option is obsolete " + "and will be removed in March 2008\n"); + + } printk(KERN_INFO "loop: module loaded\n"); return 0; - -Enomem: - printk(KERN_INFO "loop: out of memory\n"); - - list_for_each_entry_safe(lo, next, &loop_devices, lo_list) - loop_free(lo); - - unregister_blkdev(LOOP_MAJOR, "loop"); - return -ENOMEM; } static void __exit loop_exit(void) { - unsigned long range; struct loop_device *lo, *next; - range = max_loop ? max_loop : 1UL << MINORBITS; - list_for_each_entry_safe(lo, next, &loop_devices, lo_list) loop_del_one(lo); - blk_unregister_region(MKDEV(LOOP_MAJOR, 0), range); + blk_unregister_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS); if (unregister_blkdev(LOOP_MAJOR, "loop")) printk(KERN_WARNING "loop: cannot unregister blkdev\n"); } diff --git a/trunk/drivers/cdrom/mcdx.c b/trunk/drivers/cdrom/mcdx.c index 4310cc84dfed..f574962f4288 100644 --- a/trunk/drivers/cdrom/mcdx.c +++ b/trunk/drivers/cdrom/mcdx.c @@ -1053,11 +1053,11 @@ static void __exit mcdx_exit(void) if (unregister_blkdev(MAJOR_NR, "mcdx") != 0) { xwarn("cleanup() unregister_blkdev() failed\n"); } + blk_cleanup_queue(mcdx_queue); #if !MCDX_QUIET else xinfo("cleanup() succeeded\n"); #endif - blk_cleanup_queue(mcdx_queue); } #ifdef MODULE diff --git a/trunk/drivers/char/stallion.c b/trunk/drivers/char/stallion.c index 45bf2a262a85..e45113a7a472 100644 --- a/trunk/drivers/char/stallion.c +++ b/trunk/drivers/char/stallion.c @@ -2172,12 +2172,11 @@ static int __devinit stl_initech(struct stlbrd *brdp) } status = inb(ioaddr + ECH_PNLSTATUS); if ((status & ECH_PNLIDMASK) != nxtid) - break; + goto err_fr; panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL); if (!panelp) { printk("STALLION: failed to allocate memory " "(size=%Zd)\n", sizeof(struct stlpanel)); - retval = -ENOMEM; goto err_fr; } panelp->magic = STL_PANELMAGIC; @@ -2224,10 +2223,8 @@ static int __devinit stl_initech(struct stlbrd *brdp) brdp->nrports += panelp->nrports; brdp->panels[panelnr++] = panelp; if ((brdp->brdtype != BRD_ECHPCI) && - (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) { - retval = -EINVAL; + (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) goto err_fr; - } } brdp->nrpanels = panelnr; @@ -2374,7 +2371,6 @@ static int __devinit stl_pciprobe(struct pci_dev *pdev, dev_err(&pdev->dev, "too many boards found, " "maximum supported %d\n", STL_MAXBRDS); mutex_unlock(&stl_brdslock); - retval = -ENODEV; goto err_fr; } brdp->brdnr = (unsigned int)brdnr; @@ -4714,29 +4710,6 @@ static int __init stallion_module_init(void) spin_lock_init(&stallion_lock); spin_lock_init(&brd_lock); - stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); - if (!stl_serial) { - retval = -ENOMEM; - goto err; - } - - stl_serial->owner = THIS_MODULE; - stl_serial->driver_name = stl_drvname; - stl_serial->name = "ttyE"; - stl_serial->major = STL_SERIALMAJOR; - stl_serial->minor_start = 0; - stl_serial->type = TTY_DRIVER_TYPE_SERIAL; - stl_serial->subtype = SERIAL_TYPE_NORMAL; - stl_serial->init_termios = stl_deftermios; - stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; - tty_set_operations(stl_serial, &stl_ops); - - retval = tty_register_driver(stl_serial); - if (retval) { - printk("STALLION: failed to register serial driver\n"); - goto err_frtty; - } - /* * Find any dynamically supported boards. That is via module load * line options. @@ -4766,9 +4739,13 @@ static int __init stallion_module_init(void) /* this has to be _after_ isa finding because of locking */ retval = pci_register_driver(&stl_pcidriver); - if (retval && stl_nrbrds == 0) { - printk(KERN_ERR "STALLION: can't register pci driver\n"); - goto err_unrtty; + if (retval && stl_nrbrds == 0) + goto err; + + stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); + if (!stl_serial) { + retval = -ENOMEM; + goto err_pcidr; } /* @@ -4779,18 +4756,43 @@ static int __init stallion_module_init(void) printk("STALLION: failed to register serial board device\n"); stallion_class = class_create(THIS_MODULE, "staliomem"); - if (IS_ERR(stallion_class)) - printk("STALLION: failed to create class\n"); + if (IS_ERR(stallion_class)) { + retval = PTR_ERR(stallion_class); + goto err_reg; + } for (i = 0; i < 4; i++) class_device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i); + stl_serial->owner = THIS_MODULE; + stl_serial->driver_name = stl_drvname; + stl_serial->name = "ttyE"; + stl_serial->major = STL_SERIALMAJOR; + stl_serial->minor_start = 0; + stl_serial->type = TTY_DRIVER_TYPE_SERIAL; + stl_serial->subtype = SERIAL_TYPE_NORMAL; + stl_serial->init_termios = stl_deftermios; + stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; + tty_set_operations(stl_serial, &stl_ops); + + retval = tty_register_driver(stl_serial); + if (retval) { + printk("STALLION: failed to register serial driver\n"); + goto err_clsdev; + } + return 0; -err_unrtty: - tty_unregister_driver(stl_serial); -err_frtty: +err_clsdev: + for (i = 0; i < 4; i++) + class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); + class_destroy(stallion_class); +err_reg: + unregister_chrdev(STL_SIOMEMMAJOR, "staliomem"); put_tty_driver(stl_serial); +err_pcidr: + pci_unregister_driver(&stl_pcidriver); + stl_free_isabrds(); err: return retval; } @@ -4819,6 +4821,8 @@ static void __exit stallion_module_exit(void) tty_unregister_device(stl_serial, brdp->brdnr * STL_MAXPORTS + j); } + tty_unregister_driver(stl_serial); + put_tty_driver(stl_serial); for (i = 0; i < 4; i++) class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); @@ -4830,9 +4834,6 @@ static void __exit stallion_module_exit(void) pci_unregister_driver(&stl_pcidriver); stl_free_isabrds(); - - tty_unregister_driver(stl_serial); - put_tty_driver(stl_serial); } module_init(stallion_module_init); diff --git a/trunk/drivers/isdn/hardware/eicon/divasfunc.c b/trunk/drivers/isdn/hardware/eicon/divasfunc.c index d36a4c09e25d..46fc21a3f8ff 100644 --- a/trunk/drivers/isdn/hardware/eicon/divasfunc.c +++ b/trunk/drivers/isdn/hardware/eicon/divasfunc.c @@ -195,7 +195,7 @@ static int DIVA_INIT_FUNCTION connect_didd(void) /* * disconnect from didd */ -static void disconnect_didd(void) +static void DIVA_EXIT_FUNCTION disconnect_didd(void) { IDI_SYNC_REQ req; diff --git a/trunk/drivers/tc/zs.c b/trunk/drivers/tc/zs.c index 61de78a9f6ee..3524e3fc08b9 100644 --- a/trunk/drivers/tc/zs.c +++ b/trunk/drivers/tc/zs.c @@ -2182,7 +2182,7 @@ struct dec_serial_hook zs_kgdbhook = { .init_info = kgdbhook_init_info, .rx_char = kgdbhook_rx_char, .cflags = B38400 | CS8 | CLOCAL, -}; +} void __init zs_kgdb_hook(int tty_num) { diff --git a/trunk/fs/binfmt_flat.c b/trunk/fs/binfmt_flat.c index 861141b4f6d6..7b0265d7f3a8 100644 --- a/trunk/fs/binfmt_flat.c +++ b/trunk/fs/binfmt_flat.c @@ -558,7 +558,7 @@ static int load_flat_file(struct linux_binprm * bprm, if (!realdatastart) realdatastart = (unsigned long) -ENOMEM; printk("Unable to allocate RAM for process data, errno %d\n", - (int)-realdatastart); + (int)-datapos); do_munmap(current->mm, textpos, text_len); ret = realdatastart; goto err; diff --git a/trunk/include/linux/console_struct.h b/trunk/include/linux/console_struct.h index dc77fed7b285..a461f76fb004 100644 --- a/trunk/include/linux/console_struct.h +++ b/trunk/include/linux/console_struct.h @@ -9,9 +9,6 @@ * to achieve effects such as fast scrolling by changing the origin. */ -#ifndef _LINUX_CONSOLE_STRUCT_H -#define _LINUX_CONSOLE_STRUCT_H - #include #include #include @@ -133,5 +130,3 @@ extern void vc_SAK(struct work_struct *work); #define CUR_DEFAULT CUR_UNDERLINE #define CON_IS_VISIBLE(conp) (*conp->vc_display_fg == conp) - -#endif /* _LINUX_CONSOLE_STRUCT_H */ diff --git a/trunk/include/linux/kernel.h b/trunk/include/linux/kernel.h index 7a4852505914..45353d757cd0 100644 --- a/trunk/include/linux/kernel.h +++ b/trunk/include/linux/kernel.h @@ -218,14 +218,10 @@ enum { DUMP_PREFIX_ADDRESS, DUMP_PREFIX_OFFSET }; -extern void hex_dump_to_buffer(const void *buf, size_t len, - int rowsize, int groupsize, - char *linebuf, size_t linebuflen, bool ascii); -extern void print_hex_dump(const char *level, const char *prefix_str, - int prefix_type, int rowsize, int groupsize, - void *buf, size_t len, bool ascii); -extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, - void *buf, size_t len); +extern void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf, + size_t linebuflen); +extern void print_hex_dump(const char *level, int prefix_type, + void *buf, size_t len); #define hex_asc(x) "0123456789abcdef"[x] #ifdef DEBUG diff --git a/trunk/include/linux/sched.h b/trunk/include/linux/sched.h index 693f0e6c54d4..d58e74b98367 100644 --- a/trunk/include/linux/sched.h +++ b/trunk/include/linux/sched.h @@ -1162,7 +1162,6 @@ static inline void put_task_struct(struct task_struct *t) /* Not implemented yet, only for 486*/ #define PF_STARTING 0x00000002 /* being created */ #define PF_EXITING 0x00000004 /* getting shut down */ -#define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ #define PF_DUMPCORE 0x00000200 /* dumped core */ diff --git a/trunk/include/linux/slub_def.h b/trunk/include/linux/slub_def.h index a0ad37463d62..0764c829d967 100644 --- a/trunk/include/linux/slub_def.h +++ b/trunk/include/linux/slub_def.h @@ -70,8 +70,11 @@ extern struct kmem_cache kmalloc_caches[KMALLOC_SHIFT_HIGH + 1]; */ static inline int kmalloc_index(size_t size) { - if (!size) - return 0; + /* + * We should return 0 if size == 0 but we use the smallest object + * here for SLAB legacy reasons. + */ + WARN_ON_ONCE(size == 0); if (size > KMALLOC_MAX_SIZE) return -1; @@ -150,25 +153,13 @@ static inline struct kmem_cache *kmalloc_slab(size_t size) #define SLUB_DMA 0 #endif - -/* - * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. - * - * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault. - * - * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can. - * Both make kfree a no-op. - */ -#define ZERO_SIZE_PTR ((void *)16) - - static inline void *kmalloc(size_t size, gfp_t flags) { if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) { struct kmem_cache *s = kmalloc_slab(size); if (!s) - return ZERO_SIZE_PTR; + return NULL; return kmem_cache_alloc(s, flags); } else @@ -181,7 +172,7 @@ static inline void *kzalloc(size_t size, gfp_t flags) struct kmem_cache *s = kmalloc_slab(size); if (!s) - return ZERO_SIZE_PTR; + return NULL; return kmem_cache_zalloc(s, flags); } else @@ -197,7 +188,7 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node) struct kmem_cache *s = kmalloc_slab(size); if (!s) - return ZERO_SIZE_PTR; + return NULL; return kmem_cache_alloc_node(s, flags, node); } else diff --git a/trunk/kernel/exit.c b/trunk/kernel/exit.c index 5c8ecbaa19a5..5b888c24e43e 100644 --- a/trunk/kernel/exit.c +++ b/trunk/kernel/exit.c @@ -892,29 +892,13 @@ fastcall NORET_TYPE void do_exit(long code) if (unlikely(tsk->flags & PF_EXITING)) { printk(KERN_ALERT "Fixing recursive fault but reboot is needed!\n"); - /* - * We can do this unlocked here. The futex code uses - * this flag just to verify whether the pi state - * cleanup has been done or not. In the worst case it - * loops once more. We pretend that the cleanup was - * done as there is no way to return. Either the - * OWNER_DIED bit is set by now or we push the blocked - * task into the wait for ever nirwana as well. - */ - tsk->flags |= PF_EXITPIDONE; if (tsk->io_context) exit_io_context(); set_current_state(TASK_UNINTERRUPTIBLE); schedule(); } - /* - * tsk->flags are checked in the futex code to protect against - * an exiting task cleaning up the robust pi futexes. - */ - spin_lock_irq(&tsk->pi_lock); tsk->flags |= PF_EXITING; - spin_unlock_irq(&tsk->pi_lock); if (unlikely(in_atomic())) printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", @@ -928,7 +912,7 @@ fastcall NORET_TYPE void do_exit(long code) } group_dead = atomic_dec_and_test(&tsk->signal->live); if (group_dead) { - hrtimer_cancel(&tsk->signal->real_timer); + hrtimer_cancel(&tsk->signal->real_timer); exit_itimers(tsk->signal); } acct_collect(code, group_dead); @@ -981,12 +965,6 @@ fastcall NORET_TYPE void do_exit(long code) * Make sure we are holding no locks: */ debug_check_no_locks_held(tsk); - /* - * We can do this unlocked here. The futex code uses this flag - * just to verify whether the pi state cleanup has been done - * or not. In the worst case it loops once more. - */ - tsk->flags |= PF_EXITPIDONE; if (tsk->io_context) exit_io_context(); diff --git a/trunk/kernel/futex.c b/trunk/kernel/futex.c index 3b7f7713d9a4..b7ce15c67e32 100644 --- a/trunk/kernel/futex.c +++ b/trunk/kernel/futex.c @@ -430,6 +430,10 @@ static struct task_struct * futex_find_get_task(pid_t pid) p = NULL; goto out_unlock; } + if (p->exit_state != 0) { + p = NULL; + goto out_unlock; + } get_task_struct(p); out_unlock: rcu_read_unlock(); @@ -498,7 +502,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, struct futex_q *this, *next; struct plist_head *head; struct task_struct *p; - pid_t pid = uval & FUTEX_TID_MASK; + pid_t pid; head = &hb->chain; @@ -516,8 +520,6 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, return -EINVAL; WARN_ON(!atomic_read(&pi_state->refcount)); - WARN_ON(pid && pi_state->owner && - pi_state->owner->pid != pid); atomic_inc(&pi_state->refcount); *ps = pi_state; @@ -528,33 +530,15 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, /* * We are the first waiter - try to look up the real owner and attach - * the new pi_state to it, but bail out when TID = 0 + * the new pi_state to it, but bail out when the owner died bit is set + * and TID = 0: */ - if (!pid) + pid = uval & FUTEX_TID_MASK; + if (!pid && (uval & FUTEX_OWNER_DIED)) return -ESRCH; p = futex_find_get_task(pid); - if (IS_ERR(p)) - return PTR_ERR(p); - - /* - * We need to look at the task state flags to figure out, - * whether the task is exiting. To protect against the do_exit - * change of the task flags, we do this protected by - * p->pi_lock: - */ - spin_lock_irq(&p->pi_lock); - if (unlikely(p->flags & PF_EXITING)) { - /* - * The task is on the way out. When PF_EXITPIDONE is - * set, we know that the task has finished the - * cleanup: - */ - int ret = (p->flags & PF_EXITPIDONE) ? -ESRCH : -EAGAIN; - - spin_unlock_irq(&p->pi_lock); - put_task_struct(p); - return ret; - } + if (!p) + return -ESRCH; pi_state = alloc_pi_state(); @@ -567,6 +551,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb, /* Store the key for possible exit cleanups: */ pi_state->key = *key; + spin_lock_irq(&p->pi_lock); WARN_ON(!list_empty(&pi_state->list)); list_add(&pi_state->list, &p->pi_state_list); pi_state->owner = p; @@ -633,8 +618,6 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this) * preserve the owner died bit.) */ if (!(uval & FUTEX_OWNER_DIED)) { - int ret = 0; - newval = FUTEX_WAITERS | new_owner->pid; /* Keep the FUTEX_WAITER_REQUEUED flag if it was set */ newval |= (uval & FUTEX_WAITER_REQUEUED); @@ -642,15 +625,10 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this) pagefault_disable(); curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); pagefault_enable(); - if (curval == -EFAULT) - ret = -EFAULT; + return -EFAULT; if (curval != uval) - ret = -EINVAL; - if (ret) { - spin_unlock(&pi_state->pi_mutex.wait_lock); - return ret; - } + return -EINVAL; } spin_lock_irq(&pi_state->owner->pi_lock); @@ -1196,7 +1174,7 @@ static int futex_requeue(u32 __user *uaddr1, struct rw_semaphore *fshared, #ifdef CONFIG_DEBUG_PI_LIST this->list.plist.lock = &hb2->lock; #endif - } + } this->key = key2; get_futex_key_refs(&key2); drop_count++; @@ -1348,10 +1326,12 @@ static void unqueue_me_pi(struct futex_q *q) /* * Fixup the pi_state owner with current. * - * Must be called with hash bucket lock held and mm->sem held for non - * private futexes. + * The cur->mm semaphore must be held, it is released at return of this + * function. */ -static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, +static int fixup_pi_state_owner(u32 __user *uaddr, struct rw_semaphore *fshared, + struct futex_q *q, + struct futex_hash_bucket *hb, struct task_struct *curr) { u32 newtid = curr->pid | FUTEX_WAITERS; @@ -1375,24 +1355,23 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, list_add(&pi_state->list, &curr->pi_state_list); spin_unlock_irq(&curr->pi_lock); + /* Unqueue and drop the lock */ + unqueue_me_pi(q); + if (fshared) + up_read(fshared); /* * We own it, so we have to replace the pending owner * TID. This must be atomic as we have preserve the * owner died bit here. */ - ret = get_futex_value_locked(&uval, uaddr); - + ret = get_user(uval, uaddr); while (!ret) { newval = (uval & FUTEX_OWNER_DIED) | newtid; newval |= (uval & FUTEX_WAITER_REQUEUED); - - pagefault_disable(); curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); - pagefault_enable(); - if (curval == -EFAULT) - ret = -EFAULT; + ret = -EFAULT; if (curval == uval) break; uval = curval; @@ -1574,7 +1553,10 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared, */ uaddr = q.pi_state->key.uaddr; - ret = fixup_pi_state_owner(uaddr, &q, curr); + /* mmap_sem and hash_bucket lock are unlocked at + return of this function */ + ret = fixup_pi_state_owner(uaddr, fshared, + &q, hb, curr); } else { /* * Catch the rare case, where the lock was released @@ -1585,13 +1567,12 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared, if (rt_mutex_trylock(&q.pi_state->pi_mutex)) ret = 0; } + /* Unqueue and drop the lock */ + unqueue_me_pi(&q); + if (fshared) + up_read(fshared); } - /* Unqueue and drop the lock */ - unqueue_me_pi(&q); - if (fshared) - up_read(fshared); - debug_rt_mutex_free_waiter(&q.waiter); return ret; @@ -1707,7 +1688,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, struct futex_hash_bucket *hb; u32 uval, newval, curval; struct futex_q q; - int ret, lock_taken, ownerdied = 0, attempt = 0; + int ret, lock_held, attempt = 0; if (refill_pi_state_cache()) return -ENOMEM; @@ -1728,11 +1709,10 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, if (unlikely(ret != 0)) goto out_release_sem; - retry_unlocked: hb = queue_lock(&q, -1, NULL); retry_locked: - ret = lock_taken = 0; + lock_held = 0; /* * To avoid races, we attempt to take the lock here again @@ -1748,44 +1728,43 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, if (unlikely(curval == -EFAULT)) goto uaddr_faulted; - /* - * Detect deadlocks. In case of REQUEUE_PI this is a valid - * situation and we return success to user space. - */ + /* We own the lock already */ if (unlikely((curval & FUTEX_TID_MASK) == current->pid)) { + if (!detect && 0) + force_sig(SIGKILL, current); + /* + * Normally, this check is done in user space. + * In case of requeue, the owner may attempt to lock this futex, + * even if the ownership has already been given by the previous + * waker. + * In the usual case, this is a case of deadlock, but not in case + * of REQUEUE_PI. + */ if (!(curval & FUTEX_WAITER_REQUEUED)) ret = -EDEADLK; goto out_unlock_release_sem; } /* - * Surprise - we got the lock. Just return to userspace: + * Surprise - we got the lock. Just return + * to userspace: */ if (unlikely(!curval)) goto out_unlock_release_sem; uval = curval; - - /* - * Set the WAITERS flag, so the owner will know it has someone - * to wake at next unlock - */ - newval = curval | FUTEX_WAITERS; - /* - * There are two cases, where a futex might have no owner (the - * owner TID is 0): OWNER_DIED or REQUEUE. We take over the - * futex in this case. We also do an unconditional take over, - * when the owner of the futex died. - * - * This is safe as we are protected by the hash bucket lock ! + * In case of a requeue, check if there already is an owner + * If not, just take the futex. */ - if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) { - /* Keep the OWNER_DIED and REQUEUE bits */ - newval = (curval & ~FUTEX_TID_MASK) | current->pid; - ownerdied = 0; - lock_taken = 1; - } + if ((curval & FUTEX_WAITER_REQUEUED) && !(curval & FUTEX_TID_MASK)) { + /* set current as futex owner */ + newval = curval | current->pid; + lock_held = 1; + } else + /* Set the WAITERS flag, so the owner will know it has someone + to wake at next unlock */ + newval = curval | FUTEX_WAITERS; pagefault_disable(); curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval); @@ -1796,13 +1775,8 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, if (unlikely(curval != uval)) goto retry_locked; - /* - * We took the lock due to requeue or owner died take over. - */ - if (unlikely(lock_taken)) { - /* For requeue we need to fixup the pi_futex */ - if (curval & FUTEX_WAITER_REQUEUED) - set_pi_futex_owner(hb, &q.key, curr); + if (lock_held) { + set_pi_futex_owner(hb, &q.key, curr); goto out_unlock_release_sem; } @@ -1813,40 +1787,34 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, ret = lookup_pi_state(uval, hb, &q.key, &q.pi_state); if (unlikely(ret)) { - switch (ret) { + /* + * There were no waiters and the owner task lookup + * failed. When the OWNER_DIED bit is set, then we + * know that this is a robust futex and we actually + * take the lock. This is safe as we are protected by + * the hash bucket lock. We also set the waiters bit + * unconditionally here, to simplify glibc handling of + * multiple tasks racing to acquire the lock and + * cleanup the problems which were left by the dead + * owner. + */ + if (curval & FUTEX_OWNER_DIED) { + uval = newval; + newval = current->pid | + FUTEX_OWNER_DIED | FUTEX_WAITERS; - case -EAGAIN: - /* - * Task is exiting and we just wait for the - * exit to complete. - */ - queue_unlock(&q, hb); - if (fshared) - up_read(fshared); - cond_resched(); - goto retry; + pagefault_disable(); + curval = futex_atomic_cmpxchg_inatomic(uaddr, + uval, newval); + pagefault_enable(); - case -ESRCH: - /* - * No owner found for this futex. Check if the - * OWNER_DIED bit is set to figure out whether - * this is a robust futex or not. - */ - if (get_futex_value_locked(&curval, uaddr)) + if (unlikely(curval == -EFAULT)) goto uaddr_faulted; - - /* - * We simply start over in case of a robust - * futex. The code above will take the futex - * and return happy. - */ - if (curval & FUTEX_OWNER_DIED) { - ownerdied = 1; + if (unlikely(curval != uval)) goto retry_locked; - } - default: - goto out_unlock_release_sem; + ret = 0; } + goto out_unlock_release_sem; } /* @@ -1877,42 +1845,31 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, down_read(fshared); spin_lock(q.lock_ptr); - if (!ret) { - /* - * Got the lock. We might not be the anticipated owner - * if we did a lock-steal - fix up the PI-state in - * that case: - */ - if (q.pi_state->owner != curr) - ret = fixup_pi_state_owner(uaddr, &q, curr); - } else { + /* + * Got the lock. We might not be the anticipated owner if we + * did a lock-steal - fix up the PI-state in that case. + */ + if (!ret && q.pi_state->owner != curr) + /* mmap_sem is unlocked at return of this function */ + ret = fixup_pi_state_owner(uaddr, fshared, &q, hb, curr); + else { /* * Catch the rare case, where the lock was released - * when we were on the way back before we locked the - * hash bucket. + * when we were on the way back before we locked + * the hash bucket. */ - if (q.pi_state->owner == curr && - rt_mutex_trylock(&q.pi_state->pi_mutex)) { - ret = 0; - } else { - /* - * Paranoia check. If we did not take the lock - * in the trylock above, then we should not be - * the owner of the rtmutex, neither the real - * nor the pending one: - */ - if (rt_mutex_owner(&q.pi_state->pi_mutex) == curr) - printk(KERN_ERR "futex_lock_pi: ret = %d " - "pi-mutex: %p pi-state %p\n", ret, - q.pi_state->pi_mutex.owner, - q.pi_state->owner); + if (ret && q.pi_state->owner == curr) { + if (rt_mutex_trylock(&q.pi_state->pi_mutex)) + ret = 0; } + /* Unqueue and drop the lock */ + unqueue_me_pi(&q); + if (fshared) + up_read(fshared); } - /* Unqueue and drop the lock */ - unqueue_me_pi(&q); - if (fshared) - up_read(fshared); + if (!detect && ret == -EDEADLK && 0) + force_sig(SIGKILL, current); return ret != -EINTR ? ret : -ERESTARTNOINTR; @@ -1930,19 +1887,16 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared, * non-atomically. Therefore, if get_user below is not * enough, we need to handle the fault ourselves, while * still holding the mmap_sem. - * - * ... and hb->lock. :-) --ANK */ - queue_unlock(&q, hb); - if (attempt++) { ret = futex_handle_fault((unsigned long)uaddr, fshared, attempt); if (ret) - goto out_release_sem; - goto retry_unlocked; + goto out_unlock_release_sem; + goto retry_locked; } + queue_unlock(&q, hb); if (fshared) up_read(fshared); @@ -1986,9 +1940,9 @@ static int futex_unlock_pi(u32 __user *uaddr, struct rw_semaphore *fshared) goto out; hb = hash_futex(&key); -retry_unlocked: spin_lock(&hb->lock); +retry_locked: /* * To avoid races, try to do the TID -> 0 atomic transition * again. If it succeeds then we can return without waking @@ -2051,19 +2005,16 @@ static int futex_unlock_pi(u32 __user *uaddr, struct rw_semaphore *fshared) * non-atomically. Therefore, if get_user below is not * enough, we need to handle the fault ourselves, while * still holding the mmap_sem. - * - * ... and hb->lock. --ANK */ - spin_unlock(&hb->lock); - if (attempt++) { ret = futex_handle_fault((unsigned long)uaddr, fshared, attempt); if (ret) - goto out; - goto retry_unlocked; + goto out_unlock; + goto retry_locked; } + spin_unlock(&hb->lock); if (fshared) up_read(fshared); diff --git a/trunk/kernel/rtmutex.c b/trunk/kernel/rtmutex.c index a6fbb4130521..12879f6c1ec3 100644 --- a/trunk/kernel/rtmutex.c +++ b/trunk/kernel/rtmutex.c @@ -189,19 +189,6 @@ int rt_mutex_adjust_prio_chain(struct task_struct *task, if (!waiter || !waiter->task) goto out_unlock_pi; - /* - * Check the orig_waiter state. After we dropped the locks, - * the previous owner of the lock might have released the lock - * and made us the pending owner: - */ - if (orig_waiter && !orig_waiter->task) - goto out_unlock_pi; - - /* - * Drop out, when the task has no waiters. Note, - * top_waiter can be NULL, when we are in the deboosting - * mode! - */ if (top_waiter && (!task_has_pi_waiters(task) || top_waiter != task_top_pi_waiter(task))) goto out_unlock_pi; @@ -649,16 +636,9 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state, * all over without going into schedule to try * to get the lock now: */ - if (unlikely(!waiter.task)) { - /* - * Reset the return value. We might - * have returned with -EDEADLK and the - * owner released the lock while we - * were walking the pi chain. - */ - ret = 0; + if (unlikely(!waiter.task)) continue; - } + if (unlikely(ret)) break; } diff --git a/trunk/lib/hexdump.c b/trunk/lib/hexdump.c index 473f5aed6cae..e6da5b7fc29a 100644 --- a/trunk/lib/hexdump.c +++ b/trunk/lib/hexdump.c @@ -16,98 +16,42 @@ * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory * @buf: data blob to dump * @len: number of bytes in the @buf - * @rowsize: number of bytes to print per line; must be 16 or 32 - * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) * @linebuf: where to put the converted data * @linebuflen: total size of @linebuf, including space for terminating NUL - * @ascii: include ASCII after the hex output * * hex_dump_to_buffer() works on one "line" of output at a time, i.e., - * 16 or 32 bytes of input data converted to hex + ASCII output. + * 16 bytes of input data converted to hex + ASCII output. * * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data * to a hex + ASCII dump at the supplied memory location. * The converted output is always NUL-terminated. * * E.g.: - * hex_dump_to_buffer(frame->data, frame->len, 16, 1, - * linebuf, sizeof(linebuf), 1); + * hex_dump_to_buffer(frame->data, frame->len, linebuf, sizeof(linebuf)); * * example output buffer: - * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO + * 40414243 44454647 48494a4b 4c4d4e4f @ABCDEFGHIJKLMNO */ -void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, - int groupsize, char *linebuf, size_t linebuflen, - bool ascii) +void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf, + size_t linebuflen) { const u8 *ptr = buf; u8 ch; int j, lx = 0; - int ascii_column; - if (rowsize != 16 && rowsize != 32) - rowsize = 16; - - if (!len) - goto nil; - if (len > rowsize) /* limit to one line at a time */ - len = rowsize; - if ((len % groupsize) != 0) /* no mixed size output */ - groupsize = 1; - - switch (groupsize) { - case 8: { - const u64 *ptr8 = buf; - int ngroups = len / groupsize; - - for (j = 0; j < ngroups; j++) - lx += scnprintf(linebuf + lx, linebuflen - lx, - "%16.16llx ", (unsigned long long)*(ptr8 + j)); - ascii_column = 17 * ngroups + 2; - break; - } - - case 4: { - const u32 *ptr4 = buf; - int ngroups = len / groupsize; - - for (j = 0; j < ngroups; j++) - lx += scnprintf(linebuf + lx, linebuflen - lx, - "%8.8x ", *(ptr4 + j)); - ascii_column = 9 * ngroups + 2; - break; - } - - case 2: { - const u16 *ptr2 = buf; - int ngroups = len / groupsize; - - for (j = 0; j < ngroups; j++) - lx += scnprintf(linebuf + lx, linebuflen - lx, - "%4.4x ", *(ptr2 + j)); - ascii_column = 5 * ngroups + 2; - break; - } - - default: - for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen; - j++) { - ch = ptr[j]; - linebuf[lx++] = hex_asc(ch >> 4); - linebuf[lx++] = hex_asc(ch & 0x0f); + for (j = 0; (j < 16) && (j < len) && (lx + 3) < linebuflen; j++) { + if (j && !(j % 4)) linebuf[lx++] = ' '; - } - ascii_column = 3 * rowsize + 2; - break; + ch = ptr[j]; + linebuf[lx++] = hex_asc(ch >> 4); + linebuf[lx++] = hex_asc(ch & 0x0f); } - if (!ascii) - goto nil; - - while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) + if ((lx + 2) < linebuflen) { + linebuf[lx++] = ' '; linebuf[lx++] = ' '; - for (j = 0; (j < rowsize) && (j < len) && (lx + 2) < linebuflen; j++) + } + for (j = 0; (j < 16) && (j < len) && (lx + 2) < linebuflen; j++) linebuf[lx++] = isprint(ptr[j]) ? ptr[j] : '.'; -nil: linebuf[lx++] = '\0'; } EXPORT_SYMBOL(hex_dump_to_buffer); @@ -115,83 +59,46 @@ EXPORT_SYMBOL(hex_dump_to_buffer); /** * print_hex_dump - print a text hex dump to syslog for a binary blob of data * @level: kernel log level (e.g. KERN_DEBUG) - * @prefix_str: string to prefix each line with; - * caller supplies trailing spaces for alignment if desired * @prefix_type: controls whether prefix of an offset, address, or none * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) - * @rowsize: number of bytes to print per line; must be 16 or 32 - * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) * @buf: data blob to dump * @len: number of bytes in the @buf - * @ascii: include ASCII after the hex output * * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump * to the kernel log at the specified kernel log level, with an optional * leading prefix. * - * print_hex_dump() works on one "line" of output at a time, i.e., - * 16 or 32 bytes of input data converted to hex + ASCII output. - * print_hex_dump() iterates over the entire input @buf, breaking it into - * "line size" chunks to format and print. - * * E.g.: - * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, - * 16, 1, frame->data, frame->len, 1); + * print_hex_dump(KERN_DEBUG, DUMP_PREFIX_ADDRESS, frame->data, frame->len); * - * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: - * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO - * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: - * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. + * Example output using %DUMP_PREFIX_OFFSET: + * 0009ab42: 40414243 44454647 48494a4b 4c4d4e4f @ABCDEFGHIJKLMNO + * Example output using %DUMP_PREFIX_ADDRESS: + * ffffffff88089af0: 70717273 74757677 78797a7b 7c7d7e7f pqrstuvwxyz{|}~. */ -void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, - int rowsize, int groupsize, - void *buf, size_t len, bool ascii) +void print_hex_dump(const char *level, int prefix_type, void *buf, size_t len) { u8 *ptr = buf; int i, linelen, remaining = len; - unsigned char linebuf[200]; + unsigned char linebuf[100]; - if (rowsize != 16 && rowsize != 32) - rowsize = 16; - - for (i = 0; i < len; i += rowsize) { - linelen = min(remaining, rowsize); - remaining -= rowsize; - hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, - linebuf, sizeof(linebuf), ascii); + for (i = 0; i < len; i += 16) { + linelen = min(remaining, 16); + remaining -= 16; + hex_dump_to_buffer(ptr + i, linelen, linebuf, sizeof(linebuf)); switch (prefix_type) { case DUMP_PREFIX_ADDRESS: - printk("%s%s%*p: %s\n", level, prefix_str, + printk("%s%*p: %s\n", level, (int)(2 * sizeof(void *)), ptr + i, linebuf); break; case DUMP_PREFIX_OFFSET: - printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); + printk("%s%.8x: %s\n", level, i, linebuf); break; default: - printk("%s%s%s\n", level, prefix_str, linebuf); + printk("%s%s\n", level, linebuf); break; } } } EXPORT_SYMBOL(print_hex_dump); - -/** - * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params - * @prefix_str: string to prefix each line with; - * caller supplies trailing spaces for alignment if desired - * @prefix_type: controls whether prefix of an offset, address, or none - * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) - * @buf: data blob to dump - * @len: number of bytes in the @buf - * - * Calls print_hex_dump(), with log level of KERN_DEBUG, - * rowsize of 16, groupsize of 1, and ASCII output included. - */ -void print_hex_dump_bytes(const char *prefix_str, int prefix_type, - void *buf, size_t len) -{ - print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, - buf, len, 1); -} -EXPORT_SYMBOL(print_hex_dump_bytes); diff --git a/trunk/mm/shmem.c b/trunk/mm/shmem.c index b6aae2b33393..e537317bec4d 100644 --- a/trunk/mm/shmem.c +++ b/trunk/mm/shmem.c @@ -967,8 +967,6 @@ static inline int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_ *nodelist++ = '\0'; if (nodelist_parse(nodelist, *policy_nodes)) goto out; - if (!nodes_subset(*policy_nodes, node_online_map)) - goto out; } if (!strcmp(value, "default")) { *policy = MPOL_DEFAULT; diff --git a/trunk/mm/slab.c b/trunk/mm/slab.c index 6d65cf4e4b2e..2e71a328aa09 100644 --- a/trunk/mm/slab.c +++ b/trunk/mm/slab.c @@ -3539,7 +3539,7 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) check_irq_off(); objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); - if (cache_free_alien(cachep, objp)) + if (use_alien_caches && cache_free_alien(cachep, objp)) return; if (likely(ac->avail < ac->limit)) { diff --git a/trunk/mm/slub.c b/trunk/mm/slub.c index c9ab68881b43..51663a3c3c24 100644 --- a/trunk/mm/slub.c +++ b/trunk/mm/slub.c @@ -2241,7 +2241,7 @@ void *__kmalloc(size_t size, gfp_t flags) if (s) return slab_alloc(s, flags, -1, __builtin_return_address(0)); - return ZERO_SIZE_PTR; + return NULL; } EXPORT_SYMBOL(__kmalloc); @@ -2252,20 +2252,16 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) if (s) return slab_alloc(s, flags, node, __builtin_return_address(0)); - return ZERO_SIZE_PTR; + return NULL; } EXPORT_SYMBOL(__kmalloc_node); #endif size_t ksize(const void *object) { - struct page *page; + struct page *page = get_object_page(object); struct kmem_cache *s; - if (object == ZERO_SIZE_PTR) - return 0; - - page = get_object_page(object); BUG_ON(!page); s = page->slab; BUG_ON(!s); @@ -2297,13 +2293,7 @@ void kfree(const void *x) struct kmem_cache *s; struct page *page; - /* - * This has to be an unsigned comparison. According to Linus - * some gcc version treat a pointer as a signed entity. Then - * this comparison would be true for all "negative" pointers - * (which would cover the whole upper half of the address space). - */ - if ((unsigned long)x <= (unsigned long)ZERO_SIZE_PTR) + if (!x) return; page = virt_to_head_page(x); @@ -2408,12 +2398,12 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) void *ret; size_t ks; - if (unlikely(!p || p == ZERO_SIZE_PTR)) + if (unlikely(!p)) return kmalloc(new_size, flags); if (unlikely(!new_size)) { kfree(p); - return ZERO_SIZE_PTR; + return NULL; } ks = ksize(p); @@ -2662,7 +2652,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, void *caller) struct kmem_cache *s = get_slab(size, gfpflags); if (!s) - return ZERO_SIZE_PTR; + return NULL; return slab_alloc(s, gfpflags, -1, caller); } @@ -2673,7 +2663,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags, struct kmem_cache *s = get_slab(size, gfpflags); if (!s) - return ZERO_SIZE_PTR; + return NULL; return slab_alloc(s, gfpflags, node, caller); } diff --git a/trunk/mm/sparse.c b/trunk/mm/sparse.c index e03b39f3540f..545e4d3afcdf 100644 --- a/trunk/mm/sparse.c +++ b/trunk/mm/sparse.c @@ -240,27 +240,6 @@ static struct page __init *sparse_early_mem_map_alloc(unsigned long pnum) return NULL; } -/* - * Allocate the accumulated non-linear sections, allocate a mem_map - * for each and record the physical to section mapping. - */ -void __init sparse_init(void) -{ - unsigned long pnum; - struct page *map; - - for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) { - if (!valid_section_nr(pnum)) - continue; - - map = sparse_early_mem_map_alloc(pnum); - if (!map) - continue; - sparse_init_one_section(__nr_to_section(pnum), pnum, map); - } -} - -#ifdef CONFIG_MEMORY_HOTPLUG static struct page *__kmalloc_section_memmap(unsigned long nr_pages) { struct page *page, *ret; @@ -300,6 +279,27 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) get_order(sizeof(struct page) * nr_pages)); } +/* + * Allocate the accumulated non-linear sections, allocate a mem_map + * for each and record the physical to section mapping. + */ +void __init sparse_init(void) +{ + unsigned long pnum; + struct page *map; + + for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) { + if (!valid_section_nr(pnum)) + continue; + + map = sparse_early_mem_map_alloc(pnum); + if (!map) + continue; + sparse_init_one_section(__nr_to_section(pnum), pnum, map); + } +} + +#ifdef CONFIG_MEMORY_HOTPLUG /* * returns the number of sections whose mem_maps were properly * set. If this is <=0, then that means that the passed-in diff --git a/trunk/scripts/checkpatch.pl b/trunk/scripts/checkpatch.pl index aea90d30d229..e216d49624b7 100755 --- a/trunk/scripts/checkpatch.pl +++ b/trunk/scripts/checkpatch.pl @@ -1,15 +1,14 @@ #!/usr/bin/perl -w # (c) 2001, Dave Jones. (the file handling bit) -# (c) 2005, Joel Schopp (the ugly bit) +# (c) 2005, Joel Scohpp (the ugly bit) # (c) 2007, Andy Whitcroft (new conditions, test suite, etc) # Licensed under the terms of the GNU GPL License version 2 use strict; my $P = $0; -$P =~ s@.*/@@g; -my $V = '0.04'; +my $V = '0.01'; use Getopt::Long qw(:config no_auto_abbrev); @@ -27,7 +26,7 @@ my $exit = 0; if ($#ARGV < 0) { - print "usage: $P [options] patchfile\n"; + print "usage: patchstylecheckemail.pl [options] patchfile\n"; print "version: $V\n"; print "options: -q => quiet\n"; print " --no-tree => run without a kernel tree\n"; @@ -39,8 +38,7 @@ exit(2); } -my @dep_includes = (); -my @dep_functions = (); +my @deprecated = (); my $removal = 'Documentation/feature-removal-schedule.txt'; if ($tree && -f $removal) { open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n"; @@ -48,27 +46,22 @@ if (/^Files:\s+(.*\S)/) { for my $file (split(/[, ]+/, $1)) { if ($file =~ m@include/(.*)@) { - push(@dep_includes, $1); + push(@deprecated, $1); } } - - } elsif (/^Funcs:\s+(.*\S)/) { - for my $func (split(/[, ]+/, $1)) { - push(@dep_functions, $func); - } } } } -my @rawlines = (); +my @lines = (); while (<>) { chomp; - push(@rawlines, $_); + push(@lines, $_); if (eof(ARGV)) { - if (!process($ARGV, @rawlines)) { + if (!process($ARGV, @lines)) { $exit = 1; } - @rawlines = (); + @lines = (); } } @@ -106,130 +99,6 @@ sub expand_tabs { return $res; } -sub line_stats { - my ($line) = @_; - - # Drop the diff line leader and expand tabs - $line =~ s/^.//; - $line = expand_tabs($line); - - # Pick the indent from the front of the line. - my ($white) = ($line =~ /^(\s*)/); - - return (length($line), length($white)); -} - -sub sanitise_line { - my ($line) = @_; - - my $res = ''; - my $l = ''; - - my $quote = ''; - - foreach my $c (split(//, $line)) { - if ($l ne "\\" && ($c eq "'" || $c eq '"')) { - if ($quote eq '') { - $quote = $c; - $res .= $c; - $l = $c; - next; - } elsif ($quote eq $c) { - $quote = ''; - } - } - if ($quote && $c ne "\t") { - $res .= "X"; - } else { - $res .= $c; - } - - $l = $c; - } - - return $res; -} - -sub ctx_block_get { - my ($linenr, $remain, $outer) = @_; - my $line; - my $start = $linenr - 1; - my $blk = ''; - my @o; - my @c; - my @res = (); - - for ($line = $start; $remain > 0; $line++) { - next if ($rawlines[$line] =~ /^-/); - $remain--; - - $blk .= $rawlines[$line]; - - @o = ($blk =~ /\{/g); - @c = ($blk =~ /\}/g); - - if (!$outer || (scalar(@o) - scalar(@c)) == 1) { - push(@res, $rawlines[$line]); - } - - last if (scalar(@o) == scalar(@c)); - } - - return @res; -} -sub ctx_block_outer { - my ($linenr, $remain) = @_; - - return ctx_block_get($linenr, $remain, 1); -} -sub ctx_block { - my ($linenr, $remain) = @_; - - return ctx_block_get($linenr, $remain, 0); -} - -sub ctx_locate_comment { - my ($first_line, $end_line) = @_; - - # Catch a comment on the end of the line itself. - my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); - return $current_comment if (defined $current_comment); - - # Look through the context and try and figure out if there is a - # comment. - my $in_comment = 0; - $current_comment = ''; - for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { - my $line = $rawlines[$linenr - 1]; - #warn " $line\n"; - if ($linenr == $first_line and $line =~ m@^.\s*\*@) { - $in_comment = 1; - } - if ($line =~ m@/\*@) { - $in_comment = 1; - } - if (!$in_comment && $current_comment ne '') { - $current_comment = ''; - } - $current_comment .= $line . "\n" if ($in_comment); - if ($line =~ m@\*/@) { - $in_comment = 0; - } - } - - chomp($current_comment); - return($current_comment); -} -sub ctx_has_comment { - my ($first_line, $end_line) = @_; - my $cmt = ctx_locate_comment($first_line, $end_line); - - ##print "LINE: $rawlines[$end_line - 1 ]\n"; - ##print "CMMT: $cmt\n"; - - return ($cmt ne ''); -} - sub cat_vet { my ($vet) = @_; @@ -247,7 +116,7 @@ sub process { my $prevline=""; my $stashline=""; - my $length; + my $lineforcounting=''; my $indent; my $previndent=0; my $stashindent=0; @@ -270,14 +139,13 @@ sub process { #extract the filename as it passes if ($line=~/^\+\+\+\s+(\S+)/) { $realfile=$1; - $realfile =~ s@^[^/]*/@@; $in_comment = 0; next; } #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) { $is_patch = 1; - $first_line = $linenr + 1; + $first_line = 1; $in_comment = 0; $realline=$1-1; if (defined $2) { @@ -288,11 +156,10 @@ sub process { next; } -# track the line number as we move through the hunk, note that -# new versions of GNU diff omit the leading space on completely -# blank context lines so we need to count that too. - if ($line =~ /^( |\+|$)/) { +#track the line number as we move through the hunk + if ($line=~/^[ \+]/) { $realline++; + $realcnt-- if ($realcnt != 0); # track any sort of multi-line comment. Obviously if # the added text or context do not include the whole @@ -301,7 +168,7 @@ sub process { # Guestimate if this is a continuing comment. If this # is the start of a diff block and this line starts # ' *' then it is very likely a comment. - if ($linenr == $first_line and $line =~ m@^.\s*\*@) { + if ($first_line and $line =~ m@^.\s*\*@) { $in_comment = 1; } if ($line =~ m@/\*@) { @@ -311,20 +178,23 @@ sub process { $in_comment = 0; } - # Measure the line length and indent. - ($length, $indent) = line_stats($line); + $lineforcounting = $line; + $lineforcounting =~ s/^\+//; + $lineforcounting = expand_tabs($lineforcounting); + + my ($white) = ($lineforcounting =~ /^(\s*)/); + $indent = length($white); # Track the previous line. ($prevline, $stashline) = ($stashline, $line); ($previndent, $stashindent) = ($stashindent, $indent); + $first_line = 0; } - $realcnt-- if ($realcnt != 0); #make up the handle for any error we report on this line - $here = "#$linenr: "; - $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); + $here = "PATCH: $ARGV:$linenr:"; + $here .= "\nFILE: $realfile:$realline:" if ($realcnt != 0); - my $hereline = "$here\n$line\n"; my $herecurr = "$here\n$line\n\n"; my $hereprev = "$here\n$prevline\n$line\n\n"; @@ -333,8 +203,6 @@ sub process { $signoff++; } elsif ($line =~ /^\s*signed-off-by:/i) { - # This is a signoff, if ugly, so do not double report. - $signoff++; if (!($line =~ /^\s*Signed-off-by:/)) { print "use Signed-off-by:\n"; print "$herecurr"; @@ -347,28 +215,21 @@ sub process { } } -# Check for wrappage within a valid hunk of the file - if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) { - print "patch seems to be corrupt (line wrapped?) [$realcnt]\n"; - print "$herecurr"; - $clean = 0; - } - -#ignore lines being removed - if ($line=~/^-/) {next;} +#ignore lines not being added + if ($line=~/^[^\+]/) {next;} -# check we are in a valid source file if not then ignore this hunk - next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); +# check we are in a valid source file *.[hcsS] if not then ignore this hunk + next if ($realfile !~ /\.[hcsS]$/); #trailing whitespace - if ($line=~/\+.*\S\s+$/) { + if ($line=~/\S\s+$/) { my $herevet = "$here\n" . cat_vet($line) . "\n\n"; print "trailing whitespace\n"; print "$herevet"; $clean = 0; } #80 column limit - if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { + if (!($prevline=~/\/\*\*/) && length($lineforcounting) > 80) { print "line over 80 characters\n"; print "$herecurr"; $clean = 0; @@ -392,58 +253,18 @@ sub process { # next if ($in_comment); - # Remove comments from the line before processing. - $line =~ s@/\*.*\*/@@g; - $line =~ s@/\*.*@@; - $line =~ s@.*\*/@@; - - # - # Checks which may be anchored in the context. - # - - # Check for switch () and associated case and default - # statements should be at the same indent. - if ($line=~/\bswitch\s*\(.*\)/) { - my $err = ''; - my $sep = ''; - my @ctx = ctx_block_outer($linenr, $realcnt); - shift(@ctx); - for my $ctx (@ctx) { - my ($clen, $cindent) = line_stats($ctx); - if ($ctx =~ /^\+\s*(case\s+|default:)/ && - $indent != $cindent) { - $err .= "$sep$ctx\n"; - $sep = ''; - } else { - $sep = "[...]\n"; - } - } - if ($err ne '') { - print "switch and case should be at the same indent\n"; - print "$here\n$line\n$err\n"; - $clean = 0; - } - } - -#ignore lines not being added - if ($line=~/^[^\+]/) {next;} - - # - # Checks which are anchored on the added line. - # - # no C99 // comments - if ($line =~ m{//}) { + if ($line =~ m@//@ and !($line =~ m@\".*//.*\"@)) { print "do not use C99 // comments\n"; print "$herecurr"; $clean = 0; } - # Remove C99 comments. - $line =~ s@//.*@@; - # Standardise the strings and chars within the input - # to simplify matching. - $line = sanitise_line($line); + # Remove comments from the line before processing. + $line =~ s@/\*.*\*/@@g; + $line =~ s@/\*.*@@; + $line =~ s@.*\*/@@; + $line =~ s@//.*@@; #EXPORT_SYMBOL should immediately follow its function closing }. if (($line =~ /EXPORT_SYMBOL.*\(.*\)/) || @@ -472,28 +293,8 @@ sub process { } # * goes on variable not on type - my $type = '(?:char|short|int|long|unsigned|float|double|' . - 'struct\s+[A-Za-z\d_]+|' . - 'union\s+[A-Za-z\d_]+)'; - - if ($line =~ m{[A-Za-z\d_]+(\*+) [A-Za-z\d_]+}) { - print "\"foo$1 bar\" should be \"foo $1bar\"\n"; - print "$herecurr"; - $clean = 0; - } - if ($line =~ m{$type (\*) [A-Za-z\d_]+} || - $line =~ m{[A-Za-z\d_]+ (\*\*+) [A-Za-z\d_]+}) { - print "\"foo $1 bar\" should be \"foo $1bar\"\n"; - print "$herecurr"; - $clean = 0; - } - if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_](\*+)\)}) { - print "\"(foo$1)\" should be \"(foo $1)\"\n"; - print "$herecurr"; - $clean = 0; - } - if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_]\s+(\*+)\s+\)}) { - print "\"(foo $1 )\" should be \"(foo $1)\"\n"; + if ($line=~/[A-Za-z\d_]+\* [A-Za-z\d_]+/) { + print "\"foo* bar\" should be \"foo *bar\"\n"; print "$herecurr"; $clean = 0; } @@ -505,29 +306,11 @@ sub process { # $clean = 0; # } -# printk should use KERN_* levels. Note that follow on printk's on the -# same line do not need a level, so we use the current block context -# to try and find and validate the current printk. In summary the current -# printk includes all preceeding printk's which have no newline on the end. -# we assume the first bad printk is the one to report. +# printk should use KERN_* levels if ($line =~ /\bprintk\((?!KERN_)/) { - my $ok = 0; - for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { - #print "CHECK<$lines[$ln - 1]\n"; - # we have a preceeding printk if it ends - # with "\n" ignore it, else it is to blame - if ($lines[$ln - 1] =~ m{\bprintk\(}) { - if ($rawlines[$ln - 1] !~ m{\\n"}) { - $ok = 1; - } - last; - } - } - if ($ok == 0) { - print "printk() should include KERN_ facility level\n"; - print "$herecurr"; - $clean = 0; - } + print "printk() should include KERN_ facility level\n"; + print "$herecurr"; + $clean = 0; } #function brace can't be on same line, except for #defines of do while, or if closed on same line @@ -537,91 +320,86 @@ sub process { print "$herecurr"; $clean = 0; } - # Note we expand the line with the leading + as the real - # line will be displayed with the leading + and the tabs - # will therefore also expand that way. my $opline = $line; - $opline = expand_tabs($opline); - $opline =~ s/^./ /; + $opline =~ s/^.//; if (!($line=~/\#\s*include/)) { # Check operator spacing. my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); - my $off = 0; for (my $n = 0; $n < $#elements; $n += 2) { - $off += length($elements[$n]); - - my $a = ''; - $a = 'V' if ($elements[$n] ne ''); - $a = 'W' if ($elements[$n] =~ /\s$/); - $a = 'B' if ($elements[$n] =~ /(\[|\()$/); - $a = 'O' if ($elements[$n] eq ''); - $a = 'E' if ($elements[$n] eq '' && $n == 0); - + # $wN says we have white-space before or after + # $sN says we have a separator before or after + # $oN says we have another operator before or after + my $w1 = $elements[$n] =~ /\s$/; + my $s1 = $elements[$n] =~ /(\[|\(|\s)$/; + my $o1 = $elements[$n] eq ''; my $op = $elements[$n + 1]; - - my $c = ''; + my $w2 = 1; + my $s2 = 1; + my $o2 = 0; + # If we have something after the operator handle it. if (defined $elements[$n + 2]) { - $c = 'V' if ($elements[$n + 2] ne ''); - $c = 'W' if ($elements[$n + 2] =~ /^\s/); - $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); - $c = 'O' if ($elements[$n + 2] eq ''); - } else { - $c = 'E'; + $w2 = $elements[$n + 2] =~ /^\s/; + $s2 = $elements[$n + 2] =~ /^(\s|\)|\]|;)/; + $o2 = $elements[$n + 2] eq ''; } - # Pick up the preceeding and succeeding characters. - my $ca = substr($opline, $off - 1, 1); - my $cc = ''; - if (length($opline) > ($off + length($elements[$n]))) { - $cc = substr($opline, $off + 1 + length($elements[$n]), 1); + # Generate the context. + my $at = "here: "; + for (my $m = $n; $m >= 0; $m--) { + if ($elements[$m] ne '') { + $at .= $elements[$m]; + last; + } + } + $at .= $op; + for (my $m = $n + 2; defined $elements[$m]; $m++) { + if ($elements[$m] ne '') { + $at .= $elements[$m]; + last; + } } - - my $ctx = "${a}x${c}"; - - my $at = "(ctx:$ctx)"; - - my $ptr = (" " x $off) . "^"; - my $hereptr = "$hereline$ptr\n\n"; ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; + # Skip things apparently in quotes. + next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); # We need ; as an operator. // is a comment. if ($op eq ';' or $op eq '//') { # -> should have no spaces } elsif ($op eq '->') { - if ($ctx =~ /Wx.|.xW/) { + if ($s1 or $s2) { print "no spaces around that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } # , must have a space on the right. } elsif ($op eq ',') { - if ($ctx !~ /.xW|.xE/) { + if (!$s2) { print "need space after that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } # unary ! and unary ~ are allowed no space on the right } elsif ($op eq '!' or $op eq '~') { - if ($ctx !~ /[WOEB]x./) { + if (!$s1 && !$o1) { print "need space before that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } - if ($ctx =~ /.xW/) { + if ($s2) { print "no space after that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } # unary ++ and unary -- are allowed no space on one side. } elsif ($op eq '++' or $op eq '--') { - if ($ctx !~ /[WOB]x[^W]|[^W]x[WOB]/) { + if (($s1 && $s2) || ((!$s1 && !$o1) && (!$s2 && !$o2))) { print "need space one side of that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } @@ -637,28 +415,15 @@ sub process { # # - is the same # - } elsif ($op eq '&' or $op eq '-') { - if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) { - print "need space before that '$op' $at\n"; - print "$hereptr"; - $clean = 0; - } - - # * is the same as & only adding: + # * is the same only adding: # type: # (foo *) # (foo **) # - } elsif ($op eq '*') { - if ($ca eq '*') { - if ($cc =~ /\s/) { - print "no space after that '$op' $at\n"; - print "$hereptr"; - $clean = 0; - } - } elsif ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB/) { + } elsif ($op eq '&' or $op eq '-' or $op eq '*') { + if ($w2 and !$w1) { print "need space before that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } @@ -666,19 +431,18 @@ sub process { } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or $op eq '^' or $op eq '|') { - if ($ctx !~ /VxV|WxW|VxE|WxE/) { + if ($s1 != $s2) { print "need consistent spacing around '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } # All the others need spaces both sides. - } elsif ($ctx !~ /[EW]x[WE]/) { + } elsif (!$s1 or !$s2) { print "need spaces around that '$op' $at\n"; - print "$hereptr"; + print "$herecurr"; $clean = 0; } - $off += length($elements[$n + 1]); } } @@ -690,7 +454,7 @@ sub process { } #goto labels aren't indented, allow a single space however - if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and + if ($line=~/^.\s+[A-Za-z\d_]+:/ and !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { print "labels should not be indented\n"; print "$herecurr"; @@ -698,16 +462,15 @@ sub process { } # Need a space before open parenthesis after if, while etc - if ($line=~/\b(if|while|for|switch)\(/) { + if ($line=~/(if|while|for|switch)\(/) { print "need a space before the open parenthesis\n"; print "$herecurr"; $clean = 0; } # Check for illegal assignment in if conditional. - if ($line=~/\b(if|while)\s*\(.*[^<>!=]=[^=].*\)/) { - #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); - print "do not use assignment in condition\n"; + if ($line=~/(if|while)\s*\(.*[^<>!=]=[^=].*\)/) { + print "do not use assignment in if condition\n"; print "$herecurr"; $clean = 0; } @@ -721,6 +484,17 @@ sub process { $clean = 0; } + # Check for switch () {case, these must be at the + # same indent. We will only catch the first one, as our + # context is very small but people tend to be consistent + # so we will catch them out more often than not. + if ($prevline=~/\s*switch\s*\(.*\)/ and $line=~/\s*case\s+/ + and $previndent != $indent) { + print "switch and case should be at the same indent\n"; + print "$hereprev"; + $clean = 0; + } + #studly caps, commented out until figure out how to distinguish between use of existing and adding new # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { # print "No studly caps, use _\n"; @@ -746,11 +520,11 @@ sub process { } #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 - if ($prevline=~/\b(if|while|for|switch)\s*\(/) { + if ($prevline=~/(if|while|for|switch)\s*\(/) { my @opened = $prevline=~/\(/g; my @closed = $prevline=~/\)/g; my $nr_line = $linenr; - my $remaining = $realcnt - 1; + my $remaining = $realcnt; my $next_line = $line; my $extra_lines = 0; my $display_segment = $prevline; @@ -766,10 +540,10 @@ sub process { @closed = $prevline=~/\)/g; } - if (($prevline=~/\b(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and - !($next_line=~/\b(if|while|for)/) and !($next_line=~/\#define.*do.*while/)) { + if (($prevline=~/(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and + !($next_line=~/(if|while|for)/) and !($next_line=~/\#define.*do.*while/)) { print "That { should be on the previous line\n"; - print "$here\n$display_segment\n$next_line\n\n"; + print "$display_segment\n$next_line\n\n"; $clean = 0; } } @@ -784,7 +558,7 @@ sub process { } # don't include deprecated include files - for my $inc (@dep_includes) { + for my $inc (@deprecated) { if ($line =~ m@\#\s*include\s*\<$inc>@) { print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n"; print "$herecurr"; @@ -792,56 +566,9 @@ sub process { } } -# don't use deprecated functions - for my $func (@dep_functions) { - if ($line =~ /\b$func\b/) { - print "Don't use $func(): see Documentation/feature-removal-schedule.txt\n"; - print "$herecurr"; - $clean = 0; - } - } - -# no volatiles please - if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) { - print "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n"; - print "$herecurr"; - $clean = 0; - } - -# warn about #if 0 - if ($line =~ /^.#\s*if\s+0\b/) { - print "#if 0 -- if this code redundant remove it\n"; - print "$herecurr"; - $clean = 0; - } - -# warn about #ifdefs in C files -# if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { -# print "#ifdef in C files should be avoided\n"; -# print "$herecurr"; -# $clean = 0; -# } - -# check for spinlock_t definitions without a comment. - if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { - my $which = $1; - if (!ctx_has_comment($first_line, $linenr)) { - print "$1 definition without comment\n"; - print "$herecurr"; - $clean = 0; - } - } -# check for memory barriers without a comment. - if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { - if (!ctx_has_comment($first_line, $linenr)) { - print "memory barrier without comment\n"; - print "$herecurr"; - $clean = 0; - } - } -# check of hardware specific defines - if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) { - print "architecture specific defines should be avoided\n"; +# don't use kernel_thread() + if ($line =~ /\bkernel_thread\b/) { + print "Don't use kernel_thread(), use kthread(): see Documentation/feature-removal-schedule.txt\n"; print "$herecurr"; $clean = 0; }