2021-12-14 01:10:39

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH v3] 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.
---
Signed-off-by: Miaoqian Lin <[email protected]>
Tested-by: German Gomez <[email protected]>
Reviewed-by: German Gomez <[email protected]>
---
tools/perf/util/expr.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index 1d532b9fed29..f225247acc01 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -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)
--
2.17.1



2021-12-21 08:29:51

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH v3] perf expr: Fix return value of ids__new

On Tue, Dec 14, 2021 at 01:10:27AM +0000, Miaoqian Lin wrote:
> 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.

Acked-by: Jiri Olsa <[email protected]>

thanks,
jirka

> ---
> Signed-off-by: Miaoqian Lin <[email protected]>
> Tested-by: German Gomez <[email protected]>
> Reviewed-by: German Gomez <[email protected]>
> ---
> tools/perf/util/expr.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index 1d532b9fed29..f225247acc01 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -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)
> --
> 2.17.1
>


2021-12-21 14:20:04

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v3] perf expr: Fix return value of ids__new

Em Tue, Dec 14, 2021 at 01:10:27AM +0000, Miaoqian Lin escreveu:
> 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

> ---
> Changes in v3:
> fix compilation error and add tags.
> ---
> Signed-off-by: Miaoqian Lin <[email protected]>
> Tested-by: German Gomez <[email protected]>
> Reviewed-by: German Gomez <[email protected]>
> ---
> tools/perf/util/expr.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index 1d532b9fed29..f225247acc01 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -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)
> --
> 2.17.1

--

- Arnaldo

2021-12-22 04:26:09

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH v4] 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.

Signed-off-by: Miaoqian Lin <[email protected]>
Tested-by: German Gomez <[email protected]>
Reviewed-by: German Gomez <[email protected]>
---
Changes in v4:
fix the separator in commit message.
---
tools/perf/util/expr.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index 1d532b9fed29..f225247acc01 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -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)
--
2.17.1