* [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
2026-08-31 11:28 ` Mike Rapoport
0 siblings, 2 replies; 5+ 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] 5+ 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)
2026-08-31 11:28 ` Mike Rapoport
1 sibling, 1 reply; 5+ 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] 5+ 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; 5+ 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] 5+ 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-31 11:28 ` Mike Rapoport
2026-08-31 11:58 ` longwei (I)
1 sibling, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2026-08-31 11:28 UTC (permalink / raw)
To: LongWei27
Cc: Alexander Graf, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
kexec, linux-mm, linux-kernel, hewenliang4
Hi,
> 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.
Did you actually see failures here or was it an LLM suggesting that they
may happen?
> 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.
The caller does not care about the exact error value, so the diagnosis
statement is moot at best.
Moreover, libfdt does not return Linux error values.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] kho: Convert error handling to immediate return pattern
2026-08-31 11:28 ` Mike Rapoport
@ 2026-08-31 11:58 ` longwei (I)
0 siblings, 0 replies; 5+ messages in thread
From: longwei (I) @ 2026-08-31 11:58 UTC (permalink / raw)
To: Mike Rapoport
Cc: Alexander Graf, Pasha Tatashin, Pratyush Yadav, kexec, linux-mm,
linux-kernel, hewenliang4
Hi Mike Rapoport,
Thanks for the review.
To be honest, I haven't observed any actual failures in this path in our production environment.
This change was identified during our internal team code review—the err |= func() pattern looked concerning to us at first glance, so we attempted to clean it up.
However, I agree with your assessment: the caller doesn't care about the exact error value, libfdt uses its own error codes, and this is a cold path where failures are unlikely. The change is indeed unnecessary churn without a concrete bug to fix.
I'll drop this patch. Please ignore this submission.
Thanks,
Long Wei
在 2026/8/31 19:28, Mike Rapoport 写道:
> Hi,
>
>
>> 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.
>
> Did you actually see failures here or was it an LLM suggesting that they
> may happen?
>
>> 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.
>
> The caller does not care about the exact error value, so the diagnosis
> statement is moot at best.
> Moreover, libfdt does not return Linux error values.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-31 11:58 UTC | newest]
Thread overview: 5+ 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)
2026-08-31 11:28 ` Mike Rapoport
2026-08-31 11:58 ` longwei (I)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox