Re: [PATCH 7/9 net-next] sunrpc: replace if/BUG by BUG_ON

From: Julia Lawall
Date: Tue Mar 31 2015 - 15:11:40 EST




On Tue, 31 Mar 2015, Fabian Frederick wrote:

>
>
> > On 30 March 2015 at 23:25 "J. Bruce Fields" <bfields@xxxxxxxxxxxx> wrote:
> >
> >
> > Huh, I thought this wasn't recommended:
> >
> >Â Â Â Âhttp://lkml.kernel.org/r/20040828125816.206ef7fa.akpm@xxxxxxxx
> >
> >Â Â Â Â"I'd prefer that we not move code which has side-effects into
> >Â Â Â ÂBUG_ONs"
>
> Thanks for the link, I wasn't aware of that problem. Maybe we should add some
> documentation and fix coccinelle detection then ?

Maybe the comment in the Coccinelle rule could just be made more clear?
The only practical choices are to ignore all function calls and to allow
all fuction calls, since Coccinelle doesn't know which ones have side
effects.

julia

> Regards,
> Fabian
>
> >
> > --b.
> >
> > On Mon, Mar 30, 2015 at 11:13:15PM +0200, Fabian Frederick wrote:
> > > Signed-off-by: Fabian Frederick <fabf@xxxxxxxxx>
> > > ---
> > >Â net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------
> > > net/sunrpc/svc_xprt.c      Â| 3 +--
> > >Â 2 files changed, 4 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/net/sunrpc/auth_gss/svcauth_gss.c
> > > b/net/sunrpc/auth_gss/svcauth_gss.c
> > > index 1095be9..09f8a1c6 100644
> > > --- a/net/sunrpc/auth_gss/svcauth_gss.c
> > > +++ b/net/sunrpc/auth_gss/svcauth_gss.c
> > > @@ -840,11 +840,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct
> > > xdr_buf *buf, u32 seq, struct g
> > >Â Â Â Â Â Â Âreturn stat;
> > >Â Â Âif (integ_len > buf->len)
> > >Â Â Â Â Â Â Âreturn stat;
> > > -Â Âif (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len))
> > > -Â Â Â Â Â ÂBUG();
> > > +Â ÂBUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len));
> > >Â Â Â/* copy out mic... */
> > > -Â Âif (read_u32_from_xdr_buf(buf, integ_len, &mic.len))
> > > -Â Â Â Â Â ÂBUG();
> > > +Â ÂBUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len));
> > >Â Â Âif (mic.len > RPC_MAX_AUTH_SIZE)
> > >Â Â Â Â Â Â Âreturn stat;
> > >Â Â Âmic.data = kmalloc(mic.len, GFP_KERNEL);
> > > @@ -1595,8 +1593,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp)
> > >Â Â ÂBUG_ON(integ_len % 4);
> > >Â Â Â*p++ = htonl(integ_len);
> > >Â Â Â*p++ = htonl(gc->gc_seq);
> > > -Â Âif (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len))
> > > -Â Â Â Â Â ÂBUG();
> > > +Â ÂBUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len));
> > >Â Â Âif (resbuf->tail[0].iov_base == NULL) {
> > >Â Â Â Â Â Â Âif (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE)
> > >Â Â Â Â Â Â Â Â Â Â Âgoto out_err;
> > > diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
> > > index 163ac45..2f82e8b 100644
> > > --- a/net/sunrpc/svc_xprt.c
> > > +++ b/net/sunrpc/svc_xprt.c
> > > @@ -960,8 +960,7 @@ static void svc_delete_xprt(struct svc_xprt *xprt)
> > >Â Â Âstruct svc_deferred_req *dr;
> > >Â
> > >Â Â Â/* Only do this once */
> > > -Â Âif (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags))
> > > -Â Â Â Â Â ÂBUG();
> > > +Â ÂBUG_ON(test_and_set_bit(XPT_DEAD, &xprt->xpt_flags));
> > >Â
> > >Â Â Âdprintk("svc: svc_delete_xprt(%p)\n", xprt);
> > >Â Â Âxprt->xpt_ops->xpo_detach(xprt);
> > > --
> > > 1.9.1
>