mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Jianlin Lv <Jianlin.Lv@arm.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org, srikar@linux.vnet.ibm.com,
	adrian.hunter@intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf probe: Added protection to avoid endless loop
Date: Wed, 3 Feb 2021 22:25:02 +0900	[thread overview]
Message-ID: <20210203222502.a8b9b7bf8fba4e0ba0fe5681@kernel.org> (raw)
In-Reply-To: <20210203022507.677283-1-Jianlin.Lv@arm.com>

On Wed,  3 Feb 2021 10:25:07 +0800
Jianlin Lv <Jianlin.Lv@arm.com> wrote:

> if dwarf_offdie() return NULL, the continue statement forces the next
> iteration of the loop without update variable off. It will cause an
> endless loop in the process of traversing the compilation unit.
> So added exception protection for loop CUs.

Good catch!

> 
> Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
> ---
>  tools/perf/util/probe-finder.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 76dd349aa48d..887bffb1cc58 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -1156,7 +1156,7 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
>  	Dwarf_Die *diep;
>  	int ret = 0;
>  
> -	off = 0;
> +	noff = 0;
>  	pf->lcache = intlist__new(NULL);
>  	if (!pf->lcache)
>  		return -ENOMEM;
> @@ -1184,7 +1184,7 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
>  	}
>  
>  	/* Loop on CUs (Compilation Unit) */
> -	while (!dwarf_nextcu(dbg->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
> +	while (!dwarf_nextcu(dbg->dbg, off = noff, &noff, &cuhl, NULL, NULL, NULL)) {

I don't like to update variable in function argument, 

I would rather like below code;

>  		/* Get the DIE(Debugging Information Entry) of this CU */
>  		diep = dwarf_offdie(dbg->dbg, off + cuhl, &pf->cu_die);
  		if (!diep) {
+			off = noff;
			continue;
		}

Or, "goto next;" and

> @@ -1208,7 +1208,6 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
>  			if (ret < 0)
>  				break;
>  		}

next:

> -		off = noff;
>  	}
>  
>  found:
> @@ -1919,7 +1918,7 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
>  {
>  	struct line_finder lf = {.lr = lr, .found = 0};
>  	int ret = 0;
> -	Dwarf_Off off = 0, noff;
> +	Dwarf_Off off = 0, noff = 0;
>  	size_t cuhl;
>  	Dwarf_Die *diep;
>  	const char *comp_dir;
> @@ -1943,6 +1942,7 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
>  
>  	/* Loop on CUs (Compilation Unit) */
>  	while (!lf.found && ret >= 0) {
> +		off = noff;

Here too.
Can you update it?

Thank you,

>  		if (dwarf_nextcu(dbg->dbg, off, &noff, &cuhl,
>  				 NULL, NULL, NULL) != 0)
>  			break;
> @@ -1967,7 +1967,6 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
>  				ret = find_line_range_by_line(NULL, &lf);
>  			}
>  		}
> -		off = noff;
>  	}
>  
>  found:
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

      reply	other threads:[~2021-02-03 13:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03  2:25 Jianlin Lv
2021-02-03 13:25 ` Masami Hiramatsu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210203222502.a8b9b7bf8fba4e0ba0fe5681@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=Jianlin.Lv@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®