aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cb8a112030bb..33bed5e67a21 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -581,7 +581,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
581 unsigned long value = (unsigned long) ptr; 581 unsigned long value = (unsigned long) ptr;
582#ifdef CONFIG_KALLSYMS 582#ifdef CONFIG_KALLSYMS
583 char sym[KSYM_SYMBOL_LEN]; 583 char sym[KSYM_SYMBOL_LEN];
584 if (ext != 'f') 584 if (ext != 'f' && ext != 's')
585 sprint_symbol(sym, value); 585 sprint_symbol(sym, value);
586 else 586 else
587 kallsyms_lookup(value, NULL, NULL, NULL, sym); 587 kallsyms_lookup(value, NULL, NULL, NULL, sym);
@@ -671,7 +671,7 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros)
671 return p; 671 return p;
672} 672}
673 673
674static char *ip6_compressed_string(char *p, const struct in6_addr *addr) 674static char *ip6_compressed_string(char *p, const char *addr)
675{ 675{
676 int i; 676 int i;
677 int j; 677 int j;
@@ -683,7 +683,12 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
683 u8 hi; 683 u8 hi;
684 u8 lo; 684 u8 lo;
685 bool needcolon = false; 685 bool needcolon = false;
686 bool useIPv4 = ipv6_addr_v4mapped(addr) || ipv6_addr_is_isatap(addr); 686 bool useIPv4;
687 struct in6_addr in6;
688
689 memcpy(&in6, addr, sizeof(struct in6_addr));
690
691 useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6);
687 692
688 memset(zerolength, 0, sizeof(zerolength)); 693 memset(zerolength, 0, sizeof(zerolength));
689 694
@@ -695,7 +700,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
695 /* find position of longest 0 run */ 700 /* find position of longest 0 run */
696 for (i = 0; i < range; i++) { 701 for (i = 0; i < range; i++) {
697 for (j = i; j < range; j++) { 702 for (j = i; j < range; j++) {
698 if (addr->s6_addr16[j] != 0) 703 if (in6.s6_addr16[j] != 0)
699 break; 704 break;
700 zerolength[i]++; 705 zerolength[i]++;
701 } 706 }
@@ -722,7 +727,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
722 needcolon = false; 727 needcolon = false;
723 } 728 }
724 /* hex u16 without leading 0s */ 729 /* hex u16 without leading 0s */
725 word = ntohs(addr->s6_addr16[i]); 730 word = ntohs(in6.s6_addr16[i]);
726 hi = word >> 8; 731 hi = word >> 8;
727 lo = word & 0xff; 732 lo = word & 0xff;
728 if (hi) { 733 if (hi) {
@@ -741,19 +746,19 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
741 if (useIPv4) { 746 if (useIPv4) {
742 if (needcolon) 747 if (needcolon)
743 *p++ = ':'; 748 *p++ = ':';
744 p = ip4_string(p, &addr->s6_addr[12], false); 749 p = ip4_string(p, &in6.s6_addr[12], false);
745 } 750 }
746 751
747 *p = '\0'; 752 *p = '\0';
748 return p; 753 return p;
749} 754}
750 755
751static char *ip6_string(char *p, const struct in6_addr *addr, const char *fmt) 756static char *ip6_string(char *p, const char *addr, const char *fmt)
752{ 757{
753 int i; 758 int i;
754 for (i = 0; i < 8; i++) { 759 for (i = 0; i < 8; i++) {
755 p = pack_hex_byte(p, addr->s6_addr[2 * i]); 760 p = pack_hex_byte(p, *addr++);
756 p = pack_hex_byte(p, addr->s6_addr[2 * i + 1]); 761 p = pack_hex_byte(p, *addr++);
757 if (fmt[0] == 'I' && i != 7) 762 if (fmt[0] == 'I' && i != 7)
758 *p++ = ':'; 763 *p++ = ':';
759 } 764 }
@@ -768,9 +773,9 @@ static char *ip6_addr_string(char *buf, char *end, const u8 *addr,
768 char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; 773 char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
769 774
770 if (fmt[0] == 'I' && fmt[2] == 'c') 775 if (fmt[0] == 'I' && fmt[2] == 'c')
771 ip6_compressed_string(ip6_addr, (const struct in6_addr *)addr); 776 ip6_compressed_string(ip6_addr, addr);
772 else 777 else
773 ip6_string(ip6_addr, (const struct in6_addr *)addr, fmt); 778 ip6_string(ip6_addr, addr, fmt);
774 779
775 return string(buf, end, ip6_addr, spec); 780 return string(buf, end, ip6_addr, spec);
776} 781}
@@ -794,7 +799,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
794 * 799 *
795 * - 'F' For symbolic function descriptor pointers with offset 800 * - 'F' For symbolic function descriptor pointers with offset
796 * - 'f' For simple symbolic function names without offset 801 * - 'f' For simple symbolic function names without offset
797 * - 'S' For symbolic direct pointers 802 * - 'S' For symbolic direct pointers with offset
803 * - 's' For symbolic direct pointers without offset
798 * - 'R' For a struct resource pointer, it prints the range of 804 * - 'R' For a struct resource pointer, it prints the range of
799 * addresses (not the name nor the flags) 805 * addresses (not the name nor the flags)
800 * - 'M' For a 6-byte MAC address, it prints the address in the 806 * - 'M' For a 6-byte MAC address, it prints the address in the
@@ -822,6 +828,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
822 case 'F': 828 case 'F':
823 case 'f': 829 case 'f':
824 ptr = dereference_function_descriptor(ptr); 830 ptr = dereference_function_descriptor(ptr);
831 case 's':
825 /* Fallthrough */ 832 /* Fallthrough */
826 case 'S': 833 case 'S':
827 return symbol_string(buf, end, ptr, spec, *fmt); 834 return symbol_string(buf, end, ptr, spec, *fmt);
@@ -1063,10 +1070,12 @@ qualifier:
1063 * @args: Arguments for the format string 1070 * @args: Arguments for the format string
1064 * 1071 *
1065 * This function follows C99 vsnprintf, but has some extensions: 1072 * This function follows C99 vsnprintf, but has some extensions:
1066 * %pS output the name of a text symbol 1073 * %pS output the name of a text symbol with offset
1074 * %ps output the name of a text symbol without offset
1067 * %pF output the name of a function pointer with its offset 1075 * %pF output the name of a function pointer with its offset
1068 * %pf output the name of a function pointer without its offset 1076 * %pf output the name of a function pointer without its offset
1069 * %pR output the address range in a struct resource 1077 * %pR output the address range in a struct resource
1078 * %n is ignored
1070 * 1079 *
1071 * The return value is the number of characters which would 1080 * The return value is the number of characters which would
1072 * be generated for the given input, excluding the trailing 1081 * be generated for the given input, excluding the trailing
@@ -1088,13 +1097,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1088 1097
1089 /* Reject out-of-range values early. Large positive sizes are 1098 /* Reject out-of-range values early. Large positive sizes are
1090 used for unknown buffer sizes. */ 1099 used for unknown buffer sizes. */
1091 if (unlikely((int) size < 0)) { 1100 if (WARN_ON_ONCE((int) size < 0))
1092 /* There can be only one.. */
1093 static char warn = 1;
1094 WARN_ON(warn);
1095 warn = 0;
1096 return 0; 1101 return 0;
1097 }
1098 1102
1099 str = buf; 1103 str = buf;
1100 end = buf + size; 1104 end = buf + size;
@@ -1522,11 +1526,7 @@ EXPORT_SYMBOL_GPL(vbin_printf);
1522 * a binary buffer that generated by vbin_printf. 1526 * a binary buffer that generated by vbin_printf.
1523 * 1527 *
1524 * The format follows C99 vsnprintf, but has some extensions: 1528 * The format follows C99 vsnprintf, but has some extensions:
1525 * %pS output the name of a text symbol 1529 * see vsnprintf comment for details.
1526 * %pF output the name of a function pointer with its offset
1527 * %pf output the name of a function pointer without its offset
1528 * %pR output the address range in a struct resource
1529 * %n is ignored
1530 * 1530 *
1531 * The return value is the number of characters which would 1531 * The return value is the number of characters which would
1532 * be generated for the given input, excluding the trailing 1532 * be generated for the given input, excluding the trailing
@@ -1544,13 +1544,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1544 1544
1545 struct printf_spec spec = {0}; 1545 struct printf_spec spec = {0};
1546 1546
1547 if (unlikely((int) size < 0)) { 1547 if (WARN_ON_ONCE((int) size < 0))
1548 /* There can be only one.. */
1549 static char warn = 1;
1550 WARN_ON(warn);
1551 warn = 0;
1552 return 0; 1548 return 0;
1553 }
1554 1549
1555 str = buf; 1550 str = buf;
1556 end = buf + size; 1551 end = buf + size;
@@ -1776,7 +1771,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
1776 * advance both strings to next white space 1771 * advance both strings to next white space
1777 */ 1772 */
1778 if (*fmt == '*') { 1773 if (*fmt == '*') {
1779 while (!isspace(*fmt) && *fmt) 1774 while (!isspace(*fmt) && *fmt != '%' && *fmt)
1780 fmt++; 1775 fmt++;
1781 while (!isspace(*str) && *str) 1776 while (!isspace(*str) && *str)
1782 str++; 1777 str++;