Skip to content

Commit

Permalink
simple_open: automatically convert to simple_open()
Browse files Browse the repository at this point in the history
Many users of debugfs copy the implementation of default_open() when
they want to support a custom read/write function op.  This leads to a
proliferation of the default_open() implementation across the entire
tree.

Now that the common implementation has been consolidated into libfs we
can replace all the users of this function with simple_open().

This replacement was done with the following semantic patch:

<smpl>
@ open @
identifier open_f != simple_open;
identifier i, f;
@@
-int open_f(struct inode *i, struct file *f)
-{
(
-if (i->i_private)
-f->private_data = i->i_private;
|
-f->private_data = i->i_private;
)
-return 0;
-}

@ has_open depends on open @
identifier fops;
identifier open.open_f;
@@
struct file_operations fops = {
...
-.open = open_f,
+.open = simple_open,
...
};
</smpl>

[[email protected]: checkpatch fixes]
Signed-off-by: Stephen Boyd <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Julia Lawall <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
bebarino authored and torvalds committed Apr 5, 2012
1 parent 9b3ae64 commit 234e340
Show file tree
Hide file tree
Showing 63 changed files with 176 additions and 572 deletions.
8 changes: 1 addition & 7 deletions arch/arm/mach-msm/smd_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,9 @@ static ssize_t debug_read(struct file *file, char __user *buf,
return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
}

static int debug_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}

static const struct file_operations debug_ops = {
.read = debug_read,
.open = debug_open,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down
9 changes: 1 addition & 8 deletions arch/x86/kernel/kdebugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ static ssize_t setup_data_read(struct file *file, char __user *user_buf,
return count;
}

static int setup_data_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;

return 0;
}

