Skip to contentSkip to conversation

perf print-events: Remove redundant comparison with zero

PATCH In review Kang Minchul 2 participants 2 messages Nov 5, 2022 – Nov 7, 2022 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf print-events: Remove redundant comparison with zero

Since variable npmus is unsigned int, comparing with 0 is unnecessary.

---
 tools/perf/util/print-events.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/print-events.c +2 -4
index c4d5d87fae2f..6df947df1c0f 100644
@@ -311,10 +311,8 @@ int print_hwcache_events(const char *event_glob, bool name_only)
 				if ((hybrid_supported == 0) ||
 				    (hybrid_supported == npmus)) {
 					evt_list[evt_i] = strdup(name);
-					if (npmus > 0) {
-						for (j = 0; j < npmus; j++)
-							zfree(&evt_pmus[j]);
-					}
+					for (j = 0; j < npmus; j++)
+						zfree(&evt_pmus[j]);
 				} else {
 					for (j = 0; j < hybrid_supported; j++) {
 						evt_list[evt_i++] = evt_pmus[j];
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Minchul,

Quoted 13 lines · Kang Minchul

Since variable npmus is unsigned int, comparing with 0 is unnecessary.

---
 tools/perf/util/print-events.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/print-events.c +0 -0
index c4d5d87fae2f..6df947df1c0f 100644

tools/perf/util/print-events.c int print_hwcache_events(const char *event_glob, bool name_only) · line 315

Quoted 9 lines
tools/perf/util/print-events.c +2 -4
@@ -311,10 +311,8 @@ int print_hwcache_events(const char *event_glob, bool name_only)
                                if ((hybrid_supported == 0) ||
                                    (hybrid_supported == npmus)) {
                                        evt_list[evt_i] = strdup(name);
-                                       if (npmus > 0) {
-                                               for (j = 0; j < npmus; j++)
-                                                       zfree(&evt_pmus[j]);
-                                       }
+                                       for (j = 0; j < npmus; j++)
+                                               zfree(&evt_pmus[j]);

You can still have 0 npmus, but then the for loop will not be executed. So,

Thanks,
Namhyung

Quoted 6 lines
tools/perf/util/print-events.c +0 -1
                                } else {
                                        for (j = 0; j < hybrid_supported; j++) {
                                                evt_list[evt_i++] = evt_pmus[j];
--

2.34.1