Lines Matching +full:exact +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0-only
16 * bitmap_parse_user - convert an ASCII hex string in a user buffer into a bitmap
43 * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string
49 * Output format is a comma-separated list of decimal numbers and
50 * ranges if list is specified or hex digits grouped into comma-separated
53 * It is assumed that @buf is a pointer into a PAGE_SIZE, page-aligned
61 ptrdiff_t len = PAGE_SIZE - offset_in_page(buf); in bitmap_print_to_pagebuf() local
63 return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) : in bitmap_print_to_pagebuf()
64 scnprintf(buf, len, "%*pb\n", nmaskbits, maskp); in bitmap_print_to_pagebuf()
69 * bitmap_print_to_buf - convert bitmap to list or hex format ASCII string
88 return -ENOMEM; in bitmap_print_to_buf()
97 * bitmap_print_bitmask_to_buf - convert bitmap to hex bitmask format ASCII string
129 * as complex as 0,3,5,7,9,... We have no simple way to know it exact size.
155 * hand, mainly serves bin_attribute which doesn't work with exact one page,
165 * - Time complexity is O(nbits^2/count), comparing to O(nbits) for snprintf().
166 * - Memory complexity is O(nbits), comparing to O(1) for snprintf().
167 * - @off and @count are NOT offset and number of bits to print.
168 * - If printing part of bitmap as list, the resulting string is not a correct
171 * may be broken, so bitmap_parselist-like parser may fail parsing it.
172 * - If printing the whole bitmap as list by parts, user must ensure the order
174 * - If printing the whole bitmap as list by parts, user must keep bitmap
188 * bitmap_print_list_to_buf - convert bitmap to decimal list format ASCII string
206 * Region 9-38:4/10 describes the following bitmap structure:
224 for (start = r->start; start <= r->end; start += r->group_len) in bitmap_set_region()
225 bitmap_set(bitmap, start, min(r->end - start + 1, r->off)); in bitmap_set_region()
230 if (r->start > r->end || r->group_len == 0 || r->off > r->group_len) in bitmap_check_region()
231 return -EINVAL; in bitmap_check_region()
233 if (r->end >= r->nbits) in bitmap_check_region()
234 return -ERANGE; in bitmap_check_region()
243 unsigned int len; in bitmap_getnum() local
250 len = _parse_integer(str, 10, &n); in bitmap_getnum()
251 if (!len) in bitmap_getnum()
252 return ERR_PTR(-EINVAL); in bitmap_getnum()
253 if (len & KSTRTOX_OVERFLOW || n != (unsigned int)n) in bitmap_getnum()
254 return ERR_PTR(-EOVERFLOW); in bitmap_getnum()
257 return str + len; in bitmap_getnum()
290 end--; in bitmap_find_region_reverse()
297 unsigned int lastbit = r->nbits - 1; in bitmap_parse_region()
300 r->start = 0; in bitmap_parse_region()
301 r->end = lastbit; in bitmap_parse_region()
307 str = bitmap_getnum(str, &r->start, lastbit); in bitmap_parse_region()
314 if (*str != '-') in bitmap_parse_region()
315 return ERR_PTR(-EINVAL); in bitmap_parse_region()
317 str = bitmap_getnum(str + 1, &r->end, lastbit); in bitmap_parse_region()
326 return ERR_PTR(-EINVAL); in bitmap_parse_region()
328 str = bitmap_getnum(str + 1, &r->off, lastbit); in bitmap_parse_region()
333 return ERR_PTR(-EINVAL); in bitmap_parse_region()
335 return bitmap_getnum(str + 1, &r->group_len, lastbit); in bitmap_parse_region()
338 r->end = r->start; in bitmap_parse_region()
340 r->off = r->end + 1; in bitmap_parse_region()
341 r->group_len = r->end + 1; in bitmap_parse_region()
347 * bitmap_parselist - convert list format ASCII string to bitmap
353 * Input format is a comma-separated list of decimal numbers and
354 * ranges. Consecutively set bits are shown as two hyphen-separated
361 * Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769
363 * maximum allowed value; i.e (nmaskbits - 1). Keep in mind that it is
367 * Returns: 0 on success, -errno on invalid input strings. Error values:
369 * - ``-EINVAL``: wrong region format
370 * - ``-EINVAL``: invalid character in string
371 * - ``-ERANGE``: bit number specified too large for mask
372 * - ``-EOVERFLOW``: integer overflow in the input parameters
404 * bitmap_parselist_user() - convert user buffer's list format ASCII
440 c = hex_to_bin(*end--); in bitmap_get_x32_reverse()
442 return ERR_PTR(-EINVAL); in bitmap_get_x32_reverse()
450 if (hex_to_bin(*end--) >= 0) in bitmap_get_x32_reverse()
451 return ERR_PTR(-EOVERFLOW); in bitmap_get_x32_reverse()
458 * bitmap_parse - convert an ASCII hex string into a bitmap.
468 * than 32 bits (%-EOVERFLOW), and if a chunk specifies a smaller value
469 * then leading 0-bits are prepended. %-EINVAL is returned for illegal
476 const char *end = strnchrnul(start, buflen, '\n') - 1; in bitmap_parse()
487 if (!chunks--) in bitmap_parse()
488 return -EOVERFLOW; in bitmap_parse()
499 unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32; in bitmap_parse()
501 bitmap_clear(maskp, unset_bit, nmaskbits - unset_bit); in bitmap_parse()
506 return -EOVERFLOW; in bitmap_parse()