android_kernel_samsung_msm8976/arch/arm
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
..
boot ARM: Partially revert "Auto calculate ZRELADDR and provide option for exceptions" 2010-09-09 22:39:41 +01:00
common Revert "[ARM] pxa: remove now unnecessary dma_needs_bounce()" 2010-09-08 12:28:39 +01:00
configs omap: Fix omap_4430sdp_defconfig for make oldconfig 2010-08-16 09:22:04 +03:00
include/asm Revert "[ARM] pxa: remove now unnecessary dma_needs_bounce()" 2010-09-08 12:28:39 +01:00
kernel llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
lib Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm 2010-08-03 14:31:24 -07:00
mach-aaec2000
mach-at91 AT91: at91sam9261ek: remove C99 comments but keep information 2010-09-10 14:36:06 +02:00
mach-bcmring
mach-clps711x ARM: 6283/1: Remove useless PCIO_BASE definitions 2010-08-05 10:35:49 +01:00
mach-cns3xxx
mach-davinci Merge branch 'davinci-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-davinci 2010-08-08 10:00:55 -07:00
mach-dove
mach-ebsa110
mach-ep93xx ARM: 6359/1: ep93xx: move clock initialization earlier 2010-09-08 12:28:39 +01:00
mach-footbridge
mach-gemini
mach-h720x ARM: 6283/1: Remove useless PCIO_BASE definitions 2010-08-05 10:35:49 +01:00
mach-imx ARM: imx: fix build failure concerning otg/ulpi 2010-08-23 20:50:17 -07:00
mach-integrator ARM: 6283/1: Remove useless PCIO_BASE definitions 2010-08-05 10:35:49 +01:00
mach-iop13xx Merge branch 'misc' into devel 2010-07-31 14:20:02 +01:00
mach-iop32x
mach-iop33x
mach-ixp4xx Merge git://git.infradead.org/mtd-2.6 2010-08-15 17:32:47 -07:00
mach-ixp23xx ARM: 6283/1: Remove useless PCIO_BASE definitions 2010-08-05 10:35:49 +01:00
mach-ixp2000
mach-kirkwood Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6 2010-08-07 17:07:31 -07:00
mach-ks8695
mach-lh7a40x
mach-loki
mach-lpc32xx
mach-mmp [ARM] mmp: move declarations into SoC specific header file from common.h 2010-08-05 14:34:46 +08:00
mach-msm llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
mach-mv78xx0
mach-mx3 Merge branch 'imx-for-2.6.36' of git://git.pengutronix.de/git/imx/linux-2.6 2010-09-01 10:08:50 +01:00
mach-mx5 mx5/clock: fix clear bit fields issue in _clk_ccgr_disable function 2010-08-21 12:22:43 +02:00
mach-mx25 Merge branch 'imx-for-2.6.36' of git://git.pengutronix.de/git/imx/linux-2.6 2010-09-01 10:08:50 +01:00
mach-mxc91231
mach-netx
mach-nomadik
mach-ns9xxx
mach-nuc93x
mach-omap1 Merge branch 'v2.6.35-omap-mailbox-for-next' of git://gitorious.org/~doyu/lk/mainline into omap-for-linus 2010-08-04 16:10:38 +03:00
mach-omap2 OMAP3: PM: ensure IO wakeups are properly disabled 2010-08-16 09:22:05 +03:00
mach-orion5x ARM: Fix gen_nand probe structures contents 2010-08-12 02:21:18 +01:00
mach-pnx4008
mach-pxa ARM: pxa: fix CI_HSYNC and CI_VSYNC MFP defines for pxa300 2010-08-30 09:59:43 +08:00
mach-realview Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm 2010-08-03 14:31:24 -07:00
mach-rpc
mach-s3c24a0/include/mach
mach-s3c64xx ARM: SAMSUNG: Fix on build warning regarding VMALLOC_END type 2010-08-27 15:28:38 +09:00
mach-s3c2400
mach-s3c2410 ARM: SAMSUNG: Fix on build warning regarding VMALLOC_END type 2010-08-27 15:28:38 +09:00
mach-s3c2412
mach-s3c2416 s3c-fb: add device name initialization 2010-08-11 08:59:10 -07:00
mach-s3c2440 panic: keep blinking in spite of long spin timer mode 2010-08-11 08:59:22 -07:00
mach-s3c2443 s3c-fb: add device name initialization 2010-08-11 08:59:10 -07:00
mach-s5p6440 ARM: SAMSUNG: Fix on build warning regarding VMALLOC_END type 2010-08-27 15:28:38 +09:00
mach-s5p6442 ARM: SAMSUNG: Fix on build warning regarding VMALLOC_END type 2010-08-27 15:28:38 +09:00
mach-s5pc100 Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm 2010-08-11 09:13:19 -07:00
mach-s5pv210 ARM: S5P: VMALLOC_END should be unsigned long 2010-08-23 10:50:36 +09:00
mach-s5pv310 ARM: S5PV310: Fix on Secondary CPU startup 2010-08-27 18:29:58 +09:00
mach-sa1100 Merge branch 'devel' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa-linux-2.6 into devel-stable 2010-08-06 18:10:25 +01:00
mach-shark Merge branches 'at91', 'ep93xx', 'kexec', 'iop', 'lmb', 'nomadik', 'nuc', 'pl', 'spear' and 'versatile' into devel 2010-07-31 14:19:35 +01:00
mach-shmobile ARM: mach-shmobile: ap4evb: fix write protect for SDHI1 2010-08-20 20:41:23 +09:00
mach-spear3xx
mach-spear6xx
mach-stmp37xx
mach-stmp378x
mach-tegra arm: tegra: VMALLOC_END should be unsigned long 2010-08-22 12:54:23 -07:00
mach-u300 ARM: 6297/1: move U300 timer to dynamic clock lookup 2010-08-10 22:10:56 +01:00
mach-ux500 Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx 2010-08-09 21:00:07 -07:00
mach-versatile ARM: 6282/1: Remove useless definitions from versatile hardware.h 2010-08-05 10:35:49 +01:00
mach-vexpress Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm 2010-08-03 14:31:24 -07:00
mach-w90x900 i2c/nuc900: add i2c driver support for nuc900 2010-08-11 00:34:38 +01:00
mm ARM: Ensure PTE modifications via dma_alloc_coherent are visible 2010-09-08 16:27:56 +01:00
nwfpe
oprofile
plat-iop Merge branch 'misc' into devel 2010-07-31 14:20:02 +01:00
plat-mxc llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
plat-nomadik Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx 2010-08-09 21:00:07 -07:00
plat-omap arm/omap: use generic_file_llseek in iommu_debug 2010-09-16 10:33:11 +02:00
plat-orion Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6 2010-08-07 17:07:31 -07:00
plat-pxa ARM: pxa: Make id const in pwm_probe() 2010-08-30 09:59:44 +08:00
plat-s3c24xx
plat-s5p ARM: S5PV310: Fix on Secondary CPU startup 2010-08-27 18:29:58 +09:00
plat-samsung s5pc110: SDHCI-s3c can override host capabilities 2010-08-20 09:34:55 -07:00
plat-spear Merge branch 'master' into for-next 2010-08-04 15:14:38 +02:00
plat-stmp3xxx
plat-versatile
tools ARM: Update mach-types 2010-09-09 22:49:26 +01:00
vfp
Kconfig ARM: Partially revert "Auto calculate ZRELADDR and provide option for exceptions" 2010-09-09 22:39:41 +01:00
Kconfig-nommu
Kconfig.debug
Makefile ARM: 6328/1: Build with -fno-dwarf2-cfi-asm 2010-08-14 23:58:43 +01:00