From patchwork Fri Dec 8 20:05:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 176022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5692210vqy; Fri, 8 Dec 2023 12:08:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhpkcT6Q+jBMFzl+9kh0AU/7IFkuzPew+oOpClWJ9VaGcgoIm2+pk+n8qQ+eldJoHsCfYM X-Received: by 2002:a17:902:b706:b0:1cf:9790:f244 with SMTP id d6-20020a170902b70600b001cf9790f244mr629300pls.47.1702066086839; Fri, 08 Dec 2023 12:08:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702066086; cv=none; d=google.com; s=arc-20160816; b=f3k84m3QdVtJwqsKn12COfT8j9bh4dwliH1nUIUUIHUuhk5Ug0flTorEaKVUZG8qln rE7NcDcix8iKLBJXW8S0Uzyk3QW4JK5tk8qmqgd2GOD0u/1/tbj9zLW2GlR2RzIg+nZ1 OQEi2t5OndjqPJszxkg5FQstIIUfVRYhtFfOkA8FJtr0Hu+r9pcnAYs+6F/yHyN/aJOm onRKuKF9neqqDiB/UElnWUkCT0HK36TSrMG0vjcRU+qQGffv5mnln21WxGXejx9E9z+y h7Mv6g/y9WGZnq65JCWWBH3VQLudPKWAqkRp6m10q+roSlssiSHmvT+Czhvl5moxUJqz jDQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hhCmfUXiITshL+XKvr6ZeJbGZSNjGtlTEAjKvAb0jQA=; fh=arJSG3Xz207w2wMVOOEdKWDKnFh7anVx1NoYPUQafKc=; b=mWBjS1rrXCAHgNF8FszLSLG55FpsfLLrzMWMF15R3OiTBrt0jqdIDjk5x3VhZOPB6J 4mY8P+XS+CAkotzPMw5s4Zkz9Rn7PcsFQacTC58fuYVpV7yv6ZyDrtAOxO8H9bsrOq5g k7M80lJF9TNqYhlQBJet0Xr7bAMC8kxSkUz1irLjGeL9D1EaiM23vFd6NiJ2uS4eWGeW xDrQ0dUXTmxZbDTrOCNkyjW1yi07e4pvDIMkRXoKVkT8I60Z1D3G+9urQUVH+X3jhJFW tq/Txc1r/B6nTFqPczyjeGq8S4lwrubagJOxwhqWhxrRNGAQYrKpYQrYVV/36i8SwEMn Fo2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d27-20020a631d5b000000b005bd42f6085fsi1961185pgm.344.2023.12.08.12.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:08:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DC2AC8106735; Fri, 8 Dec 2023 12:08:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234207AbjLHUHw (ORCPT + 99 others); Fri, 8 Dec 2023 15:07:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234078AbjLHUHq (ORCPT ); Fri, 8 Dec 2023 15:07:46 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE33E1734; Fri, 8 Dec 2023 12:07:52 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id d5c18fa1728abe13; Fri, 8 Dec 2023 21:07:51 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 0460B6688FF; Fri, 8 Dec 2023 21:07:51 +0100 (CET) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Hans de Goede , Andy Shevchenko , Mika Westerberg Subject: [PATCH v1 1/4] ACPI: utils: Rearrange in acpi_evaluate_reference() Date: Fri, 08 Dec 2023 21:05:19 +0100 Message-ID: <4541600.LvFx2qVVIh@kreacher> In-Reply-To: <6008018.lOV4Wx5bFT@kreacher> References: <6008018.lOV4Wx5bFT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrudekiedgudefgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohephhguvghgohgvuggvsehrvgguhhgrthdrtghomhdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhm pdhrtghpthhtohepmhhikhgrrdifvghsthgvrhgsvghrgheslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 08 Dec 2023 12:08:06 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784745648704072892 X-GMAIL-MSGID: 1784745648704072892 From: Rafael J. Wysocki The code in acpi_evaluate_reference() can be improved in some ways without changing its observable behavior. Among other things: * None of the local variables in that function except for buffer needs to be initialized. * The element local variable is only used in the for () loop block, so it can be defined there. * Multiple checks can be combined. * Code duplication related to error handling can be eliminated. * Redundant inner parens can be dropped. Modify the function as per the above. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/utils.c | 58 +++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 34 deletions(-) Index: linux-pm/drivers/acpi/utils.c =================================================================== --- linux-pm.orig/drivers/acpi/utils.c +++ linux-pm/drivers/acpi/utils.c @@ -335,12 +335,10 @@ acpi_evaluate_reference(acpi_handle hand struct acpi_object_list *arguments, struct acpi_handle_list *list) { - acpi_status status = AE_OK; - union acpi_object *package = NULL; - union acpi_object *element = NULL; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - u32 i = 0; - + union acpi_object *package; + acpi_status status; + u32 i; if (!list) return AE_BAD_PARAMETER; @@ -353,45 +351,32 @@ acpi_evaluate_reference(acpi_handle hand package = buffer.pointer; - if ((buffer.length == 0) || !package) { - status = AE_BAD_DATA; - acpi_util_eval_error(handle, pathname, status); - goto end; - } - if (package->type != ACPI_TYPE_PACKAGE) { - status = AE_BAD_DATA; - acpi_util_eval_error(handle, pathname, status); - goto end; - } - if (!package->package.count) { + if (buffer.length == 0 || !package || + package->type != ACPI_TYPE_PACKAGE || !package->package.count) { status = AE_BAD_DATA; - acpi_util_eval_error(handle, pathname, status); - goto end; + goto err; } - list->handles = kcalloc(package->package.count, sizeof(*list->handles), GFP_KERNEL); + list->count = package->package.count; + list->handles = kcalloc(list->count, sizeof(*list->handles), GFP_KERNEL); if (!list->handles) { - kfree(package); - return AE_NO_MEMORY; + status = AE_NO_MEMORY; + goto err_clear; } - list->count = package->package.count; /* Extract package data. */ for (i = 0; i < list->count; i++) { - - element = &(package->package.elements[i]); + union acpi_object *element = &(package->package.elements[i]); if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { status = AE_BAD_DATA; - acpi_util_eval_error(handle, pathname, status); - break; + goto err_free; } if (!element->reference.handle) { status = AE_NULL_ENTRY; - acpi_util_eval_error(handle, pathname, status); - break; + goto err_free; } /* Get the acpi_handle. */ @@ -399,16 +384,21 @@ acpi_evaluate_reference(acpi_handle hand acpi_handle_debug(list->handles[i], "Found in reference list\n"); } - if (ACPI_FAILURE(status)) { - list->count = 0; - kfree(list->handles); - list->handles = NULL; - } - end: kfree(buffer.pointer); return status; + +err_free: + kfree(list->handles); + list->handles = NULL; + +err_clear: + list->count = 0; + +err: + acpi_util_eval_error(handle, pathname, status); + goto end; } EXPORT_SYMBOL(acpi_evaluate_reference);