static const struct file_operations fops_setup_data = {
.read = setup_data_read,
.open = setup_data_open,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down
8 changes: 1 addition & 7 deletions drivers/acpi/ec_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may "

static struct dentry *acpi_ec_debugfs_dir;

static int acpi_ec_open_io(struct inode *i, struct file *f)
{
f->private_data = i->i_private;
return 0;
}

static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
size_t count, loff_t *off)
{
Expand Down Expand Up @@ -95,7 +89,7 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,

static const struct file_operations acpi_ec_io_ops = {
.owner = THIS_MODULE,
.open = acpi_ec_open_io,
.open = simple_open,
.read = acpi_ec_read_io,
.write = acpi_ec_write_io,
.llseek = default_llseek,
Expand Down
12 changes: 3 additions & 9 deletions drivers/base/regmap/regmap-debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
return strlen(buf);
}

static int regmap_open_file(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}

static ssize_t regmap_name_read_file(struct file *file,
char __user *user_buf, size_t count,
loff_t *ppos)
Expand All @@ -57,7 +51,7 @@ static ssize_t regmap_name_read_file(struct file *file,
}

static const struct file_operations regmap_name_fops = {
.open = regmap_open_file,
.open = simple_open,
.read = regmap_name_read_file,
.llseek = default_llseek,
};
Expand Down Expand Up @@ -174,7 +168,7 @@ static ssize_t regmap_map_write_file(struct file *file,
#endif

static const struct file_operations regmap_map_fops = {
.open = regmap_open_file,
.open = simple_open,
.read = regmap_map_read_file,
.write = regmap_map_write_file,
.llseek = default_llseek,
Expand Down Expand Up @@ -243,7 +237,7 @@ static ssize_t regmap_access_read_file(struct file *file,
}

static const struct file_operations regmap_access_fops = {
.open = regmap_open_file,
.open = simple_open,
.read = regmap_access_read_file,
.llseek = default_llseek,
};
Expand Down
26 changes: 10 additions & 16 deletions drivers/bluetooth/btmrvl_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ struct btmrvl_debugfs_data {
struct dentry *txdnldready;
};

static int btmrvl_open_generic(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}

static ssize_t btmrvl_hscfgcmd_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
{
Expand Down Expand Up @@ -93,7 +87,7 @@ static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
static const struct file_operations btmrvl_hscfgcmd_fops = {
.read = btmrvl_hscfgcmd_read,
.write = btmrvl_hscfgcmd_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down Expand Up @@ -134,7 +128,7 @@ static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf,
static const struct file_operations btmrvl_psmode_fops = {
.read = btmrvl_psmode_read,
.write = btmrvl_psmode_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down Expand Up @@ -180,7 +174,7 @@ static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
static const struct file_operations btmrvl_pscmd_fops = {
.read = btmrvl_pscmd_read,
.write = btmrvl_pscmd_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down Expand Up @@ -221,7 +215,7 @@ static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf,
static const struct file_operations btmrvl_gpiogap_fops = {
.read = btmrvl_gpiogap_read,
.write = btmrvl_gpiogap_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down Expand Up @@ -265,7 +259,7 @@ static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
static const struct file_operations btmrvl_hscmd_fops = {
.read = btmrvl_hscmd_read,
.write = btmrvl_hscmd_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down Expand Up @@ -305,7 +299,7 @@ static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
static const struct file_operations btmrvl_hsmode_fops = {
.read = btmrvl_hsmode_read,
.write = btmrvl_hsmode_write,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand All @@ -323,7 +317,7 @@ static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf,

static const struct file_operations btmrvl_curpsmode_fops = {
.read = btmrvl_curpsmode_read,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand All @@ -341,7 +335,7 @@ static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,

static const struct file_operations btmrvl_psstate_fops = {
.read = btmrvl_psstate_read,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand All @@ -359,7 +353,7 @@ static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf,

static const struct file_operations btmrvl_hsstate_fops = {
.read = btmrvl_hsstate_read,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand All @@ -378,7 +372,7 @@ static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf,

static const struct file_operations btmrvl_txdnldready_fops = {
.read = btmrvl_txdnldready_read,
.open = btmrvl_open_generic,
.open = simple_open,
.llseek = default_llseek,
};

Expand Down
8 changes: 1 addition & 7 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,12 +1038,6 @@ static struct attribute_group port_attribute_group = {
.attrs = port_sysfs_entries,
};

static int debugfs_open(struct inode *inode, struct file *filp)
{
filp->private_data = inode->i_private;
return 0;
}

static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *offp)
{
Expand Down Expand Up @@ -1087,7 +1081,7 @@ static ssize_t debugfs_read(struct file *filp, char __user *ubuf,

static const struct file_operations port_debugfs_ops = {
.owner = THIS_MODULE,
.open = debugfs_open,
.open = simple_open,
.read = debugfs_read,
};

Expand Down
9 changes: 1 addition & 8 deletions drivers/dma/coh901318.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ static void coh901318_list_print(struct coh901318_chan *cohc,
static struct coh901318_base *debugfs_dma_base;
static struct dentry *dma_dentry;

static int coh901318_debugfs_open(struct inode *inode, struct file *file)
{

file->private_data = inode->i_private;
return 0;
}

static int coh901318_debugfs_read(struct file *file, char __user *buf,
size_t count, loff_t *f_pos)
{
Expand Down Expand Up @@ -158,7 +151,7 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf,

static const struct file_operations coh901318_debugfs_status_operations = {
.owner = THIS_MODULE,
.open = coh901318_debugfs_open,
.open = simple_open,
.read = coh901318_debugfs_read,
.llseek = default_llseek,
};
Expand Down
14 changes: 3 additions & 11 deletions drivers/gpu/drm/i915/i915_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,14 +1502,6 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
return 0;
}

static int
i915_debugfs_common_open(struct inode *inode,
struct file *filp)
{
filp->private_data = inode->i_private;
return 0;
}

static ssize_t
i915_wedged_read(struct file *filp,
char __user *ubuf,
Expand Down Expand Up @@ -1560,7 +1552,7 @@ i915_wedged_write(struct file *filp,

static const struct file_operations i915_wedged_fops = {
.owner = THIS_MODULE,
.open = i915_debugfs_common_open,
.open = simple_open,
.read = i915_wedged_read,
.write = i915_wedged_write,
.llseek = default_llseek,
Expand Down Expand Up @@ -1622,7 +1614,7 @@ i915_max_freq_write(struct file *filp,

static const struct file_operations i915_max_freq_fops = {
.owner = THIS_MODULE,
.open = i915_debugfs_common_open,
.open = simple_open,
.read = i915_max_freq_read,
.write = i915_max_freq_write,
.llseek = default_llseek,
Expand Down Expand Up @@ -1693,7 +1685,7 @@ i915_cache_sharing_write(struct file *filp,

static const struct file_operations i915_cache_sharing_fops = {
.owner = THIS_MODULE,
.open = i915_debugfs_common_open,
.open = simple_open,
.read = i915_cache_sharing_read,
.write = i915_cache_sharing_write,
.llseek = default_llseek,
Expand Down
16 changes: 2 additions & 14 deletions drivers/hid/hid-picolcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,12 +1525,6 @@ static const struct file_operations picolcd_debug_reset_fops = {
/*
* The "eeprom" file
*/
static int picolcd_debug_eeprom_open(struct inode *i, struct file *f)
{
f->private_data = i->i_private;
return 0;
}

static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
size_t s, loff_t *off)
{
Expand Down Expand Up @@ -1618,7 +1612,7 @@ static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
*/
static const struct file_operations picolcd_debug_eeprom_fops = {
.owner = THIS_MODULE,
.open = picolcd_debug_eeprom_open,
.open = simple_open,
.read = picolcd_debug_eeprom_read,
.write = picolcd_debug_eeprom_write,
.llseek = generic_file_llseek,
Expand All @@ -1627,12 +1621,6 @@ static const struct file_operations picolcd_debug_eeprom_fops = {
/*
* The "flash" file
*/
static int picolcd_debug_flash_open(struct inode *i, struct file *f)
{
f->private_data = i->i_private;
return 0;
}

/* record a flash address to buf (bounds check to be done by caller) */
static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off)
{
Expand Down Expand Up @@ -1817,7 +1805,7 @@ static ssize_t picolcd_debug_flash_write(struct file *f, const char __user *u,
*/
static const struct file_operations picolcd_debug_flash_fops = {
.owner = THIS_MODULE,
.open = picolcd_debug_flash_open,
.open = simple_open,
.read = picolcd_debug_flash_read,
.write = picolcd_debug_flash_write,
.llseek = generic_file_llseek,
Expand Down
8 changes: 1 addition & 7 deletions drivers/hid/hid-wiimote-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ struct wiimote_debug {
struct dentry *drm;
};

static int wiidebug_eeprom_open(struct inode *i, struct file *f)
{
f->private_data = i->i_private;
return 0;
}

static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
loff_t *off)
{
Expand Down Expand Up @@ -83,7 +77,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,

static const struct file_operations wiidebug_eeprom_fops = {
.owner = THIS_MODULE,
.open = wiidebug_eeprom_open,
.open = simple_open,
.read = wiidebug_eeprom_read,
.llseek = generic_file_llseek,
};
Expand Down
8 changes: 1 addition & 7 deletions drivers/idle/i7300_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,6 @@ static struct notifier_block i7300_idle_nb = {

MODULE_DEVICE_TABLE(pci, pci_tbl);

int stats_open_generic(struct inode *inode, struct file *fp)
{
fp->private_data = inode->i_private;
return 0;
}

static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count,
loff_t *off)
{
Expand All @@ -534,7 +528,7 @@ static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count,
}

static const struct file_operations idle_fops = {
.open = stats_open_generic,
.open = simple_open,
.read = stats_read_ul,
.llseek = default_llseek,
};
Expand Down
Loading

0 comments on commit 234e340

Please sign in to comment.