Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp790325imm; Thu, 5 Jul 2018 08:56:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpepAaFu8MJwMISL60YbtAm3fqVHMqJZavGVlV8kJMNI1RBaP1Iwjv5VJXIzaBqQliAj/3bY X-Received: by 2002:aa7:850b:: with SMTP id v11-v6mr6907255pfn.165.1530806182252; Thu, 05 Jul 2018 08:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530806182; cv=none; d=google.com; s=arc-20160816; b=N3/SLr9XWbRzfHZpsp97mLABHWKkXsK+WiDvwtUDuwGGfIXQ6KNxve3oAuYIMmRUmQ FpPXDDc7103CbXP/IhNcpuDhEcaJ9E5nkaRnqDtny5P2vlZD/TqaQu5up5Xi7IqKH3CI 0d9oE3YMCzy2jbM+czn8/H6TutZxAlMsQi7DEEHvJ5lKbWpBNNPiVrw2tvKLZR0onEBg wiIWrWasbwiYrfU3mubJVbwF1eAR6dxMTW1jJseaj5UN+45jr4jbWTms7qGOvQXEiDki rPf+AknW0woxkvMcbQcaRBpYDdHhYXe2t6t7jWdBscqZGIM+c5anXWyCjvmPahM5LtRv Epqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:dkim-signature:arc-authentication-results; bh=CQISnLtFFrcIGb0vlubPFmY0nXAf1cghUjelEs773PQ=; b=EnqYaWDIZHrJECbMCZATngJQjIW7XEVqh5NGY36AspjU2n3jHR1Tz9zm5nUhacKyCH ii2ie0dWb4jpkU/zvb/fRufkQV24NrS2RRzBldEbNiBtBqKXaExkTKywsHoui4uZit2O nGPlvXTmsAdXENKdVhys8OQ53Oyp+mg9zZ9IaZB0PKuy+Jr8zeXYmK0dOnbobqHV6O0T Wjh8G6vq3I4R71eSUGOb/OOE9QnmWxJI44BwsYgp8H9o7i/M9Gfo65vbx19ZLfT0uQdg cBTFSxvXPX2Zp/b7GK1Sbao51YRdZs50dqInEwLpL7bXPa2F4FuJVefUAtDW1nnMKL3M DKkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=mRT92MEX; dkim=fail header.i=@chromium.org header.s=google header.b=g73WYbUT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17-v6si5981225pgn.308.2018.07.05.08.56.07; Thu, 05 Jul 2018 08:56:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=mRT92MEX; dkim=fail header.i=@chromium.org header.s=google header.b=g73WYbUT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753955AbeGEPzG (ORCPT + 99 others); Thu, 5 Jul 2018 11:55:06 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:34087 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753625AbeGEPzF (ORCPT ); Thu, 5 Jul 2018 11:55:05 -0400 Received: by mail-yb0-f195.google.com with SMTP id e9-v6so3396087ybq.1 for ; Thu, 05 Jul 2018 08:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=CQISnLtFFrcIGb0vlubPFmY0nXAf1cghUjelEs773PQ=; b=mRT92MEXG5r8EekniKNXwrohmmBlw5rm7UkdjcgBOyUsTDRlJFONcuHft/BZ8xRwud nAKXHzve+wP6QgFPAFQfMwvm7PriXqnS9D+EQlhsZ8vQwyr1prRbPq15T6v/VRwHE6nj BBHtUFvLLqc+HFioC9f1eBI7rTWtLDWbt9DXqU6Lw2CVbrYArbAa4760FC0k6gaeLFaI +JXnWD1/NyxXN+1hCL/dTcum3RBtHlV4P3freyPlylX1Y4w3tofdxuuRi5QNdCC4PseZ kC0idDnWMRRQ/gKVW4qwI6eOGUM8+GauAbqPvDM7iLZR4nd8tUQmI6Wh6crnUkTU8ciS Xo+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=CQISnLtFFrcIGb0vlubPFmY0nXAf1cghUjelEs773PQ=; b=g73WYbUTC/StUuV81aNyXgdAK8D0N/9Ba/N4xCfUrwvzi8vGLgGKrLa0TY4/xHC89k nSF6oqPQLHrSn1WceQGSLjEd4KJwHeKce/xH9jtSemoRbclPjMbgsNVf8o6Qqgw9TF8X rmyzbajKK2g0SEqNpTM9x2GEVmV0D/WeJQJQ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=CQISnLtFFrcIGb0vlubPFmY0nXAf1cghUjelEs773PQ=; b=lV/FFQm/TYPOps66IyXaeNn9hqo7h5k4VmiHN1ehOlPM26OVjwm/JFeiw7wM9VtKW3 feNPlCE4myYuBM6M6EIaV/1WPGOBQ/FV4eh7MvqM5rDMZXk4zAyVjTVKwWOW7+HJ/zIc fAcYZvY6/US6k/csskQWE+9Ky1/cgvRXmUtEhZTXzSzn7yTULxKHyfGHQqVx/SpbA+js zhDoqkx7U507nKZJXepIFQUWQL8+fj1Vgdq/YbgYi3XneFmk/6VT4XhyvE+5F3bivghu YEnet+pnWGxLVWP2FBCPk42fF9mH4fRTMxYJzdw4xsoq0DwIls8kNRSEXZY4sskrQGJ1 U6iQ== X-Gm-Message-State: APt69E2lhfayl0hjgaNQebCzHdBnc23S/sAe/utpJWt7KO9CmQXHKl6J Fmd2qHtdUrRUZr1LWPmd9cJIrjVPb5D6PVafh9/9Og== X-Received: by 2002:a25:ce8e:: with SMTP id x136-v6mr3362622ybe.118.1530806104795; Thu, 05 Jul 2018 08:55:04 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:5f51:0:0:0:0:0 with HTTP; Thu, 5 Jul 2018 08:55:04 -0700 (PDT) In-Reply-To: <5a3b3ab7-f5b2-bd66-0587-569411f9af78@daenzer.net> References: <20180704172730.GA33562@beast> <5a3b3ab7-f5b2-bd66-0587-569411f9af78@daenzer.net> From: Kees Cook Date: Thu, 5 Jul 2018 08:55:04 -0700 X-Google-Sender-Auth: 6iIWj1WVP0jdNAr75ZbAfBROGvw Message-ID: Subject: Re: [PATCH] drm/amd/display: Use 2-factor allocator calls To: =?UTF-8?Q?Michel_D=C3=A4nzer?= Cc: Alex Deucher , amd-gfx list , Tony Cheng , LKML , Maling list - DRI developers , Vitaly Prosyak , Harry Wentland Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 5, 2018 at 6:37 AM, Michel D=C3=A4nzer wro= te: > On 2018-07-04 07:27 PM, Kees Cook wrote: >> As already done treewide, switch from open-coded multiplication to >> 2-factor allocation helper. >> >> Signed-off-by: Kees Cook >> --- >> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/d= rivers/gpu/drm/amd/display/modules/color/color_gamma.c >> index 98edaefa2b47..ee69c949bfbf 100644 >> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c >> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c >> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_f= unc_predefined trans, >> kvfree(rgb_regamma); >> } else if (trans =3D=3D TRANSFER_FUNCTION_HLG || >> trans =3D=3D TRANSFER_FUNCTION_HLG12) { >> - rgb_regamma =3D kvzalloc(sizeof(*rgb_regamma) * >> - (MAX_HW_POINTS + _EXTRA_POINTS), >> + rgb_regamma =3D kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, >> + sizeof(*rgb_regamma), >> GFP_KERNEL); >> if (!rgb_regamma) >> goto rgb_regamma_alloc_fail; >> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_tr= ansfer_func_predefined trans, >> kvfree(rgb_degamma); >> } else if (trans =3D=3D TRANSFER_FUNCTION_HLG || >> trans =3D=3D TRANSFER_FUNCTION_HLG12) { >> - rgb_degamma =3D kvzalloc(sizeof(*rgb_degamma) * >> - (MAX_HW_POINTS + _EXTRA_POINTS), >> + rgb_degamma =3D kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, >> + sizeof(*rgb_degamma), >> GFP_KERNEL); >> if (!rgb_degamma) >> goto rgb_degamma_alloc_fail; >> > > Since the values are constant, kvcalloc incurs the overflow checking > overhead for no gain. The way the macros are designed, they'll get entirely optimized away in that case: http://lkml.kernel.org/r/CAGXu5jLw9kMZRkzL_Q7JdyyprntHF6bdVSE_vjyzect3CenDn= g@mail.gmail.com Using this patch means if the code ever changes away from constants, it'll still be safe. And static checkers won't yell about the open-coded multiplication here. So it's only up-sides. :) -Kees --=20 Kees Cook Pixel Security