Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: Bhupesh Sharma <bhsharma@redhat.com>
Cc: bhupesh.linux@gmail.com, kexec@lists.infradead.org,
	Simon Horman <horms@verge.net.au>
Subject: Re: [PATCH] kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value
Date: Mon, 12 Nov 2018 11:24:07 +0900	[thread overview]
Message-ID: <20181112022406.GZ11663@linaro.org> (raw)
In-Reply-To: <1541968216-31282-1-git-send-email-bhsharma@redhat.com>

On Mon, Nov 12, 2018 at 02:00:16AM +0530, Bhupesh Sharma wrote:
> Vicenç reported (via [1]) that currently executing kexec with
> '--dtb' option and passing a .dtb which doesn't have a '/chosen' node
> leads to the following error:
> 
>   # kexec -d --dtb dtb_without_chosen_node.dtb --append 'cmdline' --load Image
> 
>     dtb_set_property: fdt_add_subnode failed: <valid offset/length>
>     kexec: Set device tree bootargs failed.
> 
> This happens because currently we check the return value of
> 'fdt_add_subnode()' function call in 'dt-ops.c' incorrectly:
> 
>    result = fdt_add_subnode(new_dtb, nodeoffset, node);
>    if (result) {
>    	dbgprintf("%s: fdt_add_subnode failed: %s\n", _func__,
>    		fdt_strerror(result));
>    	goto on_error;
>    }
> 
> As we can see in 'fdt_rw.c', a positive return value from
> 'fdt_add_subnode()' function doesn't indicate an error.
> 
> We can see that the Linux kernel (see 'drivers/firmware/efi/libstub/fdt.c'
> for example) also checks the 'fdt_add_subnode()' function against negative
> return values for errors. See an example below from 'update_fdt()' function in
> 'drivers/firmware/efi/libstub/fdt.c':
> 
>    node = fdt_add_subnode(fdt, 0, "chosen");
>    if (node < 0) {
>    	status = node;
>    	<..snip..>
>    	goto fdt_set_fail;
>    }
> 
> This patch fixes the same in 'kexec-tools'.

Looks good.
Thank you.
-Takahiro Akashi

> [1]. http://lists.infradead.org/pipermail/kexec/2018-October/021746.html
> 
> Cc: Simon Horman <horms@verge.net.au>
> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Reported-by: Vicente Bergas <vicencb@gmail.com>
> Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
> ---
>  kexec/dt-ops.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
> index 915dbf55afd2..f15174c3c74e 100644
> --- a/kexec/dt-ops.c
> +++ b/kexec/dt-ops.c
> @@ -84,7 +84,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
>  	if (nodeoffset == -FDT_ERR_NOTFOUND) {
>  		result = fdt_add_subnode(new_dtb, nodeoffset, node);
>  
> -		if (result) {
> +		if (result < 0) {
>  			dbgprintf("%s: fdt_add_subnode failed: %s\n", __func__,
>  				fdt_strerror(result));
>  			goto on_error;
> -- 
> 2.7.4
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2018-11-12  2:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-11 20:30 [PATCH] kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value Bhupesh Sharma
2018-11-12  2:24 ` AKASHI Takahiro [this message]
2018-11-15 14:10   ` Simon Horman
2018-11-15 14:13     ` Simon Horman
2018-11-15 18:38       ` Vicente Bergas
2018-11-15 19:40         ` Bhupesh Sharma
2018-11-16 12:03         ` Bhupesh Sharma
2018-11-16 15:29           ` Vicente Bergas
2018-11-28 22:00             ` Bhupesh Sharma
2018-11-30  5:40               ` Bhupesh Sharma
2018-11-30 14:59                 ` Vicente Bergas
2018-11-30 15:03                   ` Bhupesh Sharma
  -- strict thread matches above, loose matches on Subject: below --
2018-11-12 16:10 Vicente Bergas

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=20181112022406.GZ11663@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=bhsharma@redhat.com \
    --cc=bhupesh.linux@gmail.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.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