[PATCH] x86/mm/pat: Simplify the free_memtype() control flow

From: Ingo Molnar
Date: Thu Nov 21 2019 - 11:58:31 EST



* Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:

> On Mon, 21 Oct 2019, Davidlohr Bueso wrote:
> > int rbt_memtype_check_insert(struct memtype *new,
> > enum page_cache_mode *ret_type)
> > {
> > int err = 0;
> >
> > err = memtype_rb_check_conflict(&memtype_rbroot, new->start, new->end,
> > - new->type, ret_type);
> > -
> > - if (!err) {
> > - if (ret_type)
> > - new->type = *ret_type;
> > -
> > - new->subtree_max_end = new->end;
> > - memtype_rb_insert(&memtype_rbroot, new);
> > - }
> > + new->type, ret_type);
> > + if (err)
> > + goto done;
>
> Please return err here. That goto is pointless.
>
> > +
> > + if (ret_type)
> > + new->type = *ret_type;
> > + memtype_interval_insert(new, &memtype_rbroot);
> > +done:
> > return err;
> > }
>
> Other than that.
>
> Reviewed-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>

Thanks - I rebased the v2 version in x86/mm with this cleanup included.

Two days ago I noticed a similarly quirky control flow in free_memtype()
as well, and fixed it via the patch below.

Ingo

==============>
From: Ingo Molnar <mingo@xxxxxxxxxx>
Date: Tue, 19 Nov 2019 10:18:56 +0100
Subject: [PATCH] x86/mm/pat: Simplify the free_memtype() control flow

Simplify/streamline the quirky handling of the pat_pagerange_is_ram() logic,
and get rid of the 'err' local variable.

Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
---
arch/x86/mm/pat.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index ea7da7e62e17..af049920e59a 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -656,7 +656,6 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,

int free_memtype(u64 start, u64 end)
{
- int err = -EINVAL;
int is_range_ram;
struct memtype *entry;

@@ -671,14 +670,10 @@ int free_memtype(u64 start, u64 end)
return 0;

is_range_ram = pat_pagerange_is_ram(start, end);
- if (is_range_ram == 1) {
-
- err = free_ram_pages_type(start, end);
-
- return err;
- } else if (is_range_ram < 0) {
+ if (is_range_ram == 1)
+ return free_ram_pages_type(start, end);
+ if (is_range_ram < 0)
return -EINVAL;
- }

spin_lock(&memtype_lock);
entry = memtype_erase(start, end);