netconsole: switch to kstrto*() functions
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
0693e88e6c
commit
99f823f98f
|
@ -241,34 +241,6 @@ static struct netconsole_target *to_target(struct config_item *item)
|
||||||
NULL;
|
NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Wrapper over simple_strtol (base 10) with sanity and range checking.
|
|
||||||
* We return (signed) long only because we may want to return errors.
|
|
||||||
* Do not use this to convert numbers that are allowed to be negative.
|
|
||||||
*/
|
|
||||||
static long strtol10_check_range(const char *cp, long min, long max)
|
|
||||||
{
|
|
||||||
long ret;
|
|
||||||
char *p = (char *) cp;
|
|
||||||
|
|
||||||
WARN_ON(min < 0);
|
|
||||||
WARN_ON(max < min);
|
|
||||||
|
|
||||||
ret = simple_strtol(p, &p, 10);
|
|
||||||
|
|
||||||
if (*p && (*p != '\n')) {
|
|
||||||
printk(KERN_ERR "netconsole: invalid input\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
if ((ret < min) || (ret > max)) {
|
|
||||||
printk(KERN_ERR "netconsole: input %ld must be between "
|
|
||||||
"%ld and %ld\n", ret, min, max);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attribute operations for netconsole_target.
|
* Attribute operations for netconsole_target.
|
||||||
*/
|
*/
|
||||||
|
@ -327,12 +299,14 @@ static ssize_t store_enabled(struct netconsole_target *nt,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
|
int enabled;
|
||||||
int err;
|
int err;
|
||||||
long enabled;
|
|
||||||
|
|
||||||
enabled = strtol10_check_range(buf, 0, 1);
|
err = kstrtoint(buf, 10, &enabled);
|
||||||
if (enabled < 0)
|
if (err < 0)
|
||||||
return enabled;
|
return err;
|
||||||
|
if (enabled < 0 || enabled > 1)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (enabled) { /* 1 */
|
if (enabled) { /* 1 */
|
||||||
|
|
||||||
|
@ -384,8 +358,7 @@ static ssize_t store_local_port(struct netconsole_target *nt,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
long local_port;
|
int rv;
|
||||||
#define __U16_MAX ((__u16) ~0U)
|
|
||||||
|
|
||||||
if (nt->enabled) {
|
if (nt->enabled) {
|
||||||
printk(KERN_ERR "netconsole: target (%s) is enabled, "
|
printk(KERN_ERR "netconsole: target (%s) is enabled, "
|
||||||
|
@ -394,12 +367,9 @@ static ssize_t store_local_port(struct netconsole_target *nt,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
local_port = strtol10_check_range(buf, 0, __U16_MAX);
|
rv = kstrtou16(buf, 10, &nt->np.local_port);
|
||||||
if (local_port < 0)
|
if (rv < 0)
|
||||||
return local_port;
|
return rv;
|
||||||
|
|
||||||
nt->np.local_port = local_port;
|
|
||||||
|
|
||||||
return strnlen(buf, count);
|
return strnlen(buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,8 +377,7 @@ static ssize_t store_remote_port(struct netconsole_target *nt,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
long remote_port;
|
int rv;
|
||||||
#define __U16_MAX ((__u16) ~0U)
|
|
||||||
|
|
||||||
if (nt->enabled) {
|
if (nt->enabled) {
|
||||||
printk(KERN_ERR "netconsole: target (%s) is enabled, "
|
printk(KERN_ERR "netconsole: target (%s) is enabled, "
|
||||||
|
@ -417,12 +386,9 @@ static ssize_t store_remote_port(struct netconsole_target *nt,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
remote_port = strtol10_check_range(buf, 0, __U16_MAX);
|
rv = kstrtou16(buf, 10, &nt->np.remote_port);
|
||||||
if (remote_port < 0)
|
if (rv < 0)
|
||||||
return remote_port;
|
return rv;
|
||||||
|
|
||||||
nt->np.remote_port = remote_port;
|
|
||||||
|
|
||||||
return strnlen(buf, count);
|
return strnlen(buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue