[PATCH] tools: Fix incorrect calculation of object size by sizeof

Li Dong posted 1 patch 2 years, 7 months ago
tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] tools: Fix incorrect calculation of object size by sizeof
Posted by Li Dong 2 years, 7 months ago
What we need to calculate is the size of the object, not the size of the
pointer.

Signed-off-by: Li Dong <lidong@vivo.com>
---
 tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 59063ec98619..25fcd6630a4d 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
 	int size = __sw_hweight64(attr->sample_regs_intr) * 28;
 	char *bf = malloc(size);
 
-	regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
+	regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);
 
 	pydict_set_item_string_decref(dict, "iregs",
 			_PyUnicode_FromString(bf));
 
-	regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
+	regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);
 
 	pydict_set_item_string_decref(dict, "uregs",
 			_PyUnicode_FromString(bf));
-- 
2.31.1.windows.1
Re: [PATCH] tools: Fix incorrect calculation of object size by sizeof
Posted by Namhyung Kim 2 years, 7 months ago
Hello,

On Mon, Jun 19, 2023 at 1:21 AM Li Dong <lidong@vivo.com> wrote:
>
> What we need to calculate is the size of the object, not the size of the
> pointer.
>
> Signed-off-by: Li Dong <lidong@vivo.com>

Since this problem was introduced in the current dev cycle and not in the
mainline yet, I think we can skip the Fixes tag.

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 59063ec98619..25fcd6630a4d 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
>         int size = __sw_hweight64(attr->sample_regs_intr) * 28;
>         char *bf = malloc(size);
>
> -       regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
> +       regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);
>
>         pydict_set_item_string_decref(dict, "iregs",
>                         _PyUnicode_FromString(bf));
>
> -       regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
> +       regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);
>
>         pydict_set_item_string_decref(dict, "uregs",
>                         _PyUnicode_FromString(bf));
> --
> 2.31.1.windows.1
>