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: 57092 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp173363lbb; Fri, 20 Nov 2015 16:06:25 -0800 (PST) X-Received: by 10.68.189.1 with SMTP id ge1mr22480358pbc.42.1448064384452; Fri, 20 Nov 2015 16:06:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si1932771pfa.221.2015.11.20.16.06.24; Fri, 20 Nov 2015 16:06:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760345AbbKUAGU (ORCPT + 6 others); Fri, 20 Nov 2015 19:06:20 -0500 Received: from g2t4623.austin.hp.com ([15.73.212.78]:59901 "EHLO g2t4623.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759991AbbKUAGR (ORCPT ); Fri, 20 Nov 2015 19:06:17 -0500 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 Cc: linux-nvdimm@lists.01.org, linux-acpi@vger.kernel.org, jmoyer@redhat.com, toshi.kani@hpe.com, elliott@hpe.com, rafael.j.wysocki@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: Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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(-) -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; }