From: Shannon Zhao <zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Stefano Stabellini
<stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
stefano.stabellini-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org,
david.vrabel-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org,
catalin.marinas-5wv7dgnIgG8@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
julien.grall-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org,
xen-devel-GuqFBffKawuEi8DpZVb4nw@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org,
shannon.zhao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
peter.huangpeng-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH v3 16/17] FDT: Add a helper to get specified name subnode
Date: Tue, 26 Jan 2016 20:27:29 +0800 [thread overview]
Message-ID: <56A76631.2070802@huawei.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1601261156340.3619-7Z66fg9igcxYtxbxJUhB2Dgeux46jI+i@public.gmane.org>
On 2016/1/26 20:11, Stefano Stabellini wrote:
> On Sat, 23 Jan 2016, Shannon Zhao wrote:
>> > From: Shannon Zhao <shannon.zhao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> >
>> > Sometimes it needs to check if there is a node in FDT by full path.
>> > Introduce this helper to get the specified name subnode if it exists.
>> >
>> > Signed-off-by: Shannon Zhao <shannon.zhao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> > ---
>> > CC: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>> > ---
>> > drivers/of/fdt.c | 35 +++++++++++++++++++++++++++++++++++
>> > include/linux/of_fdt.h | 2 ++
>> > 2 files changed, 37 insertions(+)
>> >
>> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> > index 655f79d..112ec16 100644
>> > --- a/drivers/of/fdt.c
>> > +++ b/drivers/of/fdt.c
>> > @@ -645,6 +645,41 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
>> > }
>> >
>> > /**
>> > + * of_get_flat_dt_subnode_by_name - get subnode of specified node by name
>> > + *
>> > + * @node: the parent node
>> > + * @uname: the name of subnode
>> > + * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
>> > + */
>> > +
>> > +int of_get_flat_dt_subnode_by_name(unsigned long node, const char *uname)
>> > +{
>> > + const void *blob = initial_boot_params;
>> > + int offset;
>> > + const char *pathp;
>> > +
>> > + /* Find first subnode if it exists */
>> > + offset = fdt_first_subnode(blob, node);
>> > + if (offset < 0)
>> > + return -FDT_ERR_NOTFOUND;
>> > + pathp = fdt_get_name(blob, offset, NULL);
>> > + if (strncmp(pathp, uname, strlen(uname)) == 0)
>> > + return offset;
> Wouldn't this check succeed even if uname is "uefi" and the node
> name is actually "uefiiiii"? You might have to use strcmp.
>
Ah, yes. Will fix this.
>
>> > + /* Find other subnodes */
>> > + do {
>> > + offset = fdt_next_subnode(blob, offset);
>> > + if (offset < 0)
>> > + return -FDT_ERR_NOTFOUND;
>> > + pathp = fdt_get_name(blob, offset, NULL);
>> > + if (strncmp(pathp, uname, strlen(uname)) == 0)
>> > + return offset;
>> > + } while (offset >= 0);
> Rather than writing the name check twice, I think it would be best to
> code this loop as:
>
> for (offset = fdt_first_subnode(blob, offset);
> offset >= 0;
> offset = fdt_next_subnode(blob, offset)) {
>
> /* do name check */
>
>
>
Thanks for your suggestion. Will change this.
--
Shannon
next prev parent reply other threads:[~2016-01-26 12:27 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-23 3:19 [PATCH v3 00/17] Add ACPI support for Xen Dom0 on ARM64 Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 01/17] Xen: ACPI: Hide UART used by Xen Shannon Zhao
2016-01-25 12:20 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 02/17] xen/grant-table: Move xlated_setup_gnttab_pages to common place Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 04/17] arm/xen: Use xen_xlate_map_ballooned_pages to setup grant table Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 06/17] Xen: ARM: Add support for mapping platform device mmio Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 07/17] Xen: ARM: Add support for mapping AMBA " Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 08/17] Xen: public/hvm: sync changes of HVM_PARAM_CALLBACK_VIA ABI from Xen Shannon Zhao
2016-01-25 15:06 ` Stefano Stabellini
[not found] ` <1453519184-11908-1-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-23 3:19 ` [PATCH v3 03/17] Xen: xlate: Use page_to_xen_pfn instead of page_to_pfn Shannon Zhao
[not found] ` <1453519184-11908-4-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-25 13:55 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 05/17] xen: memory : Add new XENMAPSPACE type XENMAPSPACE_dev_mmio Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 09/17] xen/hvm/params: Add a new delivery type for event-channel in HVM_PARAM_CALLBACK_IRQ Shannon Zhao
2016-01-25 15:08 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 11/17] ARM: XEN: Move xen_early_init() before efi_init() Shannon Zhao
[not found] ` <1453519184-11908-12-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-25 15:25 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 10/17] arm/xen: Get event-channel irq through HVM_PARAM when booting with ACPI Shannon Zhao
[not found] ` <1453519184-11908-11-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-25 15:19 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 12/17] ARM64: ACPI: Check if it runs on Xen to enable or disable ACPI Shannon Zhao
[not found] ` <1453519184-11908-13-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-25 15:32 ` Stefano Stabellini
2016-01-27 8:27 ` Hanjun Guo
[not found] ` <56A87F77.8070506-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-01-27 8:57 ` Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 13/17] ARM: Xen: Document UEFI support on Xen ARM virtual platforms Shannon Zhao
2016-01-25 15:50 ` Stefano Stabellini
2016-01-25 15:59 ` Mark Rutland
2016-01-25 16:06 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 14/17] XEN: EFI: Move x86 specific codes to architecture directory Shannon Zhao
2016-01-25 16:44 ` Stefano Stabellini
2016-01-26 8:16 ` Shannon Zhao
2016-01-26 11:31 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1601261117200.3619-7Z66fg9igcxYtxbxJUhB2Dgeux46jI+i@public.gmane.org>
2016-01-26 12:26 ` Shannon Zhao
2016-01-23 3:19 ` [PATCH v3 15/17] ARM64: XEN: Add a function to initialize Xen specific UEFI runtime services Shannon Zhao
[not found] ` <1453519184-11908-16-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-25 16:47 ` Stefano Stabellini
2016-01-23 3:19 ` [PATCH v3 16/17] FDT: Add a helper to get specified name subnode Shannon Zhao
[not found] ` <1453519184-11908-17-git-send-email-zhaoshenglong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-01-26 12:11 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1601261156340.3619-7Z66fg9igcxYtxbxJUhB2Dgeux46jI+i@public.gmane.org>
2016-01-26 12:27 ` Shannon Zhao [this message]
2016-01-23 3:19 ` [PATCH v3 17/17] Xen: EFI: Parse DT parameters for Xen specific UEFI Shannon Zhao
2016-01-26 11:41 ` Stefano Stabellini
2016-01-26 12:05 ` Matt Fleming
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=56A76631.2070802@huawei.com \
--to=zhaoshenglong-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
--cc=david.vrabel-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org \
--cc=julien.grall-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=peter.huangpeng-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=shannon.zhao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=stefano.stabellini-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org \
--cc=stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
--cc=xen-devel-GuqFBffKawuEi8DpZVb4nw@public.gmane.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).