From patchwork Mon Sep 14 15:14:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 53592 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 6CF842056A for ; Mon, 14 Sep 2015 15:15:16 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf42616496wic.1 for ; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Yp4J8IDb8t9CWdq+Lz+mRzpX+Bj/+aggscI1Fq+Ymq0=; b=L8v33xetcDh35CK2YGdwfGBSBSfQRf6t1iHGizY14gow3eCuxt039ZhEpz/l2tvbS9 v7+EXwJTX0bF+AALXfCnZ+VdMMtD90Ta2IBePsmdtbhwVNwuQTwkj6g0FB90fM0lOZ6t cGIhAaNceWmNze1HV60GdUx3iM8jn8V//Q7Gzg+awxfEnLF9wmWbo4aZUg1POTngg7bF 6PRxpzL5m5DGFlm0ZYDLusO44kcLrEiR3NzlwkQpp+3+kC8sLUC82zLoEWIOLabm8HGq XCpa3Mf6qdMJ+s9rPjl0E1xVaT7E8tUP71/BKHw1/+RE/0gOWtu8abL0i5xKMgpwpDs5 X0wA== X-Gm-Message-State: ALoCoQlvAGdtaraW7Zso5CtFVjzCp+Aykpa73Jn+EyuJ2wjyiPpJ2HjNyfldy8BrQR1IGYO54WNq X-Received: by 10.112.139.65 with SMTP id qw1mr3166401lbb.24.1442243715573; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.11 with SMTP id ca11ls433098lad.38.gmail; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) X-Received: by 10.152.178.162 with SMTP id cz2mr8763039lac.89.1442243715426; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id q6si7476130lah.68.2015.09.14.08.15.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 08:15:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbcao8 with SMTP id ao8so69129444lbc.3 for ; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) X-Received: by 10.152.43.137 with SMTP id w9mr15135516lal.56.1442243715286; Mon, 14 Sep 2015 08:15:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1256359lbq; Mon, 14 Sep 2015 08:15:14 -0700 (PDT) X-Received: by 10.202.95.2 with SMTP id t2mr11610439oib.55.1442243714134; Mon, 14 Sep 2015 08:15:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si6989235oif.131.2015.09.14.08.15.12; Mon, 14 Sep 2015 08:15:14 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754071AbbINPPI (ORCPT + 6 others); Mon, 14 Sep 2015 11:15:08 -0400 Received: from foss.arm.com ([217.140.101.70]:46701 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755580AbbINPPG (ORCPT ); Mon, 14 Sep 2015 11:15:06 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 86F5558C; Mon, 14 Sep 2015 08:15:20 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 692533F318; Mon, 14 Sep 2015 08:15:05 -0700 (PDT) From: Sudeep Holla To: "Rafael J. Wysocki" , linux-acpi@vger.kernel.org Cc: Sudeep Holla , Lorenzo Pieralisi Subject: [PATCH] ACPI: tables: simplify acpi_parse_entries Date: Mon, 14 Sep 2015 16:14:46 +0100 Message-Id: <1442243686-15845-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sudeep.holla@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , acpi_parse_entries passes the table end pointer to the sub-table entry handler. acpi_parse_entries itself could validate the end of an entry against the table end using the length in the sub-table entry. This patch adds the validation of the sub-table entry end using the length field.This will help to eliminate the need to pass the table end to the handlers. Cc: "Rafael J. Wysocki" Signed-off-by: Sudeep Holla --- drivers/acpi/tables.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 17a6fa01a338..145d4f6a1c54 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -217,16 +217,13 @@ acpi_parse_entries(char *id, unsigned long table_size, int entry_id, unsigned int max_entries) { struct acpi_subtable_header *entry; + void *entry_end, *table_end; int count = 0; - unsigned long table_end; if (acpi_disabled) return -ENODEV; - if (!id || !handler) - return -EINVAL; - - if (!table_size) + if (!id || !handler || !table_size) return -EINVAL; if (!table_header) { @@ -234,34 +231,21 @@ acpi_parse_entries(char *id, unsigned long table_size, return -ENODEV; } - table_end = (unsigned long)table_header + table_header->length; + table_end = (void *)table_header + table_header->length; /* Parse all entries looking for a match. */ + entry = (void *)table_header + table_size; + entry_end = (void *)entry + entry->length; - entry = (struct acpi_subtable_header *) - ((unsigned long)table_header + table_size); - - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { + while (entry->length && entry_end <= table_end) { if (entry->type == entry_id && (!max_entries || count < max_entries)) { - if (handler(entry, table_end)) + if (handler(entry, (unsigned long)entry_end)) return -EINVAL; - count++; } - - /* - * If entry->length is 0, break from this loop to avoid - * infinite loop. - */ - if (entry->length == 0) { - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); - return -EINVAL; - } - - entry = (struct acpi_subtable_header *) - ((unsigned long)entry + entry->length); + entry = entry_end; + entry_end = (void *)entry + entry->length; } if (max_entries && count > max_entries) {