diff options
author | Eliad Peller <eliad@wizery.com> | 2010-10-27 08:58:29 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2010-11-15 13:24:48 -0500 |
commit | 07caf9d6c9135ae25a760867f37aab90c1008380 (patch) | |
tree | 528409cde06c5927a311d453a4e59206fca0beb5 /net/mac80211 | |
parent | 6a6733f256f18cbcf4875e13f59eedb593b755a8 (diff) |
mac80211: refactor debugfs function generation code
refactor mac80211 debugfs code by using a format© function, instead of
duplicating the code for each generated function.
this change reduces about 600B from mac80211.ko
Signed-off-by: Eliad Peller <eliad@wizery.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r-- | net/mac80211/debugfs.c | 60 | ||||
-rw-r--r-- | net/mac80211/debugfs.h | 2 | ||||
-rw-r--r-- | net/mac80211/debugfs_key.c | 19 | ||||
-rw-r--r-- | net/mac80211/debugfs_sta.c | 26 |
4 files changed, 52 insertions, 55 deletions
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 18260aa99c56..1f02e599a318 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c | |||
@@ -21,16 +21,30 @@ int mac80211_open_file_generic(struct inode *inode, struct file *file) | |||
21 | return 0; | 21 | return 0; |
22 | } | 22 | } |
23 | 23 | ||
24 | #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ | 24 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
25 | |||
26 | int mac80211_format_buffer(char __user *userbuf, size_t count, | ||
27 | loff_t *ppos, char *fmt, ...) | ||
28 | { | ||
29 | va_list args; | ||
30 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; | ||
31 | int res; | ||
32 | |||
33 | va_start(args, fmt); | ||
34 | res = vscnprintf(buf, sizeof(buf), fmt, args); | ||
35 | va_end(args); | ||
36 | |||
37 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | ||
38 | } | ||
39 | |||
40 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ | ||
25 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ | 41 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ |
26 | size_t count, loff_t *ppos) \ | 42 | size_t count, loff_t *ppos) \ |
27 | { \ | 43 | { \ |
28 | struct ieee80211_local *local = file->private_data; \ | 44 | struct ieee80211_local *local = file->private_data; \ |
29 | char buf[buflen]; \ | ||
30 | int res; \ | ||
31 | \ | 45 | \ |
32 | res = scnprintf(buf, buflen, fmt "\n", ##value); \ | 46 | return mac80211_format_buffer(userbuf, count, ppos, \ |
33 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | 47 | fmt "\n", ##value); \ |
34 | } \ | 48 | } \ |
35 | \ | 49 | \ |
36 | static const struct file_operations name## _ops = { \ | 50 | static const struct file_operations name## _ops = { \ |
@@ -46,13 +60,13 @@ static const struct file_operations name## _ops = { \ | |||
46 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); | 60 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); |
47 | 61 | ||
48 | 62 | ||
49 | DEBUGFS_READONLY_FILE(frequency, 20, "%d", | 63 | DEBUGFS_READONLY_FILE(frequency, "%d", |
50 | local->hw.conf.channel->center_freq); | 64 | local->hw.conf.channel->center_freq); |
51 | DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", | 65 | DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", |
52 | local->total_ps_buffered); | 66 | local->total_ps_buffered); |
53 | DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", | 67 | DEBUGFS_READONLY_FILE(wep_iv, "%#08x", |
54 | local->wep_iv & 0xffffff); | 68 | local->wep_iv & 0xffffff); |
55 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", | 69 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", |
56 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); | 70 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); |
57 | 71 | ||
58 | static ssize_t tsf_read(struct file *file, char __user *user_buf, | 72 | static ssize_t tsf_read(struct file *file, char __user *user_buf, |
@@ -60,13 +74,11 @@ static ssize_t tsf_read(struct file *file, char __user *user_buf, | |||
60 | { | 74 | { |
61 | struct ieee80211_local *local = file->private_data; | 75 | struct ieee80211_local *local = file->private_data; |
62 | u64 tsf; | 76 | u64 tsf; |
63 | char buf[100]; | ||
64 | 77 | ||
65 | tsf = drv_get_tsf(local); | 78 | tsf = drv_get_tsf(local); |
66 | 79 | ||
67 | snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf); | 80 | return mac80211_format_buffer(user_buf, count, ppos, "0x%016llx\n", |
68 | 81 | (unsigned long long) tsf); | |
69 | return simple_read_from_buffer(user_buf, count, ppos, buf, 19); | ||
70 | } | 82 | } |
71 | 83 | ||
72 | static ssize_t tsf_write(struct file *file, | 84 | static ssize_t tsf_write(struct file *file, |
@@ -131,12 +143,9 @@ static ssize_t noack_read(struct file *file, char __user *user_buf, | |||
131 | size_t count, loff_t *ppos) | 143 | size_t count, loff_t *ppos) |
132 | { | 144 | { |
133 | struct ieee80211_local *local = file->private_data; | 145 | struct ieee80211_local *local = file->private_data; |
134 | int res; | ||
135 | char buf[10]; | ||
136 | 146 | ||
137 | res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test); | 147 | return mac80211_format_buffer(user_buf, count, ppos, "%d\n", |
138 | 148 | local->wifi_wme_noack_test); | |
139 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | ||
140 | } | 149 | } |
141 | 150 | ||
142 | static ssize_t noack_write(struct file *file, | 151 | static ssize_t noack_write(struct file *file, |
@@ -168,12 +177,8 @@ static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf, | |||
168 | size_t count, loff_t *ppos) | 177 | size_t count, loff_t *ppos) |
169 | { | 178 | { |
170 | struct ieee80211_local *local = file->private_data; | 179 | struct ieee80211_local *local = file->private_data; |
171 | int res; | 180 | return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n", |
172 | char buf[10]; | 181 | local->uapsd_queues); |
173 | |||
174 | res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues); | ||
175 | |||
176 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | ||
177 | } | 182 | } |
178 | 183 | ||
179 | static ssize_t uapsd_queues_write(struct file *file, | 184 | static ssize_t uapsd_queues_write(struct file *file, |
@@ -215,12 +220,9 @@ static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf, | |||
215 | size_t count, loff_t *ppos) | 220 | size_t count, loff_t *ppos) |
216 | { | 221 | { |
217 | struct ieee80211_local *local = file->private_data; | 222 | struct ieee80211_local *local = file->private_data; |
218 | int res; | ||
219 | char buf[10]; | ||
220 | 223 | ||
221 | res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len); | 224 | return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n", |
222 | 225 | local->uapsd_max_sp_len); | |
223 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | ||
224 | } | 226 | } |
225 | 227 | ||
226 | static ssize_t uapsd_max_sp_len_write(struct file *file, | 228 | static ssize_t uapsd_max_sp_len_write(struct file *file, |
diff --git a/net/mac80211/debugfs.h b/net/mac80211/debugfs.h index 09cc9be34796..7c87529630f5 100644 --- a/net/mac80211/debugfs.h +++ b/net/mac80211/debugfs.h | |||
@@ -4,6 +4,8 @@ | |||
4 | #ifdef CONFIG_MAC80211_DEBUGFS | 4 | #ifdef CONFIG_MAC80211_DEBUGFS |
5 | extern void debugfs_hw_add(struct ieee80211_local *local); | 5 | extern void debugfs_hw_add(struct ieee80211_local *local); |
6 | extern int mac80211_open_file_generic(struct inode *inode, struct file *file); | 6 | extern int mac80211_open_file_generic(struct inode *inode, struct file *file); |
7 | extern int mac80211_format_buffer(char __user *userbuf, size_t count, | ||
8 | loff_t *ppos, char *fmt, ...); | ||
7 | #else | 9 | #else |
8 | static inline void debugfs_hw_add(struct ieee80211_local *local) | 10 | static inline void debugfs_hw_add(struct ieee80211_local *local) |
9 | { | 11 | { |
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c index 1243d1db5c59..5822a6ce7671 100644 --- a/net/mac80211/debugfs_key.c +++ b/net/mac80211/debugfs_key.c | |||
@@ -15,18 +15,17 @@ | |||
15 | #include "debugfs.h" | 15 | #include "debugfs.h" |
16 | #include "debugfs_key.h" | 16 | #include "debugfs_key.h" |
17 | 17 | ||
18 | #define KEY_READ(name, prop, buflen, format_string) \ | 18 | #define KEY_READ(name, prop, format_string) \ |
19 | static ssize_t key_##name##_read(struct file *file, \ | 19 | static ssize_t key_##name##_read(struct file *file, \ |
20 | char __user *userbuf, \ | 20 | char __user *userbuf, \ |
21 | size_t count, loff_t *ppos) \ | 21 | size_t count, loff_t *ppos) \ |
22 | { \ | 22 | { \ |
23 | char buf[buflen]; \ | ||
24 | struct ieee80211_key *key = file->private_data; \ | 23 | struct ieee80211_key *key = file->private_data; \ |
25 | int res = scnprintf(buf, buflen, format_string, key->prop); \ | 24 | return mac80211_format_buffer(userbuf, count, ppos, \ |
26 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | 25 | format_string, key->prop); \ |
27 | } | 26 | } |
28 | #define KEY_READ_D(name) KEY_READ(name, name, 20, "%d\n") | 27 | #define KEY_READ_D(name) KEY_READ(name, name, "%d\n") |
29 | #define KEY_READ_X(name) KEY_READ(name, name, 20, "0x%x\n") | 28 | #define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n") |
30 | 29 | ||
31 | #define KEY_OPS(name) \ | 30 | #define KEY_OPS(name) \ |
32 | static const struct file_operations key_ ##name## _ops = { \ | 31 | static const struct file_operations key_ ##name## _ops = { \ |
@@ -39,9 +38,9 @@ static const struct file_operations key_ ##name## _ops = { \ | |||
39 | KEY_READ_##format(name) \ | 38 | KEY_READ_##format(name) \ |
40 | KEY_OPS(name) | 39 | KEY_OPS(name) |
41 | 40 | ||
42 | #define KEY_CONF_READ(name, buflen, format_string) \ | 41 | #define KEY_CONF_READ(name, format_string) \ |
43 | KEY_READ(conf_##name, conf.name, buflen, format_string) | 42 | KEY_READ(conf_##name, conf.name, format_string) |
44 | #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, 20, "%d\n") | 43 | #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n") |
45 | 44 | ||
46 | #define KEY_CONF_OPS(name) \ | 45 | #define KEY_CONF_OPS(name) \ |
47 | static const struct file_operations key_ ##name## _ops = { \ | 46 | static const struct file_operations key_ ##name## _ops = { \ |
@@ -59,7 +58,7 @@ KEY_CONF_FILE(keyidx, D); | |||
59 | KEY_CONF_FILE(hw_key_idx, D); | 58 | KEY_CONF_FILE(hw_key_idx, D); |
60 | KEY_FILE(flags, X); | 59 | KEY_FILE(flags, X); |
61 | KEY_FILE(tx_rx_count, D); | 60 | KEY_FILE(tx_rx_count, D); |
62 | KEY_READ(ifindex, sdata->name, IFNAMSIZ + 2, "%s\n"); | 61 | KEY_READ(ifindex, sdata->name, "%s\n"); |
63 | KEY_OPS(ifindex); | 62 | KEY_OPS(ifindex); |
64 | 63 | ||
65 | static ssize_t key_algorithm_read(struct file *file, | 64 | static ssize_t key_algorithm_read(struct file *file, |
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c index 4601fea1784d..f0fce37f4069 100644 --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c | |||
@@ -17,20 +17,18 @@ | |||
17 | 17 | ||
18 | /* sta attributtes */ | 18 | /* sta attributtes */ |
19 | 19 | ||
20 | #define STA_READ(name, buflen, field, format_string) \ | 20 | #define STA_READ(name, field, format_string) \ |
21 | static ssize_t sta_ ##name## _read(struct file *file, \ | 21 | static ssize_t sta_ ##name## _read(struct file *file, \ |
22 | char __user *userbuf, \ | 22 | char __user *userbuf, \ |
23 | size_t count, loff_t *ppos) \ | 23 | size_t count, loff_t *ppos) \ |
24 | { \ | 24 | { \ |
25 | int res; \ | ||
26 | struct sta_info *sta = file->private_data; \ | 25 | struct sta_info *sta = file->private_data; \ |
27 | char buf[buflen]; \ | 26 | return mac80211_format_buffer(userbuf, count, ppos, \ |
28 | res = scnprintf(buf, buflen, format_string, sta->field); \ | 27 | format_string, sta->field); \ |
29 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | ||
30 | } | 28 | } |
31 | #define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n") | 29 | #define STA_READ_D(name, field) STA_READ(name, field, "%d\n") |
32 | #define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n") | 30 | #define STA_READ_U(name, field) STA_READ(name, field, "%u\n") |
33 | #define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n") | 31 | #define STA_READ_S(name, field) STA_READ(name, field, "%s\n") |
34 | 32 | ||
35 | #define STA_OPS(name) \ | 33 | #define STA_OPS(name) \ |
36 | static const struct file_operations sta_ ##name## _ops = { \ | 34 | static const struct file_operations sta_ ##name## _ops = { \ |
@@ -79,22 +77,18 @@ static ssize_t sta_num_ps_buf_frames_read(struct file *file, | |||
79 | char __user *userbuf, | 77 | char __user *userbuf, |
80 | size_t count, loff_t *ppos) | 78 | size_t count, loff_t *ppos) |
81 | { | 79 | { |
82 | char buf[20]; | ||
83 | struct sta_info *sta = file->private_data; | 80 | struct sta_info *sta = file->private_data; |
84 | int res = scnprintf(buf, sizeof(buf), "%u\n", | 81 | return mac80211_format_buffer(userbuf, count, ppos, "%u\n", |
85 | skb_queue_len(&sta->ps_tx_buf)); | 82 | skb_queue_len(&sta->ps_tx_buf)); |
86 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | ||
87 | } | 83 | } |
88 | STA_OPS(num_ps_buf_frames); | 84 | STA_OPS(num_ps_buf_frames); |
89 | 85 | ||
90 | static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf, | 86 | static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf, |
91 | size_t count, loff_t *ppos) | 87 | size_t count, loff_t *ppos) |
92 | { | 88 | { |
93 | char buf[20]; | ||
94 | struct sta_info *sta = file->private_data; | 89 | struct sta_info *sta = file->private_data; |
95 | int res = scnprintf(buf, sizeof(buf), "%d\n", | 90 | return mac80211_format_buffer(userbuf, count, ppos, "%d\n", |
96 | jiffies_to_msecs(jiffies - sta->last_rx)); | 91 | jiffies_to_msecs(jiffies - sta->last_rx)); |
97 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | ||
98 | } | 92 | } |
99 | STA_OPS(inactive_ms); | 93 | STA_OPS(inactive_ms); |
100 | 94 | ||