2022-09-18 15:53:40

by CGEL

[permalink] [raw]
Subject: [PATCH linu-next V2] mm/fault: fix comparing pointer to 0

From: Xu Panda <[email protected]>

Do not use assignment in if condition,
and comparing pointer whith NULL instead of comparing pointer to 0.

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Xu Panda <[email protected]>
---
arch/alpha/mm/fault.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
index ef427a6bdd1a..bb3fe2949313 100644
--- a/arch/alpha/mm/fault.c
+++ b/arch/alpha/mm/fault.c
@@ -194,7 +194,8 @@ do_page_fault(unsigned long address, unsigned long
mmcsr,

no_context:
/* Are we prepared to handle this fault as an exception? */
- if ((fixup = search_exception_tables(regs->pc)) != 0) {
+ fixup = search_exception_tables(regs->pc);
+ if (fixup != NULL) {
unsigned long newpc;
newpc = fixup_exception(dpf_reg, fixup, regs->pc);
regs->pc = newpc;
--
2.15.2


2022-09-18 22:15:40

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [PATCH linu-next V2] mm/fault: fix comparing pointer to 0

[email protected] writes:

> From: Xu Panda <[email protected]>
>
> Do not use assignment in if condition,
> and comparing pointer whith NULL instead of comparing pointer to 0.

Then sensible thing to do if fixup is a pointer value is to just say:

"if (fixup) {"

That will be clearer and not match the pattern you are trying to avoid.

Eric

>
> Reported-by: Zeal Robot <[email protected]>
> Signed-off-by: Xu Panda <[email protected]>
> ---
> arch/alpha/mm/fault.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
> index ef427a6bdd1a..bb3fe2949313 100644
> --- a/arch/alpha/mm/fault.c
> +++ b/arch/alpha/mm/fault.c
> @@ -194,7 +194,8 @@ do_page_fault(unsigned long address, unsigned long
> mmcsr,
>
> no_context:
> /* Are we prepared to handle this fault as an exception? */
> - if ((fixup = search_exception_tables(regs->pc)) != 0) {
> + fixup = search_exception_tables(regs->pc);
> + if (fixup != NULL) {
> unsigned long newpc;
> newpc = fixup_exception(dpf_reg, fixup, regs->pc);
> regs->pc = newpc;