lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <37bbda0e0d94d3324210fa807f4061a9e9bd66bc.camel@perches.com>
Date:   Mon, 24 Aug 2020 12:27:10 -0700
From:   Joe Perches <joe@...ches.com>
To:     Andrew Morton <akpm@...ux-foundation.org>,
        Miaohe Lin <linmiaohe@...wei.com>
Cc:     linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/mempool: Add 'else' to split mutually exclusive case

On Mon, 2020-08-24 at 12:18 -0700, Andrew Morton wrote:
> On Mon, 24 Aug 2020 07:53:54 -0400 Miaohe Lin <linmiaohe@...wei.com> wrote:
> 
> > Add else to split mutually exclusive case and avoid some unnecessary check.
> > 
> > --- a/mm/mempool.c
> > +++ b/mm/mempool.c
> > @@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
> >  	/* Mempools backed by slab allocator */
> >  	if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
> >  		__check_element(pool, element, ksize(element));
> > -
> >  	/* Mempools backed by page allocator */
> > -	if (pool->free == mempool_free_pages) {
> > +	else if (pool->free == mempool_free_pages) {
> >  		int order = (int)(long)pool->pool_data;
> >  		void *addr = kmap_atomic((struct page *)element);
> >  
> 
> It doesn't seem to change code generation (compiler is smart), but I
> think it helps readability.

style: braces should be added to the first test.

Perhaps better as:
---
 mm/mempool.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/mempool.c b/mm/mempool.c
index 79bff63ecf27..d0206eab86a4 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -57,12 +57,12 @@ static void __check_element(mempool_t *pool, void *element, size_t size)
 
 static void check_element(mempool_t *pool, void *element)
 {
-	/* Mempools backed by slab allocator */
-	if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
+	if (pool->free == mempool_free_slab ||
+	    pool->free == mempool_kfree) {
+		/* Mempools backed by slab allocator */
 		__check_element(pool, element, ksize(element));
-
-	/* Mempools backed by page allocator */
-	if (pool->free == mempool_free_pages) {
+	} else if (pool->free == mempool_free_pages) {
+		/* Mempools backed by page allocator */
 		int order = (int)(long)pool->pool_data;
 		void *addr = kmap_atomic((struct page *)element);
 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