Skip to contentSkip to conversation

perf expr: Fix return value of ids__new

PATCH Superseded Miaoqian Lin 3 participants 4 messages Dec 14, 2021 – Dec 22, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 perf expr: Fix return value of ids__new

callers of ids__new() function only do NULL checking for the return value. ids__new() calles hashmap__new(), which may return ERR_PTR(-ENOMEM). Instead of changing the checking one-by-one. return NULL instead of ERR_PTR(-ENOMEM) to keep consistent.

---
Changes in v3:
fix compilation error and add tags.
---

---
 tools/perf/util/expr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/expr.c +7 -1
index 1d532b9fed29..f225247acc01 100644
@@ -12,6 +12,7 @@
 #include "expr-bison.h"
 #include "expr-flex.h"
 #include "smt.h"
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <ctype.h>
@@ -65,7 +66,12 @@ static bool key_equal(const void *key1, const void *key2,
 
 struct hashmap *ids__new(void)
 {
-	return hashmap__new(key_hash, key_equal, NULL);
+	struct hashmap *hash;
+
+	hash = hashmap__new(key_hash, key_equal, NULL);
+	if (IS_ERR(hash))
+		return NULL;
+	return hash;
 }
 
 void ids__free(struct hashmap *ids)
Signature · 1 line
2.17.1
Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · Miaoqian Lin

callers of ids__new() function only do NULL checking for the return value. ids__new() calles hashmap__new(), which may return ERR_PTR(-ENOMEM). Instead of changing the checking one-by-one. return NULL instead of ERR_PTR(-ENOMEM) to keep consistent.

---
Changes in v3:
fix compilation error and add tags.

thanks,
jirka

Quoted 37 lines

---

---
 tools/perf/util/expr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/expr.c +7 -1
index 1d532b9fed29..f225247acc01 100644
@@ -12,6 +12,7 @@
 #include "expr-bison.h"
 #include "expr-flex.h"
 #include "smt.h"
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <ctype.h>
@@ -65,7 +66,12 @@ static bool key_equal(const void *key1, const void *key2,
 
 struct hashmap *ids__new(void)
 {
-	return hashmap__new(key_hash, key_equal, NULL);
+	struct hashmap *hash;
+
+	hash = hashmap__new(key_hash, key_equal, NULL);
+	if (IS_ERR(hash))
+		return NULL;
+	return hash;
 }
 
 void ids__free(struct hashmap *ids)
Signature · 1 line
2.17.1
#2 lore raw
In reply to Miaoqian Lin

Em Tue, Dec 14, 2021 at 01:10:27AM +0000, Miaoqian Lin escreveu:

Quoted 5 lines

callers of ids__new() function only do NULL checking for the return value. ids__new() calles hashmap__new(), which may return ERR_PTR(-ENOMEM). Instead of changing the checking one-by-one. return NULL instead of ERR_PTR(-ENOMEM) to keep consistent.

Please don't use --- as a separator inside the commit message, it breaks scripts that expect it to be a separator from the commit log message to the diffstat + patch.

Applying after fixing this.

- Arnaldo

Quoted 39 lines

---
Changes in v3:
fix compilation error and add tags.
---

---
 tools/perf/util/expr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/expr.c +7 -1
index 1d532b9fed29..f225247acc01 100644
@@ -12,6 +12,7 @@
 #include "expr-bison.h"
 #include "expr-flex.h"
 #include "smt.h"
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <ctype.h>
@@ -65,7 +66,12 @@ static bool key_equal(const void *key1, const void *key2,
 
 struct hashmap *ids__new(void)
 {
-	return hashmap__new(key_hash, key_equal, NULL);
+	struct hashmap *hash;
+
+	hash = hashmap__new(key_hash, key_equal, NULL);
+	if (IS_ERR(hash))
+		return NULL;
+	return hash;
 }
 
 void ids__free(struct hashmap *ids)
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#3 lore raw

PATCH v4 1/1 perf expr: Fix return value of ids__new

callers of ids__new() function only do NULL checking for the return value. ids__new() calles hashmap__new(), which may return ERR_PTR(-ENOMEM). Instead of changing the checking one-by-one. return NULL instead of ERR_PTR(-ENOMEM) to keep consistent.

---
Changes in v4:
fix the separator in commit message.

---
 tools/perf/util/expr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/expr.c +7 -1
index 1d532b9fed29..f225247acc01 100644
@@ -12,6 +12,7 @@
 #include "expr-bison.h"
 #include "expr-flex.h"
 #include "smt.h"
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <ctype.h>
@@ -65,7 +66,12 @@ static bool key_equal(const void *key1, const void *key2,
 
 struct hashmap *ids__new(void)
 {
-	return hashmap__new(key_hash, key_equal, NULL);
+	struct hashmap *hash;
+
+	hash = hashmap__new(key_hash, key_equal, NULL);
+	if (IS_ERR(hash))
+		return NULL;
+	return hash;
 }
 
 void ids__free(struct hashmap *ids)
Signature · 1 line
2.17.1