linux-stable/drivers/ide
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
..
aec62xx.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
ali14xx.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
alim15x3.c alim15x3: fix handling of UDMA enable bit 2010-01-19 01:52:31 -08:00
amd74xx.c amd74xx: use ->pio_mode value to determine pair device speed 2010-01-19 01:52:32 -08:00
at91_ide.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
atiixp.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
au1xxx-ide.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide-next-2.6 2010-03-04 08:24:06 -08:00
buddha.c ide: move ack_intr() method into 'struct ide_port_ops' (take 2) 2009-06-15 18:52:58 +02:00
cmd64x.c cmd64x: fix handling of address setup timings 2010-01-19 01:52:32 -08:00
cmd640.c cmd640: fix kernel oops in test_irq() method 2010-05-11 00:08:03 -07:00
cs5520.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
cs5530.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
cs5535.c cs5535: use ->pio_mode value to determine pair device speed 2010-01-19 01:52:33 -08:00
cs5536.c cs5536: use ->pio_mode value to determine pair device speed 2010-01-19 01:52:33 -08:00
cy82c693.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
delkin_cb.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
dtc2278.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
falconide.c ide: move ack_intr() method into 'struct ide_port_ops' (take 2) 2009-06-15 18:52:58 +02:00
gayle.c m68k: amiga - Amiga Gayle IDE platform device conversion 2010-05-26 19:51:09 +02:00
hpt366.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
ht6560b.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
icside.c Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/ide-2.6 2010-03-02 23:57:59 -08:00
ide-4drives.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
ide-acpi.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
ide-atapi.c block: fix some more cmd_type cleanup fallout 2010-08-07 18:22:29 +02:00
ide-cd.c Merge branch 'for-2.6.36' of git://git.kernel.dk/linux-2.6-block 2010-08-10 15:22:42 -07:00
ide-cd.h ide-cd: convert to using generic sense request 2009-04-28 07:37:30 +02:00
ide-cd_ioctl.c block: unify flags for struct bio and struct request 2010-08-07 18:20:39 +02:00
ide-cd_verbose.c
ide-cs.c pcmcia: do not use io_req_t when calling pcmcia_request_io() 2010-08-03 09:04:11 +02:00
ide-devsets.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
ide-disk.c block: remove q->prepare_flush_fn completely 2010-08-07 18:24:15 +02:00
ide-disk.h
ide-disk_ioctl.c block: push down BKL into .locked_ioctl 2010-08-07 18:25:00 +02:00
ide-disk_proc.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
ide-dma-sff.c ide: remove wmb() from ide-dma-sff.c and scc_pata.c 2009-04-08 14:12:49 +02:00
ide-dma.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide-2.6 2010-04-08 07:45:36 -07:00
ide-eh.c block: remove wrappers for request type/flags 2010-08-07 18:17:56 +02:00
ide-floppy.c block: unify flags for struct bio and struct request 2010-08-07 18:20:39 +02:00
ide-floppy.h
ide-floppy_ioctl.c block: push down BKL into .locked_ioctl 2010-08-07 18:25:00 +02:00
ide-floppy_proc.c ide: convert to ->proc_fops 2009-09-01 17:52:57 -07:00
ide-gd.c Merge branch 'for-2.6.36' of git://git.kernel.dk/linux-2.6-block 2010-08-10 15:22:42 -07:00
ide-gd.h ide: move ->failed_pc to ide_drive_t 2009-03-27 12:46:34 +01:00
ide-generic.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
ide-h8300.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
ide-io-std.c ide: refactor tf_read() method 2009-04-08 14:13:03 +02:00
ide-io.c block: fix some more cmd_type cleanup fallout 2010-08-07 18:22:29 +02:00
ide-ioctls.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
ide-iops.c ide: add SATA cable detection support 2010-01-19 01:41:57 -08:00
ide-legacy.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
ide-lib.c Merge branch 'master' into for-2.6.31 2009-05-22 20:28:35 +02:00
ide-park.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
ide-pci-generic.c pata_piccolo: Driver for old Toshiba chipsets 2009-12-03 14:35:31 -05:00
ide-pio-blacklist.c
ide-pm.c block: remove wrappers for request type/flags 2010-08-07 18:17:56 +02:00
ide-pnp.c ide: remove hw_regs_t typedef 2009-05-17 19:12:25 +02:00
ide-probe.c Revert "ide: skip probe if there are no devices on the port (v2)" 2010-03-28 18:58:28 -07:00
ide-proc.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
ide-scan-pci.c
ide-sysfs.c
ide-tape.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
ide-taskfile.c drivers/ide: Use memdup_user 2010-08-09 03:17:53 -07:00
ide-timings.c ide: ide_timing_compute() fixup 2010-01-19 11:30:09 -08:00
ide-xfer-mode.c ide: make ide_get_best_pio_mode() static 2010-01-19 01:52:36 -08:00
ide.c ide: use module_param_named rather than module_param_call 2010-08-11 23:04:39 +09:30
ide_platform.c IDE: pass IRQ flags to the IDE core 2010-04-15 14:20:53 -07:00
it821x.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
it8172.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
it8213.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
jmicron.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
Kconfig ide: update Kconfig text to mark as deprecated 2009-10-29 03:09:26 -07:00
macide.c ide: move ack_intr() method into 'struct ide_port_ops' (take 2) 2009-06-15 18:52:58 +02:00
Makefile ide: merge ide_arm and ide_generic host drivers 2009-03-31 20:15:24 +02:00
ns87415.c ide: refactor tf_read() method 2009-04-08 14:13:03 +02:00
opti621.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
palm_bk3710.c palm_bk3710: use ->pio_mode value to determine pair device speed 2010-01-19 01:52:34 -08:00
pdc202xx_new.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
pdc202xx_old.c pdc202xx_old: ignore "FIFO empty" bit in test_irq() method 2010-04-22 19:11:24 -07:00
piix.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
pmac.c powerpc/macio: Fix probing of macio devices by using the right of match table 2010-06-02 17:50:38 +10:00
q40ide.c ide: move ack_intr() method into 'struct ide_port_ops' (take 2) 2009-06-15 18:52:58 +02:00
qd65xx.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
qd65xx.h ide: do not access ide_drive_t 'drive_data' field directly 2009-06-15 22:13:44 +02:00
rapide.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
rz1000.c
sc1200.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
scc_pata.c Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/ide-2.6 2010-03-02 23:57:59 -08:00
serverworks.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
setup-pci.c ide: re-implement ide_pci_init_one() on top of ide_pci_init_two() 2009-06-10 14:37:21 +02:00
sgiioc4.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
siimage.c siimage: use ->pio_mode value to determine pair device speed 2010-01-19 01:52:35 -08:00
sis5513.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
sl82c105.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
slc90e66.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
tc86c001.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
triflex.c ide: change ->set_dma_mode method parameters 2010-01-19 01:45:29 -08:00
trm290.c ide: turn selectproc() method into dev_select() method (take 5) 2009-03-31 20:15:32 +02:00
tx4938ide.c tx493xide: use min_t() macro instead of min() 2010-08-09 03:17:55 -07:00
tx4939ide.c tx493xide: use min_t() macro instead of min() 2010-08-09 03:17:55 -07:00
umc8672.c ide: change ->set_pio_mode method parameters 2010-01-19 01:44:41 -08:00
via82cxxx.c via82cxxx: fix typo for VT6415 PCIE PATA IDE Host Controller support. 2010-08-09 03:17:51 -07:00