]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
mac80211: refactor debugfs function generation code
authorEliad Peller <eliad@wizery.com>
Wed, 27 Oct 2010 12:58:29 +0000 (14:58 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 15 Nov 2010 18:24:48 +0000 (13:24 -0500)
refactor mac80211 debugfs code by using a format&copy 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>
net/mac80211/debugfs.c
net/mac80211/debugfs.h
net/mac80211/debugfs_key.c
net/mac80211/debugfs_sta.c

index 18260aa99c56f40c509616276029cd7d55f4753d..1f02e599a3185c06de0b214711eece19ff82c136 100644 (file)
@@ -21,16 +21,30 @@ int mac80211_open_file_generic(struct inode *inode, struct file *file)
        return 0;
 }
 
-#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)             \
+#define DEBUGFS_FORMAT_BUFFER_SIZE 100
+
+int mac80211_format_buffer(char __user *userbuf, size_t count,
+                                 loff_t *ppos, char *fmt, ...)
+{
+       va_list args;
+       char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
+       int res;
+
+       va_start(args, fmt);
+       res = vscnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+}
+
+#define DEBUGFS_READONLY_FILE(name, fmt, value...)                     \
 static ssize_t name## _read(struct file *file, char __user *userbuf,   \
                            size_t count, loff_t *ppos)                 \
 {                                                                      \
        struct ieee80211_local *local = file->private_data;             \
-       char buf[buflen];                                               \
-       int res;                                                        \
                                                                        \
-       res = scnprintf(buf, buflen, fmt "\n", ##value);                \
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+       return mac80211_format_buffer(userbuf, count, ppos,             \
+                                     fmt "\n", ##value);               \
 }                                                                      \
                                                                        \
 static const struct file_operations name## _ops = {                    \
@@ -46,13 +60,13 @@ static const struct file_operations name## _ops = {                 \
        debugfs_create_file(#name, mode, phyd, local, &name## _ops);
 
 
-DEBUGFS_READONLY_FILE(frequency, 20, "%d",
+DEBUGFS_READONLY_FILE(frequency, "%d",
                      local->hw.conf.channel->center_freq);
-DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
+DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
                      local->total_ps_buffered);
-DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
+DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
                      local->wep_iv & 0xffffff);
-DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
+DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
        local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
 
 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,
 {
        struct ieee80211_local *local = file->private_data;
        u64 tsf;
-       char buf[100];
 
        tsf = drv_get_tsf(local);
 
-       snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
+       return mac80211_format_buffer(user_buf, count, ppos, "0x%016llx\n",
+                                     (unsigned long long) tsf);
 }
 
 static ssize_t tsf_write(struct file *file,
@@ -131,12 +143,9 @@ static ssize_t noack_read(struct file *file, char __user *user_buf,
                          size_t count, loff_t *ppos)
 {
        struct ieee80211_local *local = file->private_data;
-       int res;
-       char buf[10];
 
-       res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, res);
+       return mac80211_format_buffer(user_buf, count, ppos, "%d\n",
+                                     local->wifi_wme_noack_test);
 }
 
 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,
                                 size_t count, loff_t *ppos)
 {
        struct ieee80211_local *local = file->private_data;
-       int res;
-       char buf[10];
-
-       res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, res);
+       return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
+                                     local->uapsd_queues);
 }
 
 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,
                                     size_t count, loff_t *ppos)
 {
        struct ieee80211_local *local = file->private_data;
-       int res;
-       char buf[10];
 
-       res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, res);
+       return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
+                                     local->uapsd_max_sp_len);
 }
 
 static ssize_t uapsd_max_sp_len_write(struct file *file,
index 09cc9be347964a7d03ef4d4487b88b331f2df0a9..7c87529630f55eabd2ba45721d73f138dad7401a 100644 (file)
@@ -4,6 +4,8 @@
 #ifdef CONFIG_MAC80211_DEBUGFS
 extern void debugfs_hw_add(struct ieee80211_local *local);
 extern int mac80211_open_file_generic(struct inode *inode, struct file *file);
+extern int mac80211_format_buffer(char __user *userbuf, size_t count,
+                                 loff_t *ppos, char *fmt, ...);
 #else
 static inline void debugfs_hw_add(struct ieee80211_local *local)
 {
index 1243d1db5c59c842d843a265a1b7fe5131df36e1..5822a6ce76714cc85cd653f860508ceff29786c0 100644 (file)
 #include "debugfs.h"
 #include "debugfs_key.h"
 
-#define KEY_READ(name, prop, buflen, format_string)                    \
+#define KEY_READ(name, prop, format_string)                            \
 static ssize_t key_##name##_read(struct file *file,                    \
                                 char __user *userbuf,                  \
                                 size_t count, loff_t *ppos)            \
 {                                                                      \
-       char buf[buflen];                                               \
        struct ieee80211_key *key = file->private_data;                 \
-       int res = scnprintf(buf, buflen, format_string, key->prop);     \
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+       return mac80211_format_buffer(userbuf, count, ppos,             \
+                                     format_string, key->prop);        \
 }
-#define KEY_READ_D(name) KEY_READ(name, name, 20, "%d\n")
-#define KEY_READ_X(name) KEY_READ(name, name, 20, "0x%x\n")
+#define KEY_READ_D(name) KEY_READ(name, name, "%d\n")
+#define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n")
 
 #define KEY_OPS(name)                                                  \
 static const struct file_operations key_ ##name## _ops = {             \
@@ -39,9 +38,9 @@ static const struct file_operations key_ ##name## _ops = {            \
                 KEY_READ_##format(name)                                \
                 KEY_OPS(name)
 
-#define KEY_CONF_READ(name, buflen, format_string)                     \
-       KEY_READ(conf_##name, conf.name, buflen, format_string)
-#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, 20, "%d\n")
+#define KEY_CONF_READ(name, format_string)                             \
+       KEY_READ(conf_##name, conf.name, format_string)
+#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n")
 
 #define KEY_CONF_OPS(name)                                             \
 static const struct file_operations key_ ##name## _ops = {             \
@@ -59,7 +58,7 @@ KEY_CONF_FILE(keyidx, D);
 KEY_CONF_FILE(hw_key_idx, D);
 KEY_FILE(flags, X);
 KEY_FILE(tx_rx_count, D);
-KEY_READ(ifindex, sdata->name, IFNAMSIZ + 2, "%s\n");
+KEY_READ(ifindex, sdata->name, "%s\n");
 KEY_OPS(ifindex);
 
 static ssize_t key_algorithm_read(struct file *file,
index 4601fea1784dd7404b2d91c2635b211453e9e0c6..f0fce37f4069b06c7e92db28cf4e2e1dfee4c54d 100644 (file)
 
 /* sta attributtes */
 
-#define STA_READ(name, buflen, field, format_string)                   \
+#define STA_READ(name, field, format_string)                           \
 static ssize_t sta_ ##name## _read(struct file *file,                  \
                                   char __user *userbuf,                \
                                   size_t count, loff_t *ppos)          \
 {                                                                      \
-       int res;                                                        \
        struct sta_info *sta = file->private_data;                      \
-       char buf[buflen];                                               \
-       res = scnprintf(buf, buflen, format_string, sta->field);        \
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+       return mac80211_format_buffer(userbuf, count, ppos,             \
+                                     format_string, sta->field);       \
 }
-#define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n")
-#define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n")
-#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
+#define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
+#define STA_READ_U(name, field) STA_READ(name, field, "%u\n")
+#define STA_READ_S(name, field) STA_READ(name, field, "%s\n")
 
 #define STA_OPS(name)                                                  \
 static const struct file_operations sta_ ##name## _ops = {             \
@@ -79,22 +77,18 @@ static ssize_t sta_num_ps_buf_frames_read(struct file *file,
                                          char __user *userbuf,
                                          size_t count, loff_t *ppos)
 {
-       char buf[20];
        struct sta_info *sta = file->private_data;
-       int res = scnprintf(buf, sizeof(buf), "%u\n",
-                           skb_queue_len(&sta->ps_tx_buf));
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+       return mac80211_format_buffer(userbuf, count, ppos, "%u\n",
+                                     skb_queue_len(&sta->ps_tx_buf));
 }
 STA_OPS(num_ps_buf_frames);
 
 static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
                                    size_t count, loff_t *ppos)
 {
-       char buf[20];
        struct sta_info *sta = file->private_data;
-       int res = scnprintf(buf, sizeof(buf), "%d\n",
-                           jiffies_to_msecs(jiffies - sta->last_rx));
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+       return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
+                                     jiffies_to_msecs(jiffies - sta->last_rx));
 }
 STA_OPS(inactive_ms);