bitmap.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. /*
  2. * lib/bitmap.c
  3. * Helper functions for bitmap.h.
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <linux/export.h>
  9. #include <linux/thread_info.h>
  10. #include <linux/ctype.h>
  11. #include <linux/errno.h>
  12. #include <linux/bitmap.h>
  13. #include <linux/bitops.h>
  14. #include <linux/bug.h>
  15. #include <asm/uaccess.h>
  16. /*
  17. * bitmaps provide an array of bits, implemented using an an
  18. * array of unsigned longs. The number of valid bits in a
  19. * given bitmap does _not_ need to be an exact multiple of
  20. * BITS_PER_LONG.
  21. *
  22. * The possible unused bits in the last, partially used word
  23. * of a bitmap are 'don't care'. The implementation makes
  24. * no particular effort to keep them zero. It ensures that
  25. * their value will not affect the results of any operation.
  26. * The bitmap operations that return Boolean (bitmap_empty,
  27. * for example) or scalar (bitmap_weight, for example) results
  28. * carefully filter out these unused bits from impacting their
  29. * results.
  30. *
  31. * These operations actually hold to a slightly stronger rule:
  32. * if you don't input any bitmaps to these ops that have some
  33. * unused bits set, then they won't output any set unused bits
  34. * in output bitmaps.
  35. *
  36. * The byte ordering of bitmaps is more natural on little
  37. * endian architectures. See the big-endian headers
  38. * include/asm-ppc64/bitops.h and include/asm-s390/bitops.h
  39. * for the best explanations of this ordering.
  40. */
  41. int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
  42. {
  43. unsigned int k, lim = bits/BITS_PER_LONG;
  44. for (k = 0; k < lim; ++k)
  45. if (bitmap[k])
  46. return 0;
  47. if (bits % BITS_PER_LONG)
  48. if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
  49. return 0;
  50. return 1;
  51. }
  52. EXPORT_SYMBOL(__bitmap_empty);
  53. int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
  54. {
  55. unsigned int k, lim = bits/BITS_PER_LONG;
  56. for (k = 0; k < lim; ++k)
  57. if (~bitmap[k])
  58. return 0;
  59. if (bits % BITS_PER_LONG)
  60. if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
  61. return 0;
  62. return 1;
  63. }
  64. EXPORT_SYMBOL(__bitmap_full);
  65. int __bitmap_equal(const unsigned long *bitmap1,
  66. const unsigned long *bitmap2, unsigned int bits)
  67. {
  68. unsigned int k, lim = bits/BITS_PER_LONG;
  69. for (k = 0; k < lim; ++k)
  70. if (bitmap1[k] != bitmap2[k])
  71. return 0;
  72. if (bits % BITS_PER_LONG)
  73. if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
  74. return 0;
  75. return 1;
  76. }
  77. EXPORT_SYMBOL(__bitmap_equal);
  78. void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits)
  79. {
  80. unsigned int k, lim = bits/BITS_PER_LONG;
  81. for (k = 0; k < lim; ++k)
  82. dst[k] = ~src[k];
  83. if (bits % BITS_PER_LONG)
  84. dst[k] = ~src[k];
  85. }
  86. EXPORT_SYMBOL(__bitmap_complement);
  87. /**
  88. * __bitmap_shift_right - logical right shift of the bits in a bitmap
  89. * @dst : destination bitmap
  90. * @src : source bitmap
  91. * @shift : shift by this many bits
  92. * @bits : bitmap size, in bits
  93. *
  94. * Shifting right (dividing) means moving bits in the MS -> LS bit
  95. * direction. Zeros are fed into the vacated MS positions and the
  96. * LS bits shifted off the bottom are lost.
  97. */
  98. void __bitmap_shift_right(unsigned long *dst,
  99. const unsigned long *src, int shift, int bits)
  100. {
  101. int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG;
  102. int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
  103. unsigned long mask = (1UL << left) - 1;
  104. for (k = 0; off + k < lim; ++k) {
  105. unsigned long upper, lower;
  106. /*
  107. * If shift is not word aligned, take lower rem bits of
  108. * word above and make them the top rem bits of result.
  109. */
  110. if (!rem || off + k + 1 >= lim)
  111. upper = 0;
  112. else {
  113. upper = src[off + k + 1];
  114. if (off + k + 1 == lim - 1 && left)
  115. upper &= mask;
  116. }
  117. lower = src[off + k];
  118. if (left && off + k == lim - 1)
  119. lower &= mask;
  120. dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem;
  121. if (left && k == lim - 1)
  122. dst[k] &= mask;
  123. }
  124. if (off)
  125. memset(&dst[lim - off], 0, off*sizeof(unsigned long));
  126. }
  127. EXPORT_SYMBOL(__bitmap_shift_right);
  128. /**
  129. * __bitmap_shift_left - logical left shift of the bits in a bitmap
  130. * @dst : destination bitmap
  131. * @src : source bitmap
  132. * @shift : shift by this many bits
  133. * @bits : bitmap size, in bits
  134. *
  135. * Shifting left (multiplying) means moving bits in the LS -> MS
  136. * direction. Zeros are fed into the vacated LS bit positions
  137. * and those MS bits shifted off the top are lost.
  138. */
  139. void __bitmap_shift_left(unsigned long *dst,
  140. const unsigned long *src, int shift, int bits)
  141. {
  142. int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG;
  143. int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
  144. for (k = lim - off - 1; k >= 0; --k) {
  145. unsigned long upper, lower;
  146. /*
  147. * If shift is not word aligned, take upper rem bits of
  148. * word below and make them the bottom rem bits of result.
  149. */
  150. if (rem && k > 0)
  151. lower = src[k - 1];
  152. else
  153. lower = 0;
  154. upper = src[k];
  155. if (left && k == lim - 1)
  156. upper &= (1UL << left) - 1;
  157. dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem;
  158. if (left && k + off == lim - 1)
  159. dst[k + off] &= (1UL << left) - 1;
  160. }
  161. if (off)
  162. memset(dst, 0, off*sizeof(unsigned long));
  163. }
  164. EXPORT_SYMBOL(__bitmap_shift_left);
  165. int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
  166. const unsigned long *bitmap2, unsigned int bits)
  167. {
  168. unsigned int k;
  169. unsigned int nr = BITS_TO_LONGS(bits);
  170. unsigned long result = 0;
  171. for (k = 0; k < nr; k++)
  172. result |= (dst[k] = bitmap1[k] & bitmap2[k]);
  173. return result != 0;
  174. }
  175. EXPORT_SYMBOL(__bitmap_and);
  176. void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
  177. const unsigned long *bitmap2, unsigned int bits)
  178. {
  179. unsigned int k;
  180. unsigned int nr = BITS_TO_LONGS(bits);
  181. for (k = 0; k < nr; k++)
  182. dst[k] = bitmap1[k] | bitmap2[k];
  183. }
  184. EXPORT_SYMBOL(__bitmap_or);
  185. void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
  186. const unsigned long *bitmap2, unsigned int bits)
  187. {
  188. unsigned int k;
  189. unsigned int nr = BITS_TO_LONGS(bits);
  190. for (k = 0; k < nr; k++)
  191. dst[k] = bitmap1[k] ^ bitmap2[k];
  192. }
  193. EXPORT_SYMBOL(__bitmap_xor);
  194. int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
  195. const unsigned long *bitmap2, unsigned int bits)
  196. {
  197. unsigned int k;
  198. unsigned int nr = BITS_TO_LONGS(bits);
  199. unsigned long result = 0;
  200. for (k = 0; k < nr; k++)
  201. result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
  202. return result != 0;
  203. }
  204. EXPORT_SYMBOL(__bitmap_andnot);
  205. int __bitmap_intersects(const unsigned long *bitmap1,
  206. const unsigned long *bitmap2, unsigned int bits)
  207. {
  208. unsigned int k, lim = bits/BITS_PER_LONG;
  209. for (k = 0; k < lim; ++k)
  210. if (bitmap1[k] & bitmap2[k])
  211. return 1;
  212. if (bits % BITS_PER_LONG)
  213. if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
  214. return 1;
  215. return 0;
  216. }
  217. EXPORT_SYMBOL(__bitmap_intersects);
  218. int __bitmap_subset(const unsigned long *bitmap1,
  219. const unsigned long *bitmap2, unsigned int bits)
  220. {
  221. unsigned int k, lim = bits/BITS_PER_LONG;
  222. for (k = 0; k < lim; ++k)
  223. if (bitmap1[k] & ~bitmap2[k])
  224. return 0;
  225. if (bits % BITS_PER_LONG)
  226. if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
  227. return 0;
  228. return 1;
  229. }
  230. EXPORT_SYMBOL(__bitmap_subset);
  231. int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
  232. {
  233. unsigned int k, lim = bits/BITS_PER_LONG;
  234. int w = 0;
  235. for (k = 0; k < lim; k++)
  236. w += hweight_long(bitmap[k]);
  237. if (bits % BITS_PER_LONG)
  238. w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
  239. return w;
  240. }
  241. EXPORT_SYMBOL(__bitmap_weight);
  242. void bitmap_set(unsigned long *map, unsigned int start, int len)
  243. {
  244. unsigned long *p = map + BIT_WORD(start);
  245. const unsigned int size = start + len;
  246. int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
  247. unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
  248. while (len - bits_to_set >= 0) {
  249. *p |= mask_to_set;
  250. len -= bits_to_set;
  251. bits_to_set = BITS_PER_LONG;
  252. mask_to_set = ~0UL;
  253. p++;
  254. }
  255. if (len) {
  256. mask_to_set &= BITMAP_LAST_WORD_MASK(size);
  257. *p |= mask_to_set;
  258. }
  259. }
  260. EXPORT_SYMBOL(bitmap_set);
  261. void bitmap_clear(unsigned long *map, unsigned int start, int len)
  262. {
  263. unsigned long *p = map + BIT_WORD(start);
  264. const unsigned int size = start + len;
  265. int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
  266. unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
  267. while (len - bits_to_clear >= 0) {
  268. *p &= ~mask_to_clear;
  269. len -= bits_to_clear;
  270. bits_to_clear = BITS_PER_LONG;
  271. mask_to_clear = ~0UL;
  272. p++;
  273. }
  274. if (len) {
  275. mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
  276. *p &= ~mask_to_clear;
  277. }
  278. }
  279. EXPORT_SYMBOL(bitmap_clear);
  280. /*
  281. * bitmap_find_next_zero_area - find a contiguous aligned zero area
  282. * @map: The address to base the search on
  283. * @size: The bitmap size in bits
  284. * @start: The bitnumber to start searching at
  285. * @nr: The number of zeroed bits we're looking for
  286. * @align_mask: Alignment mask for zero area
  287. *
  288. * The @align_mask should be one less than a power of 2; the effect is that
  289. * the bit offset of all zero areas this function finds is multiples of that
  290. * power of 2. A @align_mask of 0 means no alignment is required.
  291. */
  292. unsigned long bitmap_find_next_zero_area(unsigned long *map,
  293. unsigned long size,
  294. unsigned long start,
  295. unsigned int nr,
  296. unsigned long align_mask)
  297. {
  298. unsigned long index, end, i;
  299. again:
  300. index = find_next_zero_bit(map, size, start);
  301. /* Align allocation */
  302. index = __ALIGN_MASK(index, align_mask);
  303. end = index + nr;
  304. if (end > size)
  305. return end;
  306. i = find_next_bit(map, end, index);
  307. if (i < end) {
  308. start = i + 1;
  309. goto again;
  310. }
  311. return index;
  312. }
  313. EXPORT_SYMBOL(bitmap_find_next_zero_area);
  314. /*
  315. * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers,
  316. * second version by Paul Jackson, third by Joe Korty.
  317. */
  318. #define CHUNKSZ 32
  319. #define nbits_to_hold_value(val) fls(val)
  320. #define BASEDEC 10 /* fancier cpuset lists input in decimal */
  321. /**
  322. * bitmap_scnprintf - convert bitmap to an ASCII hex string.
  323. * @buf: byte buffer into which string is placed
  324. * @buflen: reserved size of @buf, in bytes
  325. * @maskp: pointer to bitmap to convert
  326. * @nmaskbits: size of bitmap, in bits
  327. *
  328. * Exactly @nmaskbits bits are displayed. Hex digits are grouped into
  329. * comma-separated sets of eight digits per set. Returns the number of
  330. * characters which were written to *buf, excluding the trailing \0.
  331. */
  332. int bitmap_scnprintf(char *buf, unsigned int buflen,
  333. const unsigned long *maskp, int nmaskbits)
  334. {
  335. int i, word, bit, len = 0;
  336. unsigned long val;
  337. const char *sep = "";
  338. int chunksz;
  339. u32 chunkmask;
  340. chunksz = nmaskbits & (CHUNKSZ - 1);
  341. if (chunksz == 0)
  342. chunksz = CHUNKSZ;
  343. i = ALIGN(nmaskbits, CHUNKSZ) - CHUNKSZ;
  344. for (; i >= 0; i -= CHUNKSZ) {
  345. chunkmask = ((1ULL << chunksz) - 1);
  346. word = i / BITS_PER_LONG;
  347. bit = i % BITS_PER_LONG;
  348. val = (maskp[word] >> bit) & chunkmask;
  349. len += scnprintf(buf+len, buflen-len, "%s%0*lx", sep,
  350. (chunksz+3)/4, val);
  351. chunksz = CHUNKSZ;
  352. sep = ",";
  353. }
  354. return len;
  355. }
  356. EXPORT_SYMBOL(bitmap_scnprintf);
  357. /**
  358. * __bitmap_parse - convert an ASCII hex string into a bitmap.
  359. * @buf: pointer to buffer containing string.
  360. * @buflen: buffer size in bytes. If string is smaller than this
  361. * then it must be terminated with a \0.
  362. * @is_user: location of buffer, 0 indicates kernel space
  363. * @maskp: pointer to bitmap array that will contain result.
  364. * @nmaskbits: size of bitmap, in bits.
  365. *
  366. * Commas group hex digits into chunks. Each chunk defines exactly 32
  367. * bits of the resultant bitmask. No chunk may specify a value larger
  368. * than 32 bits (%-EOVERFLOW), and if a chunk specifies a smaller value
  369. * then leading 0-bits are prepended. %-EINVAL is returned for illegal
  370. * characters and for grouping errors such as "1,,5", ",44", "," and "".
  371. * Leading and trailing whitespace accepted, but not embedded whitespace.
  372. */
  373. int __bitmap_parse(const char *buf, unsigned int buflen,
  374. int is_user, unsigned long *maskp,
  375. int nmaskbits)
  376. {
  377. int c, old_c, totaldigits, ndigits, nchunks, nbits;
  378. u32 chunk;
  379. const char __user __force *ubuf = (const char __user __force *)buf;
  380. bitmap_zero(maskp, nmaskbits);
  381. nchunks = nbits = totaldigits = c = 0;
  382. do {
  383. chunk = ndigits = 0;
  384. /* Get the next chunk of the bitmap */
  385. while (buflen) {
  386. old_c = c;
  387. if (is_user) {
  388. if (__get_user(c, ubuf++))
  389. return -EFAULT;
  390. }
  391. else
  392. c = *buf++;
  393. buflen--;
  394. if (isspace(c))
  395. continue;
  396. /*
  397. * If the last character was a space and the current
  398. * character isn't '\0', we've got embedded whitespace.
  399. * This is a no-no, so throw an error.
  400. */
  401. if (totaldigits && c && isspace(old_c))
  402. return -EINVAL;
  403. /* A '\0' or a ',' signal the end of the chunk */
  404. if (c == '\0' || c == ',')
  405. break;
  406. if (!isxdigit(c))
  407. return -EINVAL;
  408. /*
  409. * Make sure there are at least 4 free bits in 'chunk'.
  410. * If not, this hexdigit will overflow 'chunk', so
  411. * throw an error.
  412. */
  413. if (chunk & ~((1UL << (CHUNKSZ - 4)) - 1))
  414. return -EOVERFLOW;
  415. chunk = (chunk << 4) | hex_to_bin(c);
  416. ndigits++; totaldigits++;
  417. }
  418. if (ndigits == 0)
  419. return -EINVAL;
  420. if (nchunks == 0 && chunk == 0)
  421. continue;
  422. __bitmap_shift_left(maskp, maskp, CHUNKSZ, nmaskbits);
  423. *maskp |= chunk;
  424. nchunks++;
  425. nbits += (nchunks == 1) ? nbits_to_hold_value(chunk) : CHUNKSZ;
  426. if (nbits > nmaskbits)
  427. return -EOVERFLOW;
  428. } while (buflen && c == ',');
  429. return 0;
  430. }
  431. EXPORT_SYMBOL(__bitmap_parse);
  432. /**
  433. * bitmap_parse_user - convert an ASCII hex string in a user buffer into a bitmap
  434. *
  435. * @ubuf: pointer to user buffer containing string.
  436. * @ulen: buffer size in bytes. If string is smaller than this
  437. * then it must be terminated with a \0.
  438. * @maskp: pointer to bitmap array that will contain result.
  439. * @nmaskbits: size of bitmap, in bits.
  440. *
  441. * Wrapper for __bitmap_parse(), providing it with user buffer.
  442. *
  443. * We cannot have this as an inline function in bitmap.h because it needs
  444. * linux/uaccess.h to get the access_ok() declaration and this causes
  445. * cyclic dependencies.
  446. */
  447. int bitmap_parse_user(const char __user *ubuf,
  448. unsigned int ulen, unsigned long *maskp,
  449. int nmaskbits)
  450. {
  451. if (!access_ok(VERIFY_READ, ubuf, ulen))
  452. return -EFAULT;
  453. return __bitmap_parse((const char __force *)ubuf,
  454. ulen, 1, maskp, nmaskbits);
  455. }
  456. EXPORT_SYMBOL(bitmap_parse_user);
  457. /*
  458. * bscnl_emit(buf, buflen, rbot, rtop, bp)
  459. *
  460. * Helper routine for bitmap_scnlistprintf(). Write decimal number
  461. * or range to buf, suppressing output past buf+buflen, with optional
  462. * comma-prefix. Return len of what was written to *buf, excluding the
  463. * trailing \0.
  464. */
  465. static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len)
  466. {
  467. if (len > 0)
  468. len += scnprintf(buf + len, buflen - len, ",");
  469. if (rbot == rtop)
  470. len += scnprintf(buf + len, buflen - len, "%d", rbot);
  471. else
  472. len += scnprintf(buf + len, buflen - len, "%d-%d", rbot, rtop);
  473. return len;
  474. }
  475. /**
  476. * bitmap_scnlistprintf - convert bitmap to list format ASCII string
  477. * @buf: byte buffer into which string is placed
  478. * @buflen: reserved size of @buf, in bytes
  479. * @maskp: pointer to bitmap to convert
  480. * @nmaskbits: size of bitmap, in bits
  481. *
  482. * Output format is a comma-separated list of decimal numbers and
  483. * ranges. Consecutively set bits are shown as two hyphen-separated
  484. * decimal numbers, the smallest and largest bit numbers set in
  485. * the range. Output format is compatible with the format
  486. * accepted as input by bitmap_parselist().
  487. *
  488. * The return value is the number of characters which were written to *buf
  489. * excluding the trailing '\0', as per ISO C99's scnprintf.
  490. */
  491. int bitmap_scnlistprintf(char *buf, unsigned int buflen,
  492. const unsigned long *maskp, int nmaskbits)
  493. {
  494. int len = 0;
  495. /* current bit is 'cur', most recently seen range is [rbot, rtop] */
  496. int cur, rbot, rtop;
  497. if (buflen == 0)
  498. return 0;
  499. buf[0] = 0;
  500. rbot = cur = find_first_bit(maskp, nmaskbits);
  501. while (cur < nmaskbits) {
  502. rtop = cur;
  503. cur = find_next_bit(maskp, nmaskbits, cur+1);
  504. if (cur >= nmaskbits || cur > rtop + 1) {
  505. len = bscnl_emit(buf, buflen, rbot, rtop, len);
  506. rbot = cur;
  507. }
  508. }
  509. return len;
  510. }
  511. EXPORT_SYMBOL(bitmap_scnlistprintf);
  512. /**
  513. * __bitmap_parselist - convert list format ASCII string to bitmap
  514. * @buf: read nul-terminated user string from this buffer
  515. * @buflen: buffer size in bytes. If string is smaller than this
  516. * then it must be terminated with a \0.
  517. * @is_user: location of buffer, 0 indicates kernel space
  518. * @maskp: write resulting mask here
  519. * @nmaskbits: number of bits in mask to be written
  520. *
  521. * Input format is a comma-separated list of decimal numbers and
  522. * ranges. Consecutively set bits are shown as two hyphen-separated
  523. * decimal numbers, the smallest and largest bit numbers set in
  524. * the range.
  525. *
  526. * Returns 0 on success, -errno on invalid input strings.
  527. * Error values:
  528. * %-EINVAL: second number in range smaller than first
  529. * %-EINVAL: invalid character in string
  530. * %-ERANGE: bit number specified too large for mask
  531. */
  532. static int __bitmap_parselist(const char *buf, unsigned int buflen,
  533. int is_user, unsigned long *maskp,
  534. int nmaskbits)
  535. {
  536. unsigned a, b;
  537. int c, old_c, totaldigits;
  538. const char __user __force *ubuf = (const char __user __force *)buf;
  539. int exp_digit, in_range;
  540. totaldigits = c = 0;
  541. bitmap_zero(maskp, nmaskbits);
  542. do {
  543. exp_digit = 1;
  544. in_range = 0;
  545. a = b = 0;
  546. /* Get the next cpu# or a range of cpu#'s */
  547. while (buflen) {
  548. old_c = c;
  549. if (is_user) {
  550. if (__get_user(c, ubuf++))
  551. return -EFAULT;
  552. } else
  553. c = *buf++;
  554. buflen--;
  555. if (isspace(c))
  556. continue;
  557. /*
  558. * If the last character was a space and the current
  559. * character isn't '\0', we've got embedded whitespace.
  560. * This is a no-no, so throw an error.
  561. */
  562. if (totaldigits && c && isspace(old_c))
  563. return -EINVAL;
  564. /* A '\0' or a ',' signal the end of a cpu# or range */
  565. if (c == '\0' || c == ',')
  566. break;
  567. if (c == '-') {
  568. if (exp_digit || in_range)
  569. return -EINVAL;
  570. b = 0;
  571. in_range = 1;
  572. exp_digit = 1;
  573. continue;
  574. }
  575. if (!isdigit(c))
  576. return -EINVAL;
  577. b = b * 10 + (c - '0');
  578. if (!in_range)
  579. a = b;
  580. exp_digit = 0;
  581. totaldigits++;
  582. }
  583. if (!(a <= b))
  584. return -EINVAL;
  585. if (b >= nmaskbits)
  586. return -ERANGE;
  587. while (a <= b) {
  588. set_bit(a, maskp);
  589. a++;
  590. }
  591. } while (buflen && c == ',');
  592. return 0;
  593. }
  594. int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits)
  595. {
  596. char *nl = strchrnul(bp, '\n');
  597. int len = nl - bp;
  598. return __bitmap_parselist(bp, len, 0, maskp, nmaskbits);
  599. }
  600. EXPORT_SYMBOL(bitmap_parselist);
  601. /**
  602. * bitmap_parselist_user()
  603. *
  604. * @ubuf: pointer to user buffer containing string.
  605. * @ulen: buffer size in bytes. If string is smaller than this
  606. * then it must be terminated with a \0.
  607. * @maskp: pointer to bitmap array that will contain result.
  608. * @nmaskbits: size of bitmap, in bits.
  609. *
  610. * Wrapper for bitmap_parselist(), providing it with user buffer.
  611. *
  612. * We cannot have this as an inline function in bitmap.h because it needs
  613. * linux/uaccess.h to get the access_ok() declaration and this causes
  614. * cyclic dependencies.
  615. */
  616. int bitmap_parselist_user(const char __user *ubuf,
  617. unsigned int ulen, unsigned long *maskp,
  618. int nmaskbits)
  619. {
  620. if (!access_ok(VERIFY_READ, ubuf, ulen))
  621. return -EFAULT;
  622. return __bitmap_parselist((const char __force *)ubuf,
  623. ulen, 1, maskp, nmaskbits);
  624. }
  625. EXPORT_SYMBOL(bitmap_parselist_user);
  626. /**
  627. * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap
  628. * @buf: pointer to a bitmap
  629. * @pos: a bit position in @buf (0 <= @pos < @bits)
  630. * @bits: number of valid bit positions in @buf
  631. *
  632. * Map the bit at position @pos in @buf (of length @bits) to the
  633. * ordinal of which set bit it is. If it is not set or if @pos
  634. * is not a valid bit position, map to -1.
  635. *
  636. * If for example, just bits 4 through 7 are set in @buf, then @pos
  637. * values 4 through 7 will get mapped to 0 through 3, respectively,
  638. * and other @pos values will get mapped to -1. When @pos value 7
  639. * gets mapped to (returns) @ord value 3 in this example, that means
  640. * that bit 7 is the 3rd (starting with 0th) set bit in @buf.
  641. *
  642. * The bit positions 0 through @bits are valid positions in @buf.
  643. */
  644. static int bitmap_pos_to_ord(const unsigned long *buf, int pos, int bits)
  645. {
  646. int i, ord;
  647. if (pos < 0 || pos >= bits || !test_bit(pos, buf))
  648. return -1;
  649. i = find_first_bit(buf, bits);
  650. ord = 0;
  651. while (i < pos) {
  652. i = find_next_bit(buf, bits, i + 1);
  653. ord++;
  654. }
  655. BUG_ON(i != pos);
  656. return ord;
  657. }
  658. /**
  659. * bitmap_ord_to_pos - find position of n-th set bit in bitmap
  660. * @buf: pointer to bitmap
  661. * @ord: ordinal bit position (n-th set bit, n >= 0)
  662. * @bits: number of valid bit positions in @buf
  663. *
  664. * Map the ordinal offset of bit @ord in @buf to its position in @buf.
  665. * Value of @ord should be in range 0 <= @ord < weight(buf), else
  666. * results are undefined.
  667. *
  668. * If for example, just bits 4 through 7 are set in @buf, then @ord
  669. * values 0 through 3 will get mapped to 4 through 7, respectively,
  670. * and all other @ord values return undefined values. When @ord value 3
  671. * gets mapped to (returns) @pos value 7 in this example, that means
  672. * that the 3rd set bit (starting with 0th) is at position 7 in @buf.
  673. *
  674. * The bit positions 0 through @bits are valid positions in @buf.
  675. */
  676. int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits)
  677. {
  678. int pos = 0;
  679. if (ord >= 0 && ord < bits) {
  680. int i;
  681. for (i = find_first_bit(buf, bits);
  682. i < bits && ord > 0;
  683. i = find_next_bit(buf, bits, i + 1))
  684. ord--;
  685. if (i < bits && ord == 0)
  686. pos = i;
  687. }
  688. return pos;
  689. }
  690. /**
  691. * bitmap_remap - Apply map defined by a pair of bitmaps to another bitmap
  692. * @dst: remapped result
  693. * @src: subset to be remapped
  694. * @old: defines domain of map
  695. * @new: defines range of map
  696. * @bits: number of bits in each of these bitmaps
  697. *
  698. * Let @old and @new define a mapping of bit positions, such that
  699. * whatever position is held by the n-th set bit in @old is mapped
  700. * to the n-th set bit in @new. In the more general case, allowing
  701. * for the possibility that the weight 'w' of @new is less than the
  702. * weight of @old, map the position of the n-th set bit in @old to
  703. * the position of the m-th set bit in @new, where m == n % w.
  704. *
  705. * If either of the @old and @new bitmaps are empty, or if @src and
  706. * @dst point to the same location, then this routine copies @src
  707. * to @dst.
  708. *
  709. * The positions of unset bits in @old are mapped to themselves
  710. * (the identify map).
  711. *
  712. * Apply the above specified mapping to @src, placing the result in
  713. * @dst, clearing any bits previously set in @dst.
  714. *
  715. * For example, lets say that @old has bits 4 through 7 set, and
  716. * @new has bits 12 through 15 set. This defines the mapping of bit
  717. * position 4 to 12, 5 to 13, 6 to 14 and 7 to 15, and of all other
  718. * bit positions unchanged. So if say @src comes into this routine
  719. * with bits 1, 5 and 7 set, then @dst should leave with bits 1,
  720. * 13 and 15 set.
  721. */
  722. void bitmap_remap(unsigned long *dst, const unsigned long *src,
  723. const unsigned long *old, const unsigned long *new,
  724. int bits)
  725. {
  726. int oldbit, w;
  727. if (dst == src) /* following doesn't handle inplace remaps */
  728. return;
  729. bitmap_zero(dst, bits);
  730. w = bitmap_weight(new, bits);
  731. for_each_set_bit(oldbit, src, bits) {
  732. int n = bitmap_pos_to_ord(old, oldbit, bits);
  733. if (n < 0 || w == 0)
  734. set_bit(oldbit, dst); /* identity map */
  735. else
  736. set_bit(bitmap_ord_to_pos(new, n % w, bits), dst);
  737. }
  738. }
  739. EXPORT_SYMBOL(bitmap_remap);
  740. /**
  741. * bitmap_bitremap - Apply map defined by a pair of bitmaps to a single bit
  742. * @oldbit: bit position to be mapped
  743. * @old: defines domain of map
  744. * @new: defines range of map
  745. * @bits: number of bits in each of these bitmaps
  746. *
  747. * Let @old and @new define a mapping of bit positions, such that
  748. * whatever position is held by the n-th set bit in @old is mapped
  749. * to the n-th set bit in @new. In the more general case, allowing
  750. * for the possibility that the weight 'w' of @new is less than the
  751. * weight of @old, map the position of the n-th set bit in @old to
  752. * the position of the m-th set bit in @new, where m == n % w.
  753. *
  754. * The positions of unset bits in @old are mapped to themselves
  755. * (the identify map).
  756. *
  757. * Apply the above specified mapping to bit position @oldbit, returning
  758. * the new bit position.
  759. *
  760. * For example, lets say that @old has bits 4 through 7 set, and
  761. * @new has bits 12 through 15 set. This defines the mapping of bit
  762. * position 4 to 12, 5 to 13, 6 to 14 and 7 to 15, and of all other
  763. * bit positions unchanged. So if say @oldbit is 5, then this routine
  764. * returns 13.
  765. */
  766. int bitmap_bitremap(int oldbit, const unsigned long *old,
  767. const unsigned long *new, int bits)
  768. {
  769. int w = bitmap_weight(new, bits);
  770. int n = bitmap_pos_to_ord(old, oldbit, bits);
  771. if (n < 0 || w == 0)
  772. return oldbit;
  773. else
  774. return bitmap_ord_to_pos(new, n % w, bits);
  775. }
  776. EXPORT_SYMBOL(bitmap_bitremap);
  777. /**
  778. * bitmap_onto - translate one bitmap relative to another
  779. * @dst: resulting translated bitmap
  780. * @orig: original untranslated bitmap
  781. * @relmap: bitmap relative to which translated
  782. * @bits: number of bits in each of these bitmaps
  783. *
  784. * Set the n-th bit of @dst iff there exists some m such that the
  785. * n-th bit of @relmap is set, the m-th bit of @orig is set, and
  786. * the n-th bit of @relmap is also the m-th _set_ bit of @relmap.
  787. * (If you understood the previous sentence the first time your
  788. * read it, you're overqualified for your current job.)
  789. *
  790. * In other words, @orig is mapped onto (surjectively) @dst,
  791. * using the the map { <n, m> | the n-th bit of @relmap is the
  792. * m-th set bit of @relmap }.
  793. *
  794. * Any set bits in @orig above bit number W, where W is the
  795. * weight of (number of set bits in) @relmap are mapped nowhere.
  796. * In particular, if for all bits m set in @orig, m >= W, then
  797. * @dst will end up empty. In situations where the possibility
  798. * of such an empty result is not desired, one way to avoid it is
  799. * to use the bitmap_fold() operator, below, to first fold the
  800. * @orig bitmap over itself so that all its set bits x are in the
  801. * range 0 <= x < W. The bitmap_fold() operator does this by
  802. * setting the bit (m % W) in @dst, for each bit (m) set in @orig.
  803. *
  804. * Example [1] for bitmap_onto():
  805. * Let's say @relmap has bits 30-39 set, and @orig has bits
  806. * 1, 3, 5, 7, 9 and 11 set. Then on return from this routine,
  807. * @dst will have bits 31, 33, 35, 37 and 39 set.
  808. *
  809. * When bit 0 is set in @orig, it means turn on the bit in
  810. * @dst corresponding to whatever is the first bit (if any)
  811. * that is turned on in @relmap. Since bit 0 was off in the
  812. * above example, we leave off that bit (bit 30) in @dst.
  813. *
  814. * When bit 1 is set in @orig (as in the above example), it
  815. * means turn on the bit in @dst corresponding to whatever
  816. * is the second bit that is turned on in @relmap. The second
  817. * bit in @relmap that was turned on in the above example was
  818. * bit 31, so we turned on bit 31 in @dst.
  819. *
  820. * Similarly, we turned on bits 33, 35, 37 and 39 in @dst,
  821. * because they were the 4th, 6th, 8th and 10th set bits
  822. * set in @relmap, and the 4th, 6th, 8th and 10th bits of
  823. * @orig (i.e. bits 3, 5, 7 and 9) were also set.
  824. *
  825. * When bit 11 is set in @orig, it means turn on the bit in
  826. * @dst corresponding to whatever is the twelfth bit that is
  827. * turned on in @relmap. In the above example, there were
  828. * only ten bits turned on in @relmap (30..39), so that bit
  829. * 11 was set in @orig had no affect on @dst.
  830. *
  831. * Example [2] for bitmap_fold() + bitmap_onto():
  832. * Let's say @relmap has these ten bits set:
  833. * 40 41 42 43 45 48 53 61 74 95
  834. * (for the curious, that's 40 plus the first ten terms of the
  835. * Fibonacci sequence.)
  836. *
  837. * Further lets say we use the following code, invoking
  838. * bitmap_fold() then bitmap_onto, as suggested above to
  839. * avoid the possitility of an empty @dst result:
  840. *
  841. * unsigned long *tmp; // a temporary bitmap's bits
  842. *
  843. * bitmap_fold(tmp, orig, bitmap_weight(relmap, bits), bits);
  844. * bitmap_onto(dst, tmp, relmap, bits);
  845. *
  846. * Then this table shows what various values of @dst would be, for
  847. * various @orig's. I list the zero-based positions of each set bit.
  848. * The tmp column shows the intermediate result, as computed by
  849. * using bitmap_fold() to fold the @orig bitmap modulo ten
  850. * (the weight of @relmap).
  851. *
  852. * @orig tmp @dst
  853. * 0 0 40
  854. * 1 1 41
  855. * 9 9 95
  856. * 10 0 40 (*)
  857. * 1 3 5 7 1 3 5 7 41 43 48 61
  858. * 0 1 2 3 4 0 1 2 3 4 40 41 42 43 45
  859. * 0 9 18 27 0 9 8 7 40 61 74 95
  860. * 0 10 20 30 0 40
  861. * 0 11 22 33 0 1 2 3 40 41 42 43
  862. * 0 12 24 36 0 2 4 6 40 42 45 53
  863. * 78 102 211 1 2 8 41 42 74 (*)
  864. *
  865. * (*) For these marked lines, if we hadn't first done bitmap_fold()
  866. * into tmp, then the @dst result would have been empty.
  867. *
  868. * If either of @orig or @relmap is empty (no set bits), then @dst
  869. * will be returned empty.
  870. *
  871. * If (as explained above) the only set bits in @orig are in positions
  872. * m where m >= W, (where W is the weight of @relmap) then @dst will
  873. * once again be returned empty.
  874. *
  875. * All bits in @dst not set by the above rule are cleared.
  876. */
  877. void bitmap_onto(unsigned long *dst, const unsigned long *orig,
  878. const unsigned long *relmap, int bits)
  879. {
  880. int n, m; /* same meaning as in above comment */
  881. if (dst == orig) /* following doesn't handle inplace mappings */
  882. return;
  883. bitmap_zero(dst, bits);
  884. /*
  885. * The following code is a more efficient, but less
  886. * obvious, equivalent to the loop:
  887. * for (m = 0; m < bitmap_weight(relmap, bits); m++) {
  888. * n = bitmap_ord_to_pos(orig, m, bits);
  889. * if (test_bit(m, orig))
  890. * set_bit(n, dst);
  891. * }
  892. */
  893. m = 0;
  894. for_each_set_bit(n, relmap, bits) {
  895. /* m == bitmap_pos_to_ord(relmap, n, bits) */
  896. if (test_bit(m, orig))
  897. set_bit(n, dst);
  898. m++;
  899. }
  900. }
  901. EXPORT_SYMBOL(bitmap_onto);
  902. /**
  903. * bitmap_fold - fold larger bitmap into smaller, modulo specified size
  904. * @dst: resulting smaller bitmap
  905. * @orig: original larger bitmap
  906. * @sz: specified size
  907. * @bits: number of bits in each of these bitmaps
  908. *
  909. * For each bit oldbit in @orig, set bit oldbit mod @sz in @dst.
  910. * Clear all other bits in @dst. See further the comment and
  911. * Example [2] for bitmap_onto() for why and how to use this.
  912. */
  913. void bitmap_fold(unsigned long *dst, const unsigned long *orig,
  914. int sz, int bits)
  915. {
  916. int oldbit;
  917. if (dst == orig) /* following doesn't handle inplace mappings */
  918. return;
  919. bitmap_zero(dst, bits);
  920. for_each_set_bit(oldbit, orig, bits)
  921. set_bit(oldbit % sz, dst);
  922. }
  923. EXPORT_SYMBOL(bitmap_fold);
  924. /*
  925. * Common code for bitmap_*_region() routines.
  926. * bitmap: array of unsigned longs corresponding to the bitmap
  927. * pos: the beginning of the region
  928. * order: region size (log base 2 of number of bits)
  929. * reg_op: operation(s) to perform on that region of bitmap
  930. *
  931. * Can set, verify and/or release a region of bits in a bitmap,
  932. * depending on which combination of REG_OP_* flag bits is set.
  933. *
  934. * A region of a bitmap is a sequence of bits in the bitmap, of
  935. * some size '1 << order' (a power of two), aligned to that same
  936. * '1 << order' power of two.
  937. *
  938. * Returns 1 if REG_OP_ISFREE succeeds (region is all zero bits).
  939. * Returns 0 in all other cases and reg_ops.
  940. */
  941. enum {
  942. REG_OP_ISFREE, /* true if region is all zero bits */
  943. REG_OP_ALLOC, /* set all bits in region */
  944. REG_OP_RELEASE, /* clear all bits in region */
  945. };
  946. static int __reg_op(unsigned long *bitmap, unsigned int pos, int order, int reg_op)
  947. {
  948. int nbits_reg; /* number of bits in region */
  949. int index; /* index first long of region in bitmap */
  950. int offset; /* bit offset region in bitmap[index] */
  951. int nlongs_reg; /* num longs spanned by region in bitmap */
  952. int nbitsinlong; /* num bits of region in each spanned long */
  953. unsigned long mask; /* bitmask for one long of region */
  954. int i; /* scans bitmap by longs */
  955. int ret = 0; /* return value */
  956. /*
  957. * Either nlongs_reg == 1 (for small orders that fit in one long)
  958. * or (offset == 0 && mask == ~0UL) (for larger multiword orders.)
  959. */
  960. nbits_reg = 1 << order;
  961. index = pos / BITS_PER_LONG;
  962. offset = pos - (index * BITS_PER_LONG);
  963. nlongs_reg = BITS_TO_LONGS(nbits_reg);
  964. nbitsinlong = min(nbits_reg, BITS_PER_LONG);
  965. /*
  966. * Can't do "mask = (1UL << nbitsinlong) - 1", as that
  967. * overflows if nbitsinlong == BITS_PER_LONG.
  968. */
  969. mask = (1UL << (nbitsinlong - 1));
  970. mask += mask - 1;
  971. mask <<= offset;
  972. switch (reg_op) {
  973. case REG_OP_ISFREE:
  974. for (i = 0; i < nlongs_reg; i++) {
  975. if (bitmap[index + i] & mask)
  976. goto done;
  977. }
  978. ret = 1; /* all bits in region free (zero) */
  979. break;
  980. case REG_OP_ALLOC:
  981. for (i = 0; i < nlongs_reg; i++)
  982. bitmap[index + i] |= mask;
  983. break;
  984. case REG_OP_RELEASE:
  985. for (i = 0; i < nlongs_reg; i++)
  986. bitmap[index + i] &= ~mask;
  987. break;
  988. }
  989. done:
  990. return ret;
  991. }
  992. /**
  993. * bitmap_find_free_region - find a contiguous aligned mem region
  994. * @bitmap: array of unsigned longs corresponding to the bitmap
  995. * @bits: number of bits in the bitmap
  996. * @order: region size (log base 2 of number of bits) to find
  997. *
  998. * Find a region of free (zero) bits in a @bitmap of @bits bits and
  999. * allocate them (set them to one). Only consider regions of length
  1000. * a power (@order) of two, aligned to that power of two, which
  1001. * makes the search algorithm much faster.
  1002. *
  1003. * Return the bit offset in bitmap of the allocated region,
  1004. * or -errno on failure.
  1005. */
  1006. int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order)
  1007. {
  1008. unsigned int pos, end; /* scans bitmap by regions of size order */
  1009. for (pos = 0 ; (end = pos + (1U << order)) <= bits; pos = end) {
  1010. if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
  1011. continue;
  1012. __reg_op(bitmap, pos, order, REG_OP_ALLOC);
  1013. return pos;
  1014. }
  1015. return -ENOMEM;
  1016. }
  1017. EXPORT_SYMBOL(bitmap_find_free_region);
  1018. /**
  1019. * bitmap_release_region - release allocated bitmap region
  1020. * @bitmap: array of unsigned longs corresponding to the bitmap
  1021. * @pos: beginning of bit region to release
  1022. * @order: region size (log base 2 of number of bits) to release
  1023. *
  1024. * This is the complement to __bitmap_find_free_region() and releases
  1025. * the found region (by clearing it in the bitmap).
  1026. *
  1027. * No return value.
  1028. */
  1029. void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order)
  1030. {
  1031. __reg_op(bitmap, pos, order, REG_OP_RELEASE);
  1032. }
  1033. EXPORT_SYMBOL(bitmap_release_region);
  1034. /**
  1035. * bitmap_allocate_region - allocate bitmap region
  1036. * @bitmap: array of unsigned longs corresponding to the bitmap
  1037. * @pos: beginning of bit region to allocate
  1038. * @order: region size (log base 2 of number of bits) to allocate
  1039. *
  1040. * Allocate (set bits in) a specified region of a bitmap.
  1041. *
  1042. * Return 0 on success, or %-EBUSY if specified region wasn't
  1043. * free (not all bits were zero).
  1044. */
  1045. int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order)
  1046. {
  1047. if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
  1048. return -EBUSY;
  1049. return __reg_op(bitmap, pos, order, REG_OP_ALLOC);
  1050. }
  1051. EXPORT_SYMBOL(bitmap_allocate_region);
  1052. /**
  1053. * bitmap_copy_le - copy a bitmap, putting the bits into little-endian order.
  1054. * @dst: destination buffer
  1055. * @src: bitmap to copy
  1056. * @nbits: number of bits in the bitmap
  1057. *
  1058. * Require nbits % BITS_PER_LONG == 0.
  1059. */
  1060. void bitmap_copy_le(void *dst, const unsigned long *src, int nbits)
  1061. {
  1062. unsigned long *d = dst;
  1063. int i;
  1064. for (i = 0; i < nbits/BITS_PER_LONG; i++) {
  1065. if (BITS_PER_LONG == 64)
  1066. d[i] = cpu_to_le64(src[i]);
  1067. else
  1068. d[i] = cpu_to_le32(src[i]);
  1069. }
  1070. }
  1071. EXPORT_SYMBOL(bitmap_copy_le);