android_kernel_samsung_msm8976/arch/s390/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 [S390] vdso: use ntp adjusted clock multiplier 2010-04-22 17:17:19 +02:00
vdso64 [S390] vdso: use ntp adjusted clock multiplier 2010-04-22 17:17:19 +02:00
Makefile [S390] add support for compressed kernels 2010-02-26 22:37:33 +01:00
asm-offsets.c [S390] spp: fix compilation for CONFIG_32BIT 2010-05-26 23:26:29 +02:00
audit.c
audit.h
base.S [S390] Cleanup struct _lowcore usage and defines. 2010-02-26 22:37:31 +01:00
bitmap.c [S390] move EXPORT_SYMBOLs to definitions 2009-03-26 15:24:11 +01:00
compat_audit.c
compat_exec_domain.c
compat_linux.c Mark arguments to certain syscalls as being const 2010-08-13 16:53:13 -07:00
compat_linux.h Mark arguments to certain syscalls as being const 2010-08-13 16:53:13 -07:00
compat_ptrace.h [S390] Expose a constant for the number of words representing the CRs 2009-03-26 15:24:25 +01:00
compat_signal.c [S390] 64-bit register support for 31-bit processes 2009-10-06 10:35:10 +02:00
compat_wrapper.S [S390] wire up prlimit64 and fanotify* syscalls 2010-08-13 10:06:54 +02:00
cpcmd.c [S390] convert cpcmd printks to pr_xxx macros. 2008-12-25 13:39:19 +01:00
crash.c
debug.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
diag.c
dis.c [S390] add z9-ec/z10 instruction to kernel disassembler 2010-02-26 22:37:32 +01:00
early.c [S390] virtualization aware cpu measurement 2010-05-17 10:00:15 +02:00
ebcdic.c
entry.S [S390] Fix IRQ tracing in case of PER 2010-07-27 19:29:42 +02:00
entry.h [S390] s390: fix build error (sys_execve) 2010-08-24 09:26:34 +02:00
entry64.S [S390] Fix IRQ tracing in case of PER 2010-07-27 19:29:42 +02:00
ftrace.c Merge branch 'tracing-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-02-28 10:17:55 -08:00
head.S [S390] initrd: change default load address 2010-08-09 18:12:54 +02:00
head31.S [S390] correct address of _stext with CONFIG_SHARED_KERNEL=y 2010-05-12 09:32:26 +02:00
head64.S [S390] correct address of _stext with CONFIG_SHARED_KERNEL=y 2010-05-12 09:32:26 +02:00
init_task.c Use new __init_task_data macro in arch init_task.c files. 2009-09-21 06:27:08 +02:00
ipl.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
irq.c [S390] Fix init irq proc build break. 2009-02-11 10:37:39 +01:00
kprobes.c [S390] kprobes: forbid probing of stnsm/stosm/epsw 2010-05-26 23:26:29 +02:00
machine_kexec.c [S390] smp: always reboot on cpu 0 2010-02-26 22:37:30 +01:00
mcount.S [S390] improve mcount code 2009-09-11 10:29:43 +02:00
mcount64.S [S390] improve mcount code 2009-09-11 10:29:43 +02:00
mem_detect.c [S390] s390: hibernation support for s390 2009-06-16 10:31:22 +02:00
module.c [S390] kprobes: add parameter check to module_free() 2010-06-08 18:58:23 +02:00
nmi.c [S390] idle time accounting vs. machine checks 2010-05-17 10:00:15 +02:00
process.c Make do_execve() take a const filename pointer 2010-08-17 18:07:43 -07:00
processor.c [S390] More cleanup for struct _lowcore 2010-05-17 10:00:15 +02:00
ptrace.c [S390] add breaking event address for user space 2010-05-17 10:00:15 +02:00
reipl.S [S390] Cleanup struct _lowcore usage and defines. 2010-02-26 22:37:31 +01:00
reipl64.S [S390] Cleanup struct _lowcore usage and defines. 2010-02-26 22:37:31 +01:00
relocate_kernel.S
relocate_kernel64.S
s390_ext.c [S390] idle time accounting vs. machine checks 2010-05-17 10:00:15 +02:00
s390_ksyms.c [S390] move EXPORT_SYMBOLs to definitions 2009-03-26 15:24:11 +01:00
sclp.S Merge branch 'for-next' into for-linus 2010-03-08 16:55:37 +01:00
setup.c [S390] spp: fix compilation for CONFIG_32BIT 2010-05-26 23:26:29 +02:00
signal.c [S390] add breaking event address for user space 2010-05-17 10:00:15 +02:00
smp.c [S390] fix tlb flushing vs. concurrent /proc accesses 2010-08-24 09:26:34 +02:00
stacktrace.c
suspend.c [S390] hibernate: make sure pfn_is_nosave handles lowcore pages 2009-09-22 22:58:45 +02:00
switch_cpu.S [S390] Cleanup struct _lowcore usage and defines. 2010-02-26 22:37:31 +01:00
switch_cpu64.S [S390] Cleanup struct _lowcore usage and defines. 2010-02-26 22:37:31 +01:00
swsusp_asm64.S Merge branch 'for-35' of git://repo.or.cz/linux-kbuild 2010-06-01 08:55:52 -07:00
sys_s390.c [S390] sys_personality: follow u_long to unsigned int conversion 2010-08-13 10:06:54 +02:00
syscalls.S [S390] wire up prlimit64 and fanotify* syscalls 2010-08-13 10:06:54 +02:00
sysinfo.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
time.c Merge branch 'timers-timekeeping-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 13:18:29 -07:00
topology.c [S390] topology: expose core identifier 2010-05-17 10:00:16 +02:00
traps.c [S390] debug: enable exception-trace debug facility 2010-05-17 10:00:17 +02:00
vdso.c [S390] vdso: remove redundant check for CONFIG_64BIT 2010-05-17 10:00:16 +02:00
vmlinux.lds.S [S390] Enable kmemleak on s390. 2009-10-06 10:35:06 +02:00
vtime.c [S390] idle time accounting vs. machine checks 2010-05-17 10:00:15 +02:00