Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4213089pxb; Sat, 5 Feb 2022 06:52:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCwMKSou1nD3IP8RIVLOMRlBsKMeaBNWNY4v2u+VrrAeRGTAnfY8YhIPI4sfc8rawlqYi2 X-Received: by 2002:a17:902:e852:: with SMTP id t18mr8433313plg.104.1644072760872; Sat, 05 Feb 2022 06:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644072760; cv=none; d=google.com; s=arc-20160816; b=vt2MteNV8bLQ4NpuD2iXEJHw3VIT2FdV1nqsniEn+VgJlEmzB1j5Q8cPHJgulQqiQR RnB6Er+rYaEiVMiIjTDl8ajwY56C5RP3c5H+YFxHVFNXjPqLbtTCwgzDhyGkXCf9JpsV cDgFFbuaCJ+E5D0QGe/adFVe/CXMesoL46qksC3fa2UeORucP1C5JkVyxjUJoam06VPZ WPuN4qx3drXj2Hy9b00owyJyBeodOYhCUIHc0fX/HRejuRZcHCax2VZC9YFgtIVTpRNp SyFTSHOTgEuQlutgaE0LZAzuIWwhQgxHw5oNdMFPlYVbhS0Qc2HXyyvRcRI3LV61VeqA sWTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Q7D7yChC4Ve1A7vyHnhrbMGs/c6jDZuzQHm+kegPE5E=; b=Duif5pfNMrRFoKhD2t3VB7oulxGajpFwcvEMOJihy+tOhNIrM/XSUOiA0vykS0gQ93 GbMK5DwVJ5PAW/+ktpwDyKKNmp2oolhI7j8uGcMvMyUMuKp6gBovoc443puzijrD+oCZ CRk1xq9TkWRJz5BiunAmWU2BrTueoWjmFtT+A7r9wo1lc1EhnpJ7YWuRSSBqH74uPHqL xhFgDYgw4WOidjavd33qFXVZ48G+PGv/mtQMpXCRr3PdrfwD09d19dgjqyVl6K3Pbdcl P2bcFNHfA8eoqaEdkozsafV2WC9NPfi56qMeaIRmov3awxxJeNXp0Y/Haw6hRIGEzWtd dyvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x6si4293939plb.319.2022.02.05.06.52.28; Sat, 05 Feb 2022 06:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379598AbiBEHkx (ORCPT + 99 others); Sat, 5 Feb 2022 02:40:53 -0500 Received: from smtp06.smtpout.orange.fr ([80.12.242.128]:64900 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379589AbiBEHkw (ORCPT ); Sat, 5 Feb 2022 02:40:52 -0500 Received: from pop-os.home ([90.126.236.122]) by smtp.orange.fr with ESMTPA id GFggn1Io9IQAdGFggnd94L; Sat, 05 Feb 2022 08:40:51 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sat, 05 Feb 2022 08:40:51 +0100 X-ME-IP: 90.126.236.122 From: Christophe JAILLET To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Lee Jones , Daniel Thompson , Jingoo Han , Helge Deller Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: [PATCH] backlight: pwm_bl: Avoid open coded arithmetic in memory allocation Date: Sat, 5 Feb 2022 08:40:48 +0100 Message-Id: X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kmalloc_array()/kcalloc() should be used to avoid potential overflow when a multiplication is needed to compute the size of the requested memory. So turn a kzalloc()+explicit size computation into an equivalent kcalloc(). Signed-off-by: Christophe JAILLET --- drivers/video/backlight/pwm_bl.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 8d8959a70e44..c0523a0269ee 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -263,9 +263,8 @@ static int pwm_backlight_parse_dt(struct device *dev, /* read brightness levels from DT property */ if (num_levels > 0) { - size_t size = sizeof(*data->levels) * num_levels; - - data->levels = devm_kzalloc(dev, size, GFP_KERNEL); + data->levels = devm_kcalloc(dev, num_levels, + sizeof(*data->levels), GFP_KERNEL); if (!data->levels) return -ENOMEM; @@ -320,8 +319,8 @@ static int pwm_backlight_parse_dt(struct device *dev, * Create a new table of brightness levels with all the * interpolated steps. */ - size = sizeof(*table) * num_levels; - table = devm_kzalloc(dev, size, GFP_KERNEL); + table = devm_kcalloc(dev, num_levels, sizeof(*table), + GFP_KERNEL); if (!table) return -ENOMEM; /* -- 2.32.0