sample: eliminate clever code to determine which proc file is accessed

Linux 3.19 would break sample.c and it's not the first breakage in
sample.c. File operations is a perpetual portability issue. Write
separate structures and .open functions for every proc file.
This commit is contained in:
Pavel Roskin 2014-12-24 13:03:09 -05:00
parent 28fc586124
commit a7531fd223

View File

@ -1042,17 +1042,10 @@ proc_read_nodes(struct ieee80211vap *vap, const int size, char *buf, int space)
} }
static int static int
proc_ratesample_open(struct inode *inode, struct file *file) proc_ratesample_open(struct inode *inode, struct file *file, unsigned long size)
{ {
struct proc_ieee80211_priv *pv; struct proc_ieee80211_priv *pv;
struct ieee80211vap *vap = PDE_DATA(inode); struct ieee80211vap *vap = PDE_DATA(inode);
unsigned long size;
/* Determine what size packets to get stats for based on proc filename */
size = simple_strtoul(file->f_dentry->d_name.name +
strlen("ratestats_"), NULL, 0);
if (size < 250 || size > 3000)
return -ENOENT;
if (!(file->private_data = kzalloc(sizeof(struct proc_ieee80211_priv), if (!(file->private_data = kzalloc(sizeof(struct proc_ieee80211_priv),
GFP_KERNEL))) GFP_KERNEL)))
@ -1081,10 +1074,42 @@ proc_ratesample_open(struct inode *inode, struct file *file)
return 0; return 0;
} }
static struct file_operations proc_ratesample_ops = { static int
proc_ratesample_open_250(struct inode *inode, struct file *file, unsigned long size)
{
proc_ratesample_open(inode, file, 250);
}
static int
proc_ratesample_open_1600(struct inode *inode, struct file *file, unsigned long size)
{
proc_ratesample_open(inode, file, 1600);
}
static int
proc_ratesample_open_3000(struct inode *inode, struct file *file, unsigned long size)
{
proc_ratesample_open(inode, file, 3000);
}
static struct file_operations proc_ratesample_ops_250 = {
.read = NULL, .read = NULL,
.write = NULL, .write = NULL,
.open = proc_ratesample_open, .open = proc_ratesample_open_250,
.release = NULL,
};
static struct file_operations proc_ratesample_ops_1600 = {
.read = NULL,
.write = NULL,
.open = proc_ratesample_open_1600,
.release = NULL,
};
static struct file_operations proc_ratesample_ops_3000 = {
.read = NULL,
.write = NULL,
.open = proc_ratesample_open_3000,
.release = NULL, .release = NULL,
}; };
@ -1092,9 +1117,9 @@ static void
ath_rate_dynamic_proc_register(struct ieee80211vap *vap) ath_rate_dynamic_proc_register(struct ieee80211vap *vap)
{ {
/* Create proc entries for the rate control algorithm */ /* Create proc entries for the rate control algorithm */
ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_250"); ieee80211_proc_vcreate(vap, &proc_ratesample_ops_250, "ratestats_250");
ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_1600"); ieee80211_proc_vcreate(vap, &proc_ratesample_ops_1600, "ratestats_1600");
ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_3000"); ieee80211_proc_vcreate(vap, &proc_ratesample_ops_3000, "ratestats_3000");
} }
static struct ieee80211_rate_ops ath_rate_ops = { static struct ieee80211_rate_ops ath_rate_ops = {