android_kernel_samsung_msm8976/arch/x86/kernel
Arnd Bergmann 6038f373a3 llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.

The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.

New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time.  Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.

The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.

Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.

Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.

===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
//   but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}

@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}

@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
   *off = E
|
   *off += E
|
   func(..., off, ...)
|
   E = *off
)
...+>
}

@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}

@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
  *off = E
|
  *off += E
|
  func(..., off, ...)
|
  E = *off
)
...+>
}

@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}

@ fops0 @
identifier fops;
@@
struct file_operations fops = {
 ...
};

@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
 .llseek = llseek_f,
...
};

@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
 .read = read_f,
...
};

@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
 .write = write_f,
...
};

@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
 .open = open_f,
...
};

// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
...  .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};

@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
...  .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};

// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
...  .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};

// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};

// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};

@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+	.llseek = default_llseek, /* write accesses f_pos */
};

// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////

@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
 .write = write_f,
 .read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};

@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};

@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};

@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-10-15 15:53:27 +02:00
..
acpi Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 10:07:34 -07:00
apic x86, apic: Fix apic=debug boot crash 2010-08-20 10:18:28 +02:00
cpu llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
.gitignore
Makefile x86, olpc: Add support for calling into OpenFirmware 2010-06-18 14:54:36 -07:00
alternative.c x86, alternatives: BUG on encountering an invalid CPU feature number 2010-07-13 14:57:50 -07:00
amd_iommu.c x86/amd-iommu: Export cache-coherency capability 2010-07-27 17:14:24 +02:00
amd_iommu_init.c x86/amd-iommu: Fall back to GART if initialization fails 2010-06-01 10:20:15 +02:00
apb_timer.c x86, mrst: add more timer config options 2010-05-19 13:45:39 -07:00
aperture_64.c x86, gcc-4.6: Fix set but not read variables 2010-07-20 15:38:30 -07:00
apm_32.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
asm-offsets.c
asm-offsets_32.c
asm-offsets_64.c tracing: Define NR_syscalls for x86_64 2009-08-26 21:29:58 +02:00
audit_64.c
bios_uv.c Merge branch 'x86-uv-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-02-28 11:00:55 -08:00
bootflag.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
check.c
cpuid.c x86: convert cpu notifier to return encapsulate errno value 2010-05-27 09:12:48 -07:00
crash.c x86, UV: Make kdump avoid stack dumps 2010-07-21 11:33:27 -07:00
crash_dump_32.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
crash_dump_64.c
doublefault_32.c x86: Use get_desc_base() 2009-07-19 18:27:51 +02:00
dumpstack.c x86: Unify dumpstack.h and stacktrace.h 2010-06-08 23:29:52 +02:00
dumpstack_32.c x86: Unify dumpstack.h and stacktrace.h 2010-06-08 23:29:52 +02:00
dumpstack_64.c x86: Unify dumpstack.h and stacktrace.h 2010-06-08 23:29:52 +02:00
e820.c suspend: Move NVS save/restore code to generic suspend functionality 2010-06-10 11:02:34 -04:00
early-quirks.c x86: Force HPET readback_cmp for all ATI chipsets 2010-07-15 17:10:02 +02:00
early_printk.c earlyprintk,vga,kdb: Fix \b and \r for earlyprintk=vga with kdb 2010-05-20 21:04:31 -05:00
efi.c x86: Remove trailing spaces in messages 2010-02-07 17:47:51 +01:00
efi_32.c
efi_64.c x86: Make 64-bit efi_ioremap use ioremap on MMIO regions 2009-08-03 13:34:25 -07:00
efi_stub_32.S
efi_stub_64.S
entry_32.S Merge branch 'x86-alternatives-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 16:24:17 -07:00
entry_64.S Mark arguments to certain syscalls as being const 2010-08-13 16:53:13 -07:00
ftrace.c Merge branch 'tracing/core' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing into tracing/core 2010-02-27 10:06:10 +01:00
head.c
head32.c fix typos concerning "initiali[zs]e" 2010-06-16 18:05:05 +02:00
head64.c x86: Make sure free_init_pages() frees pages on page boundary 2010-03-29 18:55:33 +02:00
head_32.S x86-32: Separate 1:1 pagetables from swapper_pg_dir 2010-08-18 09:17:20 -07:00
head_64.S x86-64: Simplify loading initial_gs 2010-07-21 21:23:51 -07:00
hpet.c x86/hpet: Use the FSEC_PER_SEC constant for femto-second periods 2010-08-12 09:53:39 -07:00
hw_breakpoint.c x86: Support for instruction breakpoints 2010-06-24 23:35:27 +02:00
i386_ksyms_32.c x86: Don't generate cmpxchg8b_emu if CONFIG_X86_CMPXCHG64=y 2009-10-01 08:42:24 +02:00
i387.c Merge branch 'kvm-updates/2.6.36' of git://git.kernel.org/pub/scm/virt/kvm/kvm 2010-08-22 11:27:36 -07:00
i8237.c
i8253.c i8253: Convert i8253_lock to raw_spinlock 2010-03-02 10:28:38 +01:00
i8259.c x86, i8259: Only register sysdev if we have a real 8259 PIC 2010-07-20 15:27:33 -07:00
init_task.c Rename .data.cacheline_aligned to .data..cacheline_aligned. 2010-03-03 11:25:58 +01:00
io_delay.c
ioport.c x86-64, paravirt: Call set_iopl_mask() on 64 bits 2009-12-09 16:54:08 -08:00
irq.c genirq: Convert irq_desc.lock to raw_spinlock 2009-12-14 23:55:33 +01:00
irq_32.c x86: Unify fixup_irqs() for 32-bit and 64-bit kernels 2009-11-02 15:56:34 +01:00
irq_64.c x86: Unify fixup_irqs() for 32-bit and 64-bit kernels 2009-11-02 15:56:34 +01:00
irqinit.c x86: Merge simd_math_error() into math_error() 2010-05-03 13:39:29 -07:00
k8.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
kdebugfs.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
kgdb.c kgdb: add missing __percpu markup in arch/x86/kernel/kgdb.c 2010-08-16 15:58:30 -05:00
kprobes.c kprobes/x86: Fix the return address of multiple kretprobes 2010-08-19 12:49:56 +02:00
kvm.c KVM guest: do not batch pte updates from interrupt context 2009-09-10 18:10:50 +03:00
kvmclock.c x86, paravirt: don't compute pvclock adjustments if we trust the tsc 2010-05-19 11:41:05 +03:00
ldt.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
machine_kexec_32.c Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-12-08 13:27:33 -08:00
machine_kexec_64.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
mca_32.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
microcode_amd.c Revert "x86: ucode-amd: Load ucode-patches once ..." 2010-01-23 06:21:59 +01:00
microcode_core.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
microcode_intel.c x86: Improve Intel microcode loader performance 2010-03-11 13:49:06 +01:00
mmconf-fam10h_64.c x86: Move range related operation to one file 2010-02-10 17:47:17 -08:00
module.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
mpparse.c x86, apic: Map the local apic when parsing the MP table. 2010-08-05 16:26:42 -07:00
mrst.c Merge branch 'x86-mrst-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 10:06:28 -07:00
msr.c x86: convert cpu notifier to return encapsulate errno value 2010-05-27 09:12:48 -07:00
olpc.c x86, olpc: Constify an olpc_ofw() arg 2010-07-30 18:02:21 -07:00
olpc_ofw.c x86, olpc: Constify an olpc_ofw() arg 2010-07-30 18:02:21 -07:00
paravirt-spinlocks.c locking: Convert __raw_spin* functions to arch_spin* 2009-12-14 23:55:32 +01:00
paravirt.c x86, paravirt: Remove kmap_atomic_pte paravirt op. 2010-02-27 14:41:35 -08:00
paravirt_patch_32.c
paravirt_patch_64.c
pci-calgary_64.c x86, Calgary: Limit the max PHB number to 256 2010-06-30 22:41:42 -07:00
pci-dma.c x86: Detect whether we should use Xen SWIOTLB. 2010-08-02 15:18:33 -04:00
pci-gart_64.c Merge branch 'iommu/fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu into x86/urgent 2010-04-13 13:24:54 +02:00
pci-nommu.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
pci-swiotlb.c x86: remove unnecessary sync_single_range_* in swiotlb_dma_ops 2010-05-27 09:12:52 -07:00
pcspeaker.c
pmtimer_64.c
probe_roms_32.c
process.c Make do_execve() take a const filename pointer 2010-08-17 18:07:43 -07:00
process_32.c x86, perf: Add power_end event to process_*.c cpu_idle routine 2010-06-18 11:35:10 +02:00
process_64.c x86, perf: Add power_end event to process_*.c cpu_idle routine 2010-06-18 11:35:10 +02:00
ptrace.c hw-breakpoints: Tag ptrace breakpoint as exclude_kernel 2010-05-01 04:32:07 +02:00
pvclock.c x86, paravirt: don't compute pvclock adjustments if we trust the tsc 2010-05-19 11:41:05 +03:00
quirks.c x86: Force HPET readback_cmp for all ATI chipsets 2010-07-15 17:10:02 +02:00
reboot.c x86: Fix rebooting on Dell Precision WorkStation T7400 2010-06-20 09:24:13 +02:00
reboot_fixups_32.c cs5535: move the DIVIL MSR definition into linux/cs5535.h 2009-12-15 08:53:28 -08:00
relocate_kernel_32.S
relocate_kernel_64.S
rtc.c Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-09-18 14:05:47 -07:00
scx200_32.c
setup.c x86-32: Separate 1:1 pagetables from swapper_pg_dir 2010-08-18 09:17:20 -07:00
setup_percpu.c Fix up trivial spelling errors ('taht' -> 'that') 2010-07-21 09:25:42 -07:00
sfi.c x86, irq: Rename gsi_end gsi_top, and fix off by one errors 2010-06-09 13:34:06 -07:00
signal.c x86: Merge sys_sigaltstack 2009-12-09 16:28:59 -08:00
smp.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
smpboot.c x86, hotplug: Serialize CPU hotplug to avoid bringup concurrency issues 2010-08-19 14:47:43 -07:00
stacktrace.c x86: Unify save_stack_address() and save_stack_address_nosched() 2010-06-09 17:32:19 +02:00
step.c x86, ptrace: Fix block-step 2010-03-26 11:33:57 +01:00
sys_i386_32.c Make do_execve() take a const filename pointer 2010-08-17 18:07:43 -07:00
sys_x86_64.c improve sys_newuname() for compat architectures 2010-03-12 15:52:32 -08:00
syscall_64.c
syscall_table_32.S x86: fix up system call numbering nit 2010-08-10 15:35:10 -07:00
tboot.c Merge branch 'kvm-updates/2.6.35' of git://git.kernel.org/pub/scm/virt/kvm/kvm 2010-05-21 17:16:21 -07:00
tce_64.c
test_nx.c
test_rodata.c
time.c x86: Convert i8259_lock to raw_spinlock 2010-02-16 18:21:32 +01:00
tlb_uv.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
tls.c
tls.h
topology.c
trampoline.c x86, mm: Fix CONFIG_VMSPLIT_1G and 2G_OPT trampoline 2010-08-24 23:05:17 -07:00
trampoline_32.S x86: cpuinit-annotate SMP boot trampolines properly 2009-09-20 20:23:37 +02:00
trampoline_64.S x86: Fix Suspend to RAM freeze on Acer Aspire 1511Lmi laptop 2009-10-12 18:06:48 +02:00
traps.c Merge branch 'perf/nmi' into perf/core 2010-08-05 08:45:05 +02:00
tsc.c x86, tsc: Fix a preemption leak in restore_sched_clock_state() 2010-09-10 18:17:45 -07:00
tsc_sync.c locking: Convert __raw_spin* functions to arch_spin* 2009-12-14 23:55:32 +01:00
uv_irq.c Merge branch 'x86-uv-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-05-18 09:46:35 -07:00
uv_sysfs.c x86: Remove trailing spaces in messages 2010-02-07 17:47:51 +01:00
uv_time.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
verify_cpu_64.S x86: Use symbolic MSR names 2010-07-21 21:23:40 -07:00
visws_quirks.c Merge remote branch 'origin/x86/apic' into x86/mrst 2010-02-22 16:25:18 -08:00
vm86_32.c x86, 32-bit: Convert sys_vm86 & sys_vm86old 2009-12-09 16:29:23 -08:00
vmi_32.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
vmiclock_32.c Merge branch 'for-next' into for-linus 2010-03-08 16:55:37 +01:00
vmlinux.lds.S Merge branch 'for-35' of git://repo.or.cz/linux-kbuild 2010-06-01 08:55:52 -07:00
vsmp_64.c
vsyscall_64.c timkeeping: Fix update_vsyscall to provide wall_to_monotonic offset 2010-07-27 12:40:54 +02:00
x86_init.c x86: Add i8042 pre-detection hook to x86_platform_ops 2010-07-07 17:05:06 -07:00
x8664_ksyms_64.c x86-64: Don't export init_level4_pgt 2010-04-28 17:25:47 -07:00
xsave.c Merge branch 'x86-xsave-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 16:25:13 -07:00