cpumask.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /*
  19. * Allow cropping out bits beyond the end of the array.
  20. * Move to "lib" directory if more clients want to use this routine.
  21. */
  22. int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits)
  23. {
  24. unsigned a, b;
  25. bitmap_zero(maskp, nmaskbits);
  26. do {
  27. if (!isdigit(*bp))
  28. return -EINVAL;
  29. a = simple_strtoul(bp, (char **)&bp, 10);
  30. b = a;
  31. if (*bp == '-') {
  32. bp++;
  33. if (!isdigit(*bp))
  34. return -EINVAL;
  35. b = simple_strtoul(bp, (char **)&bp, 10);
  36. }
  37. if (!(a <= b))
  38. return -EINVAL;
  39. if (b >= nmaskbits)
  40. b = nmaskbits-1;
  41. while (a <= b) {
  42. set_bit(a, maskp);
  43. a++;
  44. }
  45. if (*bp == ',')
  46. bp++;
  47. } while (*bp != '\0' && *bp != '\n');
  48. return 0;
  49. }