Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1290019 > unrolled thread

[PATCH] mm/zswap: change incorrect strncmp use to strcmp

Started byDan Streetman <ddstreet@ieee.org>
First post2015-12-12 00:40 +0100
Last post2015-12-12 00:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mm/zswap: change incorrect strncmp use to strcmp Dan Streetman <ddstreet@ieee.org> - 2015-12-12 00:40 +0100
    Re: [PATCH] mm/zswap: change incorrect strncmp use to strcmp Andrew Morton <akpm@linux-foundation.org> - 2015-12-12 00:50 +0100

#1290019 — [PATCH] mm/zswap: change incorrect strncmp use to strcmp

FromDan Streetman <ddstreet@ieee.org>
Date2015-12-12 00:40 +0100
Subject[PATCH] mm/zswap: change incorrect strncmp use to strcmp
Message-ID<qEFs6-2HI-27@gated-at.bofh.it>
Change the use of strncmp in zswap_pool_find_get() to strcmp.

The use of strncmp is no longer correct, now that zswap_zpool_type is
not an array; sizeof() will return the size of a pointer, which isn't
the right length to compare.  We don't need to use strncmp anyway,
because the existing params and the passed in params are all guaranteed
to be null terminated, so strcmp should be used.

Reported-by: Weijie Yang <weijie.yang@samsung.com>
Cc: Seth Jennings <sjennings@variantweb.net>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
---
 mm/zswap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index 025f8dc..bf14508 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -541,6 +541,7 @@ static struct zswap_pool *zswap_pool_last_get(void)
 	return last;
 }
 
+/* type and compressor must be null-terminated */
 static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
 {
 	struct zswap_pool *pool;
@@ -548,10 +549,9 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
 	assert_spin_locked(&zswap_pools_lock);
 
 	list_for_each_entry_rcu(pool, &zswap_pools, list) {
-		if (strncmp(pool->tfm_name, compressor, sizeof(pool->tfm_name)))
+		if (strcmp(pool->tfm_name, compressor))
 			continue;
-		if (strncmp(zpool_get_type(pool->zpool), type,
-			    sizeof(zswap_zpool_type)))
+		if (strcmp(zpool_get_type(pool->zpool), type))
 			continue;
 		/* if we can't get it, it's about to be destroyed */
 		if (!zswap_pool_get(pool))
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1290021

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-12-12 00:50 +0100
Message-ID<qEFBM-2LA-7@gated-at.bofh.it>
In reply to#1290019
On Fri, 11 Dec 2015 18:33:11 -0500 Dan Streetman <ddstreet@ieee.org> wrote:

> Change the use of strncmp in zswap_pool_find_get() to strcmp.
> 
> The use of strncmp is no longer correct, now that zswap_zpool_type is
> not an array; sizeof() will return the size of a pointer, which isn't
> the right length to compare.

whoops

>  We don't need to use strncmp anyway,
> because the existing params and the passed in params are all guaranteed
> to be null terminated, so strcmp should be used.
> 

Thanks, I'll queue this for 4.4.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web