android_kernel_samsung_msm8976/drivers/char
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
..
agp intel_agp,i915: Add more sandybridge graphics device ids 2010-09-07 11:16:44 +01:00
hw_random llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
ip2 llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
ipmi llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
mwave llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
pcmcia llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
rio llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
tpm tpm_tis: fix subsequent suspend failures 2010-07-26 10:25:45 +10:00
xilinx_hwicap llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
.gitignore
Kconfig pc8736x_gpio: depends on X86_32 2010-08-12 08:43:29 -07:00
Makefile tty: implement BTM as mutex instead of BKL 2010-08-10 13:47:44 -07:00
amiserial.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
apm-emulation.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
applicom.c drivers/char/applicom.c: use memdup_user 2010-05-27 09:12:50 -07:00
applicom.h
bfin-otp.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
bfin_jtag_comm.c
briq_panel.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
bsr.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
cd1865.h
consolemap.c
cp437.uni
cs5535_gpio.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
cyclades.c tty: introduce wait_event_interruptible_tty 2010-08-10 13:47:43 -07:00
defkeymap.c_shipped
defkeymap.map
digi1.h
digiFep1.h
digiPCI.h
ds1302.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
ds1620.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
dsp56k.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
dtlk.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
efirtc.c
epca.c epca: Kill the big kernel lock 2010-08-10 13:47:40 -07:00
epca.h
epcaconfig.h
generic_nvram.c
generic_serial.c
genrtc.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
hangcheck-timer.c Input: sysrq - drop tty argument form handle_sysrq() 2010-08-21 00:34:45 -07:00
hpet.c
hvc_beat.c
hvc_console.c Input: sysrq - drop tty argument form handle_sysrq() 2010-08-21 00:34:45 -07:00
hvc_console.h
hvc_irq.c
hvc_iseries.c
hvc_iucv.c Add param ops struct for hvc_iucv driver. 2010-08-11 23:04:16 +09:30
hvc_rtas.c
hvc_tile.c arch/tile: catch up on various minor cleanups. 2010-07-06 13:42:15 -04:00
hvc_udbg.c
hvc_vio.c
hvc_xen.c
hvcs.c
hvsi.c Input: sysrq - drop tty argument form handle_sysrq() 2010-08-21 00:34:45 -07:00
i8k.c
isicom.c isicom: kill off the BKL 2010-08-10 13:47:40 -07:00
istallion.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
keyboard.c tty: Move the vt_tty field from the vc_data into the standard tty_port 2010-08-10 13:47:42 -07:00
lp.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
mbcs.c
mbcs.h
mem.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
misc.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
mmtimer.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
moxa.c
moxa.h
mspec.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
mxser.c mxser: remove unnesesary NULL check 2010-08-10 13:47:45 -07:00
mxser.h
n_gsm.c drivers/char/n_gsm.c: add missing spin_unlock_irqrestore 2010-08-11 08:59:20 -07:00
n_hdlc.c tty: replace BKL with a new tty_lock 2010-08-10 13:47:43 -07:00
n_r3964.c tty: introduce wait_event_interruptible_tty 2010-08-10 13:47:43 -07:00
n_tty.c tty: Add EXTPROC support for LINEMODE 2010-08-10 13:47:39 -07:00
nozomi.c kfifo: fix kfifo miss use of nozami.c 2010-08-11 08:59:23 -07:00
nsc_gpio.c
nvram.c
nwbutton.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
nwbutton.h
nwflash.c
pc8736x_gpio.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
ppdev.c drivers/char/ppdev.c: use kasprintf 2010-05-27 09:12:50 -07:00
ps3flash.c drop unused dentry argument to ->fsync 2010-05-27 22:05:02 -04:00
pty.c tty: fix fu_list abuse 2010-08-18 08:35:47 -04:00
ramoops.c char drivers: RAM oops/panic logger 2010-05-27 09:12:50 -07:00
random.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
raw.c raw: use explicit llseek file operations 2010-09-16 10:33:14 +02:00
riscom8.c riscom8: kill use of lock_kernel 2010-08-10 13:47:40 -07:00
riscom8.h
riscom8_reg.h
rocket.c rocket: add a mutex_unlock() 2010-08-23 18:17:21 -07:00
rocket.h
rocket_int.h
rtc.c of/device: Replace struct of_device with struct platform_device 2010-08-06 09:25:50 -06:00
scc.h
scx200_gpio.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
selection.c tty: remove tty_lock_nested 2010-08-10 13:47:44 -07:00
ser_a2232.c
ser_a2232.h
ser_a2232fw.ax
ser_a2232fw.h
serial167.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
snsc.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
snsc.h
snsc_event.c
sonypi.c
specialix.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
specialix_io8.h
stallion.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
sx.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
sx.h
sxboards.h
sxwindow.h
synclink.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
synclink_gt.c synclink: add mutex_unlock() on error path 2010-08-23 18:17:21 -07:00
synclinkmp.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
sysrq.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
tb0219.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
tlclk.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
toshiba.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
tty_audit.c
tty_buffer.c tty: fix obsolete comment on tty_insert_flip_string_fixed_flag 2010-05-21 09:34:30 -07:00
tty_io.c tty: fix tty_line must not be equal to number of allocated tty pointers in tty driver 2010-09-03 17:29:04 -07:00
tty_ioctl.c tty: Add EXTPROC support for LINEMODE 2010-08-10 13:47:39 -07:00
tty_ldisc.c tty: remove tty_lock_nested 2010-08-10 13:47:44 -07:00
tty_mutex.c tty: implement BTM as mutex instead of BKL 2010-08-10 13:47:44 -07:00
tty_port.c tty: release BTM while sleeping in block_til_ready 2010-08-10 13:47:44 -07:00
uv_mmtimer.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
vc_screen.c tty: replace BKL with a new tty_lock 2010-08-10 13:47:43 -07:00
viotape.c viotape: use noop_llseek 2010-09-16 10:33:15 +02:00
virtio_console.c virtio: console: Fix crash when port is unplugged and blocked for write 2010-06-03 22:39:19 +09:30
vme_scc.c
vt.c vt: Fix console corruption on driver hand-over. 2010-09-03 17:29:03 -07:00
vt_ioctl.c Input: use PIT_TICK_RATE in vt beep ioctl 2010-08-28 21:39:09 -07:00