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


Groups > linux.kernel > #1229313 > unrolled thread

[PATCH 32/38] fs/cachefiles: remove invalid checks

Started byAndrzej Hajda <a.hajda@samsung.com>
First post2015-09-21 15:40 +0200
Last post2015-09-21 18:20 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 32/38] fs/cachefiles: remove invalid checks Andrzej Hajda <a.hajda@samsung.com> - 2015-09-21 15:40 +0200
    Re: [PATCH 32/38] fs/cachefiles: remove invalid checks David Howells <dhowells@redhat.com> - 2015-09-21 15:50 +0200
      Re: [PATCH 32/38] fs/cachefiles: remove invalid checks David Howells <dhowells@redhat.com> - 2015-09-21 18:20 +0200

#1229313 — [PATCH 32/38] fs/cachefiles: remove invalid checks

FromAndrzej Hajda <a.hajda@samsung.com>
Date2015-09-21 15:40 +0200
Subject[PATCH 32/38] fs/cachefiles: remove invalid checks
Message-ID<qb9u2-83M-1@gated-at.bofh.it>
Unsigned values cannot be lesser than zero.

The problem has been detected using proposed semantic patch
scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 fs/cachefiles/bind.c   | 9 +++------
 fs/cachefiles/daemon.c | 6 +++---
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
index 6af790f..6b50c88 100644
--- a/fs/cachefiles/bind.c
+++ b/fs/cachefiles/bind.c
@@ -39,13 +39,10 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
 	       args);
 
 	/* start by checking things over */
-	ASSERT(cache->fstop_percent >= 0 &&
-	       cache->fstop_percent < cache->fcull_percent &&
-	       cache->fcull_percent < cache->frun_percent &&
-	       cache->frun_percent  < 100);
+	ASSERT(cache->fstop_percent < cache->fcull_percent &&
+	       cache->fcull_percent < cache->frun_percent);
 
-	ASSERT(cache->bstop_percent >= 0 &&
-	       cache->bstop_percent < cache->bcull_percent &&
+	ASSERT(cache->bstop_percent < cache->bcull_percent &&
 	       cache->bcull_percent < cache->brun_percent &&
 	       cache->brun_percent  < 100);
 
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index f601def..996ecd2 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
 	if (test_bit(CACHEFILES_DEAD, &cache->flags))
 		return -EIO;
 
-	if (datalen < 0 || datalen > PAGE_SIZE - 1)
+	if (datalen > PAGE_SIZE - 1)
 		return -EOPNOTSUPP;
 
 	/* drag the command string into the kernel so we can parse it */
@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
 	if (args[0] != '%' || args[1] != '\0')
 		return -EINVAL;
 
-	if (fstop < 0 || fstop >= cache->fcull_percent)
+	if (fstop >= cache->fcull_percent)
 		return cachefiles_daemon_range_error(cache, args);
 
 	cache->fstop_percent = fstop;
@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
 	if (args[0] != '%' || args[1] != '\0')
 		return -EINVAL;
 
-	if (bstop < 0 || bstop >= cache->bcull_percent)
+	if (bstop >= cache->bcull_percent)
 		return cachefiles_daemon_range_error(cache, args);
 
 	cache->bstop_percent = bstop;
-- 
1.9.1

--
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]


#1229358

FromDavid Howells <dhowells@redhat.com>
Date2015-09-21 15:50 +0200
Message-ID<qb9DL-8gq-77@gated-at.bofh.it>
In reply to#1229313
Andrzej Hajda <a.hajda@samsung.com> wrote:

> The problem has been detected using proposed semantic patch
> scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

This is a problem in your test.  There's no actual problem with the code.

> -	ASSERT(cache->fstop_percent >= 0 &&

This is fine.  The compiler should just ignore it.

> -	       cache->fstop_percent < cache->fcull_percent &&
> -	       cache->fcull_percent < cache->frun_percent &&
> -	       cache->frun_percent  < 100);
> +	ASSERT(cache->fstop_percent < cache->fcull_percent &&
> +	       cache->fcull_percent < cache->frun_percent);

You've lost the upper bound check.

> -	if (datalen < 0 || datalen > PAGE_SIZE - 1)
> -	if (fstop < 0 || fstop >= cache->fcull_percent)
> -	if (bstop < 0 || bstop >= cache->bcull_percent)

These are all fine.  The compiler should just ignore them.

David
--
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] | [next] | [standalone]


#1229529

FromDavid Howells <dhowells@redhat.com>
Date2015-09-21 18:20 +0200
Message-ID<qbbYT-3k6-41@gated-at.bofh.it>
In reply to#1229358
David Howells <dhowells@redhat.com> wrote:

> > -	ASSERT(cache->fstop_percent >= 0 &&
> 
> This is fine.  The compiler should just ignore it.

By fine, I mean fine as-is.  It shouldn't need changing.

David
--
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