Patchwork bridge: Fix return value of br_multicast_add_group()

login
register
mail settings
Submitter Tobias Klauser
Date Dec. 9, 2010, 2:02 p.m.
Message ID <1291903356-30618-1-git-send-email-tklauser@distanz.ch>
Download mbox | patch
Permalink /patch/74893/
State Superseded
Delegated to: David Miller
Headers show

Comments

Tobias Klauser - Dec. 9, 2010, 2:02 p.m.
If br_multicast_new_group returns NULL, we would return 0 (no error) to
the caller, which is not what we want. Instead we should return -ENOMEM
in this case.

Also replace IS_ERR(x) || !x by IS_ERR_OR_NULL(x)

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 net/bridge/br_multicast.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Stephen Hemminger - Dec. 9, 2010, 4:29 p.m.
On Thu,  9 Dec 2010 15:02:36 +0100
Tobias Klauser <tklauser@distanz.ch> wrote:

> If br_multicast_new_group returns NULL, we would return 0 (no error) to
> the caller, which is not what we want. Instead we should return -ENOMEM
> in this case.
> 
> Also replace IS_ERR(x) || !x by IS_ERR_OR_NULL(x)
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
>  net/bridge/br_multicast.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
> index 326e599..d4e1e81 100644
> --- a/net/bridge/br_multicast.c
> +++ b/net/bridge/br_multicast.c
> @@ -713,8 +713,11 @@ static int br_multicast_add_group(struct net_bridge *br,
>  
>  	mp = br_multicast_new_group(br, port, group);
>  	err = PTR_ERR(mp);
> -	if (unlikely(IS_ERR(mp) || !mp))
> +	if (IS_ERR_OR_NULL(mp)) {
> +		if (!mp)
> +			err = -ENOMEM;
>  		goto err;
> +	}
>  
>  	if (!port) {
>  		hlist_add_head(&mp->mglist, &br->mglist);

I would rather fix br_multicast_new_group so it never returns
NULL. Instead return PTR_ERR(-ENOMEM) on out of memory.
Tobias Klauser - Dec. 9, 2010, 6:53 p.m.
On 2010-12-09 at 17:29:24 +0100, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> On Thu,  9 Dec 2010 15:02:36 +0100
> Tobias Klauser <tklauser@distanz.ch> wrote:
> 
> > If br_multicast_new_group returns NULL, we would return 0 (no error) to
> > the caller, which is not what we want. Instead we should return -ENOMEM
> > in this case.
> > 
> > Also replace IS_ERR(x) || !x by IS_ERR_OR_NULL(x)
> > 
> > Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> > ---
> >  net/bridge/br_multicast.c |    5 ++++-
> >  1 files changed, 4 insertions(+), 1 deletions(-)
> > 
> > diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
> > index 326e599..d4e1e81 100644
> > --- a/net/bridge/br_multicast.c
> > +++ b/net/bridge/br_multicast.c
> > @@ -713,8 +713,11 @@ static int br_multicast_add_group(struct net_bridge *br,
> >  
> >  	mp = br_multicast_new_group(br, port, group);
> >  	err = PTR_ERR(mp);
> > -	if (unlikely(IS_ERR(mp) || !mp))
> > +	if (IS_ERR_OR_NULL(mp)) {
> > +		if (!mp)
> > +			err = -ENOMEM;
> >  		goto err;
> > +	}
> >  
> >  	if (!port) {
> >  		hlist_add_head(&mp->mglist, &br->mglist);
> 
> I would rather fix br_multicast_new_group so it never returns
> NULL. Instead return PTR_ERR(-ENOMEM) on out of memory.

Ok, I'll change that and send an updated patch.

Thanks a lot
Tobias
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 326e599..d4e1e81 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -713,8 +713,11 @@  static int br_multicast_add_group(struct net_bridge *br,
 
 	mp = br_multicast_new_group(br, port, group);
 	err = PTR_ERR(mp);
-	if (unlikely(IS_ERR(mp) || !mp))
+	if (IS_ERR_OR_NULL(mp)) {
+		if (!mp)
+			err = -ENOMEM;
 		goto err;
+	}
 
 	if (!port) {
 		hlist_add_head(&mp->mglist, &br->mglist);