diff options
author | Johannes Berg <johannes.berg@intel.com> | 2013-11-13 09:10:21 +0100 |
---|---|---|
committer | Emmanuel Grumbach <emmanuel.grumbach@intel.com> | 2013-12-09 22:29:04 +0200 |
commit | 1fa3f57a1ca19ad45ff5fa248d509fc442e82a63 (patch) | |
tree | a424611bc2bc266b8a933d5b931b52c6f8337e9f /drivers/net/wireless/iwlwifi/mvm/debugfs.h | |
parent | 7f09d70436729dee9dfa7ab11fda9d384c4bdf9f (diff) | |
download | op-kernel-dev-1fa3f57a1ca19ad45ff5fa248d509fc442e82a63.zip op-kernel-dev-1fa3f57a1ca19ad45ff5fa248d509fc442e82a63.tar.gz |
iwlwifi: mvm: refactor debugfs copy_from_user()
Abstract the copy_from_user() pattern into the macros defining
debugfs files, reducing the code and making adding new files
safer by avoiding having deal with copy_from_user() directly.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/mvm/debugfs.h')
-rw-r--r-- | drivers/net/wireless/iwlwifi/mvm/debugfs.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/drivers/net/wireless/iwlwifi/mvm/debugfs.h b/drivers/net/wireless/iwlwifi/mvm/debugfs.h index faa73b8..85f9f95 100644 --- a/drivers/net/wireless/iwlwifi/mvm/debugfs.h +++ b/drivers/net/wireless/iwlwifi/mvm/debugfs.h @@ -68,17 +68,34 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \ .llseek = generic_file_llseek, \ } -#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \ +#define MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \ +static ssize_t _iwl_dbgfs_##name##_write(struct file *file, \ + const char __user *user_buf, \ + size_t count, loff_t *ppos) \ +{ \ + argtype *arg = file->private_data; \ + char buf[buflen] = {}; \ + size_t buf_size = min(count, sizeof(buf) - 1); \ + \ + if (copy_from_user(buf, user_buf, buf_size)) \ + return -EFAULT; \ + \ + return iwl_dbgfs_##name##_write(arg, buf, buf_size, ppos); \ +} \ + +#define _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype) \ +MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \ static const struct file_operations iwl_dbgfs_##name##_ops = { \ - .write = iwl_dbgfs_##name##_write, \ + .write = _iwl_dbgfs_##name##_write, \ .read = iwl_dbgfs_##name##_read, \ .open = simple_open, \ .llseek = generic_file_llseek, \ }; -#define MVM_DEBUGFS_WRITE_FILE_OPS(name) \ +#define _MVM_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype) \ +MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \ static const struct file_operations iwl_dbgfs_##name##_ops = { \ - .write = iwl_dbgfs_##name##_write, \ + .write = _iwl_dbgfs_##name##_write, \ .open = simple_open, \ .llseek = generic_file_llseek, \ }; |