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>
72 prefix_chars = cp - startp; in simple_strntoull()
74 rv = _parse_integer_limit(cp, base, &result, max_chars - prefix_chars); in simple_strntoull()
89 * simple_strtoull - convert a string to an unsigned long long
104 * simple_strtoul - convert a string to an unsigned long
118 * simple_strtol - convert a string to a signed long
127 if (*cp == '-') in simple_strtol()
128 return -simple_strtoul(cp + 1, endp, base); in simple_strtol()
139 * case cp[0] == '-' && max_chars == 1. in simple_strntoll()
143 if (*cp == '-' && max_chars > 0) in simple_strntoll()
144 return -simple_strntoull(cp + 1, endp, base, max_chars - 1); in simple_strntoll()
150 * simple_strtoll - convert a string to a signed long long
169 i = i*10 + *((*s)++) - '0'; in skip_atoi()
186 * It turns out there is precisely one 26 bit fixed-point
188 * holds for all x in [0, 10^8-1], namely a = 0x28f5c29. The actual
192 * For dividing a number in the range [10^4, 10^6-1] by 100, we still
193 * need a 32x32->64 bit multiply, so we simply use the same constant.
195 * For dividing a number in the range [100, 10^4-1] by 100, there are
219 * below. All other callers pass a non-zero value of r.
232 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
241 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_trunc8()
250 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_trunc8()
270 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
275 *((u16 *)buf) = decpair[q - 100*r]; in put_dec_full8()
280 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full8()
310 *((u16 *)buf) = decpair[r - 100*q]; in put_dec_full4()
321 * (second call in the put_dec code, assuming n is all-ones).
328 put_dec_full4(buf, x - q * 10000); in put_dec_helper4()
335 * Performs no 64-bit division and hence should be fast on 32-bit machines.
365 else while (buf[-1] == '0') in put_dec()
366 --buf; in put_dec()
381 /* put_dec requires 2-byte alignment of the buffer. */ in num_to_str()
390 len = put_dec(tmp, num) - tmp; in num_to_str()
397 width = width - len; in num_to_str()
405 buf[idx + width] = tmp[len - idx - 1]; in num_to_str()
414 #define ZEROPAD 16 /* pad with zero, must be 16 == '0' - ' ' */
419 static_assert(ZEROPAD == ('0' - ' '));
449 signed int precision:16; /* # of digits/chars */ member
453 #define FIELD_WIDTH_MAX ((1 << 23) - 1)
454 #define PRECISION_MAX ((1 << 15) - 1)
460 /* put_dec requires 2-byte alignment of the buffer. */ in number()
468 int precision = spec.precision; in number() local
478 sign = '-'; in number()
479 num = -(signed long long)num; in number()
480 field_width--; in number()
483 field_width--; in number()
486 field_width--; in number()
491 field_width -= 2; in number()
493 field_width--; in number()
501 int mask = spec.base - 1; in number()
511 i = put_dec(tmp, num) - tmp; in number()
515 if (i > precision) in number()
516 precision = i; in number()
518 field_width -= precision; in number()
520 while (--field_width >= 0) { in number()
549 while (--field_width >= 0) { in number()
556 while (i <= --precision) { in number()
562 while (--i >= 0) { in number()
568 while (--field_width >= 0) { in number()
586 spec.precision = -1; in special_hex_number()
596 size = end - buf; in move_right()
602 if (len > size - spaces) in move_right()
603 len = size - spaces; in move_right()
625 spaces = spec.field_width - n; in widen_string()
627 move_right(buf - n, end, n, spaces); in widen_string()
630 while (spaces--) { in widen_string()
643 int lim = spec.precision; in string_nocheck()
645 while (lim--) { in string_nocheck()
667 * Somebody passed ERR_PTR(-1234) or some other non-existing in err_ptr()
668 * Efoo - or perhaps CONFIG_SYMBOLIC_ERRNAME=n. Fall back to in err_ptr()
685 if (spec.precision == -1) in error_string()
686 spec.precision = 2 * sizeof(void *); in error_string()
715 return -EFAULT; in check_pointer()
737 if (spec.field_width == -1) { in pointer_string()
783 return -EBUSY; in subsys_initcall()
821 /* When debugging early boot use non-cryptographically secure hash. */ in ptr_to_id()
868 if (spec.field_width == -1) in restricted_pointer()
870 return error_string(buf, end, "pK-error", spec); in restricted_pointer()
884 !uid_eq(cred->euid, cred->uid) || in restricted_pointer()
885 !gid_eq(cred->egid, cred->gid)) in restricted_pointer()
910 depth = fmt[1] - '0'; in dentry_name()
923 p = READ_ONCE(d->d_parent); in dentry_name()
924 array[i] = READ_ONCE(d->d_name.name); in dentry_name()
932 s = array[--i]; in dentry_name()
933 for (n = 0; n != spec.precision; n++, buf++) { in dentry_name()
939 s = array[--i]; in dentry_name()
955 return dentry_name(buf, end, f->f_path.dentry, spec, fmt); in file_dentry_name()
967 hd = bdev->bd_disk; in bdev_name()
968 buf = string(buf, end, hd->disk_name, spec); in bdev_name()
969 if (bdev->bd_partno) { in bdev_name()
970 if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) { in bdev_name()
975 buf = number(buf, end, bdev->bd_partno, spec); in bdev_name()
1013 .field_width = -1,
1014 .precision = -1,
1019 .precision = -1,
1025 .precision = -1,
1031 .precision = -1,
1038 .precision = -1,
1056 .precision = -1, in resource_string()
1062 .precision = -1, in resource_string()
1068 .precision = -1, in resource_string()
1072 .field_width = -1, in resource_string()
1073 .precision = 10, in resource_string()
1077 /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) in resource_string()
1078 * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ in resource_string()
1080 #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) in resource_string()
1081 #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") in resource_string()
1082 #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") in resource_string()
1094 if (res->flags & IORESOURCE_IO) { in resource_string()
1097 } else if (res->flags & IORESOURCE_MEM) { in resource_string()
1100 } else if (res->flags & IORESOURCE_IRQ) { in resource_string()
1103 } else if (res->flags & IORESOURCE_DMA) { in resource_string()
1106 } else if (res->flags & IORESOURCE_BUS) { in resource_string()
1114 if (decode && res->flags & IORESOURCE_UNSET) { in resource_string()
1118 p = number(p, pend, res->start, *specp); in resource_string()
1119 if (res->start != res->end) { in resource_string()
1120 *p++ = '-'; in resource_string()
1121 p = number(p, pend, res->end, *specp); in resource_string()
1125 if (res->flags & IORESOURCE_MEM_64) in resource_string()
1127 if (res->flags & IORESOURCE_PREFETCH) in resource_string()
1129 if (res->flags & IORESOURCE_WINDOW) in resource_string()
1131 if (res->flags & IORESOURCE_DISABLED) in resource_string()
1135 p = number(p, pend, res->flags, default_flag_spec); in resource_string()
1163 separator = '-'; in hex_string()
1184 if (separator && i != len - 1) { in hex_string()
1209 chunksz = nr_bits & (CHUNKSZ - 1); in bitmap_string()
1213 i = ALIGN(nr_bits, CHUNKSZ) - CHUNKSZ; in bitmap_string()
1214 for (; i >= 0; i -= CHUNKSZ) { in bitmap_string()
1218 chunkmask = ((1ULL << chunksz) - 1); in bitmap_string()
1262 *buf = '-'; in bitmap_list_string()
1263 buf = number(++buf, end, rtop - 1, default_dec_spec); in bitmap_list_string()
1283 separator = '-'; in mac_address_string()
1297 p = hex_byte_pack(p, addr[5 - i]); in mac_address_string()
1324 step = -1; in ip4_string()
1329 step = -1; in ip4_string()
1339 char temp[4] __aligned(2); /* hold each IP quad in reverse order */ in ip4_string()
1340 int digits = put_dec_trunc8(temp, addr[index]) - temp; in ip4_string()
1347 /* reverse the digits in the quad */ in ip4_string()
1348 while (digits--) in ip4_string()
1365 int colonpos = -1; in ip6_compressed_string()
1398 colonpos = -1; in ip6_compressed_string()
1407 i += longest - 1; in ip6_compressed_string()
1492 const u8 *addr = (const u8 *) &sa->sin6_addr; in ip6_addr_string_sa()
1529 p = number(p, pend, ntohs(sa->sin6_port), spec); in ip6_addr_string_sa()
1533 p = number(p, pend, ntohl(sa->sin6_flowinfo & in ip6_addr_string_sa()
1538 p = number(p, pend, sa->sin6_scope_id, spec); in ip6_addr_string_sa()
1552 const u8 *addr = (const u8 *) &sa->sin_addr.s_addr; in ip4_addr_string_sa()
1573 p = number(p, pend, ntohs(sa->sin_port), spec); in ip4_addr_string_sa()
1601 switch (sa->raw.sa_family) { in ip_addr_string()
1603 return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt); in ip_addr_string()
1605 return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt); in ip_addr_string()
1669 buf += string_escape_mem(addr, len, buf, buf < end ? end - buf : 0, flags, NULL); in escaped_string()
1682 va_copy(va, *va_fmt->va); in va_format()
1683 buf += vsnprintf(buf, end > buf ? end - buf : 0, va_fmt->fmt, va); in va_format()
1724 *p++ = '-'; in uuid_string()
1760 char output[sizeof("0123 little-endian (0x01234567)")]; in fourcc_string()
1777 /* Print non-control ASCII characters as-is, dot otherwise */ in fourcc_string()
1782 strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); in fourcc_string()
1787 p = special_hex_number(p, output + sizeof(output) - 2, orig, sizeof(u32)); in fourcc_string()
1822 int year = tm->tm_year + (r ? 0 : 1900); in date_str()
1823 int mon = tm->tm_mon + (r ? 0 : 1); in date_str()
1827 *buf = '-'; in date_str()
1832 *buf = '-'; in date_str()
1835 return number(buf, end, tm->tm_mday, default_dec02_spec); in date_str()
1841 buf = number(buf, end, tm->tm_hour, default_dec02_spec); in time_str()
1846 buf = number(buf, end, tm->tm_min, default_dec02_spec); in time_str()
1851 return number(buf, end, tm->tm_sec, default_dec02_spec); in time_str()
1968 for ( ; flags && names->name; names++) { in format_flags()
1969 mask = names->mask; in format_flags()
1973 buf = string(buf, end, names->name, default_str_spec); in format_flags()
2113 for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) { in fwnode_full_name_string()
2145 str_spec.field_width = -1; in device_node_string()
2162 int precision; in device_node_string() local
2176 precision = str_spec.precision; in device_node_string()
2177 str_spec.precision = strchrnul(p, '@') - p; in device_node_string()
2179 str_spec.precision = precision; in device_node_string()
2182 buf = number(buf, end, (unsigned int)dn->phandle, default_dec_spec); in device_node_string()
2184 case 'P': /* path-spec */ in device_node_string()
2191 tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-'; in device_node_string()
2192 tbuf[1] = of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-'; in device_node_string()
2193 tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-'; in device_node_string()
2194 tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-'; in device_node_string()
2220 return widen_string(buf, buf - buf_start, end, spec); in device_node_string()
2230 str_spec.field_width = -1; in fwnode_string()
2250 return widen_string(buf, buf - buf_start, end, spec); in fwnode_string()
2291 * - 'S' For symbolic direct pointers (or function descriptors) with offset
2292 * - 's' For symbolic direct pointers (or function descriptors) without offset
2293 * - '[Ss]R' as above with __builtin_extract_return_addr() translation
2294 * - 'S[R]b' as above with module build ID (for use in backtraces)
2295 * - '[Ff]' %pf and %pF were obsoleted and later removed in favor of
2296 * %ps and %pS. Be careful when re-using these specifiers.
2297 * - 'B' For backtraced symbolic direct pointers with offset
2298 * - 'Bb' as above with module build ID (for use in backtraces)
2299 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
2300 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
2301 * - 'b[l]' For a bitmap, the number of bits is determined by the field
2304 * range-list format instead of hex format
2305 * - 'M' For a 6-byte MAC address, it prints the address in the
2306 * usual colon-separated hex notation
2307 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
2308 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
2309 * with a dash-separated hex notation
2310 * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
2311 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
2312 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
2313 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
2317 * - 'i' [46] for 'raw' IPv4/IPv6 addresses
2319 * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
2323 * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
2324 * - 'I[6S]c' for IPv6 addresses printed as specified by
2326 * - 'E[achnops]' For an escaped buffer, where rules are defined by combination
2329 * a - ESCAPE_ANY
2330 * c - ESCAPE_SPECIAL
2331 * h - ESCAPE_HEX
2332 * n - ESCAPE_NULL
2333 * o - ESCAPE_OCTAL
2334 * p - ESCAPE_NP
2335 * s - ESCAPE_SPACE
2337 * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
2338 * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2345 * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
2347 * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
2348 * - 'V' For a struct va_format which contains a format string * and va_list *,
2349 * call vsnprintf(->format, *->va_list).
2353 * - 'K' For a kernel pointer that should be hidden from unprivileged users.
2356 * - 'NF' For a netdev_features_t
2357 * - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value.
2358 * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
2365 * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
2367 * - 'd[234]' For a dentry name (optionally 2-4 last components)
2368 * - 'D[234]' Same as 'd' but for a struct file
2369 * - 'g' For block_device name (gendisk + partition number)
2370 * - 't[RT][dt][r][s]' For time and date as represented by:
2373 * - 'C' For a clock, it prints the name (Common Clock Framework) or address
2375 * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
2377 * - 'G' For flags to be printed as a collection of symbolic strings that would
2382 * - 'OF[fnpPcCF]' For a device tree object
2391 * - 'fw[fP]' For a firmware node (struct fwnode_handle) pointer
2395 * - 'x' For printing the address unmodified. Equivalent to "%lx".
2397 * - '[ku]s' For a BPF/tracing related format specifier, e.g. used out of
2403 * Documentation/core-api/printk-formats.rst
2485 WARN_ONCE(1, "Please remove %%pA from non-Rust code\n"); in pointer()
2492 /* %pe with a non-ERR_PTR gets treated as plain %p */ in pointer()
2518 * 'z' changed to 'Z' --davidm 1/25/99
2519 * 'Z' changed to 'z' --adobriyan 2017-01-25
2524 * @flags: various flags such as +, -, # tokens..
2527 * @precision: precision of a number
2537 if (spec->type == FORMAT_TYPE_WIDTH) { in format_decode()
2538 if (spec->field_width < 0) { in format_decode()
2539 spec->field_width = -spec->field_width; in format_decode()
2540 spec->flags |= LEFT; in format_decode()
2542 spec->type = FORMAT_TYPE_NONE; in format_decode()
2543 goto precision; in format_decode()
2546 /* we finished early by reading the precision */ in format_decode()
2547 if (spec->type == FORMAT_TYPE_PRECISION) { in format_decode()
2548 if (spec->precision < 0) in format_decode()
2549 spec->precision = 0; in format_decode()
2551 spec->type = FORMAT_TYPE_NONE; in format_decode()
2556 spec->type = FORMAT_TYPE_NONE; in format_decode()
2563 /* Return the current non-format string */ in format_decode()
2565 return fmt - start; in format_decode()
2568 spec->flags = 0; in format_decode()
2576 case '-': spec->flags |= LEFT; break; in format_decode()
2577 case '+': spec->flags |= PLUS; break; in format_decode()
2578 case ' ': spec->flags |= SPACE; break; in format_decode()
2579 case '#': spec->flags |= SPECIAL; break; in format_decode()
2580 case '0': spec->flags |= ZEROPAD; break; in format_decode()
2589 spec->field_width = -1; in format_decode()
2592 spec->field_width = skip_atoi(&fmt); in format_decode()
2595 spec->type = FORMAT_TYPE_WIDTH; in format_decode()
2596 return ++fmt - start; in format_decode()
2599 precision: in format_decode()
2600 /* get the precision */ in format_decode()
2601 spec->precision = -1; in format_decode()
2605 spec->precision = skip_atoi(&fmt); in format_decode()
2606 if (spec->precision < 0) in format_decode()
2607 spec->precision = 0; in format_decode()
2610 spec->type = FORMAT_TYPE_PRECISION; in format_decode()
2611 return ++fmt - start; in format_decode()
2633 spec->base = 10; in format_decode()
2636 spec->type = FORMAT_TYPE_CHAR; in format_decode()
2637 return ++fmt - start; in format_decode()
2640 spec->type = FORMAT_TYPE_STR; in format_decode()
2641 return ++fmt - start; in format_decode()
2644 spec->type = FORMAT_TYPE_PTR; in format_decode()
2645 return ++fmt - start; in format_decode()
2648 spec->type = FORMAT_TYPE_PERCENT_CHAR; in format_decode()
2649 return ++fmt - start; in format_decode()
2651 /* integer number formats - set up the flags and "break" */ in format_decode()
2653 spec->base = 8; in format_decode()
2657 spec->flags |= SMALL; in format_decode()
2661 spec->base = 16; in format_decode()
2666 spec->flags |= SIGN; in format_decode()
2681 spec->type = FORMAT_TYPE_INVALID; in format_decode()
2682 return fmt - start; in format_decode()
2686 spec->type = FORMAT_TYPE_LONG_LONG; in format_decode()
2689 spec->type = FORMAT_TYPE_ULONG + (spec->flags & SIGN); in format_decode()
2691 spec->type = FORMAT_TYPE_SIZE_T; in format_decode()
2693 spec->type = FORMAT_TYPE_PTRDIFF; in format_decode()
2696 spec->type = FORMAT_TYPE_UBYTE + (spec->flags & SIGN); in format_decode()
2699 spec->type = FORMAT_TYPE_USHORT + (spec->flags & SIGN); in format_decode()
2702 spec->type = FORMAT_TYPE_UINT + (spec->flags & SIGN); in format_decode()
2705 return ++fmt - start; in format_decode()
2711 spec->field_width = width; in set_field_width()
2712 if (WARN_ONCE(spec->field_width != width, "field width %d too large", width)) { in set_field_width()
2713 spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); in set_field_width()
2720 spec->precision = prec; in set_precision()
2721 if (WARN_ONCE(spec->precision != prec, "precision %d too large", prec)) { in set_precision()
2722 spec->precision = clamp(prec, 0, PRECISION_MAX); in set_precision()
2727 * vsnprintf - Format a string and place it in a buffer
2736 * - ``%n`` is unsupported
2737 * - ``%p*`` is handled by pointer()
2739 * See pointer() or Documentation/core-api/printk-formats.rst for more
2760 /* Reject out-of-range values early. Large positive sizes are in vsnprintf()
2770 end = ((void *)-1); in vsnprintf()
2771 size = end - buf; in vsnprintf()
2784 if (copy > end - str) in vsnprintf()
2785 copy = end - str; in vsnprintf()
2804 while (--spec.field_width > 0) { in vsnprintf()
2815 while (--spec.field_width > 0) { in vsnprintf()
2899 end[-1] = '\0'; in vsnprintf()
2903 return str-buf; in vsnprintf()
2909 * vscnprintf - Format a string and place it in a buffer
2935 return size - 1; in vscnprintf()
2940 * snprintf - Format a string and place it in a buffer
2967 * scnprintf - Format a string and place it in a buffer
2991 * vsprintf - Format a string and place it in a buffer
3011 * sprintf - Format a string and place it in a buffer
3038 * vbin_printf() - VA arguments to binary data
3039 * bstr_printf() - Binary data to text string
3043 * vbin_printf - Parse a format string and place args' binary value in a buffer
3153 end[-1] = '\0'; /* Must be nul terminated */ in vbin_printf()
3191 return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; in vbin_printf()
3197 * bstr_printf - Format a string from binary arguments and place it in a buffer
3247 end = ((void *)-1); in bstr_printf()
3248 size = end - buf; in bstr_printf()
3261 if (copy > end - str) in bstr_printf()
3262 copy = end - str; in bstr_printf()
3281 while (--spec.field_width > 0) { in bstr_printf()
3291 while (--spec.field_width > 0) { in bstr_printf()
3326 if (copy > end - str) in bstr_printf()
3327 copy = end - str; in bstr_printf()
3397 end[-1] = '\0'; in bstr_printf()
3403 return str - buf; in bstr_printf()
3408 * bprintf - Parse a format string and place args' binary value in a buffer
3433 * vsscanf - Unformat a buffer into a list of arguments
3492 field_width = -1; in vsscanf()
3500 qualifier = -1; in vsscanf()
3520 *va_arg(args, int *) = str - buf; in vsscanf()
3535 if (field_width == -1) in vsscanf()
3539 } while (--field_width > 0 && *str); in vsscanf()
3546 if (field_width == -1) in vsscanf()
3552 while (*str && !isspace(*str) && field_width--) in vsscanf()
3561 * (1) It does NOT support ranges i.e. '-' is NOT a special in vsscanf()
3581 if (field_width == -1) in vsscanf()
3601 /* match must be non-empty */ in vsscanf()
3605 while (test_bit((u8)*str, set) && field_width--) in vsscanf()
3642 if (is_sign && digit == '-') { in vsscanf()
3710 * sscanf - Unformat a buffer into a list of arguments