Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp871442rdb; Tue, 30 Jan 2024 00:36:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEevt0E0Vw8neA24G4HW49A0G7AHo6c3hIVvOIz67XrWAFfyQI0uekemMBd5w8SpsCjJF9a X-Received: by 2002:a17:906:28c4:b0:a26:90a0:696e with SMTP id p4-20020a17090628c400b00a2690a0696emr5967938ejd.41.1706603769114; Tue, 30 Jan 2024 00:36:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706603769; cv=pass; d=google.com; s=arc-20160816; b=KAd17SNbUDmUEIerjK49PRkDpj/aPx+WovcCiPjh8V/26VkEf51s09ibMC6EOjYHBs DHkgcc9XBZmxbMwcl4mnfCK9vwpwX4B5txFnsX7AyTgdz6uNr8sYJISfJDlIMXrbsoKh sZaQ3uiWXL52LxiVVZgutafy6horBqOn3L9sXp+2O7rMmN1oVzXLds6OtMyxOOnSDWsd 05hnjLl4fpY6qDAofmeOm3hNQ0nBlqNdKs54JNQKSP2FWxweU593E5t9nKMDGT8HbS+x +mpaD99txw93FaZx2MBOacVIq4c8Jeec44g5VM7drf52oMk+cVVzE5pBWok+O+nRYRMA XCUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JasWBnhzaBBwL8IWjrLvC1xDNgyb4YEKl491mVYdN2Q=; fh=yxIEwdp5evhiHO6ykUAXfdY5yyuoP+eoISt10tCiEFU=; b=q0Pv6PpHg1K4rEJAMWHmtMIRhqzQxD/E4qcRCIGretZi0C8KN6urXldI9gAxxR8A5g dGoqtwxJvSEyDdIe+6l/v1NgSf1lomo5KQ86xNH8u74AzTqIbyeTeZn0mTR8ZxXOxcXn Tne/+ECDwI+vgFk2scnxh/Qz89Vg3hH9gx+97NaXbLSeW7TjttWydde5LzJFxxGniFXC R1ZsT4gfHsxVdR4ZfusZERNaKBDUUmlCJUREnvVhYlgCUVq/7G1JGGp6v9BdvqL9aYhv X84faoZ8EOkH8TQfoZ8MtxxRFhdVoZHXRMfnhoRJKo//dRqcH8Iblunezn1UleDSEUXl ssKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=stIGp61e; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44145-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ka23-20020a170907991700b00a35ed50c3b6si1029737ejc.1007.2024.01.30.00.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:36:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=stIGp61e; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44145-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D97CC1F2B2D2 for ; Tue, 30 Jan 2024 08:36:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44BFB56B70; Tue, 30 Jan 2024 08:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="stIGp61e" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60A683F9E7; Tue, 30 Jan 2024 08:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603742; cv=none; b=XLI5qXr8NjnAvSpN0hnKdb443mDfW+8WUo46anBGgvgN8bpQrLSD5qzhDbh1D8UxZNbeh5VFA5axPyiBPcIAahXafJMRR66AZjOhAoEEPXZQynOTHf07OS9ajk3r8YbA9afWFfdnmF22nP6r9bUlN29nssbwdbSo1HNhaE9yqOk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603742; c=relaxed/simple; bh=N0kg3YjJSti8U3lrmYd2PIZvWMjVDyjRAbAKeR5/VQI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WIiw0lR3SVF2oMvgnlikhPPZt9eaU3zmG67COdptYXclJ9WI18AB00UQvb9QDNYlafkeivBeIYR33vP4FTdbRVBGJjhe0aktbXi9fZMS7Qlo7pQu1yQz6HDLkAIG0/lfDazyLYYtvEbWOV9Bi4F28HDYCveJULb5ZzPkYMZUZOE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=stIGp61e; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D69BC433C7; Tue, 30 Jan 2024 08:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706603741; bh=N0kg3YjJSti8U3lrmYd2PIZvWMjVDyjRAbAKeR5/VQI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=stIGp61ecKDJCp1aKRrgyOnjdbW+DOKiNvEnjoYFJMS3mAwrPVRuj/Y9kajPVMGmf TR6tosqeQN0mmn/BsIWJvq69h6P937eA+qeluljHRzp/yik8a/kiiXPx+0eipPTHji 9cAQ8Mv+DpGyjxnJI9UQIms/uGRXSjIdpnggugM//gmoGIQCV8ZcAJwtjnWl2h7zXI zRDs2FwSPcer4UfsteWT/XqwWQidtlDu/DXJ77yYe6miDSvUmD2OZ2VDw1IZVj7UVI 160/yowj4poODko5QTeP0qaC9TE4u9bcCcDDI0ZzIcx56f/KCu8J/9kJESmmmOP+R1 UnzJlR/YtXBaQ== Date: Tue, 30 Jan 2024 14:05:33 +0530 From: Manivannan Sadhasivam To: Erick Archer Cc: Manivannan Sadhasivam , Jeffrey Hugo , "Rafael J. Wysocki" , Dan Carpenter , Greg Kroah-Hartman , Alex Elder , "Gustavo A. R. Silva" , linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] bus: mhi: ep: Use kcalloc() instead of kzalloc() Message-ID: <20240130083533.GN32821@thinkpad> References: <20240128112722.4334-1-erick.archer@gmx.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240128112722.4334-1-erick.archer@gmx.com> On Sun, Jan 28, 2024 at 12:27:22PM +0100, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1]. > > Here the multiplication is obviously safe because the "event_rings" > member never can have a value greater than 255 (8 bits). This member > is set twice using always FIELD_GET: > > mhi_cntrl->event_rings = FIELD_GET(MHICFG_NER_MASK, regval); > mhi_cntrl->event_rings = FIELD_GET(MHICFG_NER_MASK, regval); > > And the MHICFG_NER_MASK macro defines the 8 bits mask that guarantees > a maximum value of 255. > > However, using kcalloc() is more appropriate [1] and improves > readability. This patch has no effect on runtime behavior. > > Link: https://github.com/KSPP/linux/issues/162 [1] > Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] > Reviewed-by: Gustavo A. R. Silva > Signed-off-by: Erick Archer Reviewed-by: Manivannan Sadhasivam - Mani > --- > Changes in v2: > - Add more info in the commit message to better explain the change. > (Dan Carpenter) > - Add the "Reviewed-by:" tag. > > Previous versions: > v1 - https://lore.kernel.org/linux-hardening/20240120152518.13006-1-erick.archer@gmx.com/ > --- > drivers/bus/mhi/ep/main.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c > index 65fc1d738bec..8d7a4102bdb7 100644 > --- a/drivers/bus/mhi/ep/main.c > +++ b/drivers/bus/mhi/ep/main.c > @@ -1149,8 +1149,9 @@ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl) > mhi_ep_mmio_mask_interrupts(mhi_cntrl); > mhi_ep_mmio_init(mhi_cntrl); > > - mhi_cntrl->mhi_event = kzalloc(mhi_cntrl->event_rings * (sizeof(*mhi_cntrl->mhi_event)), > - GFP_KERNEL); > + mhi_cntrl->mhi_event = kcalloc(mhi_cntrl->event_rings, > + sizeof(*mhi_cntrl->mhi_event), > + GFP_KERNEL); > if (!mhi_cntrl->mhi_event) > return -ENOMEM; > > -- > 2.25.1 > -- மணிவண்ணன் சதாசிவம்