From patchwork Sat Aug 20 00:48:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Stone X-Patchwork-Id: 9291483 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A261B607FF for ; Sat, 20 Aug 2016 00:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BC682960A for ; Sat, 20 Aug 2016 00:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C92029613; Sat, 20 Aug 2016 00:48:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F38C22960A for ; Sat, 20 Aug 2016 00:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755883AbcHTAsV (ORCPT ); Fri, 19 Aug 2016 20:48:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33374 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754617AbcHTAsU (ORCPT ); Fri, 19 Aug 2016 20:48:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29BB88E384; Sat, 20 Aug 2016 00:48:20 +0000 (UTC) Received: from fidelio.ahs3.com (ovpn-116-175.phx2.redhat.com [10.3.116.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7K0mGwG014247; Fri, 19 Aug 2016 20:48:19 -0400 From: Al Stone To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ahs3@redhat.com, "Rafael J . Wysocki" , Len Brown Subject: [PATCH v2 2/3] ACPI: fix acpi_parse_entries_array() so it traverses all subtables Date: Fri, 19 Aug 2016 18:48:12 -0600 Message-Id: <1471654093-6962-3-git-send-email-ahs3@redhat.com> In-Reply-To: <1471654093-6962-1-git-send-email-ahs3@redhat.com> References: <1471654093-6962-1-git-send-email-ahs3@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 20 Aug 2016 00:48:20 +0000 (UTC) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The acpi_parse_entries_array() function currently returns the very first time there is any error found by one of the callback functions, or if one of the callbacks returns a non-zero value. However, the ACPI subtables being traversed could still have valid entries that could be used by one of the callback functions. And, if the comments are correct, that is what should happen -- always traverse all of the subtables, calling as many of the callbacks as possible. This patch makes the function consistent with its description so that it will properly invoke all callbacks for all matching entries, for all subtables, instead of stopping abruptly as it does today. This does change the semantics of using acpi_parse_entries_array(). In examining all users of the function, none of them rely on the current behavior; that is, there appears to be no assumption that either all subtables are traversed and all callbacks invoked, or that the function will return immediately on any error from a callback. Each callback operates independently. Hence, there should be no functional change due to this change in semantics. Future patches being prepared will rely on this new behavior; indeed, they were written assuming the acpi_parse_entries_array() function operated as its comments describe. For example, a callback that counts the number of subtables of a specific type can now be assured that as many subtables as possible have been enumerated. Signed-off-by: Al Stone Cc: Rafael J. Wysocki Cc: Len Brown --- drivers/acpi/tables.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 3e167b4..0d5d17f 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -246,6 +246,7 @@ acpi_parse_entries_array(char *id, unsigned long table_size, struct acpi_subtable_header *entry; unsigned long table_end; int count = 0; + int errs = 0; int i; if (acpi_disabled) @@ -278,8 +279,10 @@ acpi_parse_entries_array(char *id, unsigned long table_size, if (entry->type != proc[i].id) continue; if (!proc[i].handler || - proc[i].handler(entry, table_end)) - return -EINVAL; + (!errs && proc[i].handler(entry, table_end))) { + errs++; + continue; + } proc[i].count++; break; @@ -305,7 +308,7 @@ acpi_parse_entries_array(char *id, unsigned long table_size, id, proc->id, count - max_entries, count); } - return count; + return errs ? -EINVAL : count; } int __init