public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergei Zviagintsev <sergei@s15v.net>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Daniel Mack <daniel@zonque.org>,
	David Herrmann <dh.herrmann@googlemail.com>,
	Djalal Harouni <tixxdz@opendz.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc()
Date: Thu, 2 Jul 2015 17:06:29 +0300	[thread overview]
Message-ID: <20150702140629.GT17917@localhost.localdomain> (raw)
In-Reply-To: <CANq1E4S-4bRYaQxdP3wwyz35PTELXvPwtKHoDOdzmvx+L6vCVA@mail.gmail.com>

Hi,

On Thu, Jul 02, 2015 at 10:35:30AM +0200, David Herrmann wrote:
> Hi
> 
> On Sun, Jun 28, 2015 at 3:17 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> > Replace the use of max() with explicit and obvious overflow check.
> >
> > Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> > ---
> >  ipc/kdbus/connection.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/ipc/kdbus/connection.c b/ipc/kdbus/connection.c
> > index af044f93c14f..1d44e280eff0 100644
> > --- a/ipc/kdbus/connection.c
> > +++ b/ipc/kdbus/connection.c
> > @@ -668,9 +668,11 @@ int kdbus_conn_quota_inc(struct kdbus_conn *c, struct kdbus_user *u,
> >
> >         id = u ? u->id : KDBUS_USER_KERNEL_ID;
> >         if (id >= c->n_quota) {
> > -               unsigned int users;
> > +               unsigned int users = KDBUS_ALIGN8(id) + 8;
> > +
> > +               if (users < id) /* overflow */
> > +                       users = id;
> >
> > -               users = max(KDBUS_ALIGN8(id) + 8, id);
> 
> To me, the max() looks fine. I mean, it should be obvious that it
> checks for an overflow, right? Otherwise, I'd prefer adding a comment
> instead of the explicit conditional.

Well, at first sight I assumed that there was some clever algorithm
which later had been quick-fixed and so on...

I am not sure about commenting current variant, as CodingStyle
tells us to write obvious code instead of explanations. And if it is
already obvious, then it doesn't need a comment, right? :)

In another letter of this series I mentioned commits af8e2f750985
and ac5c385cc67a from out-of-tree kdbus repo, which show that not all of
these overflow things are obvious for maintainer, not talking about
someone who isn't familiar with the code.

> 
> Thanks
> David
> 
> >                 quota = krealloc(c->quota, users * sizeof(*quota),
> >                                  GFP_KERNEL | __GFP_ZERO);
> >                 if (!quota)
> > --
> > 1.8.3.1
> >

  reply	other threads:[~2015-07-02 14:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-28 13:17 [PATCH RFC 0/5] kdbus: minor quota code improvements Sergei Zviagintsev
2015-06-28 13:17 ` [PATCH RFC 1/5] kdbus: fix typos in kdbus_conn_quota_inc() Sergei Zviagintsev
2015-07-02  8:31   ` David Herrmann
2015-07-02  9:51     ` Sergei Zviagintsev
2015-07-02 10:26       ` David Herrmann
2015-06-28 13:17 ` [PATCH RFC 2/5] kdbus: use standard kernel types in struct kdbus_quota Sergei Zviagintsev
2015-07-02  8:32   ` David Herrmann
2015-06-28 13:17 ` [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc() Sergei Zviagintsev
2015-07-02  8:35   ` David Herrmann
2015-07-02 14:06     ` Sergei Zviagintsev [this message]
2015-06-28 13:17 ` [PATCH RFC 4/5] kdbus: handle WARN_ON cases properly when decrementing quota Sergei Zviagintsev
2015-07-02  8:37   ` David Herrmann
2015-07-02 10:27     ` Sergei Zviagintsev
2015-06-28 13:17 ` [PATCH RFC 5/5] kdbus: improve tests on incrementing quota Sergei Zviagintsev
2015-07-02  8:50   ` David Herrmann
2015-07-02 13:45     ` Sergei Zviagintsev
2015-07-02 14:13       ` Djalal Harouni
2015-07-02 17:47         ` Sergei Zviagintsev
2015-07-04 11:48           ` David Herrmann
2015-07-04 11:42       ` David Herrmann
2015-07-04 13:32         ` Sergei Zviagintsev
2015-07-06 18:48 ` [PATCH RFC 0/5] kdbus: minor quota code improvements David Herrmann
2015-07-07 16:29   ` Sergei Zviagintsev
2015-07-07 22:21     ` Greg Kroah-Hartman

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=20150702140629.GT17917@localhost.localdomain \
    --to=sergei@s15v.net \
    --cc=daniel@zonque.org \
    --cc=dh.herrmann@gmail.com \
    --cc=dh.herrmann@googlemail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tixxdz@opendz.org \
    /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