All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v4 1/7] libtracefs: Implement tracefs_instances()
Date: Fri, 2 Jul 2021 14:39:48 +0300	[thread overview]
Message-ID: <97c4e671-5ee9-3c1a-b957-1d0b6fbc0eb3@gmail.com> (raw)
In-Reply-To: <20210702073332.357ca775@rorschach.local.home>



On 2.07.21 г. 14:33, Steven Rostedt wrote:
> On Fri, 2 Jul 2021 14:10:46 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
> 
>>> +static int build_list(const char *name, void *data)
>>> +{
>>> +	struct instance_list *list = data;
>>> +	char **instances;
>>> +	int ret = -1;
>>> +
>>> +	if (!match(name, list->re))
>>> +		return 0;
>>> +
>>> +	instances = realloc(list->list, list->size + 2);
>>> +	if (!instances)
>>> +		goto out;
>>> +
>>> +	list->list = instances;
>> Hi Steven,
>>
>> I am not sure what was your original intention here, but this doesn't
>> seem to work properly. Maybe we need something like this:
>>
>> 	int size =  sizeof(*instances) * (list->size + 2);
>> 	instances = realloc(list->list, size);
> 
> Bah, that's what I get for trying to "multitask" while coding :-p
> That was suppose to be:
> 
> 	instances = realloc(list->list, sizeof(*instances) * (list->size + 2);
> 
> as you stated, but I'll keep it one line.
> 
>> 	if (!instances)
>> 		goto out;
>>
>> 	instances[list->size + 1] = NULL;

but you still need to make sure it is NULL terminated.
Y.

>>
>>
>>
>>
>>> +	list->list[list->size] = strdup(name);
>>> +	if (!list->list[list->size])
>>> +		goto out;
>>> +
>>> +	list->size++;
>>> +	ret = 0;
>>> +
>>> + out:
>>> +	list->failed = ret;
>>> +	return ret;
>>> +}
>>> +
>>> +/**
>>> + * tracefs_instances - return a list of instance names
>>> + * @regex: A regex of instances to filter on (NULL to match all)
>>> + *
>>> + * Returns a list of names of existing instances, that must be
>>> + * freed with tracefs_list_free(). Note, if there are no matches
>>> + * then an empty list will be returned (not NULL).
>>> + * NULL on error.
>>> + */
>>> +char **tracefs_instances(const char *regex)
>>> +{
>>> +	struct instance_list list = { .re = NULL, .list = NULL };
>>> +	regex_t re;
>>> +	int ret;
>>> +
>>> +	if (regex) {
>>> +		ret = regcomp(&re, regex, REG_ICASE|REG_NOSUB);
>>> +		if (ret < 0)
>>> +			return NULL;
>>> +		list.re = &re;
>>> +	}
>>> +
>>> +	ret = tracefs_instances_walk(build_list, &list);
>>> +	if (ret < 0 || list.failed) {
>>> +		tracefs_list_free(list.list);
>>> +		list.list = NULL;
>>> +	} else {
>>> +		if (!list.list) {
>>> +			/* No matches should produce an empty list */
>>> +			list.list = malloc(sizeof(*list.list));
>>> +			if (list.list)
>>> +				list.list[0] = NULL;
>>> +		}
>>
>> Or you can just do:
>> 				return calloc(1, sizeof(*list.list));
> 
> Which I do in tracefs_get_probes(), must have missed this one.
> 
> Will update, thanks for the review.
> 
> 
> -- Steve
> 
> 
>>
>> Thanks!
>> Yordan
>>
>>> +	}
>>> +	return list.list;
>>> +}

  reply	other threads:[~2021-07-02 11:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02  3:54 [PATCH v4 0/7] libtracefs: Facilitate adding and removing kprobes Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 1/7] libtracefs: Implement tracefs_instances() Steven Rostedt
2021-07-02 11:10   ` Yordan Karadzhov (VMware)
2021-07-02 11:33     ` Steven Rostedt
2021-07-02 11:39       ` Yordan Karadzhov (VMware) [this message]
2021-07-02 11:50         ` Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 2/7] libtracefs: Implement tracefs_kprobe_raw() Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 3/7] libtracefs: Implement tracefs_kretprobe_raw() Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 4/7] libtracefs: Implement tracefs_get_kprobes() Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 5/7] libtracefs: Implement tracefs_kprobe_clear_all() to remove all kprobes Steven Rostedt
2021-07-02 11:15   ` Yordan Karadzhov (VMware)
2021-07-02 11:35     ` Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 6/7] libtracefs: Implement tracefs_kprobe_clear_probe() Steven Rostedt
2021-07-02  3:54 ` [PATCH v4 7/7] libtracefs: Add man pages for kprobe functions Steven Rostedt

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=97c4e671-5ee9-3c1a-b957-1d0b6fbc0eb3@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.