fs: introduce a default_open for simple f_op->open use
Subsystems (6)
RFC PATCH 1/1 fs: introduce a default_open for simple f_op->open use
There are many f_op->open implementations that simply do:
file->private_data = inode->i_private;
This introduces a new global symbol, default_open, that can be used instead of the private implementations.
This also removes a couple private implementations that share the same symbol name.
---
If this patch looks reasonable, I have some additional patches that convert all other similar f_op->open implemenations to use default_open tree wide. The full diffstat looks like this:
arch/arm/mach-msm/smd_debug.c | 8 +----- arch/arm/plat-mxc/audmux-v2.c | 8 +----- arch/arm/plat-omap/iommu-debug.c | 10 +------ arch/x86/kernel/kdebugfs.c | 9 +------ drivers/acpi/ec_sys.c | 8 +----- drivers/bluetooth/btmrvl_debugfs.c | 26 +++++++------------ drivers/char/virtio_console.c | 8 +----- drivers/dma/coh901318.c | 9 +------ drivers/gpu/drm/i915/i915_debugfs.c | 10 +------ drivers/hid/hid-picolcd.c | 15 +--------- drivers/idle/i7300_idle.c | 8 +----- drivers/mfd/ab3100-core.c | 8 +----- drivers/misc/ibmasm/ibmasmfs.c | 10 +------ drivers/mtd/ubi/debug.c | 8 ------ drivers/net/caif/caif_spi.c | 10 +------ drivers/net/cxgb4/cxgb4_main.c | 8 +----- drivers/net/wimax/i2400m/debugfs.c | 14 +--------- drivers/net/wireless/ath/ath5k/debug.c | 23 ++++++----------- drivers/net/wireless/ath/ath9k/debug.c | 32 +++++++++-------------- drivers/net/wireless/ath/ath9k/htc_drv_debug.c | 26 +++++++------------ drivers/net/wireless/ath/ath9k/rc.c | 8 +----- drivers/net/wireless/ath/carl9170/debug.c | 8 +----- drivers/net/wireless/b43/debugfs.c | 8 +----- drivers/net/wireless/b43legacy/debugfs.c | 8 +----- drivers/net/wireless/iwlegacy/iwl-3945-rs.c | 8 +----- drivers/net/wireless/iwlegacy/iwl-4965-rs.c | 11 ++------ drivers/net/wireless/iwlegacy/iwl-debugfs.c | 13 ++------- drivers/net/wireless/iwlwifi/iwl-agn-rs.c | 11 ++------ drivers/net/wireless/iwlwifi/iwl-debugfs.c | 12 ++------ drivers/net/wireless/iwmc3200wifi/debugfs.c | 15 +++-------- drivers/net/wireless/iwmc3200wifi/sdio.c | 8 +----- drivers/net/wireless/libertas/debugfs.c | 10 +------ drivers/net/wireless/mwifiex/debugfs.c | 18 ++----------- drivers/net/wireless/wl1251/debugfs.c | 14 +++------- drivers/net/wireless/wl12xx/debugfs.c | 22 ++++++---------- drivers/oprofile/oprofilefs.c | 8 ------ drivers/spi/dw_spi.c | 7 +---- drivers/tty/serial/mfd.c | 10 +------ drivers/usb/core/inode.c | 8 ------ drivers/usb/host/ehci-dbg.c | 9 +------ drivers/uwb/uwb-debug.c | 9 +------ fs/debugfs/file.c | 8 ------ fs/dlm/debug_fs.c | 8 +----- fs/open.c | 7 +++++ fs/pstore/inode.c | 8 +----- include/linux/fs.h | 1 + kernel/trace/blktrace.c | 18 +------------ net/mac80211/debugfs.c | 20 +++++--------- net/mac80211/debugfs.h | 1 - net/mac80211/debugfs_key.c | 4 +- net/mac80211/debugfs_netdev.c | 2 +- net/mac80211/debugfs_sta.c | 4 +- net/mac80211/rate.c | 2 +- net/wireless/debugfs.c | 10 +------ security/inode.c | 8 ------ sound/soc/soc-core.c | 8 +----- sound/soc/soc-dapm.c | 16 +---------- 57 files changed, 135 insertions(+), 473 deletions(-)
drivers/mtd/ubi/debug.c +0 -8
@@ -386,14 +386,6 @@ out:return count; } -static int default_open (struct inode *inode,struct file *file) -{ -if (inode->i_private) - file->private_data = inode->i_private; - -return 0 ; -} -/* File operations for all UBI debugfs files */ static const struct file_operations dfs_fops = { .read = dfs_file_read,
drivers/oprofile/oprofilefs.c +0 -8
@@ -110,14 +110,6 @@ static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_ } -static int default_open (struct inode *inode,struct file *filp) -{ -if (inode->i_private) - filp->private_data = inode->i_private; -return 0 ; -} - -static const struct file_operations ulong_fops = { .read = ulong_read_file, .write = ulong_write_file,
drivers/usb/core/inode.c +0 -8
@@ -432,14 +432,6 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)return retval; } -static int default_open (struct inode *inode,struct file *file) -{ -if (inode->i_private) - file->private_data = inode->i_private; - -return 0 ; -} -static const struct file_operations default_file_operations = { .read = default_read_file, .write = default_write_file,
fs/debugfs/file.c +0 -8
@@ -31,14 +31,6 @@ static ssize_t default_write_file(struct file *file, const char __user *buf,return count; } -static int default_open (struct inode *inode,struct file *file) -{ -if (inode->i_private) - file->private_data = inode->i_private; - -return 0 ; -} -const struct file_operations debugfs_file_operations = { .read = default_read_file, .write = default_write_file,
fs/open.c +7 -0
@@ -666,6 +666,13 @@ static inline int __get_file_write_access(struct inode *inode,return error; } +int default_open (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; +return 0 ; +} +EXPORT_SYMBOL (default_open); + static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, struct file *f, int (*open)(struct inode *, struct file *),
include/linux/fs.h +1 -0
@@ -1989,6 +1989,7 @@ extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, struct file *filp);extern int do_fallocate (struct file *file,int mode,loff_t offset,loff_t len); +extern int default_open (struct inode *inode,struct file *file);extern long do_sys_open (int dfd,const char __user *filename,int flags,int mode);extern struct file *filp_open (const char *,int ,int );
security/inode.c +0 -8
@@ -41,14 +41,6 @@ static ssize_t default_write_file(struct file *file, const char __user *buf,return count; } -static int default_open (struct inode *inode,struct file *file) -{ -if (inode->i_private) - file->private_data = inode->i_private; - -return 0 ; -} -static const struct file_operations default_file_ops = { .read = default_read_file, .write = default_write_file,
Quoted 22 lines · H Hartley Sweeten
There are many
f_op->openimplementations that simply do:file->private_data = inode->i_private;This introduces a new global symbol,
default_open, that can be used instead of the private implementations.This also removes a couple private implementations that share the same symbol name.
Signed-off-by H Hartley Sweeten <[email protected]>Cc Alexander Viro <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Artem Bityutskiy <[email protected]>Cc David Woodhouse <[email protected]>Cc Robert Richter <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc James Morris <[email protected]>Cc Nick Piggin <[email protected]>Cc Andi Kleen <[email protected]>Cc Dave Chinner <[email protected]>
Quoted 5 lines
---
If this patch looks reasonable, I have some additional patches that convert all other similar
f_op->openimplemenations to usedefault_opentree wide. The full diffstat looks like this:
Looks good to me, thanks.
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html