linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com,
	james.clark@arm.com
Subject: Re: [PATCH V2 1/8] tools lib: adopt str_has_suffix() from bpftool/gen.c
Date: Thu, 11 Apr 2024 12:41:50 -0300	[thread overview]
Message-ID: <ZhgEvt5_O7eWDdGk@x1> (raw)
In-Reply-To: <40b33222-45cc-4aea-9e08-1813b2268db9@arm.com>

On Thu, Apr 11, 2024 at 05:45:25PM +0530, Chaitanya S Prakash wrote:
> On 4/9/24 05:02, Masami Hiramatsu (Google) wrote:
> > On Mon,  8 Apr 2024 11:52:23 +0530
> > Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com> wrote:
> > > and add it to tools/lib/string.c The function is modified to return
> > > strlen(suffix) on success and 0 on failure.
> > > +++ b/tools/include/linux/string.h
> > > @@ -42,6 +42,8 @@ static inline bool strstarts(const char *str, const char *prefix)
> > >   	return strncmp(str, prefix, strlen(prefix)) == 0;
> > >   }
> > > +size_t str_has_suffix(const char *str, const char *suffix);
> > > +
> > >   extern char * __must_check skip_spaces(const char *);
> > >   extern char *strim(char *);
> > > diff --git a/tools/lib/string.c b/tools/lib/string.c
> > > index 8b6892f959ab..9cb515048239 100644
> > > --- a/tools/lib/string.c
> > > +++ b/tools/lib/string.c
> > > @@ -226,3 +226,29 @@ void *memchr_inv(const void *start, int c, size_t bytes)
> > >   	return check_bytes8(start, value, bytes % 8);
> > >   }
> > > +
> > > +/**
> > > + * str_has_suffix - Test is a string has a given suffix
> > > + * @str: The string to be tested
> > > + * @suffix: The string to see if @str ends with
> > > + *
> > > + * Returns:
> > > + * * strlen(@suffix) if @str ends with @suffix
> > > + * * 0 if @str does not end with @suffix
> > I think this should return boolean, because user will never check the
> > return value is strlen(@suffix). (and user always use the return value
> > as a boolean)
 
> This is in accordance with Arnaldo's comments on V1 of the patch series.
> Please find the link for the same below.
 
> https://lore.kernel.org/all/ZdYPf3wMl35VemsL@x1/

Yeah, when I saw str_has_prefix() I thought it too clever, but then, why
not, there are use cases, in the kernel, where that is useful.

And one thing with tools/ that we try hard is to reduce the differences
of programming in the kernel and in there, so that people used to
functions in the kernel use them in tools/ with the same semantics.

So in these "the user will never do things like this" moments I try to
look at the users in the codebase where we're lifting the function, and
in there _there_ are uses of the strlen() return, to my surprise.

- Arnaldo
 
> > > +size_t str_has_suffix(const char *str, const char *suffix)
> > > +{
> > > +	size_t i;
> > > +	size_t str_len = strlen(str);
> > > +	size_t suffix_len = strlen(suffix);
> > > +
> > > +	if (str_len < suffix_len)
> > > +		return 0;
> > > +
> > > +	for (i = 0; i < suffix_len ; i++) {
> > > +		if (str[str_len  - i - 1] != suffix[suffix_len - i - 1])
> > > +			return 0;
> > > +	}
> > > +
> > > +	return suffix_len;

  reply	other threads:[~2024-04-11 15:41 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  6:22 [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Chaitanya S Prakash
2024-04-08  6:22 ` [PATCH V2 1/8] tools lib: adopt str_has_suffix() from bpftool/gen.c Chaitanya S Prakash
2024-04-08 23:32   ` Masami Hiramatsu
2024-04-11 12:15     ` Chaitanya S Prakash
2024-04-11 15:41       ` Arnaldo Carvalho de Melo [this message]
2024-04-08  6:22 ` [PATCH V2 2/8] perf util: Delete ends_with() and replace its use with str_has_suffix() Chaitanya S Prakash
2024-04-08  6:22 ` [PATCH V2 3/8] perf util: Replace an instance of strtailcmp() by str_has_suffix() Chaitanya S Prakash
2024-04-08 23:20   ` Masami Hiramatsu
2024-04-08  6:22 ` [PATCH V2 4/8] tools lib: Adopt str_has_prefix() from kernel Chaitanya S Prakash
2024-04-08 23:33   ` Masami Hiramatsu
2024-04-08  6:22 ` [PATCH V2 5/8] tools: Delete strstarts() and replace its usage with str_has_prefix() Chaitanya S Prakash
2024-04-18  7:32   ` kernel test robot
2024-04-08  6:22 ` [PATCH V2 6/8] perf tools: Enable configs required for test_uprobe_from_different_cu.sh Chaitanya S Prakash
2024-04-08 23:11   ` Masami Hiramatsu
2024-04-16 21:19     ` Arnaldo Carvalho de Melo
2024-04-08  6:22 ` [PATCH V2 7/8] perf tools: Only treat files as map files when they have the extension .map Chaitanya S Prakash
2024-04-09 10:21   ` James Clark
2024-04-08  6:22 ` [PATCH V2 8/8] perf test: Check output of the probe ... --funcs command Chaitanya S Prakash
2024-04-08 23:09   ` Masami Hiramatsu
2024-04-16 21:22     ` Arnaldo Carvalho de Melo
2024-04-17 18:26     ` Arnaldo Carvalho de Melo
2024-04-23 11:53       ` Chaitanya S Prakash
2024-04-09  5:32 ` [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Alexey Dobriyan
2024-04-11 12:10   ` Chaitanya S Prakash
2024-04-14 11:41     ` Alexey Dobriyan
2024-04-17 13:24       ` James Clark
2024-04-17 13:39         ` Arnaldo Carvalho de Melo
2024-04-10  3:34 ` Chaitanya S Prakash
2024-04-11 18:49 ` Arnaldo Carvalho de Melo

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=ZhgEvt5_O7eWDdGk@x1 \
    --to=acme@kernel.org \
    --cc=ChaitanyaS.Prakash@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=james.clark@arm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).