linux/drivers/rtc
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
..
class.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
hctosys.c rtc/hctosys: only claim the RTC provided the system time if it did 2010-03-12 15:52:28 -08:00
interface.c headers: remove sched.h from interrupt.h 2009-10-11 11:20:58 -07:00
Kconfig Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm 2010-08-11 09:13:19 -07:00
Makefile rtc: add support for DS3232 RTC 2010-08-11 08:59:08 -07:00
rtc-ab3100.c mfd: AB3100 register access change to abx500 API 2010-05-28 01:37:45 +02:00
rtc-ab8500.c rtc: AB8500 RTC driver 2010-05-27 09:12:41 -07:00
rtc-at32ap700x.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
rtc-at91rm9200.c rtc: at91rm9200 fixes 2009-09-23 07:39:46 -07:00
rtc-at91sam9.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
rtc-au1xxx.c rtc: t reaches -1, tested 0 2009-02-11 14:25:36 -08:00
rtc-bfin.c rtc-bfin: fix state restoration when resuming 2010-09-09 18:57:22 -07:00
rtc-bq32k.c rtc: add driver for BQ32000 I2C RTC 2009-12-16 07:20:00 -08:00
rtc-bq4802.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
rtc-cmos.c drivers/rtc: remove unneeded ifdef CONFIG_PM 2010-08-11 08:59:08 -07:00
rtc-coh901331.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
rtc-core.h
rtc-davinci.c davinci: update gfp/slab.h includes 2010-06-28 10:19:19 +10:00
rtc-dev.c headers: remove sched.h from interrupt.h 2009-10-11 11:20:58 -07:00
rtc-dm355evm.c rtc: rtc-dm355evm driver 2009-02-05 12:56:46 -08:00
rtc-ds1216.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
rtc-ds1286.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
rtc-ds1302.c rtc-ds1302: add some abstraction for new platform support 2010-05-25 08:07:08 -07:00
rtc-ds1305.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-ds1307.c rtc: fix ds1388 time corruption 2010-06-29 15:29:31 -07:00
rtc-ds1374.c i2c: Remove all i2c_set_clientdata(client, NULL) in drivers 2010-06-03 11:33:58 +02:00
rtc-ds1390.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
rtc-ds1511.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-ds1553.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-ds1672.c rtc: use set_mmss when set_time is not available 2009-01-06 15:59:25 -08:00
rtc-ds1742.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-ds3232.c rtc: add support for DS3232 RTC 2010-08-11 08:59:08 -07:00
rtc-ds3234.c spi: prefix modalias with "spi:" 2009-09-23 07:39:43 -07:00
rtc-efi.c rtc: add platform driver for EFI 2009-04-01 08:59:24 -07:00
rtc-ep93xx.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
rtc-fm3130.c rtc: fixes and new functionality for fm3130 2010-08-11 08:59:07 -07:00
rtc-generic.c parisc: rtc: Rename rtc-parisc to rtc-generic 2009-04-02 01:05:31 +00:00
rtc-imxdi.c rtc: driver for the DryIce block found in i.MX25 chips 2010-08-11 08:59:07 -07:00
rtc-isl1208.c rtc-isl1208: use sysfs_{create/remove}_group 2010-05-25 08:07:08 -07:00
rtc-isl12022.c rtc-isl12022: properly handle military hour format 2010-08-11 08:59:08 -07:00
rtc-jz4740.c RTC: Add JZ4740 RTC driver 2010-08-05 13:26:17 +01:00
rtc-lib.c rtc: convert LEAP_YEAR into an inline 2009-04-01 08:59:24 -07:00
rtc-m41t80.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
rtc-m41t94.c spi: prefix modalias with "spi:" 2009-09-23 07:39:43 -07:00
rtc-m48t35.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
rtc-m48t59.c rtc/m48t59: use rtc_valid_tm() to check returned tm 2010-08-11 08:59:07 -07:00
rtc-m48t86.c rtc/m48t86: use rtc_valid_tm() to check returned tm 2010-08-11 08:59:07 -07:00
rtc-max6900.c rtc/max6900: use rtc_valid_tm() to check returning tm 2010-08-11 08:59:07 -07:00
rtc-max6902.c spi: prefix modalias with "spi:" 2009-09-23 07:39:43 -07:00
rtc-max8925.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
rtc-mc13783.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
rtc-mpc5121.c of/device: Replace struct of_device with struct platform_device 2010-08-06 09:25:50 -06:00
rtc-msm6242.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
rtc-mv.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
rtc-mxc.c rtc/rtc-mxc: remove six unused fields 2010-08-11 08:59:06 -07:00
rtc-nuc900.c rtc/nuc900: fix build warning 2010-08-11 08:59:08 -07:00
rtc-omap.c Revert "rtc: omap: let device wakeup capability be configured from chip init logic" 2010-05-19 11:37:20 -07:00
rtc-pcap.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
rtc-pcf2123.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
rtc-pcf8563.c drivers/rtc/rtc-pcf8563.c: remove unused struct 2010-08-11 08:59:06 -07:00
rtc-pcf8583.c rtc: fix driver data issues in several rtc drivers 2009-12-16 07:19:58 -08:00
rtc-pcf50633.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
rtc-pl030.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
rtc-pl031.c drivers/rtc/rtc-pl031.c: do not mark PL031 IRQ as shared 2010-09-09 18:57:24 -07:00
rtc-proc.c proc 2/2: remove struct proc_dir_entry::owner 2009-03-31 01:14:44 +04:00
rtc-ps3.c powerpc/ps3: Add rtc-ps3 2009-04-02 01:05:32 +00:00
rtc-pxa.c rtc/pxa: remove unnecessary private ops->ioctl() 2010-08-11 08:59:07 -07:00
rtc-r9701.c spi: prefix modalias with "spi:" 2009-09-23 07:39:43 -07:00
rtc-rp5c01.c rtc: rp5c01: add NVRAM support 2010-08-11 08:59:08 -07:00
rtc-rs5c313.c
rtc-rs5c348.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
rtc-rs5c372.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
rtc-rx8025.c comment typo fixes: charater => character 2010-07-19 11:21:26 +02:00
rtc-rx8581.c drivers/rtc/rtc-rx8581.c: fix setdatetime 2010-07-27 14:32:06 -07:00
rtc-s3c.c rtc: rtc-s3c: Add BCD register initialization codes 2010-08-05 18:32:51 +09:00
rtc-s35390a.c i2c: Remove all i2c_set_clientdata(client, NULL) in drivers 2010-06-03 11:33:58 +02:00
rtc-sa1100.c const: constify remaining dev_pm_ops 2009-12-15 08:53:25 -08:00
rtc-sh.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
rtc-starfire.c
rtc-stk17ta8.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-stmp3xxx.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
rtc-sun4v.c
rtc-sysfs.c rtc/hctosys: only claim the RTC provided the system time if it did 2010-03-12 15:52:28 -08:00
rtc-test.c rtc: make rtc_update_irq callable with irqs enabled 2009-06-19 16:46:05 -07:00
rtc-twl.c rtc-twl: Storage class should be before const qualifier 2010-03-06 11:26:47 -08:00
rtc-tx4939.c sysfs: add struct file* to bin_attr callbacks 2010-05-21 09:37:31 -07:00
rtc-v3020.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
rtc-vr41xx.c rtc-vr41xx: use resource_size() 2009-12-16 07:20:00 -08:00
rtc-wm831x.c rtc: use genirq directly in rtc-wm831x 2010-05-25 08:07:08 -07:00
rtc-wm8350.c rtc: Suppress duplicate enable/disable of WM8350 update interrupt 2010-03-07 22:16:56 +01:00
rtc-x1205.c rtc-x1205: unconditionally set date when setting clock 2009-12-16 07:20:00 -08:00