xen/x86: Use min macro instead of ternary operator
PATCH 1/1 xen/x86: Use min macro instead of ternary operator
Replace ternary operator with macro min as it is shorter and thus increases code readability. Macro min return the minimum of the two compared values.
--- xen/arch/x86/bzimage.c | 2 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/bzimage.c +1 -1
@@ -136,7 +136,7 @@ int __init bzimage_parse(void *image_base, void **image_start, *image_len = output_len; } -return err >0 ?0 : err; +return min (0 , err); }/*
xen/arch/x86/mm.c +1 -1
@@ -1988,7 +1988,7 @@ static int demote_l3_table(struct page_info *page) page->partial_flags = partial_flags; rc = -ERESTART ; } -return rc >0 ?0 : rc; +return min (0 , rc); }static int demote_l4_table (struct page_info *page)
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -1069,7 +1069,7 @@ static int ept_change_entry_type_range(struct p2m_domain *p2m,if ( sync )ept_sync_domain (p2m); -return rc <0 ? rc :0 ; +return min (rc,0 ); }static void ept_memory_type_changed (struct p2m_domain *p2m)
Signature · 1 line
2.17.1
Hi,
Quoted 3 lines · Simran Singhal
Replace ternary operator with macro min as it is shorter and thus increases code readability. Macro min return the minimum of the two compared values.
While I understand the ternary operator is doing exactly the same as a min(), I read the current code as "If there is an error then return the error code, otherwise return 0".
This is quite different from the meaning of "min" which is "I want the minimum of the two values". Therefore I am not convinced using min() is the right thing to do.
Quoted 47 lines
Signed-off-by Simran Singhal <[email protected]>--- xen/arch/x86/bzimage.c | 2 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/bzimage.c +1
-1@@ -136,7 +136,7 @@ int __init bzimage_parse(void *image_base, void **image_start, *image_len = output_len; } -return err >0 ?0 : err; +return min (0 , err); }/* xen/arch/x86/mm.c +1
-1@@ -1988,7 +1988,7 @@ static int demote_l3_table(struct page_info *page) page->partial_flags = partial_flags; rc = -ERESTART ; } -return rc >0 ?0 : rc; +return min (0 , rc); }static int demote_l4_table (struct page_info *page)xen/arch/x86/mm/p2m-ept.c +1
-1@@ -1069,7 +1069,7 @@ static int ept_change_entry_type_range(struct p2m_domain *p2m,if ( sync )ept_sync_domain (p2m); -return rc <0 ? rc :0 ; +return min (rc,0 ); }static void ept_memory_type_changed (struct p2m_domain *p2m)
Signature · 1 line
Julien Grall
Quoted 7 lines · Julien Grall
Hi,
Quoted 3 lines · Simran Singhal
Replace ternary operator with macro min as it is shorter and thus increases code readability. Macro min return the minimum of the two compared values.
Quoted 7 lines
While I understand the ternary operator is doing exactly the same as a
min(), I read the current code as "If there is an error then return the error code, otherwise return 0".This is quite different from the meaning of "min" which is "I want the minimum of the two values". Therefore I am not convinced using
min()is the right thing to do.
I agree with Julien's assessment.
Wei.