public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] fs/xfs: Drop unnecessary NULL test
@ 2009-07-13 10:10 Julia Lawall
  2009-07-14 10:34 ` Olaf Weber
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2009-07-13 10:10 UTC (permalink / raw)
  To: felixb, xfs-masters, xfs, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

The result of container_of should not be NULL.  In particular, in this case
the argument to the enclosing function has passed though INIT_DELAYED_WORK,
which dereferences it, implying that its container cannot be NULL.

The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression x,e;
@@
x = container_of(...)
... when != x = e
* x == NULL
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 fs/xfs/xfs_mru_cache.c              |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_mru_cache.c b/fs/xfs/xfs_mru_cache.c
index 4b0613d..0651ce7 100644
--- a/fs/xfs/xfs_mru_cache.c
+++ b/fs/xfs/xfs_mru_cache.c
@@ -280,8 +280,8 @@ _xfs_mru_cache_reap(
 	xfs_mru_cache_t		*mru = container_of(work, xfs_mru_cache_t, work.work);
 	unsigned long		now, next;
 
-	ASSERT(mru && mru->lists);
-	if (!mru || !mru->lists)
+	ASSERT(mru->lists);
+	if (!mru->lists)
 		return;
 
 	spin_lock(&mru->lock);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] fs/xfs: Drop unnecessary NULL test
  2009-07-13 10:10 [PATCH 1/2] fs/xfs: Drop unnecessary NULL test Julia Lawall
@ 2009-07-14 10:34 ` Olaf Weber
  2009-07-14 12:15   ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Olaf Weber @ 2009-07-14 10:34 UTC (permalink / raw)
  To: Julia Lawall; +Cc: felixb, xfs-masters, xfs, linux-kernel, kernel-janitors

Julia Lawall writes:

> From: Julia Lawall <julia@diku.dk>
> The result of container_of should not be NULL.  In particular, in this case
> the argument to the enclosing function has passed though INIT_DELAYED_WORK,
> which dereferences it, implying that its container cannot be NULL.

Given the defn of container_of() it seems clear that neither its input
pointer nor its result should ever be NULL.

In this particular case, there is a check for NULL and early exit in
xfs_mru_cache_create(), the function that does the INIT_DELAYED_WORK().

Olaf

> The semantic match that finds this problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)

> // <smpl>
> @@
> expression x,e;
> @@
> x = container_of(...)
> ... when != x = e
> * x == NULL
> // </smpl>

> Signed-off-by: Julia Lawall <julia@diku.dk>

Acked-By: Olaf Weber <olaf@sgi.com>

> ---
>  fs/xfs/xfs_mru_cache.c              |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)

> diff --git a/fs/xfs/xfs_mru_cache.c b/fs/xfs/xfs_mru_cache.c
> index 4b0613d..0651ce7 100644
> --- a/fs/xfs/xfs_mru_cache.c
> +++ b/fs/xfs/xfs_mru_cache.c
> @@ -280,8 +280,8 @@ _xfs_mru_cache_reap(
>  	xfs_mru_cache_t		*mru = container_of(work, xfs_mru_cache_t, work.work);
>  	unsigned long		now, next;
 
> -	ASSERT(mru && mru->lists);
> -	if (!mru || !mru->lists)
> +	ASSERT(mru->lists);
> +	if (!mru->lists)
>  		return;
 
>  	spin_lock(&mru->lock);

-- 
Olaf Weber                 SGI               Phone:  +31(0)30-6696752
                           Veldzigt 2b       Fax:    +31(0)30-6696799
Technical Lead             3454 PW de Meern  Vnet:   955-7151
Storage Software           The Netherlands   Email:  olaf@sgi.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] fs/xfs: Drop unnecessary NULL test
  2009-07-14 10:34 ` Olaf Weber
@ 2009-07-14 12:15   ` Julia Lawall
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2009-07-14 12:15 UTC (permalink / raw)
  To: Olaf Weber; +Cc: felixb, xfs-masters, xfs, linux-kernel, kernel-janitors

On Tue, 14 Jul 2009, Olaf Weber wrote:

> Julia Lawall writes:
> 
> > From: Julia Lawall <julia@diku.dk>
> > The result of container_of should not be NULL.  In particular, in this case
> > the argument to the enclosing function has passed though INIT_DELAYED_WORK,
> > which dereferences it, implying that its container cannot be NULL.
> 
> Given the defn of container_of() it seems clear that neither its input
> pointer nor its result should ever be NULL.

container_of just does pointer arithmetic.  The result of that arithmetic 
can be NULL, ie if the argument was obtained from an expression of the 
form &x->f where x was NULL.  But in principle, values should be checked 
for NULL beforehand.

julia

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-14 12:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-13 10:10 [PATCH 1/2] fs/xfs: Drop unnecessary NULL test Julia Lawall
2009-07-14 10:34 ` Olaf Weber
2009-07-14 12:15   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox