Commit 581f725c authored by Vasanthakumar Thiagarajan's avatar Vasanthakumar Thiagarajan Committed by John W. Linville

ath9k: Fix write callback of 'debug' which configures debug mask

Handle error condition on copy_from_user() properly and
make sure a NUL terminated char[] is sent to strict_strtoul()
for proper conversion.
Signed-off-by: default avatarVasanthakumar Thiagarajan <vasanth@atheros.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 76963bb6
...@@ -49,8 +49,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf, ...@@ -49,8 +49,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
{ {
struct ath_softc *sc = file->private_data; struct ath_softc *sc = file->private_data;
char buf[32]; char buf[32];
unsigned int len = 0; unsigned int len;
len += snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.debug_mask);
len = snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.debug_mask);
return simple_read_from_buffer(user_buf, count, ppos, buf, len); return simple_read_from_buffer(user_buf, count, ppos, buf, len);
} }
...@@ -60,12 +61,17 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf, ...@@ -60,12 +61,17 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
struct ath_softc *sc = file->private_data; struct ath_softc *sc = file->private_data;
unsigned long mask; unsigned long mask;
char buf[32]; char buf[32];
if (copy_from_user(buf, user_buf, (sizeof(buf) - 1) < count ? ssize_t len;
(sizeof(buf) - 1) : count))
return 0; len = min(count, sizeof(buf) - 1);
buf[sizeof(buf)-1] = 0; if (copy_from_user(buf, user_buf, len))
if (strict_strtoul(buf, 0, &mask) == 0) return -EINVAL;
sc->debug.debug_mask = mask;
buf[len] = '\0';
if (strict_strtoul(buf, 0, &mask))
return -EINVAL;
sc->debug.debug_mask = mask;
return count; return count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment