Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

auxdisplay: charlcd: deduplicate simple_strtoul()

Like in commit 8b2303de399f ("serial: core: Fix handling of options
after MMIO address") we may use simple_strtoul() which in comparison to
kstrtoul() can do conversion in-place without additional and unnecessary
code to be written.

Link: http://lkml.kernel.org/r/20190801192904.41087-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Mans Rullgard <mans@mansr.com>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Linus Torvalds
d717e7da 885e68e8

+7 -27
+7 -27
drivers/auxdisplay/charlcd.c
··· 288 288 } 289 289 290 290 /* 291 - * Parses an unsigned integer from a string, until a non-digit character 292 - * is found. The empty string is not accepted. No overflow checks are done. 293 - * 294 - * Returns whether the parsing was successful. Only in that case 295 - * the output parameters are written to. 296 - * 297 - * TODO: If the kernel adds an inplace version of kstrtoul(), this function 298 - * could be easily replaced by that. 299 - */ 300 - static bool parse_n(const char *s, unsigned long *res, const char **next_s) 301 - { 302 - if (!isdigit(*s)) 303 - return false; 304 - 305 - *res = 0; 306 - while (isdigit(*s)) { 307 - *res = *res * 10 + (*s - '0'); 308 - ++s; 309 - } 310 - 311 - *next_s = s; 312 - return true; 313 - } 314 - 315 - /* 316 291 * Parses a movement command of the form "(.*);", where the group can be 317 292 * any number of subcommands of the form "(x|y)[0-9]+". 318 293 * ··· 311 336 { 312 337 unsigned long new_x = *x; 313 338 unsigned long new_y = *y; 339 + char *p; 314 340 315 341 for (;;) { 316 342 if (!*s) ··· 321 345 break; 322 346 323 347 if (*s == 'x') { 324 - if (!parse_n(s + 1, &new_x, &s)) 348 + new_x = simple_strtoul(s + 1, &p, 10); 349 + if (p == s + 1) 325 350 return false; 351 + s = p; 326 352 } else if (*s == 'y') { 327 - if (!parse_n(s + 1, &new_y, &s)) 353 + new_y = simple_strtoul(s + 1, &p, 10); 354 + if (p == s + 1) 328 355 return false; 356 + s = p; 329 357 } else { 330 358 return false; 331 359 }