bitmap.c 35 KB

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