Re: [PATCH 2/2] net/netlabel: Avoid call to genlmsg_cancel

From: Julia Lawall
Date: Fri Jan 28 2011 - 10:29:17 EST


On Fri, 28 Jan 2011, Paul Moore wrote:

> On Fri, 2011-01-28 at 15:58 +0100, Julia Lawall wrote:
> > On Fri, 28 Jan 2011, Paul Moore wrote:
> >
> > > On Fri, 2011-01-28 at 15:17 +0100, Julia Lawall wrote:
> > > > genlmsg_cancel subtracts some constants from its second argument before
> > > > calling nlmsg_cancel. nlmsg_cancel then calls nlmsg_trim on the same
> > > > arguments. nlmsg_trim tests for NULL before doing any computation, but a
> > > > NULL second argument to genlmsg_cancel is no longer NULL due to the initial
> > > > subtraction. Nothing else happens in this execution, so the call to
> > > > genlmsg_cancel is simply unnecessary in this case.
> > > >
> > > > The semantic match that finds this problem is as follows:
> > > > (http://coccinelle.lip6.fr/)
> > > >
> > > > // <smpl>
> > > > @@
> > > > expression data;
> > > > @@
> > > >
> > > > if (data == NULL) { ...
> > > > * genlmsg_cancel(..., data);
> > > > ...
> > > > return ...;
> > > > }
> > > > // </smpl>
> > > >
> > > > Signed-off-by: Julia Lawall <julia@xxxxxxx>
> > >
> > > In all of the cases below, these functions are called multiple times to
> > > generate data chunks (additional netlink attributes) which are appended
> > > to an existing skbuff. I believe that the calls to genlmsg_cancel() are
> > > still needed to help cleanup in the case where the functions fail on the
> > > Nth call.
> > >
> > > If I'm wrong, feel free to enlighten me.
> >
> > Perhaps something is needed, but I don't see how the current code can
> > work. The call is genlmsg_cancel(cb_arg->skb, NULL) in each case.
>
> Ah yes, you're right. You will have to forgive me as it has been quite
> a while since I have looked at NetLabel's netlink code.
>
> You also might consider putting a NULL check in genlmsg_cancel() similar
> to the check nlmsg_trim(); that seems like a worthwhile addition.

OK, I'll do that.

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