* [PATCH] vmalloc:Merge multiple if conditional sentences
@ 2022-06-23 6:45 Lv qian
2022-06-23 7:34 ` Muchun Song
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Lv qian @ 2022-06-23 6:45 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, kernel, Lv qian
Merge multiple if statements to improve code readability
Signed-off-by: Lv qian <lvqian@nfschina.com>
---
mm/vmalloc.c | 66 ++++++++++++++--------------------------------------
1 file changed, 18 insertions(+), 48 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index effd1ff6a4b4..6902a180f8f7 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -135,22 +135,12 @@ static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
unsigned int max_page_shift)
{
- if (max_page_shift < PMD_SHIFT)
- return 0;
-
- if (!arch_vmap_pmd_supported(prot))
- return 0;
-
- if ((end - addr) != PMD_SIZE)
- return 0;
-
- if (!IS_ALIGNED(addr, PMD_SIZE))
- return 0;
-
- if (!IS_ALIGNED(phys_addr, PMD_SIZE))
- return 0;
-
- if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr))
+ if (max_page_shift < PMD_SHIFT ||
+ !arch_vmap_pmd_supported(prot) ||
+ (end - addr) != PMD_SIZE ||
+ !IS_ALIGNED(addr, PMD_SIZE) ||
+ !IS_ALIGNED(phys_addr, PMD_SIZE) ||
+ (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)))
return 0;
return pmd_set_huge(pmd, phys_addr, prot);
@@ -185,22 +175,12 @@ static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
unsigned int max_page_shift)
{
- if (max_page_shift < PUD_SHIFT)
- return 0;
-
- if (!arch_vmap_pud_supported(prot))
- return 0;
-
- if ((end - addr) != PUD_SIZE)
- return 0;
-
- if (!IS_ALIGNED(addr, PUD_SIZE))
- return 0;
-
- if (!IS_ALIGNED(phys_addr, PUD_SIZE))
- return 0;
-
- if (pud_present(*pud) && !pud_free_pmd_page(pud, addr))
+ if (max_page_shift < PUD_SHIFT ||
+ !arch_vmap_pud_supported(prot) ||
+ (end - addr) != PUD_SIZE ||
+ !IS_ALIGNED(addr, PUD_SIZE) ||
+ !IS_ALIGNED(phys_addr, PUD_SIZE) ||
+ (pud_present(*pud) && !pud_free_pmd_page(pud, addr)))
return 0;
return pud_set_huge(pud, phys_addr, prot);
@@ -236,22 +216,12 @@ static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
unsigned int max_page_shift)
{
- if (max_page_shift < P4D_SHIFT)
- return 0;
-
- if (!arch_vmap_p4d_supported(prot))
- return 0;
-
- if ((end - addr) != P4D_SIZE)
- return 0;
-
- if (!IS_ALIGNED(addr, P4D_SIZE))
- return 0;
-
- if (!IS_ALIGNED(phys_addr, P4D_SIZE))
- return 0;
-
- if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
+ if (max_page_shift < P4D_SHIFT ||
+ !arch_vmap_p4d_supported(prot) ||
+ (end - addr) != P4D_SIZE ||
+ !IS_ALIGNED(addr, P4D_SIZE) ||
+ !IS_ALIGNED(phys_addr, P4D_SIZE) ||
+ (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)))
return 0;
return p4d_set_huge(p4d, phys_addr, prot);
--
2.18.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vmalloc:Merge multiple if conditional sentences
2022-06-23 6:45 [PATCH] vmalloc:Merge multiple if conditional sentences Lv qian
@ 2022-06-23 7:34 ` Muchun Song
2022-06-23 8:12 ` Christophe Leroy
2022-06-23 18:39 ` Uladzislau Rezki
2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2022-06-23 7:34 UTC (permalink / raw)
To: Lv qian; +Cc: akpm, linux-mm, linux-kernel, kernel
On Thu, Jun 23, 2022 at 02:45:27PM +0800, Lv qian wrote:
> Merge multiple if statements to improve code readability
>
Hi Lv qian,
Why do you think it is more readable? For me, the original one
is more readable than yours.
Thanks.
> Signed-off-by: Lv qian <lvqian@nfschina.com>
> ---
> mm/vmalloc.c | 66 ++++++++++++++--------------------------------------
> 1 file changed, 18 insertions(+), 48 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index effd1ff6a4b4..6902a180f8f7 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -135,22 +135,12 @@ static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PMD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pmd_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PMD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PMD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PMD_SIZE))
> - return 0;
> -
> - if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr))
> + if (max_page_shift < PMD_SHIFT ||
> + !arch_vmap_pmd_supported(prot) ||
> + (end - addr) != PMD_SIZE ||
> + !IS_ALIGNED(addr, PMD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PMD_SIZE) ||
> + (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)))
> return 0;
>
> return pmd_set_huge(pmd, phys_addr, prot);
> @@ -185,22 +175,12 @@ static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PUD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pud_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PUD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PUD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PUD_SIZE))
> - return 0;
> -
> - if (pud_present(*pud) && !pud_free_pmd_page(pud, addr))
> + if (max_page_shift < PUD_SHIFT ||
> + !arch_vmap_pud_supported(prot) ||
> + (end - addr) != PUD_SIZE ||
> + !IS_ALIGNED(addr, PUD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PUD_SIZE) ||
> + (pud_present(*pud) && !pud_free_pmd_page(pud, addr)))
> return 0;
>
> return pud_set_huge(pud, phys_addr, prot);
> @@ -236,22 +216,12 @@ static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < P4D_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_p4d_supported(prot))
> - return 0;
> -
> - if ((end - addr) != P4D_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, P4D_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, P4D_SIZE))
> - return 0;
> -
> - if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
> + if (max_page_shift < P4D_SHIFT ||
> + !arch_vmap_p4d_supported(prot) ||
> + (end - addr) != P4D_SIZE ||
> + !IS_ALIGNED(addr, P4D_SIZE) ||
> + !IS_ALIGNED(phys_addr, P4D_SIZE) ||
> + (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)))
> return 0;
>
> return p4d_set_huge(p4d, phys_addr, prot);
> --
> 2.18.2
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vmalloc:Merge multiple if conditional sentences
2022-06-23 6:45 [PATCH] vmalloc:Merge multiple if conditional sentences Lv qian
2022-06-23 7:34 ` Muchun Song
@ 2022-06-23 8:12 ` Christophe Leroy
2022-06-23 18:39 ` Uladzislau Rezki
2 siblings, 0 replies; 4+ messages in thread
From: Christophe Leroy @ 2022-06-23 8:12 UTC (permalink / raw)
To: Lv qian, akpm; +Cc: linux-mm, linux-kernel, kernel
Le 23/06/2022 à 08:45, Lv qian a écrit :
> Merge multiple if statements to improve code readability
Your change reduces the code readability, it doesn't increase it.
>
> Signed-off-by: Lv qian <lvqian@nfschina.com>
> ---
> mm/vmalloc.c | 66 ++++++++++++++--------------------------------------
> 1 file changed, 18 insertions(+), 48 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index effd1ff6a4b4..6902a180f8f7 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -135,22 +135,12 @@ static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PMD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pmd_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PMD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PMD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PMD_SIZE))
> - return 0;
> -
> - if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr))
> + if (max_page_shift < PMD_SHIFT ||
> + !arch_vmap_pmd_supported(prot) ||
> + (end - addr) != PMD_SIZE ||
> + !IS_ALIGNED(addr, PMD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PMD_SIZE) ||
> + (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)))
> return 0;
>
> return pmd_set_huge(pmd, phys_addr, prot);
> @@ -185,22 +175,12 @@ static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PUD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pud_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PUD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PUD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PUD_SIZE))
> - return 0;
> -
> - if (pud_present(*pud) && !pud_free_pmd_page(pud, addr))
> + if (max_page_shift < PUD_SHIFT ||
> + !arch_vmap_pud_supported(prot) ||
> + (end - addr) != PUD_SIZE ||
> + !IS_ALIGNED(addr, PUD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PUD_SIZE) ||
> + (pud_present(*pud) && !pud_free_pmd_page(pud, addr)))
> return 0;
>
> return pud_set_huge(pud, phys_addr, prot);
> @@ -236,22 +216,12 @@ static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < P4D_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_p4d_supported(prot))
> - return 0;
> -
> - if ((end - addr) != P4D_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, P4D_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, P4D_SIZE))
> - return 0;
> -
> - if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
> + if (max_page_shift < P4D_SHIFT ||
> + !arch_vmap_p4d_supported(prot) ||
> + (end - addr) != P4D_SIZE ||
> + !IS_ALIGNED(addr, P4D_SIZE) ||
> + !IS_ALIGNED(phys_addr, P4D_SIZE) ||
> + (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)))
> return 0;
>
> return p4d_set_huge(p4d, phys_addr, prot);
> --
> 2.18.2
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vmalloc:Merge multiple if conditional sentences
2022-06-23 6:45 [PATCH] vmalloc:Merge multiple if conditional sentences Lv qian
2022-06-23 7:34 ` Muchun Song
2022-06-23 8:12 ` Christophe Leroy
@ 2022-06-23 18:39 ` Uladzislau Rezki
2 siblings, 0 replies; 4+ messages in thread
From: Uladzislau Rezki @ 2022-06-23 18:39 UTC (permalink / raw)
To: Lv qian; +Cc: akpm, linux-mm, linux-kernel, kernel
> Merge multiple if statements to improve code readability
>
> Signed-off-by: Lv qian <lvqian@nfschina.com>
> ---
> mm/vmalloc.c | 66 ++++++++++++++--------------------------------------
> 1 file changed, 18 insertions(+), 48 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index effd1ff6a4b4..6902a180f8f7 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -135,22 +135,12 @@ static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PMD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pmd_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PMD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PMD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PMD_SIZE))
> - return 0;
> -
> - if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr))
> + if (max_page_shift < PMD_SHIFT ||
> + !arch_vmap_pmd_supported(prot) ||
> + (end - addr) != PMD_SIZE ||
> + !IS_ALIGNED(addr, PMD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PMD_SIZE) ||
> + (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)))
> return 0;
>
> return pmd_set_huge(pmd, phys_addr, prot);
> @@ -185,22 +175,12 @@ static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < PUD_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_pud_supported(prot))
> - return 0;
> -
> - if ((end - addr) != PUD_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, PUD_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, PUD_SIZE))
> - return 0;
> -
> - if (pud_present(*pud) && !pud_free_pmd_page(pud, addr))
> + if (max_page_shift < PUD_SHIFT ||
> + !arch_vmap_pud_supported(prot) ||
> + (end - addr) != PUD_SIZE ||
> + !IS_ALIGNED(addr, PUD_SIZE) ||
> + !IS_ALIGNED(phys_addr, PUD_SIZE) ||
> + (pud_present(*pud) && !pud_free_pmd_page(pud, addr)))
> return 0;
>
> return pud_set_huge(pud, phys_addr, prot);
> @@ -236,22 +216,12 @@ static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
> phys_addr_t phys_addr, pgprot_t prot,
> unsigned int max_page_shift)
> {
> - if (max_page_shift < P4D_SHIFT)
> - return 0;
> -
> - if (!arch_vmap_p4d_supported(prot))
> - return 0;
> -
> - if ((end - addr) != P4D_SIZE)
> - return 0;
> -
> - if (!IS_ALIGNED(addr, P4D_SIZE))
> - return 0;
> -
> - if (!IS_ALIGNED(phys_addr, P4D_SIZE))
> - return 0;
> -
> - if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
> + if (max_page_shift < P4D_SHIFT ||
> + !arch_vmap_p4d_supported(prot) ||
> + (end - addr) != P4D_SIZE ||
> + !IS_ALIGNED(addr, P4D_SIZE) ||
> + !IS_ALIGNED(phys_addr, P4D_SIZE) ||
> + (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)))
> return 0;
>
> return p4d_set_huge(p4d, phys_addr, prot);
> --
> 2.18.2
>
IMO, it is more complicated to understand.
--
Uladzsislau Rezki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-23 19:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 6:45 [PATCH] vmalloc:Merge multiple if conditional sentences Lv qian
2022-06-23 7:34 ` Muchun Song
2022-06-23 8:12 ` Christophe Leroy
2022-06-23 18:39 ` Uladzislau Rezki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.