diff options
Diffstat (limited to 'tools/perf/util/intlist.c')
| -rw-r--r-- | tools/perf/util/intlist.c | 36 | 
1 files changed, 33 insertions, 3 deletions
diff --git a/tools/perf/util/intlist.c b/tools/perf/util/intlist.c index 9d0740024ba..11a8d86f7fe 100644 --- a/tools/perf/util/intlist.c +++ b/tools/perf/util/intlist.c @@ -59,16 +59,40 @@ void intlist__remove(struct intlist *ilist, struct int_node *node)  struct int_node *intlist__find(struct intlist *ilist, int i)  { -	struct int_node *node = NULL; -	struct rb_node *rb_node = rblist__find(&ilist->rblist, (void *)((long)i)); +	struct int_node *node; +	struct rb_node *rb_node; + +	if (ilist == NULL) +		return NULL; +	node = NULL; +	rb_node = rblist__find(&ilist->rblist, (void *)((long)i));  	if (rb_node)  		node = container_of(rb_node, struct int_node, rb_node);  	return node;  } -struct intlist *intlist__new(void) +static int intlist__parse_list(struct intlist *ilist, const char *s) +{ +	char *sep; +	int err; + +	do { +		long value = strtol(s, &sep, 10); +		err = -EINVAL; +		if (*sep != ',' && *sep != '\0') +			break; +		err = intlist__add(ilist, value); +		if (err) +			break; +		s = sep + 1; +	} while (*sep != '\0'); + +	return err; +} + +struct intlist *intlist__new(const char *slist)  {  	struct intlist *ilist = malloc(sizeof(*ilist)); @@ -77,9 +101,15 @@ struct intlist *intlist__new(void)  		ilist->rblist.node_cmp    = intlist__node_cmp;  		ilist->rblist.node_new    = intlist__node_new;  		ilist->rblist.node_delete = intlist__node_delete; + +		if (slist && intlist__parse_list(ilist, slist)) +			goto out_delete;  	}  	return ilist; +out_delete: +	intlist__delete(ilist); +	return NULL;  }  void intlist__delete(struct intlist *ilist)  |