Commit 1f9c6e1b authored by Dan Carpenter's avatar Dan Carpenter Committed by Kalle Valo

mwifiex: fix mwifiex_rdeeprom_read()

There were several bugs here.

1)  The done label was in the wrong place so we didn't copy any
    information out when there was no command given.

2)  We were using PAGE_SIZE as the size of the buffer instead of
    "PAGE_SIZE - pos".

3)  snprintf() returns the number of characters that would have been
    printed if there were enough space.  If there was not enough space
    (and we had fixed the memory corruption bug #2) then it would result
    in an information leak when we do simple_read_from_buffer().  I've
    changed it to use scnprintf() instead.

I also removed the initialization at the start of the function, because
I thought it made the code a little more clear.

Fixes: 5e6e3a92 ('wireless: mwifiex: initial commit for Marvell mwifiex driver')
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Acked-by: default avatarAmitkumar Karwar <akarwar@marvell.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 2b8fa9e8
...@@ -731,7 +731,7 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf, ...@@ -731,7 +731,7 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
(struct mwifiex_private *) file->private_data; (struct mwifiex_private *) file->private_data;
unsigned long addr = get_zeroed_page(GFP_KERNEL); unsigned long addr = get_zeroed_page(GFP_KERNEL);
char *buf = (char *) addr; char *buf = (char *) addr;
int pos = 0, ret = 0, i; int pos, ret, i;
u8 value[MAX_EEPROM_DATA]; u8 value[MAX_EEPROM_DATA];
if (!buf) if (!buf)
...@@ -739,7 +739,7 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf, ...@@ -739,7 +739,7 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
if (saved_offset == -1) { if (saved_offset == -1) {
/* No command has been given */ /* No command has been given */
pos += snprintf(buf, PAGE_SIZE, "0"); pos = snprintf(buf, PAGE_SIZE, "0");
goto done; goto done;
} }
...@@ -748,17 +748,17 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf, ...@@ -748,17 +748,17 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
(u16) saved_bytes, value); (u16) saved_bytes, value);
if (ret) { if (ret) {
ret = -EINVAL; ret = -EINVAL;
goto done; goto out_free;
} }
pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes); pos = snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
for (i = 0; i < saved_bytes; i++) for (i = 0; i < saved_bytes; i++)
pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]); pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
done: done:
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
out_free:
free_page(addr); free_page(addr);
return ret; return ret;
} }
......
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