aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2015-10-02 14:15:13 -0400
committerStephen Boyd <sboyd@codeaurora.org>2015-10-02 14:22:23 -0400
commit9f30a04d768f64280dc0c40b730746e82f298d88 (patch)
treee112853eb73627ed7b9a2ef8e4feab6685a0200e /lib/string_helpers.c
parent9e294bf88a583825a413df408b9fe9e658fb93ac (diff)
parent7aba4f5201d1b7b3ddb0b03883d9edf69851ddad (diff)
Merge branch 'for-4.3-rc/ti-clk-fixes' of https://github.com/t-kristo/linux-pm into clk-fixes
Pull fixes from Tero Kristo: "A few TI clock driver fixes to pull against 4.3-rc" * 'for-4.3-rc/ti-clk-fixes' of https://github.com/t-kristo/linux-pm: (3 commits) clk: ti: dflt: fix enable_reg validity check clk: ti: fix dual-registration of uart4_ick clk: ti: clk-7xx: Remove hardwired ABE clock configuration
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index c98ae818eb4e..5939f63d90cd 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -59,7 +59,11 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
59 } 59 }
60 60
61 exp = divisor[units] / (u32)blk_size; 61 exp = divisor[units] / (u32)blk_size;
62 if (size >= exp) { 62 /*
63 * size must be strictly greater than exp here to ensure that remainder
64 * is greater than divisor[units] coming out of the if below.
65 */
66 if (size > exp) {
63 remainder = do_div(size, divisor[units]); 67 remainder = do_div(size, divisor[units]);
64 remainder *= blk_size; 68 remainder *= blk_size;
65 i++; 69 i++;
@@ -410,7 +414,7 @@ static bool escape_hex(unsigned char c, char **dst, char *end)
410 * @dst: destination buffer (escaped) 414 * @dst: destination buffer (escaped)
411 * @osz: destination buffer size 415 * @osz: destination buffer size
412 * @flags: combination of the flags (bitwise OR): 416 * @flags: combination of the flags (bitwise OR):
413 * %ESCAPE_SPACE: 417 * %ESCAPE_SPACE: (special white space, not space itself)
414 * '\f' - form feed 418 * '\f' - form feed
415 * '\n' - new line 419 * '\n' - new line
416 * '\r' - carriage return 420 * '\r' - carriage return
@@ -432,16 +436,18 @@ static bool escape_hex(unsigned char c, char **dst, char *end)
432 * all previous together 436 * all previous together
433 * %ESCAPE_HEX: 437 * %ESCAPE_HEX:
434 * '\xHH' - byte with hexadecimal value HH (2 digits) 438 * '\xHH' - byte with hexadecimal value HH (2 digits)
435 * @esc: NULL-terminated string of characters any of which, if found in 439 * @only: NULL-terminated string containing characters used to limit
436 * the source, has to be escaped 440 * the selected escape class. If characters are included in @only
441 * that would not normally be escaped by the classes selected
442 * in @flags, they will be copied to @dst unescaped.
437 * 443 *
438 * Description: 444 * Description:
439 * The process of escaping byte buffer includes several parts. They are applied 445 * The process of escaping byte buffer includes several parts. They are applied
440 * in the following sequence. 446 * in the following sequence.
441 * 1. The character is matched to the printable class, if asked, and in 447 * 1. The character is matched to the printable class, if asked, and in
442 * case of match it passes through to the output. 448 * case of match it passes through to the output.
443 * 2. The character is not matched to the one from @esc string and thus 449 * 2. The character is not matched to the one from @only string and thus
444 * must go as is to the output. 450 * must go as-is to the output.
445 * 3. The character is checked if it falls into the class given by @flags. 451 * 3. The character is checked if it falls into the class given by @flags.
446 * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any 452 * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any
447 * character. Note that they actually can't go together, otherwise 453 * character. Note that they actually can't go together, otherwise
@@ -458,11 +464,11 @@ static bool escape_hex(unsigned char c, char **dst, char *end)
458 * dst for a '\0' terminator if and only if ret < osz. 464 * dst for a '\0' terminator if and only if ret < osz.
459 */ 465 */
460int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, 466int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
461 unsigned int flags, const char *esc) 467 unsigned int flags, const char *only)
462{ 468{
463 char *p = dst; 469 char *p = dst;
464 char *end = p + osz; 470 char *end = p + osz;
465 bool is_dict = esc && *esc; 471 bool is_dict = only && *only;
466 472
467 while (isz--) { 473 while (isz--) {
468 unsigned char c = *src++; 474 unsigned char c = *src++;
@@ -471,7 +477,7 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
471 * Apply rules in the following sequence: 477 * Apply rules in the following sequence:
472 * - the character is printable, when @flags has 478 * - the character is printable, when @flags has
473 * %ESCAPE_NP bit set 479 * %ESCAPE_NP bit set
474 * - the @esc string is supplied and does not contain a 480 * - the @only string is supplied and does not contain a
475 * character under question 481 * character under question
476 * - the character doesn't fall into a class of symbols 482 * - the character doesn't fall into a class of symbols
477 * defined by given @flags 483 * defined by given @flags
@@ -479,7 +485,7 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
479 * output buffer. 485 * output buffer.
480 */ 486 */
481 if ((flags & ESCAPE_NP && isprint(c)) || 487 if ((flags & ESCAPE_NP && isprint(c)) ||
482 (is_dict && !strchr(esc, c))) { 488 (is_dict && !strchr(only, c))) {
483 /* do nothing */ 489 /* do nothing */
484 } else { 490 } else {
485 if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) 491 if (flags & ESCAPE_SPACE && escape_space(c, &p, end))