cpumask.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/cpumask.h>
  15. #include <linux/ctype.h>
  16. #include <linux/errno.h>
  17. #include <linux/smp.h>
  18. #include <linux/export.h>
  19. /*
  20. * Allow cropping out bits beyond the end of the array.
  21. * Move to "lib" directory if more clients want to use this routine.
  22. */
  23. int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits)
  24. {
  25. unsigned a, b;
  26. bitmap_zero(maskp, nmaskbits);
  27. do {
  28. if (!isdigit(*bp))
  29. return -EINVAL;
  30. a = simple_strtoul(bp, (char **)&bp, 10);
  31. b = a;
  32. if (*bp == '-') {
  33. bp++;
  34. if (!isdigit(*bp))
  35. return -EINVAL;
  36. b = simple_strtoul(bp, (char **)&bp, 10);
  37. }
  38. if (!(a <= b))
  39. return -EINVAL;
  40. if (b >= nmaskbits)
  41. b = nmaskbits-1;
  42. while (a <= b) {
  43. set_bit(a, maskp);
  44. a++;
  45. }
  46. if (*bp == ',')
  47. bp++;
  48. } while (*bp != '\0' && *bp != '\n');
  49. return 0;
  50. }
  51. EXPORT_SYMBOL(bitmap_parselist_crop);