Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1002324ybt; Fri, 19 Jun 2020 21:13:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx205jfA3o08IU7fNcL33ksbA1W7cWT50FWsMspCdSzImOZNT3fcKh8QBkzthT5vJwT88Ki X-Received: by 2002:aa7:cb4a:: with SMTP id w10mr6282764edt.46.1592626431242; Fri, 19 Jun 2020 21:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592626431; cv=none; d=google.com; s=arc-20160816; b=Vd8qpHMdIoBq3mX8E31tHNU+sgDxd10jNIznzGGMfHvXN202+qnrT1j/wjVifti4+G uWmbk0pl65dVhjx7e/SDoKNf5ER3JG74UJQNZeYecrx7riCrFQu8cPZ8mUhSnPiM06dJ e5/BJLOVNyHk2zr7ivmsPZpPyCzP8g9dIyOaZya4/S0b9v6eel/AuVvJqR5vGpOKLkVI iAV+hGlsA5MqN/0d0r51qNp1tfzFJpqFB2BP/QAXiYVz+gxLx0O/au3p6LP0mjBsfjK/ Ykq1aki8H5dwLMaObkPDVmGDgS+9iY/TLrRId9X9+ZUkfb+Gn5iVP9DawneJwTg6Z8ju 2Iig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=NNL6Pp/dubIVXcxGLgSSK0jYQF6ad7aItdqe8dYV1qE=; b=Ms6m/uyhD1NBwlcwGnBF3x7qV5gfxcbNGe/x7MnXDs8lXzEcLrm5+iQYG1MR3UWtEL oWAHCGpGxmEs8+WC0+ECPQ/cIt8XYgAYeFCJuQsvNgYpEMJJ/sNYajwYQjexz6GnMhwj KJKrh1pn0l2mUHeA7SwH2x5/RJm+j9oRajOEpeT4c12ttqKe3rgRsrI7r7eiE1dx+YSw AYOy75NofOHxTw71kuKvtozEfy1BwHFxVcV4Ep+NIelQqCE4kim2091o+UkXmjsW2Gg1 t98Lz44WFDttb6V1omnWJLSLrpWu3hrhVhU02stp7R1jPtiL9rp+wt/Rg3PT5zNwJvXs lvvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QDZweeUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qw12si4890870ejb.492.2020.06.19.21.13.29; Fri, 19 Jun 2020 21:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QDZweeUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731941AbgFSRPt (ORCPT + 99 others); Fri, 19 Jun 2020 13:15:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:47302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730935AbgFSRPs (ORCPT ); Fri, 19 Jun 2020 13:15:48 -0400 Received: from embeddedor (unknown [189.207.59.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E1372083B; Fri, 19 Jun 2020 17:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592586947; bh=+FyC0mh1S4XX7z9Bu1BeiFerSfQCPVxis2shYUF8fQw=; h=Date:From:To:Cc:Subject:From; b=QDZweeUl/sMm1oC/exF1AxZFPz74hmvE1UK3P4+gxKBOfxa3YpcvC5ZTRrP1a3ZaE knb8+kpYwMt3g2MvH33Jm+9s+NBPWxSSl4pOzYZVIJ97dO/3hPjb7MAYA+wCcFDvWW BxpG75TKZIRbLQx3YwutyPixN7BDC5sVe70wanO4= Date: Fri, 19 Jun 2020 12:21:12 -0500 From: "Gustavo A. R. Silva" To: Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] nvdimm/region: Use struct_size() in kzalloc() Message-ID: <20200619172112.GA31702@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This issue was found with the help of Coccinelle and, audited and fixed manually. Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83 Signed-off-by: Gustavo A. R. Silva --- drivers/nvdimm/region_devs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 4502f9c4708d..8365fb1a9114 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1063,8 +1063,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, struct nd_blk_region *ndbr; ndbr_desc = to_blk_region_desc(ndr_desc); - ndbr = kzalloc(sizeof(*ndbr) + sizeof(struct nd_mapping) - * ndr_desc->num_mappings, + ndbr = kzalloc(struct_size(ndbr, nd_region.mapping, ndr_desc->num_mappings), GFP_KERNEL); if (ndbr) { nd_region = &ndbr->nd_region; -- 2.27.0