Skip to contentSkip to conversation

Fill in lacking parts and Refactor several parts

PATCH New Taeung Song 2 participants 8 messages Feb 1, 2017 – Feb 10, 2017 perf events

lore
Share & tools
lore
#0 lore raw

v3 cover Fill in lacking parts and Refactor several parts

v3:
- Split a patch in accordance with "no functional changes" or "change logic" (Arnaldo)
- Change the title of commit message (Arnaldo)

v2:
- Check the return of perf_config() and warn the user with config error message (Arnaldo)
- Change commit messages (Jiri)
- Add only one macro instead of two macros (Jiri)

Taeung Song (4):
perf tools: Only increase index if perf_evsel__new_idx() succeeds perf tools: Fill in a lacking part no checking NULL after zalloc() in
parse-events.c
perf tools: Use zfree() instead of free() and assigning NULL to the
pointer
perf tools: Use zfree() to be more safe in parse-events.c

 tools/perf/util/parse-events.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/4 perf tools: Only increase index if perf_evsel__new_idx() succeeds

Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/parse-events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.c +2 -1
index 3c876b8..5d90fe7 100644
@@ -310,10 +310,11 @@ __add_event(struct list_head *list, int *idx,
 
 	event_attr_init(attr);
 
-	evsel = perf_evsel__new_idx(attr, (*idx)++);
+	evsel = perf_evsel__new_idx(attr, *idx);
 	if (!evsel)
 		return NULL;
 
+	(*idx)++;
 	evsel->cpus     = cpu_map__get(cpus);
 	evsel->own_cpus = cpu_map__get(cpus);
 
Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/core] perf tools: Only increase index if perf_evsel__new_idx() succeeds

perf tools: Only increase index if perf_evsel__new_idx() succeeds
Commit-ID:  75fc5ae5cc53fff71041ecadeb3354a2b4c9fe42
Gitweb:     http://git.kernel.org/tip/75fc5ae5cc53fff71041ecadeb3354a2b4c9fe42
Author:     Taeung Song <[email protected]>
AuthorDate: Wed, 1 Feb 2017 21:34:04 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 8 Feb 2017 09:41:10 -0300

perf tools: Only increase index if perf_evsel__new_idx() succeeds

---
 tools/perf/util/parse-events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.c +2 -1
index 6dbcba7..2720600 100644
@@ -310,10 +310,11 @@ __add_event(struct list_head *list, int *idx,
 
 	event_attr_init(attr);
 
-	evsel = perf_evsel__new_idx(attr, (*idx)++);
+	evsel = perf_evsel__new_idx(attr, *idx);
 	if (!evsel)
 		return NULL;
 
+	(*idx)++;
 	evsel->cpus     = cpu_map__get(cpus);
 	evsel->own_cpus = cpu_map__get(cpus);
 
#3 lore raw

PATCH v3 2/4 perf tools: Fill in a lacking part no checking NULL after zalloc() in parse-events.c

In reply to Taeung Song
---
 tools/perf/util/parse-events.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/parse-events.c +2 -0
index 5d90fe7..0c3b81a 100644
@@ -211,6 +211,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 				closedir(evt_dir);
 				closedir(sys_dir);
 				path = zalloc(sizeof(*path));
+				if (!path)
+					return NULL;
 				path->system = malloc(MAX_EVENT_LENGTH);
 				if (!path->system) {
 					free(path);
Signature · 1 line
2.7.4
#4 lore raw

[tip:perf/core] perf tools: Add missing check for failure in a zalloc() call

perf tools: Add missing check for failure in a zalloc() call
Commit-ID:  5aa365f29867eb739cde0713f00c7d80f36e0739
Gitweb:     http://git.kernel.org/tip/5aa365f29867eb739cde0713f00c7d80f36e0739
Author:     Taeung Song <[email protected]>
AuthorDate: Wed, 1 Feb 2017 21:34:05 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 8 Feb 2017 09:41:11 -0300

perf tools: Add missing check for failure in a zalloc() call

---
 tools/perf/util/parse-events.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/parse-events.c +2 -0
index 2720600..1f1f77d 100644
@@ -211,6 +211,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 				closedir(evt_dir);
 				closedir(sys_dir);
 				path = zalloc(sizeof(*path));
+				if (!path)
+					return NULL;
 				path->system = malloc(MAX_EVENT_LENGTH);
 				if (!path->system) {
 					free(path);
#5 lore raw

PATCH v3 3/4 perf tools: Use zfree() instead of free() and assigning NULL to the pointer

In reply to Taeung Song
---
 tools/perf/util/parse-events.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +2 -4
index 0c3b81a..316f054 100644
@@ -254,8 +254,7 @@ struct tracepoint_path *tracepoint_name_to_path(const char *name)
 	if (path->system == NULL || path->name == NULL) {
 		zfree(&path->system);
 		zfree(&path->name);
-		free(path);
-		path = NULL;
+		zfree(&path);
 	}
 
 	return path;
@@ -1482,8 +1481,7 @@ static void perf_pmu__parse_cleanup(void)
 			p = perf_pmu_events_list + i;
 			free(p->symbol);
 		}
-		free(perf_pmu_events_list);
-		perf_pmu_events_list = NULL;
+		zfree(&perf_pmu_events_list);
 		perf_pmu_events_list_num = 0;
 	}
 }
