Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp1444012rdb; Sat, 26 Aug 2023 02:50:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGo3vZwfHZoNu8FWguPLlsl7K2oK+ewN7cIPXiRQwOwkwt7Uw7v5MeIXYQRzhRAWZ4LvDCz X-Received: by 2002:a17:906:300c:b0:9a1:6252:16a0 with SMTP id 12-20020a170906300c00b009a1625216a0mr15362482ejz.46.1693043444900; Sat, 26 Aug 2023 02:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693043444; cv=none; d=google.com; s=arc-20160816; b=zpkW5Lk7Nc1c4gmtN6QWwC/5norH3/5xiezDyY5t76PBWj0e0xssWdG/X1mp/pB5Dj IgpJSvj3jjvZemqFjrcJPn2Qv05549ZPs73Og9D2PMD1pq8WMl7eTmNWitkN25Xw7QqR FD6lsrtpoLp758Kj/CNl3bMUALmCsOK3913qLLsbnpSVw2BNmY5pyBGxewDfzVLk3IxQ SyKlkNP/ShfI0c54O9KrHZHGqnzuW28PgQakRUHSffgOeqNuR7g2AMbBL5UxA8yXiPdO o5E6qkFcoAhnfZ+AwXRdvQ6erjS2ZiSwZSKn/PoxBDDCQBuOY5gI2aI+L9t7P1C2Proa 5mXw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0tiSPs6tf/71glGIhHIYNMi/x4Z7BY11RIj2P5G186w=; fh=GXX+fv+9/KxNDsyU79Hcm/XSMDFg/BuK5TcR5PwU7vM=; b=yw+Yr6rnK7FUVgDcSy9tNN/axljD0ejR/UR/X3IjBaOpowjDnVllSr/fVgwVFItcKo 78+m/+jQUefEjjp0bMtjjrVv2sAGhCAiLhR4FpbcElBWOGoNbzLlT2Eoi5EhEihn/e92 wtaHTYATSfLIOojh0KVI7FuhXeLzfnQEg+HPKKTEMUgYvdhUIfUSfdDqsNPby499pLyl 5eJJQn0XpypP2M4nFuYWlAzEuJYFQoZvh+/e2e5B1lt5NjREuo5saB/H2z7Z/Fot8Ea+ lpsjXdp7U8SngU3OJaZ/9pYCaS9v65IweNYuQjP+8WydpaKebZBYGyxeETC5ZvDA1B8I Rv3Q== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u13-20020a170906b10d00b0099bd0683c1esi1870913ejy.949.2023.08.26.02.50.03; Sat, 26 Aug 2023 02:50:44 -0700 (PDT) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231901AbjHZHWO (ORCPT + 99 others); Sat, 26 Aug 2023 03:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbjHZHVm (ORCPT ); Sat, 26 Aug 2023 03:21:42 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4846E2139; Sat, 26 Aug 2023 00:21:35 -0700 (PDT) Received: from dggpeml500003.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RXp9q2qVBz1L9Vf; Sat, 26 Aug 2023 15:19:59 +0800 (CST) Received: from huawei.com (10.175.103.91) by dggpeml500003.china.huawei.com (7.185.36.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 15:21:31 +0800 From: Yu Liao To: , , , , CC: , , , , , , Subject: [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper Date: Sat, 26 Aug 2023 15:16:54 +0800 Message-ID: <20230826071654.564372-2-liaoyu15@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230826071654.564372-1-liaoyu15@huawei.com> References: <20230826071654.564372-1-liaoyu15@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500003.china.huawei.com (7.185.36.200) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: Yu Liao Reviewed-by: Dave Jiang --- drivers/acpi/nfit/core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 305f590c54a8..2f7217600307 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -712,8 +712,7 @@ static bool add_spa(struct acpi_nfit_desc *acpi_desc, } } - nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof_spa(spa), - GFP_KERNEL); + nfit_spa = devm_kzalloc(dev, struct_size(nfit_spa, spa, 1), GFP_KERNEL); if (!nfit_spa) return false; INIT_LIST_HEAD(&nfit_spa->list); @@ -741,7 +740,7 @@ static bool add_memdev(struct acpi_nfit_desc *acpi_desc, return true; } - nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev), + nfit_memdev = devm_kzalloc(dev, struct_size(nfit_memdev, memdev, 1), GFP_KERNEL); if (!nfit_memdev) return false; @@ -812,8 +811,7 @@ static bool add_dcr(struct acpi_nfit_desc *acpi_desc, return true; } - nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr), - GFP_KERNEL); + nfit_dcr = devm_kzalloc(dev, struct_size(nfit_dcr, dcr, 1), GFP_KERNEL); if (!nfit_dcr) return false; INIT_LIST_HEAD(&nfit_dcr->list); @@ -855,7 +853,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt) { if (idt->header.length < sizeof(*idt)) return 0; - return sizeof(*idt) + sizeof(u32) * idt->line_count; + return struct_size(idt, line_offset, idt->line_count); } static bool add_idt(struct acpi_nfit_desc *acpi_desc, -- 2.25.1