From: Matthew Wilcox <willy@infradead.org>
To: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@alien8.de>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] overflow.h: Rename __ab_c_size() to __calc_size()
Date: Fri, 5 Apr 2019 09:25:27 -0700 [thread overview]
Message-ID: <20190405162527.GP22763@bombadil.infradead.org> (raw)
In-Reply-To: <CAGXu5jK6+ZcJQqchySsMicEy-Kd=TFRTE1M_JdhX4TaJDAPiaQ@mail.gmail.com>
On Fri, Apr 05, 2019 at 09:13:24AM -0700, Kees Cook wrote:
> On Fri, Apr 5, 2019 at 1:24 AM Borislav Petkov <bp@alien8.de> wrote:
> >
> > On Fri, Apr 05, 2019 at 10:09:31AM +0200, Rasmus Villemoes wrote:
> > > On 05/04/2019 09.52, Borislav Petkov wrote:
> > > > On Fri, Apr 05, 2019 at 08:26:45AM +0200, Rasmus Villemoes wrote:
> > >
> > > >> It computes a*b+c with overflow checking at each step. calc_size
> > > >> is way too generic and doesn't say anything at all about how the
> > > >> calc(ulation) is done.
> > > >
> > > > Ok, whatever.
> > > >
> > > > Then it would need at least a comment above it to state what it does. I
> > > > don't want to go and parse the macros each time.
> > >
> > > It's an internal helper, and struct_size is fully kernel-doc'ed. But
> > > yeah, a comment wouldn't hurt, and let's rename the parameters so they
> > > match the abc naming.
> > >
> > > diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> > > index 40b48e2133cb..6534a727cadb 100644
> > > --- a/include/linux/overflow.h
> > > +++ b/include/linux/overflow.h
> > > @@ -278,11 +278,15 @@ static inline __must_check size_t
> > > array3_size(size_t a, size_t b, size_t c)
> > > return bytes;
> > > }
> > >
> > > -static inline __must_check size_t __ab_c_size(size_t n, size_t size,
> > > size_t c)
> > > +/*
> > > + * Compute a*b+c, returning SIZE_MAX on overflow. Internal helper for
> > > + * struct_size() below.
> > > + */
>
> May as well make this kern-doc too?
I don't think that's a good idea; we should only document functions we
want other people to use.
> > > +static inline __must_check size_t __ab_c_size(size_t a, size_t b, size_t c)
I could also go for renaming this to __size_ab_plus_c.
For a bit of history ... the origins of this was a system which had
alloc_ab (a * b)
alloc_abc (a * b * c)
alloc_ab_c (a * b + c)
alloc_ab_cd (a * b + c * d)
In the process of getting it upstreamed, it changed from kmalloc_ab_c to
kmalloc(struct_size(...)) and we never bothered to change the name of
__ab_c_size().
next prev parent reply other threads:[~2019-04-05 16:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 4:57 Borislav Petkov
2019-04-05 6:26 ` Rasmus Villemoes
2019-04-05 7:52 ` Borislav Petkov
2019-04-05 8:09 ` Rasmus Villemoes
2019-04-05 8:24 ` Borislav Petkov
2019-04-05 16:13 ` Kees Cook
2019-04-05 16:25 ` Matthew Wilcox [this message]
2019-04-06 9:32 ` Borislav Petkov
2019-04-06 11:32 ` Rasmus Villemoes
2019-04-10 20:40 ` [tip:core/core] overflow.h: Add comment documenting __ab_c_size() tip-bot for Rasmus Villemoes
2019-04-12 11:49 ` tip-bot for Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190405162527.GP22763@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=bp@alien8.de \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®