cpumask.c 1.3 KB

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