aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/netconsole.c
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2011-05-07 16:33:13 -0400
committerDavid S. Miller <davem@davemloft.net>2011-05-09 15:10:48 -0400
commit99f823f98fb981b55c663a3783c3d2293958ece4 (patch)
treee7c17a9193efab3834c9497a90a623e729f1edf6 /drivers/net/netconsole.c
parent0693e88e6ccf615d9674548d8b924cdd9a1c976c (diff)
netconsole: switch to kstrto*() functions
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netconsole.c')
-rw-r--r--drivers/net/netconsole.c62
1 files changed, 14 insertions, 48 deletions
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index eb41e44921e6..62fdbaa1fb60 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -242,34 +242,6 @@ static struct netconsole_target *to_target(struct config_item *item)
242} 242}
243 243
244/* 244/*
245 * Wrapper over simple_strtol (base 10) with sanity and range checking.
246 * We return (signed) long only because we may want to return errors.
247 * Do not use this to convert numbers that are allowed to be negative.
248 */
249static long strtol10_check_range(const char *cp, long min, long max)
250{
251 long ret;
252 char *p = (char *) cp;
253
254 WARN_ON(min < 0);
255 WARN_ON(max < min);
256
257 ret = simple_strtol(p, &p, 10);
258
259 if (*p && (*p != '\n')) {
260 printk(KERN_ERR "netconsole: invalid input\n");
261 return -EINVAL;
262 }
263 if ((ret < min) || (ret > max)) {
264 printk(KERN_ERR "netconsole: input %ld must be between "
265 "%ld and %ld\n", ret, min, max);
266 return -EINVAL;
267 }
268
269 return ret;
270}
271
272/*
273 * Attribute operations for netconsole_target. 245 * Attribute operations for netconsole_target.
274 */ 246 */
275 247
@@ -327,12 +299,14 @@ static ssize_t store_enabled(struct netconsole_target *nt,
327 const char *buf, 299 const char *buf,
328 size_t count) 300 size_t count)
329{ 301{
302 int enabled;
330 int err; 303 int err;
331 long enabled;
332 304
333 enabled = strtol10_check_range(buf, 0, 1); 305 err = kstrtoint(buf, 10, &enabled);
334 if (enabled < 0) 306 if (err < 0)
335 return enabled; 307 return err;
308 if (enabled < 0 || enabled > 1)
309 return -EINVAL;
336 310
337 if (enabled) { /* 1 */ 311 if (enabled) { /* 1 */
338 312
@@ -384,8 +358,7 @@ static ssize_t store_local_port(struct netconsole_target *nt,
384 const char *buf, 358 const char *buf,
385 size_t count) 359 size_t count)
386{ 360{
387 long local_port; 361 int rv;
388#define __U16_MAX ((__u16) ~0U)
389 362
390 if (nt->enabled) { 363 if (nt->enabled) {
391 printk(KERN_ERR "netconsole: target (%s) is enabled, " 364 printk(KERN_ERR "netconsole: target (%s) is enabled, "
@@ -394,12 +367,9 @@ static ssize_t store_local_port(struct netconsole_target *nt,
394 return -EINVAL; 367 return -EINVAL;
395 } 368 }
396 369
397 local_port = strtol10_check_range(buf, 0, __U16_MAX); 370 rv = kstrtou16(buf, 10, &nt->np.local_port);
398 if (local_port < 0) 371 if (rv < 0)
399 return local_port; 372 return rv;
400
401 nt->np.local_port = local_port;
402
403 return strnlen(buf, count); 373 return strnlen(buf, count);
404} 374}
405 375
@@ -407,8 +377,7 @@ static ssize_t store_remote_port(struct netconsole_target *nt,
407 const char *buf, 377 const char *buf,
408 size_t count) 378 size_t count)
409{ 379{
410 long remote_port; 380 int rv;
411#define __U16_MAX ((__u16) ~0U)
412 381
413 if (nt->enabled) { 382 if (nt->enabled) {
414 printk(KERN_ERR "netconsole: target (%s) is enabled, " 383 printk(KERN_ERR "netconsole: target (%s) is enabled, "
@@ -417,12 +386,9 @@ static ssize_t store_remote_port(struct netconsole_target *nt,
417 return -EINVAL; 386 return -EINVAL;
418 } 387 }
419 388
420 remote_port = strtol10_check_range(buf, 0, __U16_MAX); 389 rv = kstrtou16(buf, 10, &nt->np.remote_port);
421 if (remote_port < 0) 390 if (rv < 0)
422 return remote_port; 391 return rv;
423
424 nt->np.remote_port = remote_port;
425
426 return strnlen(buf, count); 392 return strnlen(buf, count);
427} 393}
428 394