Re: [PATCH 02/22] Don't expect blocksize to always be 8 when calculating padding

J. Bruce Fields
2010-03-15T23:37:03Z

On Mon, Mar 15, 2010 at 12:02:10PM -0400, Trond Myklebust wrote:
> On Mon, 2010-03-15 at 08:20 -0400, steved@redhat.com wrote:
> > From: Kevin Coffman <kwc@citi.umich.edu>
> >
> > Allow blocksizes other than 8 when calculating padding
> >
> > Signed-off-by: Kevin Coffman <kwc@citi.umich.edu>
> > Signed-off-by: Steve Dickson <steved@redhat.com>
> > ---
> > net/sunrpc/auth_gss/gss_krb5_wrap.c | 5 +----
> > 1 files changed, 1 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c
> > index a0660f5..4c14b0a 100644
> > --- a/net/sunrpc/auth_gss/gss_krb5_wrap.c
> > +++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c
> > @@ -13,10 +13,7 @@
> > static inline int
> > gss_krb5_padding(int blocksize, int length)
> > {
> > - /* Most of the code is block-size independent but currently we
> > - * use only 8: */
> > - BUG_ON(blocksize != 8);
> > - return 8 - (length & 7);
> > + return blocksize - (length & (blocksize - 1));
> > }
> >
>
> What happens if blocksize is not a power of 2?

It's extremely unlikely we'll care about any blocksize other than 8 or
16 bytes, but may as well make this:

return blocksize - (length % blocksize)

--b.