lkml.org 
[lkml]   [2015]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH RFC 3/5] kdbus: do explicit overflow check in kdbus_conn_quota_inc()
From
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
>


\
 
 \ /
  Last update: 2015-07-02 11:01    [W:0.463 / U:2.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site