linux/arch/powerpc/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
..
vdso32 powerpc: Rework VDSO gettimeofday to prevent time going backwards 2010-07-28 21:06:47 +02:00
vdso64 powerpc: Rework VDSO gettimeofday to prevent time going backwards 2010-07-28 21:06:47 +02:00
.gitignore
align.c powerpc: Handle VSX alignment faults correctly in little-endian mode 2009-12-18 14:55:43 +11:00
asm-offsets.c powerpc: Rework VDSO gettimeofday to prevent time going backwards 2010-07-28 21:06:47 +02:00
audit.c
btext.c lmb: rename to memblock 2010-07-14 17:14:00 +10:00
cacheinfo.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
cacheinfo.h
clock.c
compat_audit.c
cpu_setup_6xx.S powerpc: Use names rather than numbers for SPRGs (v2) 2009-08-20 10:12:27 +10:00
cpu_setup_44x.S
cpu_setup_fsl_booke.S powerpc/fsl-booke: Enable L1 cache on e500v1/e500v2/e500mc CPUs 2009-06-15 21:45:30 -05:00
cpu_setup_pa6t.S
cpu_setup_ppc970.S
cputable.c powerpc/47x: Remove redundant line from cputable.c 2010-08-23 07:37:01 -04:00
crash.c powerpc/kdump: Stop all other CPUs before running crash handlers 2010-08-24 15:26:27 +10:00
crash_dump.c Merge commit 'gcl/next' into next 2010-08-04 10:26:03 +10:00
dbell.c powerpc/book3e: Resend doorbell exceptions to ourself 2010-07-09 16:11:19 +10:00
dma-iommu.c powerpc: Change archdata dma_data to a union 2009-09-24 15:31:43 +10:00
dma-swiotlb.c of: Merge of_platform_bus_type with platform_bus_type 2010-07-24 09:57:51 -06:00
dma.c lmb: rename to memblock 2010-07-14 17:14:00 +10:00
e500-pmu.c powerpc/perf: e500 support 2010-03-05 03:04:08 -06:00
entry_32.S powerpc/47x: Base ppc476 support 2010-05-05 09:11:10 -04:00
entry_64.S powerpc/perf_event: Fix oops due to perf_event_do_pending call 2010-05-12 14:34:00 +10:00
exceptions-64e.S powerpc/book3e: Fix single step when using HW page tables 2010-07-14 14:13:51 +10:00
exceptions-64s.S powerpc, hw_breakpoints: Implement hw_breakpoints for 64-bit server processors 2010-06-22 19:40:50 +10:00
firmware.c powerpc: Make powerpc_firmware_features __read_mostly 2010-02-09 13:56:07 +11:00
fpu.S powerpc: Use names rather than numbers for SPRGs (v2) 2009-08-20 10:12:27 +10:00
fsl_booke_entry_mapping.S powerpc/fsl-booke: Fix address issue when using relocatable kernels 2010-07-11 11:04:08 -05:00
ftrace.c Merge branch 'tracing-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-20 10:56:46 -07:00
head_8xx.S powerpc/8xx: Use SPRG2 and DAR registers to stash r11 and cr. 2010-04-07 18:00:34 +10:00
head_32.S KVM: PPC: Add KVM intercept handlers 2010-05-17 12:18:52 +03:00
head_40x.S powerpc: Use names rather than numbers for SPRGs (v2) 2009-08-20 10:12:27 +10:00
head_44x.S powerpc/47x: Make sure mcsr is cleared before enabling machine check interrupts 2010-08-23 07:36:58 -04:00
head_64.S powerpc: Don't use kernel stack with translation off 2010-08-31 11:35:13 +10:00
head_booke.h powerpc/booke: Add Stack Marking support to Booke Exception Prolog 2010-05-05 08:01:52 -04:00
head_fsl_booke.S powerpc/kexec: Add support for FSL-BookE 2010-05-24 21:25:32 -05:00
hw_breakpoint.c powerpc, hw_breakpoint: Tell generic code we have no instruction breakpoints 2010-06-30 13:54:58 +10:00
ibmebus.c powerpc: remove references to of_device and to_of_device 2010-07-24 09:58:21 -06:00
idle.c powerpc: Re-enable preemption before cpu_die() 2010-08-24 15:26:29 +10:00
idle_6xx.S
idle_book3e.S powerpc/book3e: Add generic 64-bit idle powersave support 2010-07-14 14:13:18 +10:00
idle_e500.S
idle_power4.S
init_task.c Use new __init_task_data macro in arch init_task.c files. 2009-09-21 06:27:08 +02:00
io.c powerpc: tiny memcpy_(to|from)io optimisation 2009-11-04 16:43:12 -07:00
iomap.c
iommu.c powerpc: Remove unused 'protect4gb' boot parameter 2010-05-21 17:31:13 +10:00
irq.c powerpc/4xx: Index interrupt stacks by physical cpu 2010-08-23 07:37:53 -04:00
isa-bridge.c
kgdb.c kgdb,powerpc: Replace hardcoded offset by BREAK_INSTR_SIZE 2010-08-05 09:22:22 -05:00
kprobes.c powerpc/kprobes: Remove resume_execution() in kprobes 2010-06-02 17:50:37 +10:00
l2cr_6xx.S
legacy_serial.c of/address: Clean up function declarations 2010-08-01 01:42:42 -06:00
lparcfg.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
machine_kexec.c Merge commit 'gcl/next' into next 2010-08-04 10:26:03 +10:00
machine_kexec_32.c
machine_kexec_64.c powerpc/kexec: Fix orphaned offline CPUs across kexec 2010-07-31 15:05:22 +10:00
Makefile Merge branch 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6 2010-08-05 15:57:35 -07:00
misc.S perf: Drop the skip argument from perf_arch_fetch_regs_caller 2010-06-08 23:31:27 +02:00
misc_32.S powerpc/kexec: Adds correct calling convention for kexec purgatory 2010-08-31 11:35:12 +10:00
misc_64.S powerpc: Unconditionally enabled irq stacks 2010-06-15 15:02:37 +10:00
module.c module: cleanup FIXME comments about trimming exception table entries. 2009-06-12 21:47:05 +09:30
module_32.c
module_64.c
mpc7450-pmu.c perf: Do the big rename: Performance Counters -> Performance Events 2009-09-21 14:28:04 +02:00
msi.c
nvram_64.c arch/powerpc: Fix continuation line formats 2010-02-09 13:55:05 +11:00
of_platform.c of: remove of_default_bus_ids 2010-07-24 09:58:22 -06:00
paca.c Merge commit 'gcl/next' into next 2010-08-04 10:26:03 +10:00
pci-common.c of/address: Clean up function declarations 2010-08-01 01:42:42 -06:00
pci_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
pci_64.c of: add 'of_' prefix to machine_is_compatible() 2010-02-09 08:33:00 -07:00
pci_dn.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_of_scan.c powerpc/pci: Fix checking for child bridges in PCI code. 2010-08-24 15:28:27 +10:00
perf_callchain.c perf: Fix inconsistency between IP and callchain sampling 2010-01-28 14:31:20 +01:00
perf_event.c Merge branch 'linus' into perf/core 2010-07-21 21:43:06 +02:00
perf_event_fsl_emb.c perf, powerpc: fsl_emb: Restore setting perf_sample_data.period 2010-08-03 10:56:45 +10:00
pmc.c powerpc: Convert pmc_owner_lock to raw_spinlock 2010-02-19 14:52:33 +11:00
power4-pmu.c perf: Do the big rename: Performance Counters -> Performance Events 2009-09-21 14:28:04 +02:00
power5+-pmu.c powerpc: perf_event: Enable SDAR in continous sample mode 2009-10-28 16:13:02 +11:00
power5-pmu.c powerpc: perf_event: Enable SDAR in continous sample mode 2009-10-28 16:13:02 +11:00
power6-pmu.c powerpc: perf_event: Enable SDAR in continous sample mode 2009-10-28 16:13:02 +11:00
power7-pmu.c powerpc: perf_event: Enable SDAR in continous sample mode 2009-10-28 16:13:02 +11:00
ppc32.h
ppc970-pmu.c powerpc: perf_event: Enable SDAR in continous sample mode 2009-10-28 16:13:02 +11:00
ppc_ksyms.c KVM: PPC: elide struct thread_struct instances from stack 2010-08-01 10:39:24 +03:00
ppc_save_regs.S
proc_powerpc.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
process.c powerpc: Inline ppc64_runlatch_off 2010-08-24 15:26:30 +10:00
prom.c powerpc: Fix erroneous lmb->memblock conversions 2010-07-23 12:56:57 +10:00
prom_init.c powerpc: Print decimal values in prom_init.c 2010-07-31 15:05:20 +10:00
prom_init_check.sh powerpc: Fix compile errors in prom_init_check for gcc 4.5 2010-07-08 18:11:39 +10:00
prom_parse.c of/address: Merge all of the bus translation code 2010-07-05 16:14:26 -06:00
ptrace.c powerpc, hw_breakpoints: Implement hw_breakpoints for 64-bit server processors 2010-06-22 19:40:50 +10:00
ptrace32.c headers: smp_lock.h redux 2009-07-12 12:22:34 -07:00
reloc_64.S
rtas-proc.c powerpc: Move /proc/ppc64 to /proc/powerpc update 2010-01-15 13:26:17 +11:00
rtas-rtc.c
rtas.c Merge commit 'gcl/next' into next 2010-08-04 10:26:03 +10:00
rtas_flash.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
rtas_pci.c
rtasd.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
setup-common.c powerpc: fix i8042 module build error 2010-08-06 20:49:20 -06:00
setup.h
setup_32.c powerpc/4xx: Index interrupt stacks by physical cpu 2010-08-23 07:37:53 -04:00
setup_64.c powerpc: Correct smt_enabled=X boot option for > 2 threads per core 2010-08-24 15:26:30 +10:00
signal.c powerpc, hw_breakpoint: Enable hw-breakpoints while handling intervening signals 2010-06-22 19:40:50 +10:00
signal.h
signal_32.c powerpc/booke: Add support for advanced debug registers 2010-02-17 14:03:17 +11:00
signal_64.c
smp-tbsync.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
smp.c powerpc: Silence __cpu_up() under normal operation 2010-08-24 15:26:29 +10:00
softemu8xx.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
stacktrace.c
suspend.c update email address 2010-07-19 10:56:54 +02:00
swsusp.c
swsusp_32.S powerpc/swsusp_32: Fix TLB invalidation 2010-01-15 13:20:07 +11:00
swsusp_64.c
swsusp_asm64.S
swsusp_booke.S powerpc/fsl-booke: Add hibernation support for FSL BookE processors 2010-05-21 07:41:53 -05:00
sys_ppc32.c powerpc: Wire up fanotify_init, fanotify_mark, prlimit64 syscalls 2010-08-24 15:28:28 +10:00
syscalls.c Add generic sys_olduname() 2010-03-12 15:52:32 -08:00
sysfs.c powerpc: Use smt_snooze_delay=-1 to always busy loop 2010-05-21 17:31:12 +10:00
systbl.S
systbl_chk.c
systbl_chk.sh
tau_6xx.c tree-wide: fix assorted typos all over the place 2009-12-04 15:39:55 +01:00
time.c powerpc/perf_event: Reduce latency of calling perf_event_do_pending 2010-08-31 11:35:13 +10:00
traps.c powerpc/book3e: Move doorbell_exception from traps.c to dbell.c 2010-07-09 15:25:18 +10:00
udbg.c powerpc: gamecube/wii: early debugging using usbgecko 2009-12-12 22:24:31 -07:00
udbg_16550.c trivial: fix typo "for for" in multiple files 2009-09-21 15:14:54 +02:00
vdso.c lmb: rename to memblock 2010-07-14 17:14:00 +10:00
vecemu.c
vector.S powerpc: Fix usage of 64-bit instruction in 32-bit altivec code 2009-12-09 18:10:12 +11:00
vio.c powerpc: Fix bogus it_blocksize in VIO iommu code 2010-08-24 15:26:31 +10:00
vmlinux.lds.S Rename .data.read_mostly to .data..read_mostly. 2010-03-03 11:26:00 +01:00