You can't use kstrtoul() with an int or it causes memory corruption.
Also j should be unsigned or we have underflow bugs.
I considered changing "j" to unsigned long but everything fits in a u32.
Fixes: 8e3d04fd7d70 ('cxgb4: Add MPS tracing support')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
static ssize_t mps_trc_write(struct file *file, const char __user *buf,
size_t count, loff_t *pos)
{
static ssize_t mps_trc_write(struct file *file, const char __user *buf,
size_t count, loff_t *pos)
{
u32 *data, *mask;
struct trace_params tp;
const struct inode *ino;
unsigned int trcidx;
char *s, *p, *word, *end;
struct adapter *adap;
u32 *data, *mask;
struct trace_params tp;
const struct inode *ino;
unsigned int trcidx;
char *s, *p, *word, *end;
struct adapter *adap;
ino = file_inode(file);
trcidx = (uintptr_t)ino->i_private & 3;
ino = file_inode(file);
trcidx = (uintptr_t)ino->i_private & 3;
if (!strncmp(word, "qid=", 4)) {
end = (char *)word + 4;
if (!strncmp(word, "qid=", 4)) {
end = (char *)word + 4;
- ret = kstrtoul(end, 10, (unsigned long *)&j);
+ ret = kstrtouint(end, 10, &j);
if (ret)
goto out;
if (!adap->trace_rss) {
if (ret)
goto out;
if (!adap->trace_rss) {
}
if (!strncmp(word, "snaplen=", 8)) {
end = (char *)word + 8;
}
if (!strncmp(word, "snaplen=", 8)) {
end = (char *)word + 8;
- ret = kstrtoul(end, 10, (unsigned long *)&j);
+ ret = kstrtouint(end, 10, &j);
if (ret || j > 9600) {
inval: count = -EINVAL;
goto out;
if (ret || j > 9600) {
inval: count = -EINVAL;
goto out;
}
if (!strncmp(word, "minlen=", 7)) {
end = (char *)word + 7;
}
if (!strncmp(word, "minlen=", 7)) {
end = (char *)word + 7;
- ret = kstrtoul(end, 10, (unsigned long *)&j);
+ ret = kstrtouint(end, 10, &j);
if (ret || j > TFMINPKTSIZE_M)
goto inval;
tp.min_len = j;
if (ret || j > TFMINPKTSIZE_M)
goto inval;
tp.min_len = j;
}
if (*word == '@') {
end = (char *)word + 1;
}
if (*word == '@') {
end = (char *)word + 1;
- ret = kstrtoul(end, 10, (unsigned long *)&j);
+ ret = kstrtouint(end, 10, &j);
if (*end && *end != '\n')
goto inval;
if (j & 7) /* doesn't start at multiple of 8 */
if (*end && *end != '\n')
goto inval;
if (j & 7) /* doesn't start at multiple of 8 */