mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net/x25: Add missing x25_neigh_put
@ 2008-01-01 21:07 Julia Lawall
  2008-01-02  3:31 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-01-01 21:07 UTC (permalink / raw)
  To: eis, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

The function x25_get_neigh increments a reference count.  At the point of
the second goto out, the result of calling x25_get_neigh is only stored in
a local variable, and thus no one outside the function will be able to
decrease the reference count.  Thus, x25_neigh_put should be called before
the return in this case.


The problem was found using the following semantic match.
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>

@@
type T,T1,T2;
identifier E;
statement S;
expression x1,x2,x3;
int ret;
@@

  T E;
  ...
* if ((E = x25_get_neigh(...)) == NULL)
  S
  ... when != x25_neigh_put(...,(T1)E,...)
      when != if (E != NULL) { ... x25_neigh_put(...,(T1)E,...); ...}
      when != x1 = (T1)E
      when != E = x3;
      when any
  if (...) {
    ... when != x25_neigh_put(...,(T2)E,...)
        when != if (E != NULL) { ... x25_neigh_put(...,(T2)E,...); ...}
        when != x2 = (T2)E
(
*   return;
|
*   return ret;
)
  }
// </smpl>

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

diff -u -p a/net/x25/x25_forward.c b/net/x25/x25_forward.c
--- a/net/x25/x25_forward.c	2008-01-01 09:49:39.000000000 +0100
+++ b/net/x25/x25_forward.c	2008-01-01 14:26:05.000000000 +0100
@@ -118,13 +118,14 @@ int x25_forward_data(int lci, struct x25
 		goto out;
 
 	if ( (skbn = pskb_copy(skb, GFP_ATOMIC)) == NULL){
-		goto out;
+		goto output;
 
 	}
 	x25_transmit_link(skbn, nb);
 
-	x25_neigh_put(nb);
 	rc = 1;
+output:
+	x25_neigh_put(nb);
 out:
 	return rc;
 }

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

* Re: [PATCH] net/x25: Add missing x25_neigh_put
  2008-01-01 21:07 [PATCH] net/x25: Add missing x25_neigh_put Julia Lawall
@ 2008-01-02  3:31 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-01-02  3:31 UTC (permalink / raw)
  To: julia; +Cc: eis, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>
Date: Tue, 1 Jan 2008 22:07:04 +0100 (CET)

> The function x25_get_neigh increments a reference count.  At the point of
> the second goto out, the result of calling x25_get_neigh is only stored in
> a local variable, and thus no one outside the function will be able to
> decrease the reference count.  Thus, x25_neigh_put should be called before
> the return in this case.

Patch applied, thanks.

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

end of thread, other threads:[~2008-01-02  3:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-01 21:07 [PATCH] net/x25: Add missing x25_neigh_put Julia Lawall
2008-01-02  3:31 ` David Miller

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

all inboxes | Powered by JetHome®