Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2152978rdb; Mon, 20 Nov 2023 03:42:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj17GLi2e4V8b5p6Ow46FLGuvECijRvSxyhAw0A+vkEua8T3WKjtLw6yLvfyO2hJQcuDhx X-Received: by 2002:a05:6808:e88:b0:3b5:6bf3:c4cc with SMTP id k8-20020a0568080e8800b003b56bf3c4ccmr8327637oil.29.1700480565212; Mon, 20 Nov 2023 03:42:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700480565; cv=none; d=google.com; s=arc-20160816; b=ds/9reLQ/ddZYkLuBKBiF4J1NRQmATw6hwwi3ihIM9y0YDO+xiLuX6mCxnN0jaVUBs WsTkbz98GmT2GsVsOJFMkD/mg1wMMB7wx+2K/NuEZiKMAdVC/K6UZlHo3llSku9P5ntY 6udVgi/uHBf9+eoy36Xwcq8X72L0Cz2BD7eNtVxe0bCuILCuhSYC+JizLNDC3FDh96cN mYx36PpPceB0nwg0R90Be7aXYOSbCFE6RAz4rdLtxOFgheMtobdpBzmJzWBBLpabuNBO mQBZjqhKSHa3S91UKe+ORocFuG1pP7uZn/+v937lzzjFssWjcFl5ro+AdLDJw08lDmRO orjA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=V1guMx9hj3Dnab92EYIslORuUgAICHvH5VtGffdWtLk=; fh=V3OVXkngcbQ8/8/9vdZIBGRZEyi0UZX4Uk9RtAcrg74=; b=n/FNOr4A9rWdR3Xfak1HDJVK6T19ry+zEGhiyxRh+QvihSx9/y2jIIt/b+BhTuBDzI D57olYzeMIvN0rqcAtVmOWzs32PT/NXwABCDm+1lcSXCLJrj+hOLOj+I9gXueh9gvu58 EF+G4IuCb9aEfmcgppSWSl0ELQN3YKnMhxsgej7uxctr2WJFxjAwHaeUaS+a0FyeRqR/ c3KIuxRmD6JB2CLabi9rVF+NyWzKNyqoR1ajoSas940K6XwP1XEglB9iLYC2K4Zg7Rae 8qkl+LGd3WnCMfBGOR6SQjg6cKL/vDM7Az6A9sX5waIianSd2P3H2XGQz+gKNYUMxDNF YHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gIFZwA0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b16-20020a63cf50000000b005b7160263f2si8005022pgj.154.2023.11.20.03.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:42:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gIFZwA0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3FF3280A2228; Mon, 20 Nov 2023 03:42:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbjKTLmY (ORCPT + 99 others); Mon, 20 Nov 2023 06:42:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbjKTLmX (ORCPT ); Mon, 20 Nov 2023 06:42:23 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE119C; Mon, 20 Nov 2023 03:42:19 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1cc68c1fac2so37381845ad.0; Mon, 20 Nov 2023 03:42:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700480539; x=1701085339; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=V1guMx9hj3Dnab92EYIslORuUgAICHvH5VtGffdWtLk=; b=gIFZwA0K5/MKAb7JICdh1SolFlR47t9EKgWqcM7cUTLt3GvLsdUhOMj1NqA5ph/5XC Ith7vnud1hAaHuU09S0pfHYSh3/r/DWNaN4VwIFTMurRkhddgIEzobMwo8CQpZOYm3Il ZAALo2qK01nOohng+0zEsZ8xQuQd8dbJja6V3eXpaCw+ENjxElmOyMpgvQ1IjsWbCRRT lBq/XAV9OXm4uH4BR5pVzAHugfpVkbbDHtw1oNNqS1ZHZZZhTo08Wz67ys0gfloj6VM5 eqAFLyr7mwNGGhHSYFS9Ljcef70lMTYfREAViHocifGI2VBCKe6tDi7MKu7AyiParKJh SH5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700480539; x=1701085339; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V1guMx9hj3Dnab92EYIslORuUgAICHvH5VtGffdWtLk=; b=WyGngqxauHllOPKsHEcTSfbkbplB9f+LJZ4uEUW7fdWwJ3sM27SEe9bCryvCaL1IFR vtlEbVPHCAdH5rOIX07M9tHNH6c/l70sMi7tmx6SJOiBncjM6RlwoU5iHugymD05OZDh fVBMPW8GwYK1kr4jQaIABFHs7zG79Buy1+bWE6B1uU/NSsFHoC51IaO0yC5/lsQwDjWX EEGfvxB8kBhzigvWq55/RR6st5t6B75Gj4q1lDyD4Ie12zCYgePMaHBv3ma1c3beWJo5 oq4jYy3V1H5Z9VdKa0YCAxg+JUxcW8sezpsYdFHVT5/j4lumknyz33a3cWa8lF4kvHJj 9q3w== X-Gm-Message-State: AOJu0YwT7NNkA5bTzTk6l35eA4SHTnEscjyzrTOp59yz4jSs/AwFrz91 zrP1cJoz1zDN0Bt8DxFUbCw= X-Received: by 2002:a17:902:d4cb:b0:1cc:29b5:a2b7 with SMTP id o11-20020a170902d4cb00b001cc29b5a2b7mr10115355plg.51.1700480539081; Mon, 20 Nov 2023 03:42:19 -0800 (PST) Received: from code.. ([144.202.108.46]) by smtp.gmail.com with ESMTPSA id q15-20020a170902dacf00b001cf57827d69sm3024922plx.87.2023.11.20.03.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:42:18 -0800 (PST) From: Yuntao Wang To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH] ACPI: Correct and clean up the logic of acpi_parse_entries_array() Date: Mon, 20 Nov 2023 19:41:43 +0800 Message-ID: <20231120114143.95305-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:42:34 -0800 (PST) The original intention of acpi_parse_entries_array() is to return the number of all matching entries on success. This number may be greater than the value of the max_entries parameter. When this happens, the function will output a warning message, indicating that `count - max_entries` matching entries remain unprocessed and have been ignored. However, commit 4ceacd02f5a1 ("ACPI / table: Always count matched and successfully parsed entries") changed this logic to return the number of entries successfully processed by the handler. In this case, when the max_entries parameter is not zero, the number of entries successfully processed can never be greater than the value of max_entries. In other words, the expression `count > max_entries` will always evaluate to false. This means that the logic in the final if statement will never be executed. Commit 99b0efd7c886 ("ACPI / tables: do not report the number of entries ignored by acpi_parse_entries()") mentioned this issue, but it tried to fix it by removing part of the warning message. This is meaningless because the pr_warn statement will never be executed in the first place. Commit 8726d4f44150 ("ACPI / tables: fix acpi_parse_entries_array() so it traverses all subtables") introduced an errs variable, which is intended to make acpi_parse_entries_array() always traverse all of the subtables, calling as many of the callbacks as possible. However, it seems that the commit does not achieve this goal. For example, when a handler returns an error, none of the handlers will be called again in the subsequent iterations. This result appears to be no different from before the change. This patch corrects and cleans up the logic of acpi_parse_entries_array(), making it return the number of all matching entries, rather than the number of entries successfully processed by handlers. Additionally, if an error occurs when executing a handler, the function will return -EINVAL immediately. This patch should not affect existing users of acpi_parse_entries_array(). Signed-off-by: Yuntao Wang --- lib/fw_table.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/fw_table.c b/lib/fw_table.c index b51f30a28e47..b655e6f4b647 100644 --- a/lib/fw_table.c +++ b/lib/fw_table.c @@ -85,11 +85,6 @@ acpi_get_subtable_type(char *id) return ACPI_SUBTABLE_COMMON; } -static __init_or_acpilib bool has_handler(struct acpi_subtable_proc *proc) -{ - return proc->handler || proc->handler_arg; -} - static __init_or_acpilib int call_handler(struct acpi_subtable_proc *proc, union acpi_subtable_headers *hdr, unsigned long end) @@ -133,7 +128,6 @@ acpi_parse_entries_array(char *id, unsigned long table_size, unsigned long table_end, subtable_len, entry_len; struct acpi_subtable_entry entry; int count = 0; - int errs = 0; int i; table_end = (unsigned long)table_header + table_header->length; @@ -145,25 +139,19 @@ acpi_parse_entries_array(char *id, unsigned long table_size, ((unsigned long)table_header + table_size); subtable_len = acpi_get_subtable_header_length(&entry); - while (((unsigned long)entry.hdr) + subtable_len < table_end) { - if (max_entries && count >= max_entries) - break; - + while (((unsigned long)entry.hdr) + subtable_len < table_end) { for (i = 0; i < proc_num; i++) { if (acpi_get_entry_type(&entry) != proc[i].id) continue; - if (!has_handler(&proc[i]) || - (!errs && - call_handler(&proc[i], entry.hdr, table_end))) { - errs++; - continue; - } + + if (!max_entries || count < max_entries) + if (call_handler(&proc[i], entry.hdr, table_end)) + return -EINVAL; proc[i].count++; + count++; break; } - if (i != proc_num) - count++; /* * If entry->length is 0, break from this loop to avoid @@ -180,9 +168,9 @@ acpi_parse_entries_array(char *id, unsigned long table_size, } if (max_entries && count > max_entries) { - pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n", - id, proc->id, count); + pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n", + id, proc->id, count - max_entries, count); } - return errs ? -EINVAL : count; + return count; } -- 2.42.1