• Home
  • Raw
  • Download

Lines Matching +full:quad +full:- +full:precision

1 // SPDX-License-Identifier: GPL-2.0-only
8 /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
10 * Wirzenius wrote this portably, Torvalds fucked it up :-)
15 * - changed to provide snprintf and vsnprintf functions
17 * - scnprintf and vscnprintf
23 #include <linux/clk-provider.h>
65 prefix_chars = cp - startp; in simple_strntoull()
67 rv = _parse_integer_limit(cp, base, &result, max_chars - prefix_chars); in simple_strntoull()
82 * simple_strtoull - convert a string to an unsigned long long
96 * simple_strtoul - convert a string to an unsigned long
110 * simple_strtol - convert a string to a signed long
119 if (*cp == '-') in simple_strtol()
120 return -simple_strtoul(cp + 1, endp, base); in simple_strtol()
131 * case cp[0] == '-' && max_chars == 1. in simple_strntoll()
135 if (*cp == '-' && max_chars > 0) in simple_strntoll()
136 return -simple_strntoull(cp + 1, max_chars - 1, endp, base); in simple_strntoll()
142 * simple_strtoll - convert a string to a signed long long
161 i = i*10 + *((*s)++) - '0'; in skip_atoi()
178 * It turns out there is precisely one 26 bit fixed-point
180 * holds for all x in [0, 10^8-1], namely a = 0x28f5c29. The actual
184 * For dividing a number in the range [10^4, 10^6-1] by 100, we still
185 * need a 32x32->64 bit multiply, so we simply use the same constant.
187 * For dividing a number in the range [100, 10^4-1] by 100, there are
211 * below. All other callers pass a non-zero value of r.
224 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
233 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_trunc8()
242 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
262 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
267 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_full8()
272 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
302 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full4()
313 * (second call in the put_dec code, assuming n is all-ones).
320 put_dec_full4(buf, x - q * 10000); in put_dec_helper4()
327 * Performs no 64-bit division and hence should be fast on 32-bit machines.
357 else while (buf[-1] == '0') in put_dec()
358 --buf; in put_dec()
373 /* put_dec requires 2-byte alignment of the buffer. */ in num_to_str()
382 len = put_dec(tmp, num) - tmp; in num_to_str()
389 width = width - len; in num_to_str()
397 buf[idx + width] = tmp[len - idx - 1]; in num_to_str()
406 #define ZEROPAD 16 /* pad with zero, must be 16 == '0' - ' ' */
410 static_assert(ZEROPAD == ('0' - ' '));
440 signed int precision:16; /* # of digits/chars */ member
444 #define FIELD_WIDTH_MAX ((1 << 23) - 1)
445 #define PRECISION_MAX ((1 << 15) - 1)
451 /* put_dec requires 2-byte alignment of the buffer. */ in number()
459 int precision = spec.precision; in number() local
469 sign = '-'; in number()
470 num = -(signed long long)num; in number()
471 field_width--; in number()
474 field_width--; in number()
477 field_width--; in number()
482 field_width -= 2; in number()
484 field_width--; in number()
492 int mask = spec.base - 1; in number()
502 i = put_dec(tmp, num) - tmp; in number()
506 if (i > precision) in number()
507 precision = i; in number()
509 field_width -= precision; in number()
511 while (--field_width >= 0) { in number()
540 while (--field_width >= 0) { in number()
547 while (i <= --precision) { in number()
553 while (--i >= 0) { in number()
559 while (--field_width >= 0) { in number()
577 spec.precision = -1; in special_hex_number()
587 size = end - buf; in move_right()
593 if (len > size - spaces) in move_right()
594 len = size - spaces; in move_right()
616 spaces = spec.field_width - n; in widen_string()
618 move_right(buf - n, end, n, spaces); in widen_string()
621 while (spaces--) { in widen_string()
634 int lim = spec.precision; in string_nocheck()
636 while (lim--) { in string_nocheck()
658 * Somebody passed ERR_PTR(-1234) or some other non-existing in err_ptr()
659 * Efoo - or perhaps CONFIG_SYMBOLIC_ERRNAME=n. Fall back to in err_ptr()
676 if (spec.precision == -1) in error_string()
677 spec.precision = 2 * sizeof(void *); in error_string()
706 return -EFAULT; in check_pointer()
728 if (spec.field_width == -1) { in pointer_string()
785 } else if (ret == -EALREADY) { in initialize_ptr_random()
801 return -EAGAIN; in __ptr_to_hashval()
836 /* When debugging early boot use non-cryptographically secure hash. */ in ptr_to_id()
870 if (spec.field_width == -1) in restricted_pointer()
872 return error_string(buf, end, "pK-error", spec); in restricted_pointer()
886 !uid_eq(cred->euid, cred->uid) || in restricted_pointer()
887 !gid_eq(cred->egid, cred->gid)) in restricted_pointer()
912 depth = fmt[1] - '0'; in dentry_name()
925 p = READ_ONCE(d->d_parent); in dentry_name()
926 array[i] = READ_ONCE(d->d_name.name); in dentry_name()
934 s = array[--i]; in dentry_name()
935 for (n = 0; n != spec.precision; n++, buf++) { in dentry_name()
941 s = array[--i]; in dentry_name()
957 return dentry_name(buf, end, f->f_path.dentry, spec, fmt); in file_dentry_name()
969 hd = bdev->bd_disk; in bdev_name()
970 buf = string(buf, end, hd->disk_name, spec); in bdev_name()
971 if (bdev->bd_partno) { in bdev_name()
972 if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) { in bdev_name()
977 buf = number(buf, end, bdev->bd_partno, spec); in bdev_name()
1011 .field_width = -1,
1012 .precision = -1,
1017 .precision = -1,
1023 .precision = -1,
1029 .precision = -1,
1036 .precision = -1,
1054 .precision = -1, in resource_string()
1060 .precision = -1, in resource_string()
1066 .precision = -1, in resource_string()
1070 .field_width = -1, in resource_string()
1071 .precision = 10, in resource_string()
1075 /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) in resource_string()
1076 * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ in resource_string()
1078 #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) in resource_string()
1079 #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") in resource_string()
1080 #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") in resource_string()
1092 if (res->flags & IORESOURCE_IO) { in resource_string()
1095 } else if (res->flags & IORESOURCE_MEM) { in resource_string()
1098 } else if (res->flags & IORESOURCE_IRQ) { in resource_string()
1101 } else if (res->flags & IORESOURCE_DMA) { in resource_string()
1104 } else if (res->flags & IORESOURCE_BUS) { in resource_string()
1112 if (decode && res->flags & IORESOURCE_UNSET) { in resource_string()
1116 p = number(p, pend, res->start, *specp); in resource_string()
1117 if (res->start != res->end) { in resource_string()
1118 *p++ = '-'; in resource_string()
1119 p = number(p, pend, res->end, *specp); in resource_string()
1123 if (res->flags & IORESOURCE_MEM_64) in resource_string()
1125 if (res->flags & IORESOURCE_PREFETCH) in resource_string()
1127 if (res->flags & IORESOURCE_WINDOW) in resource_string()
1129 if (res->flags & IORESOURCE_DISABLED) in resource_string()
1133 p = number(p, pend, res->flags, default_flag_spec); in resource_string()
1161 separator = '-'; in hex_string()
1182 if (separator && i != len - 1) { in hex_string()
1207 chunksz = nr_bits & (CHUNKSZ - 1); in bitmap_string()
1211 i = ALIGN(nr_bits, CHUNKSZ) - CHUNKSZ; in bitmap_string()
1212 for (; i >= 0; i -= CHUNKSZ) { in bitmap_string()
1216 chunkmask = ((1ULL << chunksz) - 1); in bitmap_string()
1265 *buf = '-'; in bitmap_list_string()
1291 separator = '-'; in mac_address_string()
1305 p = hex_byte_pack(p, addr[5 - i]); in mac_address_string()
1332 step = -1; in ip4_string()
1337 step = -1; in ip4_string()
1347 char temp[4] __aligned(2); /* hold each IP quad in reverse order */ in ip4_string()
1348 int digits = put_dec_trunc8(temp, addr[index]) - temp; in ip4_string()
1355 /* reverse the digits in the quad */ in ip4_string()
1356 while (digits--) in ip4_string()
1373 int colonpos = -1; in ip6_compressed_string()
1406 colonpos = -1; in ip6_compressed_string()
1415 i += longest - 1; in ip6_compressed_string()
1500 const u8 *addr = (const u8 *) &sa->sin6_addr; in ip6_addr_string_sa()
1537 p = number(p, pend, ntohs(sa->sin6_port), spec); in ip6_addr_string_sa()
1541 p = number(p, pend, ntohl(sa->sin6_flowinfo & in ip6_addr_string_sa()
1546 p = number(p, pend, sa->sin6_scope_id, spec); in ip6_addr_string_sa()
1560 const u8 *addr = (const u8 *) &sa->sin_addr.s_addr; in ip4_addr_string_sa()
1581 p = number(p, pend, ntohs(sa->sin_port), spec); in ip4_addr_string_sa()
1609 switch (sa->raw.sa_family) { in ip_addr_string()
1611 return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt); in ip_addr_string()
1613 return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt); in ip_addr_string()
1677 buf += string_escape_mem(addr, len, buf, buf < end ? end - buf : 0, flags, NULL); in escaped_string()
1690 va_copy(va, *va_fmt->va); in va_format()
1691 buf += vsnprintf(buf, end > buf ? end - buf : 0, va_fmt->fmt, va); in va_format()
1732 *p++ = '-'; in uuid_string()
1792 int year = tm->tm_year + (r ? 0 : 1900); in date_str()
1793 int mon = tm->tm_mon + (r ? 0 : 1); in date_str()
1797 *buf = '-'; in date_str()
1802 *buf = '-'; in date_str()
1805 return number(buf, end, tm->tm_mday, default_dec02_spec); in date_str()
1811 buf = number(buf, end, tm->tm_hour, default_dec02_spec); in time_str()
1816 buf = number(buf, end, tm->tm_min, default_dec02_spec); in time_str()
1821 return number(buf, end, tm->tm_sec, default_dec02_spec); in time_str()
1926 for ( ; flags && names->name; names++) { in format_flags()
1927 mask = names->mask; in format_flags()
1931 buf = string(buf, end, names->name, default_str_spec); in format_flags()
1961 flags &= (1UL << NR_PAGEFLAGS) - 1; in flags_string()
1986 for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) { in fwnode_full_name_string()
2018 str_spec.field_width = -1; in device_node_string()
2035 int precision; in device_node_string() local
2049 precision = str_spec.precision; in device_node_string()
2050 str_spec.precision = strchrnul(p, '@') - p; in device_node_string()
2052 str_spec.precision = precision; in device_node_string()
2055 buf = number(buf, end, (unsigned int)dn->phandle, default_dec_spec); in device_node_string()
2057 case 'P': /* path-spec */ in device_node_string()
2064 tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-'; in device_node_string()
2065 tbuf[1] = of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-'; in device_node_string()
2066 tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-'; in device_node_string()
2067 tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-'; in device_node_string()
2093 return widen_string(buf, buf - buf_start, end, spec); in device_node_string()
2103 str_spec.field_width = -1; in fwnode_string()
2123 return widen_string(buf, buf - buf_start, end, spec); in fwnode_string()
2136 * - 'S' For symbolic direct pointers (or function descriptors) with offset
2137 * - 's' For symbolic direct pointers (or function descriptors) without offset
2138 * - '[Ss]R' as above with __builtin_extract_return_addr() translation
2139 * - '[Ff]' %pf and %pF were obsoleted and later removed in favor of
2140 * %ps and %pS. Be careful when re-using these specifiers.
2141 * - 'B' For backtraced symbolic direct pointers with offset
2142 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
2143 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
2144 * - 'b[l]' For a bitmap, the number of bits is determined by the field
2147 * range-list format instead of hex format
2148 * - 'M' For a 6-byte MAC address, it prints the address in the
2149 * usual colon-separated hex notation
2150 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
2151 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
2152 * with a dash-separated hex notation
2153 * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
2154 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
2155 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
2156 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
2160 * - 'i' [46] for 'raw' IPv4/IPv6 addresses
2162 * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
2166 * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
2167 * - 'I[6S]c' for IPv6 addresses printed as specified by
2169 * - 'E[achnops]' For an escaped buffer, where rules are defined by combination
2172 * a - ESCAPE_ANY
2173 * c - ESCAPE_SPECIAL
2174 * h - ESCAPE_HEX
2175 * n - ESCAPE_NULL
2176 * o - ESCAPE_OCTAL
2177 * p - ESCAPE_NP
2178 * s - ESCAPE_SPACE
2180 * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
2181 * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2188 * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
2190 * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
2191 * - 'V' For a struct va_format which contains a format string * and va_list *,
2192 * call vsnprintf(->format, *->va_list).
2196 * - 'K' For a kernel pointer that should be hidden from unprivileged users
2197 * - 'NF' For a netdev_features_t
2198 * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
2205 * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
2207 * - 'd[234]' For a dentry name (optionally 2-4 last components)
2208 * - 'D[234]' Same as 'd' but for a struct file
2209 * - 'g' For block_device name (gendisk + partition number)
2210 * - 't[RT][dt][r]' For time and date as represented by:
2213 * - 'C' For a clock, it prints the name (Common Clock Framework) or address
2215 * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
2217 * - 'G' For flags to be printed as a collection of symbolic strings that would
2222 * - 'OF[fnpPcCF]' For a device tree object
2231 * - 'fw[fP]' For a firmware node (struct fwnode_handle) pointer
2235 * - 'x' For printing the address. Equivalent to "%lx".
2236 * - '[ku]s' For a BPF/tracing related format specifier, e.g. used out of
2242 * Documentation/core-api/printk-formats.rst
2319 /* %pe with a non-ERR_PTR gets treated as plain %p */ in pointer()
2346 * 'z' changed to 'Z' --davidm 1/25/99
2347 * 'Z' changed to 'z' --adobriyan 2017-01-25
2352 * @flags: various flags such as +, -, # tokens..
2355 * @precision: precision of a number
2365 if (spec->type == FORMAT_TYPE_WIDTH) { in format_decode()
2366 if (spec->field_width < 0) { in format_decode()
2367 spec->field_width = -spec->field_width; in format_decode()
2368 spec->flags |= LEFT; in format_decode()
2370 spec->type = FORMAT_TYPE_NONE; in format_decode()
2371 goto precision; in format_decode()
2374 /* we finished early by reading the precision */ in format_decode()
2375 if (spec->type == FORMAT_TYPE_PRECISION) { in format_decode()
2376 if (spec->precision < 0) in format_decode()
2377 spec->precision = 0; in format_decode()
2379 spec->type = FORMAT_TYPE_NONE; in format_decode()
2384 spec->type = FORMAT_TYPE_NONE; in format_decode()
2391 /* Return the current non-format string */ in format_decode()
2393 return fmt - start; in format_decode()
2396 spec->flags = 0; in format_decode()
2404 case '-': spec->flags |= LEFT; break; in format_decode()
2405 case '+': spec->flags |= PLUS; break; in format_decode()
2406 case ' ': spec->flags |= SPACE; break; in format_decode()
2407 case '#': spec->flags |= SPECIAL; break; in format_decode()
2408 case '0': spec->flags |= ZEROPAD; break; in format_decode()
2417 spec->field_width = -1; in format_decode()
2420 spec->field_width = skip_atoi(&fmt); in format_decode()
2423 spec->type = FORMAT_TYPE_WIDTH; in format_decode()
2424 return ++fmt - start; in format_decode()
2427 precision: in format_decode()
2428 /* get the precision */ in format_decode()
2429 spec->precision = -1; in format_decode()
2433 spec->precision = skip_atoi(&fmt); in format_decode()
2434 if (spec->precision < 0) in format_decode()
2435 spec->precision = 0; in format_decode()
2438 spec->type = FORMAT_TYPE_PRECISION; in format_decode()
2439 return ++fmt - start; in format_decode()
2461 spec->base = 10; in format_decode()
2464 spec->type = FORMAT_TYPE_CHAR; in format_decode()
2465 return ++fmt - start; in format_decode()
2468 spec->type = FORMAT_TYPE_STR; in format_decode()
2469 return ++fmt - start; in format_decode()
2472 spec->type = FORMAT_TYPE_PTR; in format_decode()
2473 return ++fmt - start; in format_decode()
2476 spec->type = FORMAT_TYPE_PERCENT_CHAR; in format_decode()
2477 return ++fmt - start; in format_decode()
2479 /* integer number formats - set up the flags and "break" */ in format_decode()
2481 spec->base = 8; in format_decode()
2485 spec->flags |= SMALL; in format_decode()
2489 spec->base = 16; in format_decode()
2494 spec->flags |= SIGN; in format_decode()
2508 spec->type = FORMAT_TYPE_INVALID; in format_decode()
2509 return fmt - start; in format_decode()
2513 spec->type = FORMAT_TYPE_LONG_LONG; in format_decode()
2516 spec->type = FORMAT_TYPE_ULONG + (spec->flags & SIGN); in format_decode()
2518 spec->type = FORMAT_TYPE_SIZE_T; in format_decode()
2520 spec->type = FORMAT_TYPE_PTRDIFF; in format_decode()
2523 spec->type = FORMAT_TYPE_UBYTE + (spec->flags & SIGN); in format_decode()
2526 spec->type = FORMAT_TYPE_USHORT + (spec->flags & SIGN); in format_decode()
2529 spec->type = FORMAT_TYPE_UINT + (spec->flags & SIGN); in format_decode()
2532 return ++fmt - start; in format_decode()
2538 spec->field_width = width; in set_field_width()
2539 if (WARN_ONCE(spec->field_width != width, "field width %d too large", width)) { in set_field_width()
2540 spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); in set_field_width()
2547 spec->precision = prec; in set_precision()
2548 if (WARN_ONCE(spec->precision != prec, "precision %d too large", prec)) { in set_precision()
2549 spec->precision = clamp(prec, 0, PRECISION_MAX); in set_precision()
2554 * vsnprintf - Format a string and place it in a buffer
2563 * - ``%n`` is unsupported
2564 * - ``%p*`` is handled by pointer()
2566 * See pointer() or Documentation/core-api/printk-formats.rst for more
2587 /* Reject out-of-range values early. Large positive sizes are in vsnprintf()
2597 end = ((void *)-1); in vsnprintf()
2598 size = end - buf; in vsnprintf()
2611 if (copy > end - str) in vsnprintf()
2612 copy = end - str; in vsnprintf()
2631 while (--spec.field_width > 0) { in vsnprintf()
2642 while (--spec.field_width > 0) { in vsnprintf()
2726 end[-1] = '\0'; in vsnprintf()
2730 return str-buf; in vsnprintf()
2736 * vscnprintf - Format a string and place it in a buffer
2759 return size - 1; in vscnprintf()
2765 * snprintf - Format a string and place it in a buffer
2792 * scnprintf - Format a string and place it in a buffer
2816 * vsprintf - Format a string and place it in a buffer
2836 * sprintf - Format a string and place it in a buffer
2863 * vbin_printf() - VA arguments to binary data
2864 * bstr_printf() - Binary data to text string
2868 * vbin_printf - Parse a format string and place args' binary value in a buffer
2978 end[-1] = '\0'; /* Must be nul terminated */ in vbin_printf()
3016 return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; in vbin_printf()
3022 * bstr_printf - Format a string from binary arguments and place it in a buffer
3072 end = ((void *)-1); in bstr_printf()
3073 size = end - buf; in bstr_printf()
3086 if (copy > end - str) in bstr_printf()
3087 copy = end - str; in bstr_printf()
3106 while (--spec.field_width > 0) { in bstr_printf()
3116 while (--spec.field_width > 0) { in bstr_printf()
3151 if (copy > end - str) in bstr_printf()
3152 copy = end - str; in bstr_printf()
3222 end[-1] = '\0'; in bstr_printf()
3228 return str - buf; in bstr_printf()
3233 * bprintf - Parse a format string and place args' binary value in a buffer
3258 * vsscanf - Unformat a buffer into a list of arguments
3317 field_width = -1; in vsscanf()
3325 qualifier = -1; in vsscanf()
3345 *va_arg(args, int *) = str - buf; in vsscanf()
3360 if (field_width == -1) in vsscanf()
3364 } while (--field_width > 0 && *str); in vsscanf()
3371 if (field_width == -1) in vsscanf()
3377 while (*str && !isspace(*str) && field_width--) in vsscanf()
3386 * (1) It does NOT support ranges i.e. '-' is NOT a special in vsscanf()
3406 if (field_width == -1) in vsscanf()
3426 /* match must be non-empty */ in vsscanf()
3430 while (test_bit((u8)*str, set) && field_width--) in vsscanf()
3467 if (is_sign && digit == '-') in vsscanf()
3533 * sscanf - Unformat a buffer into a list of arguments