Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1175815 > unrolled thread
| Started by | David Herrmann <dh.herrmann@gmail.com> |
|---|---|
| First post | 2015-07-02 10:40 +0200 |
| Last post | 2015-07-02 16:10 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc() David Herrmann <dh.herrmann@gmail.com> - 2015-07-02 10:40 +0200
Re: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc() Sergei Zviagintsev <sergei@s15v.net> - 2015-07-02 16:10 +0200
| From | David Herrmann <dh.herrmann@gmail.com> |
|---|---|
| Date | 2015-07-02 10:40 +0200 |
| Subject | Re: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc() |
| Message-ID | <pHIci-jZ-3@gated-at.bofh.it> |
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.
Thanks
David
> quota = krealloc(c->quota, users * sizeof(*quota),
> GFP_KERNEL | __GFP_ZERO);
> if (!quota)
> --
> 1.8.3.1
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Sergei Zviagintsev <sergei@s15v.net> |
|---|---|
| Date | 2015-07-02 16:10 +0200 |
| Subject | Re: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc() |
| Message-ID | <pHNlE-3HS-31@gated-at.bofh.it> |
| In reply to | #1175815 |
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
> >
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web