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>
71 prefix_chars = cp - startp; in simple_strntoull()
73 rv = _parse_integer_limit(cp, base, &result, max_chars - prefix_chars); in simple_strntoull()
88 * simple_strtoull - convert a string to an unsigned long long
103 * simple_strtoul - convert a string to an unsigned long
117 * simple_strtol - convert a string to a signed long
126 if (*cp == '-') in simple_strtol()
127 return -simple_strtoul(cp + 1, endp, base); in simple_strtol()
138 * case cp[0] == '-' && max_chars == 1. in simple_strntoll()
142 if (*cp == '-' && max_chars > 0) in simple_strntoll()
143 return -simple_strntoull(cp + 1, max_chars - 1, endp, base); in simple_strntoll()
149 * simple_strtoll - convert a string to a signed long long
168 i = i*10 + *((*s)++) - '0'; in skip_atoi()
185 * It turns out there is precisely one 26 bit fixed-point
187 * holds for all x in [0, 10^8-1], namely a = 0x28f5c29. The actual
191 * For dividing a number in the range [10^4, 10^6-1] by 100, we still
192 * need a 32x32->64 bit multiply, so we simply use the same constant.
194 * For dividing a number in the range [100, 10^4-1] by 100, there are
218 * below. All other callers pass a non-zero value of r.
231 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
240 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_trunc8()
249 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
269 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
274 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_full8()
279 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
309 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full4()
320 * (second call in the put_dec code, assuming n is all-ones).
327 put_dec_full4(buf, x - q * 10000); in put_dec_helper4()
334 * Performs no 64-bit division and hence should be fast on 32-bit machines.
364 else while (buf[-1] == '0') in put_dec()
365 --buf; in put_dec()
380 /* put_dec requires 2-byte alignment of the buffer. */ in num_to_str()
389 len = put_dec(tmp, num) - tmp; in num_to_str()
396 width = width - len; in num_to_str()
404 buf[idx + width] = tmp[len - idx - 1]; in num_to_str()
413 #define ZEROPAD 16 /* pad with zero, must be 16 == '0' - ' ' */
418 static_assert(ZEROPAD == ('0' - ' '));
448 signed int precision:16; /* # of digits/chars */ member
452 #define FIELD_WIDTH_MAX ((1 << 23) - 1)
453 #define PRECISION_MAX ((1 << 15) - 1)
459 /* put_dec requires 2-byte alignment of the buffer. */ in number()
467 int precision = spec.precision; in number() local
477 sign = '-'; in number()
478 num = -(signed long long)num; in number()
479 field_width--; in number()
482 field_width--; in number()
485 field_width--; in number()
490 field_width -= 2; in number()
492 field_width--; in number()
500 int mask = spec.base - 1; in number()
510 i = put_dec(tmp, num) - tmp; in number()
514 if (i > precision) in number()
515 precision = i; in number()
517 field_width -= precision; in number()
519 while (--field_width >= 0) { in number()
548 while (--field_width >= 0) { in number()
555 while (i <= --precision) { in number()
561 while (--i >= 0) { in number()
567 while (--field_width >= 0) { in number()
585 spec.precision = -1; in special_hex_number()
595 size = end - buf; in move_right()
601 if (len > size - spaces) in move_right()
602 len = size - spaces; in move_right()
624 spaces = spec.field_width - n; in widen_string()
626 move_right(buf - n, end, n, spaces); in widen_string()
629 while (spaces--) { in widen_string()
642 int lim = spec.precision; in string_nocheck()
644 while (lim--) { in string_nocheck()
666 * Somebody passed ERR_PTR(-1234) or some other non-existing in err_ptr()
667 * Efoo - or perhaps CONFIG_SYMBOLIC_ERRNAME=n. Fall back to in err_ptr()
684 if (spec.precision == -1) in error_string()
685 spec.precision = 2 * sizeof(void *); in error_string()
714 return -EFAULT; in check_pointer()
736 if (spec.field_width == -1) { in pointer_string()
782 return -EBUSY; in subsys_initcall()
820 /* When debugging early boot use non-cryptographically secure hash. */ in ptr_to_id()
867 if (spec.field_width == -1) in restricted_pointer()
869 return error_string(buf, end, "pK-error", spec); in restricted_pointer()
883 !uid_eq(cred->euid, cred->uid) || in restricted_pointer()
884 !gid_eq(cred->egid, cred->gid)) in restricted_pointer()
909 depth = fmt[1] - '0'; in dentry_name()
922 p = READ_ONCE(d->d_parent); in dentry_name()
923 array[i] = READ_ONCE(d->d_name.name); in dentry_name()
931 s = array[--i]; in dentry_name()
932 for (n = 0; n != spec.precision; n++, buf++) { in dentry_name()
938 s = array[--i]; in dentry_name()
954 return dentry_name(buf, end, f->f_path.dentry, spec, fmt); in file_dentry_name()
966 hd = bdev->bd_disk; in bdev_name()
967 buf = string(buf, end, hd->disk_name, spec); in bdev_name()
968 if (bdev->bd_partno) { in bdev_name()
969 if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) { in bdev_name()
974 buf = number(buf, end, bdev->bd_partno, spec); in bdev_name()
1012 .field_width = -1,
1013 .precision = -1,
1018 .precision = -1,
1024 .precision = -1,
1030 .precision = -1,
1037 .precision = -1,
1055 .precision = -1, in resource_string()
1061 .precision = -1, in resource_string()
1067 .precision = -1, in resource_string()
1071 .field_width = -1, in resource_string()
1072 .precision = 10, in resource_string()
1076 /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) in resource_string()
1077 * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ in resource_string()
1079 #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) in resource_string()
1080 #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") in resource_string()
1081 #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") in resource_string()
1093 if (res->flags & IORESOURCE_IO) { in resource_string()
1096 } else if (res->flags & IORESOURCE_MEM) { in resource_string()
1099 } else if (res->flags & IORESOURCE_IRQ) { in resource_string()
1102 } else if (res->flags & IORESOURCE_DMA) { in resource_string()
1105 } else if (res->flags & IORESOURCE_BUS) { in resource_string()
1113 if (decode && res->flags & IORESOURCE_UNSET) { in resource_string()
1117 p = number(p, pend, res->start, *specp); in resource_string()
1118 if (res->start != res->end) { in resource_string()
1119 *p++ = '-'; in resource_string()
1120 p = number(p, pend, res->end, *specp); in resource_string()
1124 if (res->flags & IORESOURCE_MEM_64) in resource_string()
1126 if (res->flags & IORESOURCE_PREFETCH) in resource_string()
1128 if (res->flags & IORESOURCE_WINDOW) in resource_string()
1130 if (res->flags & IORESOURCE_DISABLED) in resource_string()
1134 p = number(p, pend, res->flags, default_flag_spec); in resource_string()
1162 separator = '-'; in hex_string()
1183 if (separator && i != len - 1) { in hex_string()
1208 chunksz = nr_bits & (CHUNKSZ - 1); in bitmap_string()
1212 i = ALIGN(nr_bits, CHUNKSZ) - CHUNKSZ; in bitmap_string()
1213 for (; i >= 0; i -= CHUNKSZ) { in bitmap_string()
1217 chunkmask = ((1ULL << chunksz) - 1); in bitmap_string()
1261 *buf = '-'; in bitmap_list_string()
1262 buf = number(++buf, end, rtop - 1, default_dec_spec); in bitmap_list_string()
1282 separator = '-'; in mac_address_string()
1296 p = hex_byte_pack(p, addr[5 - i]); in mac_address_string()
1323 step = -1; in ip4_string()
1328 step = -1; in ip4_string()
1338 char temp[4] __aligned(2); /* hold each IP quad in reverse order */ in ip4_string()
1339 int digits = put_dec_trunc8(temp, addr[index]) - temp; in ip4_string()
1346 /* reverse the digits in the quad */ in ip4_string()
1347 while (digits--) in ip4_string()
1364 int colonpos = -1; in ip6_compressed_string()
1397 colonpos = -1; in ip6_compressed_string()
1406 i += longest - 1; in ip6_compressed_string()
1491 const u8 *addr = (const u8 *) &sa->sin6_addr; in ip6_addr_string_sa()
1528 p = number(p, pend, ntohs(sa->sin6_port), spec); in ip6_addr_string_sa()
1532 p = number(p, pend, ntohl(sa->sin6_flowinfo & in ip6_addr_string_sa()
1537 p = number(p, pend, sa->sin6_scope_id, spec); in ip6_addr_string_sa()
1551 const u8 *addr = (const u8 *) &sa->sin_addr.s_addr; in ip4_addr_string_sa()
1572 p = number(p, pend, ntohs(sa->sin_port), spec); in ip4_addr_string_sa()
1600 switch (sa->raw.sa_family) { in ip_addr_string()
1602 return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt); in ip_addr_string()
1604 return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt); in ip_addr_string()
1668 buf += string_escape_mem(addr, len, buf, buf < end ? end - buf : 0, flags, NULL); in escaped_string()
1681 va_copy(va, *va_fmt->va); in va_format()
1682 buf += vsnprintf(buf, end > buf ? end - buf : 0, va_fmt->fmt, va); in va_format()
1723 *p++ = '-'; in uuid_string()
1759 char output[sizeof("0123 little-endian (0x01234567)")]; in fourcc_string()
1776 /* Print non-control ASCII characters as-is, dot otherwise */ in fourcc_string()
1781 strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); in fourcc_string()
1786 p = special_hex_number(p, output + sizeof(output) - 2, orig, sizeof(u32)); in fourcc_string()
1821 int year = tm->tm_year + (r ? 0 : 1900); in date_str()
1822 int mon = tm->tm_mon + (r ? 0 : 1); in date_str()
1826 *buf = '-'; in date_str()
1831 *buf = '-'; in date_str()
1834 return number(buf, end, tm->tm_mday, default_dec02_spec); in date_str()
1840 buf = number(buf, end, tm->tm_hour, default_dec02_spec); in time_str()
1845 buf = number(buf, end, tm->tm_min, default_dec02_spec); in time_str()
1850 return number(buf, end, tm->tm_sec, default_dec02_spec); in time_str()
1967 for ( ; flags && names->name; names++) { in format_flags()
1968 mask = names->mask; in format_flags()
1972 buf = string(buf, end, names->name, default_str_spec); in format_flags()
2112 for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) { in fwnode_full_name_string()
2144 str_spec.field_width = -1; in device_node_string()
2161 int precision; in device_node_string() local
2175 precision = str_spec.precision; in device_node_string()
2176 str_spec.precision = strchrnul(p, '@') - p; in device_node_string()
2178 str_spec.precision = precision; in device_node_string()
2181 buf = number(buf, end, (unsigned int)dn->phandle, default_dec_spec); in device_node_string()
2183 case 'P': /* path-spec */ in device_node_string()
2190 tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-'; in device_node_string()
2191 tbuf[1] = of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-'; in device_node_string()
2192 tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-'; in device_node_string()
2193 tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-'; in device_node_string()
2219 return widen_string(buf, buf - buf_start, end, spec); in device_node_string()
2229 str_spec.field_width = -1; in fwnode_string()
2249 return widen_string(buf, buf - buf_start, end, spec); in fwnode_string()
2290 * - 'S' For symbolic direct pointers (or function descriptors) with offset
2291 * - 's' For symbolic direct pointers (or function descriptors) without offset
2292 * - '[Ss]R' as above with __builtin_extract_return_addr() translation
2293 * - 'S[R]b' as above with module build ID (for use in backtraces)
2294 * - '[Ff]' %pf and %pF were obsoleted and later removed in favor of
2295 * %ps and %pS. Be careful when re-using these specifiers.
2296 * - 'B' For backtraced symbolic direct pointers with offset
2297 * - 'Bb' as above with module build ID (for use in backtraces)
2298 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
2299 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
2300 * - 'b[l]' For a bitmap, the number of bits is determined by the field
2303 * range-list format instead of hex format
2304 * - 'M' For a 6-byte MAC address, it prints the address in the
2305 * usual colon-separated hex notation
2306 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
2307 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
2308 * with a dash-separated hex notation
2309 * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
2310 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
2311 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
2312 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
2316 * - 'i' [46] for 'raw' IPv4/IPv6 addresses
2318 * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
2322 * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
2323 * - 'I[6S]c' for IPv6 addresses printed as specified by
2325 * - 'E[achnops]' For an escaped buffer, where rules are defined by combination
2328 * a - ESCAPE_ANY
2329 * c - ESCAPE_SPECIAL
2330 * h - ESCAPE_HEX
2331 * n - ESCAPE_NULL
2332 * o - ESCAPE_OCTAL
2333 * p - ESCAPE_NP
2334 * s - ESCAPE_SPACE
2336 * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
2337 * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2344 * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
2346 * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
2347 * - 'V' For a struct va_format which contains a format string * and va_list *,
2348 * call vsnprintf(->format, *->va_list).
2352 * - 'K' For a kernel pointer that should be hidden from unprivileged users.
2355 * - 'NF' For a netdev_features_t
2356 * - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value.
2357 * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
2364 * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
2366 * - 'd[234]' For a dentry name (optionally 2-4 last components)
2367 * - 'D[234]' Same as 'd' but for a struct file
2368 * - 'g' For block_device name (gendisk + partition number)
2369 * - 't[RT][dt][r][s]' For time and date as represented by:
2372 * - 'C' For a clock, it prints the name (Common Clock Framework) or address
2374 * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
2376 * - 'G' For flags to be printed as a collection of symbolic strings that would
2381 * - 'OF[fnpPcCF]' For a device tree object
2390 * - 'fw[fP]' For a firmware node (struct fwnode_handle) pointer
2394 * - 'x' For printing the address unmodified. Equivalent to "%lx".
2396 * - '[ku]s' For a BPF/tracing related format specifier, e.g. used out of
2402 * Documentation/core-api/printk-formats.rst
2484 WARN_ONCE(1, "Please remove %%pA from non-Rust code\n"); in pointer()
2491 /* %pe with a non-ERR_PTR gets treated as plain %p */ in pointer()
2517 * 'z' changed to 'Z' --davidm 1/25/99
2518 * 'Z' changed to 'z' --adobriyan 2017-01-25
2523 * @flags: various flags such as +, -, # tokens..
2526 * @precision: precision of a number
2536 if (spec->type == FORMAT_TYPE_WIDTH) { in format_decode()
2537 if (spec->field_width < 0) { in format_decode()
2538 spec->field_width = -spec->field_width; in format_decode()
2539 spec->flags |= LEFT; in format_decode()
2541 spec->type = FORMAT_TYPE_NONE; in format_decode()
2542 goto precision; in format_decode()
2545 /* we finished early by reading the precision */ in format_decode()
2546 if (spec->type == FORMAT_TYPE_PRECISION) { in format_decode()
2547 if (spec->precision < 0) in format_decode()
2548 spec->precision = 0; in format_decode()
2550 spec->type = FORMAT_TYPE_NONE; in format_decode()
2555 spec->type = FORMAT_TYPE_NONE; in format_decode()
2562 /* Return the current non-format string */ in format_decode()
2564 return fmt - start; in format_decode()
2567 spec->flags = 0; in format_decode()
2575 case '-': spec->flags |= LEFT; break; in format_decode()
2576 case '+': spec->flags |= PLUS; break; in format_decode()
2577 case ' ': spec->flags |= SPACE; break; in format_decode()
2578 case '#': spec->flags |= SPECIAL; break; in format_decode()
2579 case '0': spec->flags |= ZEROPAD; break; in format_decode()
2588 spec->field_width = -1; in format_decode()
2591 spec->field_width = skip_atoi(&fmt); in format_decode()
2594 spec->type = FORMAT_TYPE_WIDTH; in format_decode()
2595 return ++fmt - start; in format_decode()
2598 precision: in format_decode()
2599 /* get the precision */ in format_decode()
2600 spec->precision = -1; in format_decode()
2604 spec->precision = skip_atoi(&fmt); in format_decode()
2605 if (spec->precision < 0) in format_decode()
2606 spec->precision = 0; in format_decode()
2609 spec->type = FORMAT_TYPE_PRECISION; in format_decode()
2610 return ++fmt - start; in format_decode()
2632 spec->base = 10; in format_decode()
2635 spec->type = FORMAT_TYPE_CHAR; in format_decode()
2636 return ++fmt - start; in format_decode()
2639 spec->type = FORMAT_TYPE_STR; in format_decode()
2640 return ++fmt - start; in format_decode()
2643 spec->type = FORMAT_TYPE_PTR; in format_decode()
2644 return ++fmt - start; in format_decode()
2647 spec->type = FORMAT_TYPE_PERCENT_CHAR; in format_decode()
2648 return ++fmt - start; in format_decode()
2650 /* integer number formats - set up the flags and "break" */ in format_decode()
2652 spec->base = 8; in format_decode()
2656 spec->flags |= SMALL; in format_decode()
2660 spec->base = 16; in format_decode()
2665 spec->flags |= SIGN; in format_decode()
2680 spec->type = FORMAT_TYPE_INVALID; in format_decode()
2681 return fmt - start; in format_decode()
2685 spec->type = FORMAT_TYPE_LONG_LONG; in format_decode()
2688 spec->type = FORMAT_TYPE_ULONG + (spec->flags & SIGN); in format_decode()
2690 spec->type = FORMAT_TYPE_SIZE_T; in format_decode()
2692 spec->type = FORMAT_TYPE_PTRDIFF; in format_decode()
2695 spec->type = FORMAT_TYPE_UBYTE + (spec->flags & SIGN); in format_decode()
2698 spec->type = FORMAT_TYPE_USHORT + (spec->flags & SIGN); in format_decode()
2701 spec->type = FORMAT_TYPE_UINT + (spec->flags & SIGN); in format_decode()
2704 return ++fmt - start; in format_decode()
2710 spec->field_width = width; in set_field_width()
2711 if (WARN_ONCE(spec->field_width != width, "field width %d too large", width)) { in set_field_width()
2712 spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); in set_field_width()
2719 spec->precision = prec; in set_precision()
2720 if (WARN_ONCE(spec->precision != prec, "precision %d too large", prec)) { in set_precision()
2721 spec->precision = clamp(prec, 0, PRECISION_MAX); in set_precision()
2726 * vsnprintf - Format a string and place it in a buffer
2735 * - ``%n`` is unsupported
2736 * - ``%p*`` is handled by pointer()
2738 * See pointer() or Documentation/core-api/printk-formats.rst for more
2759 /* Reject out-of-range values early. Large positive sizes are in vsnprintf()
2769 end = ((void *)-1); in vsnprintf()
2770 size = end - buf; in vsnprintf()
2783 if (copy > end - str) in vsnprintf()
2784 copy = end - str; in vsnprintf()
2803 while (--spec.field_width > 0) { in vsnprintf()
2814 while (--spec.field_width > 0) { in vsnprintf()
2898 end[-1] = '\0'; in vsnprintf()
2902 return str-buf; in vsnprintf()
2908 * vscnprintf - Format a string and place it in a buffer
2934 return size - 1; in vscnprintf()
2939 * snprintf - Format a string and place it in a buffer
2966 * scnprintf - Format a string and place it in a buffer
2990 * vsprintf - Format a string and place it in a buffer
3010 * sprintf - Format a string and place it in a buffer
3037 * vbin_printf() - VA arguments to binary data
3038 * bstr_printf() - Binary data to text string
3042 * vbin_printf - Parse a format string and place args' binary value in a buffer
3152 end[-1] = '\0'; /* Must be nul terminated */ in vbin_printf()
3190 return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; in vbin_printf()
3196 * bstr_printf - Format a string from binary arguments and place it in a buffer
3246 end = ((void *)-1); in bstr_printf()
3247 size = end - buf; in bstr_printf()
3260 if (copy > end - str) in bstr_printf()
3261 copy = end - str; in bstr_printf()
3280 while (--spec.field_width > 0) { in bstr_printf()
3290 while (--spec.field_width > 0) { in bstr_printf()
3325 if (copy > end - str) in bstr_printf()
3326 copy = end - str; in bstr_printf()
3396 end[-1] = '\0'; in bstr_printf()
3402 return str - buf; in bstr_printf()
3407 * bprintf - Parse a format string and place args' binary value in a buffer
3432 * vsscanf - Unformat a buffer into a list of arguments
3491 field_width = -1; in vsscanf()
3499 qualifier = -1; in vsscanf()
3519 *va_arg(args, int *) = str - buf; in vsscanf()
3534 if (field_width == -1) in vsscanf()
3538 } while (--field_width > 0 && *str); in vsscanf()
3545 if (field_width == -1) in vsscanf()
3551 while (*str && !isspace(*str) && field_width--) in vsscanf()
3560 * (1) It does NOT support ranges i.e. '-' is NOT a special in vsscanf()
3580 if (field_width == -1) in vsscanf()
3600 /* match must be non-empty */ in vsscanf()
3604 while (test_bit((u8)*str, set) && field_width--) in vsscanf()
3641 if (is_sign && digit == '-') { in vsscanf()
3711 * sscanf - Unformat a buffer into a list of arguments