linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
To: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: maddy@linux.ibm.com, dan@danny.cz, kjain@linux.ibm.com,
	skiboot@lists.ozlabs.org, disgoel@linux.ibm.com,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH V3 1/3] core/device: Add function to return child node using name at substring "@"
Date: Thu, 23 Feb 2023 13:49:02 +0530	[thread overview]
Message-ID: <20230223081902.pysisjgloflv22ip@in.ibm.com> (raw)
In-Reply-To: <20230216080859.19161-1-atrajeev@linux.vnet.ibm.com>

On 2023-02-16 13:38:57 Thu, Athira Rajeev wrote:
> Add a function dt_find_by_name_substr() that returns the child node if
> it matches till first occurence at "@" of a given name, otherwise NULL.
> This is helpful for cases with node name like: "name@addr". In
> scenarios where nodes are added with "name@addr" format and if the
> value of "addr" is not known, that node can't be matched with node
> name or addr. Hence matching with substring as node name will return
> the expected result. Patch adds dt_find_by_name_substr() function
> and testcase for the same in core/test/run-device.c
> 
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> ---
[...]
> diff --git a/core/device.c b/core/device.c
> index 2de37c74..26562235 100644
> --- a/core/device.c
> +++ b/core/device.c
> @@ -395,6 +395,41 @@ struct dt_node *dt_find_by_name(struct dt_node *root, const char *name)
>  }
>  
>  
> +struct dt_node *dt_find_by_name_substr(struct dt_node *root, const char *name)
> +{
> +	struct dt_node *child, *match;
> +	char *node, *child_node = NULL;
> +

> +	node = malloc(strlen(name) + 1);
> +	if (!node)
> +		return NULL;
> +	memcpy(node, name, strlen(name));
> +	node[strlen(name)] = '\0';

You may want to use strdup() which does exactly what you trying to do:

	node = strdup(name);
	if (!node)
		return NULL;

> +	node = strtok(node, "@");
> +	list_for_each(&root->children, child, list) {

> +		child_node = malloc(strlen(child->name) + 1);
> +		if (!child_node)
> +			goto err;
> +		memcpy(child_node, child->name, strlen(child->name));
> +		child_node[strlen(child->name)] = '\0';

same here ^^^

Rest looks fine to me.

Reviewed-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>

Thanks,
-Mahesh.

      parent reply	other threads:[~2023-02-23  8:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16  8:08 [PATCH V3 1/3] core/device: Add function to return child node using name at substring "@" Athira Rajeev
2023-02-16  8:08 ` [PATCH V3 2/3] skiboot: Update IMC code to use dt_find_by_name_substr for checking dt nodes Athira Rajeev
2023-02-16  8:08 ` [PATCH V3 3/3] skiboot: Update IMC PMU node names for power10 Athira Rajeev
2023-02-20  4:09 ` [Skiboot] [PATCH V3 1/3] core/device: Add function to return child node using name at substring "@" Athira Rajeev
2023-02-23  8:19 ` Mahesh J Salgaonkar [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=20230223081902.pysisjgloflv22ip@in.ibm.com \
    --to=mahesh@linux.ibm.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=dan@danny.cz \
    --cc=disgoel@linux.ibm.com \
    --cc=kjain@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=skiboot@lists.ozlabs.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).