From patchwork Sat Nov 21 00:05:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linda Knippers X-Patchwork-Id: 7672611 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 056A19F1C2 for ; Sat, 21 Nov 2015 00:06:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 172AC20499 for ; Sat, 21 Nov 2015 00:06:20 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 074B0204AE for ; Sat, 21 Nov 2015 00:06:19 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F009C1A1FC7; Fri, 20 Nov 2015 16:06:18 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from g2t4623.austin.hp.com (g2t4623.austin.hp.com [15.73.212.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7ADED1A1FC7 for ; Fri, 20 Nov 2015 16:06:17 -0800 (PST) Received: from g1t6215.austin.hpicorp.net (g1t6215.austin.hpicorp.net [15.67.1.191]) by g2t4623.austin.hp.com (Postfix) with ESMTP id 656751BB; Sat, 21 Nov 2015 00:06:16 +0000 (UTC) Received: from localhost.localdomain (ospra1.fc.hp.com [16.79.38.118]) by g1t6215.austin.hpicorp.net (Postfix) with ESMTP id 50ABC87; Sat, 21 Nov 2015 00:06:14 +0000 (UTC) From: Linda Knippers To: dan.j.williams@intel.com, vishal.l.verma@intel.com Subject: [PATCH 1/3] nfit: Account for table size length variation Date: Fri, 20 Nov 2015 19:05:47 -0500 Message-Id: X-Mailer: git-send-email 1.9.3 In-Reply-To: References: In-Reply-To: References: Cc: linux-nvdimm@lists.01.org, rafael.j.wysocki@intel.com, linux-acpi@vger.kernel.org X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The size of NFIT tables don't necessarily match the size of the data structures that we use for them. For example, the NVDIMM Control Region Structure table is shorter for a device with no block control windows than for a device with block control windows. Other tables, such as Flush Hint Address Structure and the Interleave Structure are variable length by definition. Account for the size difference when comparing table entries by using the actual table size from the table header if it's less than the structure size. Signed-off-by: Linda Knippers --- drivers/acpi/nfit.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/nfit.c b/drivers/acpi/nfit.c index f7dab53..710092a 100644 --- a/drivers/acpi/nfit.c +++ b/drivers/acpi/nfit.c @@ -235,9 +235,13 @@ static bool add_spa(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_spa *nfit_spa; + size_t length = sizeof(*spa); + + if (length > spa->header.length) + length = spa->header.length; list_for_each_entry(nfit_spa, &prev->spas, list) { - if (memcmp(nfit_spa->spa, spa, sizeof(*spa)) == 0) { + if (memcmp(nfit_spa->spa, spa, length) == 0) { list_move_tail(&nfit_spa->list, &acpi_desc->spas); return true; } @@ -261,9 +265,13 @@ static bool add_memdev(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_memdev *nfit_memdev; + size_t length = sizeof(*memdev); + + if (length > memdev->header.length) + length = memdev->header.length; list_for_each_entry(nfit_memdev, &prev->memdevs, list) - if (memcmp(nfit_memdev->memdev, memdev, sizeof(*memdev)) == 0) { + if (memcmp(nfit_memdev->memdev, memdev, length) == 0) { list_move_tail(&nfit_memdev->list, &acpi_desc->memdevs); return true; } @@ -286,9 +294,13 @@ static bool add_dcr(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_dcr *nfit_dcr; + size_t length = sizeof(*dcr); + + if (length > dcr->header.length) + length = dcr->header.length; list_for_each_entry(nfit_dcr, &prev->dcrs, list) - if (memcmp(nfit_dcr->dcr, dcr, sizeof(*dcr)) == 0) { + if (memcmp(nfit_dcr->dcr, dcr, length) == 0) { list_move_tail(&nfit_dcr->list, &acpi_desc->dcrs); return true; } @@ -310,9 +322,13 @@ static bool add_bdw(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_bdw *nfit_bdw; + size_t length = sizeof(*bdw); + + if (length > bdw->header.length) + length = bdw->header.length; list_for_each_entry(nfit_bdw, &prev->bdws, list) - if (memcmp(nfit_bdw->bdw, bdw, sizeof(*bdw)) == 0) { + if (memcmp(nfit_bdw->bdw, bdw, length) == 0) { list_move_tail(&nfit_bdw->list, &acpi_desc->bdws); return true; } @@ -334,9 +350,13 @@ static bool add_idt(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_idt *nfit_idt; + size_t length = sizeof(*idt); + + if (length > idt->header.length) + length = idt->header.length; list_for_each_entry(nfit_idt, &prev->idts, list) - if (memcmp(nfit_idt->idt, idt, sizeof(*idt)) == 0) { + if (memcmp(nfit_idt->idt, idt, length) == 0) { list_move_tail(&nfit_idt->list, &acpi_desc->idts); return true; } @@ -358,9 +378,13 @@ static bool add_flush(struct acpi_nfit_desc *acpi_desc, { struct device *dev = acpi_desc->dev; struct nfit_flush *nfit_flush; + size_t length = sizeof(*flush); + + if (length > flush->header.length) + length = flush->header.length; list_for_each_entry(nfit_flush, &prev->flushes, list) - if (memcmp(nfit_flush->flush, flush, sizeof(*flush)) == 0) { + if (memcmp(nfit_flush->flush, flush, length) == 0) { list_move_tail(&nfit_flush->list, &acpi_desc->flushes); return true; }