* [PATCH V2] kho: Convert error handling to immediate return pattern
[not found] <00c96a62-f783-497c-a7ac-1de495e4af06@huawei.com>
@ 2026-08-24 2:44 ` LongWei27
2026-08-24 2:54 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: LongWei27 @ 2026-08-24 2:44 UTC (permalink / raw)
To: Alexander Graf, Mike Rapoport, Pasha Tatashin
Cc: Pratyush Yadav, kexec, linux-mm, linux-kernel, hewenliang4,
Long Wei
From: Long Wei <longwei27@huawei.com>
Replace the chained error accumulation (err |= func()) with immediate
per-step error checking and early return in kho_out_fdt_setup().
Two problems with the current approach:
1. It continues executing FDT operations even after a failure, which
is pointless and potentially unsafe on an invalid FDT context.
2. Bitwise OR of multiple negative error codes produces a result that
may not represent any actual error, making debugging misleading.
Early return fails fast and preserves the original error code for
accurate diagnosis.
No functional change intended.
Signed-off-by: Long Wei <longwei27@huawei.com>
---
kernel/liveupdate/kexec_handover.c | 32 +++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 175c08a6e..93443ad84 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1438,20 +1438,34 @@ static __init int kho_out_fdt_setup(void)
int err;
err = fdt_create(root, PAGE_SIZE);
- err |= fdt_finish_reservemap(root);
- err |= fdt_begin_node(root, "");
- err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
+ if (err)
+ return err;
+ err = fdt_finish_reservemap(root);
+ if (err)
+ return err;
+ err = fdt_begin_node(root, "");
+ if (err)
+ return err;
+ err = fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
+ if (err)
+ return err;
preserved_mem_tree_pa = virt_to_phys(tree->root);
- err |= fdt_property(root, KHO_FDT_MEMORY_MAP_PROP_NAME,
- &preserved_mem_tree_pa,
- sizeof(preserved_mem_tree_pa));
+ err = fdt_property(root, KHO_FDT_MEMORY_MAP_PROP_NAME,
+ &preserved_mem_tree_pa,
+ sizeof(preserved_mem_tree_pa));
+ if (err)
+ return err;
- err |= fdt_end_node(root);
- err |= fdt_finish(root);
+ err = fdt_end_node(root);
+ if (err)
+ return err;
+ err = fdt_finish(root);
+ if (err)
+ return err;
- return err;
+ return 0;
}
static void __init kho_in_kexec_metadata(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V2] kho: Convert error handling to immediate return pattern
2026-08-24 2:44 ` [PATCH V2] kho: Convert error handling to immediate return pattern LongWei27
@ 2026-08-24 2:54 ` Matthew Wilcox
2026-08-24 6:34 ` longwei (I)
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2026-08-24 2:54 UTC (permalink / raw)
To: LongWei27
Cc: Alexander Graf, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
kexec, linux-mm, linux-kernel, hewenliang4
On Mon, Aug 24, 2026 at 10:44:48AM +0800, LongWei27 wrote:
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -1438,20 +1438,34 @@ static __init int kho_out_fdt_setup(void)
> int err;
>
> err = fdt_create(root, PAGE_SIZE);
> - err |= fdt_finish_reservemap(root);
> - err |= fdt_begin_node(root, "");
> - err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
> + if (err)
> + return err;
> + err = fdt_finish_reservemap(root);
> + if (err)
> + return err;
> + err = fdt_begin_node(root, "");
> + if (err)
> + return err;
> + err = fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
> + if (err)
> + return err;
Less verbose:
err = fdt_create(root, PAGE_SIZE);
- err |= fdt_finish_reservemap(root);
- err |= fdt_begin_node(root, "");
- err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
+ if (!err)
+ err = fdt_finish_reservemap(root);
+ if (!err)
+ err = fdt_begin_node(root, "");
+ if (!err)
+ err = fdt_property_string(root, "compatible",
+ KHO_FDT_COMPATIBLE);
up to the maintainer which one they prefer ...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] kho: Convert error handling to immediate return pattern
2026-08-24 2:54 ` Matthew Wilcox
@ 2026-08-24 6:34 ` longwei (I)
0 siblings, 0 replies; 3+ messages in thread
From: longwei (I) @ 2026-08-24 6:34 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Alexander Graf, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
kexec, linux-mm, linux-kernel, hewenliang4
Hi Matthew,
Thanks for the review.
I chose the explicit `if (err) return err` pattern for clarity and
"fail fast" behavior. However, I'm happy to adopt the chained pattern
if the maintainer prefers it.
Thanks,
Long Wei
在 2026/8/24 10:54, Matthew Wilcox 写道:
> On Mon, Aug 24, 2026 at 10:44:48AM +0800, LongWei27 wrote:
>> +++ b/kernel/liveupdate/kexec_handover.c
>> @@ -1438,20 +1438,34 @@ static __init int kho_out_fdt_setup(void)
>> int err;
>>
>> err = fdt_create(root, PAGE_SIZE);
>> - err |= fdt_finish_reservemap(root);
>> - err |= fdt_begin_node(root, "");
>> - err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
>> + if (err)
>> + return err;
>> + err = fdt_finish_reservemap(root);
>> + if (err)
>> + return err;
>> + err = fdt_begin_node(root, "");
>> + if (err)
>> + return err;
>> + err = fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
>> + if (err)
>> + return err;
>
> Less verbose:
>
> err = fdt_create(root, PAGE_SIZE);
> - err |= fdt_finish_reservemap(root);
> - err |= fdt_begin_node(root, "");
> - err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
> + if (!err)
> + err = fdt_finish_reservemap(root);
> + if (!err)
> + err = fdt_begin_node(root, "");
> + if (!err)
> + err = fdt_property_string(root, "compatible",
> + KHO_FDT_COMPATIBLE);
>
> up to the maintainer which one they prefer ...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-24 6:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <00c96a62-f783-497c-a7ac-1de495e4af06@huawei.com>
2026-08-24 2:44 ` [PATCH V2] kho: Convert error handling to immediate return pattern LongWei27
2026-08-24 2:54 ` Matthew Wilcox
2026-08-24 6:34 ` longwei (I)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox