/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314#include <linux/cpumask.h>15#include <linux/ctype.h>16#include <linux/errno.h>17#include <linux/smp.h>1819/*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*/23int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits)24{25unsigned a, b;2627bitmap_zero(maskp, nmaskbits);28do {29if (!isdigit(*bp))30return -EINVAL;31a = simple_strtoul(bp, (char **)&bp, 10);32b = a;33if (*bp == '-') {34bp++;35if (!isdigit(*bp))36return -EINVAL;37b = simple_strtoul(bp, (char **)&bp, 10);38}39if (!(a <= b))40return -EINVAL;41if (b >= nmaskbits)42b = nmaskbits-1;43while (a <= b) {44set_bit(a, maskp);45a++;46}47if (*bp == ',')48bp++;49} while (*bp != '\0' && *bp != '\n');50return 0;51}525354