Signature · 1 line
2.7.4
#6 lore raw

[tip:perf/core] perf tools: Use zfree() instead of ad hoc equivalent

perf tools: Use zfree() instead of ad hoc equivalent
Commit-ID:  506fde11a35f39e1b44478339c41e94dfd278aa2
Gitweb:     http://git.kernel.org/tip/506fde11a35f39e1b44478339c41e94dfd278aa2
Author:     Taeung Song <[email protected]>
AuthorDate: Wed, 1 Feb 2017 21:34:06 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 8 Feb 2017 09:41:11 -0300

perf tools: Use zfree() instead of ad hoc equivalent

We have zfree(&ptr) for this very common pattern:

   free(ptr);
   ptr = NULL;

So use it in a few more places.

---
 tools/perf/util/parse-events.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +2 -4
index 1f1f77d..ab1ba22 100644
@@ -254,8 +254,7 @@ struct tracepoint_path *tracepoint_name_to_path(const char *name)
 	if (path->system == NULL || path->name == NULL) {
 		zfree(&path->system);
 		zfree(&path->name);
-		free(path);
-		path = NULL;
+		zfree(&path);
 	}
 
 	return path;
@@ -1482,8 +1481,7 @@ static void perf_pmu__parse_cleanup(void)
 			p = perf_pmu_events_list + i;
 			free(p->symbol);
 		}
-		free(perf_pmu_events_list);
-		perf_pmu_events_list = NULL;
+		zfree(&perf_pmu_events_list);
 		perf_pmu_events_list_num = 0;
 	}
 }
#7 lore raw

PATCH v3 4/4 perf tools: Use zfree() to be more safe in parse-events.c

In reply to Taeung Song
---
 tools/perf/util/parse-events.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/parse-events.c +6 -6
index 316f054..ac47c12 100644
@@ -1479,7 +1479,7 @@ static void perf_pmu__parse_cleanup(void)
 
 		for (i = 0; i < perf_pmu_events_list_num; i++) {
 			p = perf_pmu_events_list + i;
-			free(p->symbol);
+			zfree(&p->symbol);
 		}
 		zfree(&perf_pmu_events_list);
 		perf_pmu_events_list_num = 0;
@@ -1564,7 +1564,7 @@ perf_pmu__parse_check(const char *name)
 	r = bsearch(&p, perf_pmu_events_list,
 			(size_t) perf_pmu_events_list_num,
 			sizeof(struct perf_pmu_event_symbol), comp_pmu);
-	free(p.symbol);
+	zfree(&p.symbol);
 	return r ? r->type : PMU_EVENT_SYMBOL_ERR;
 }
 
@@ -1711,8 +1711,8 @@ static void parse_events_print_error(struct parse_events_error *err,
 		fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err->str);
 		if (err->help)
 			fprintf(stderr, "\n%s\n", err->help);
-		free(err->str);
-		free(err->help);
+		zfree(&err->str);
+		zfree(&err->help);
 	}
 
 	fprintf(stderr, "Run 'perf list' for a list of valid events\n");
@@ -2407,7 +2407,7 @@ void parse_events_terms__purge(struct list_head *terms)
 
 	list_for_each_entry_safe(term, h, terms, list) {
 		if (term->array.nr_ranges)
-			free(term->array.ranges);
+			zfree(&term->array.ranges);
 		list_del_init(&term->list);
 		free(term);
 	}
@@ -2423,7 +2423,7 @@ void parse_events_terms__delete(struct list_head *terms)
 
 void parse_events__clear_array(struct parse_events_array *a)
 {
-	free(a->ranges);
+	zfree(&a->ranges);
 }
 
 void parse_events_evlist_error(struct parse_events_evlist *data,
Signature · 1 line
2.7.4