Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2539666iob; Fri, 6 May 2022 05:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4JRgVk8S1xWg8QlZnon237f369XLvkuOpI0mUqm2/CTaHqX1q50Wo7Y5zEqmP5nb4O6i9 X-Received: by 2002:a50:8754:0:b0:428:659b:2b62 with SMTP id 20-20020a508754000000b00428659b2b62mr991315edv.204.1651839554610; Fri, 06 May 2022 05:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651839554; cv=none; d=google.com; s=arc-20160816; b=Mo12gABHiQg1IWLQmT8iOJfNFlEIZJy35hBpOA1MpI3qChRLAmTYeqx8FG2PJ/QPIW nWnTOL+IuAkGwEQTgT68hr0mfyVaF6yMG61LGSDhb1DSMPFhVPif8YhwexOClmoysRma pZZs4bKkdkUp/PM4o9HN9slSesuxii9HMSKrRV8lmDQtlp5HLvfXDayLoz/E/YTXI8QE qx9pdPmIhSTeWecVh6KbjOmo5/QxOSifiXjXSiUiuO0Dbc3A6Ixsdu0KnJGX/T8qJXE0 /DULIYc5Q4YLRfc+jXI9lHbY7ZDigMQo7MY84ysPR8C3KxPbmceoc+mTH3BW9BIeB1Ew 0Dqw== 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; bh=ooGD6ESxZmc2stnBVG5pfKardvyvkRBGrfB/JinPV8A=; b=IziEWfnnHwqIqSaeyWRKqgrJDLSxIyQ/siAGZkdL4VEXFYJp2GHQxjNFus7sOnMCJB 3ypCjCrXa3a4PuMwe+XjrQx+gA/4BEGbzrHA1VlzquZmc4LJbVXMZnjBJ6+QKnXMC7X4 u0wenRAkMJGkOglMUe13M/M8d8o2N1bgCjhSxiF7JpSBuAJlAmZ6pGWMTY/05CEi1zrq wEz2D4gCsT/8N33KLk0kYjoNGe2BWsib3/dmgFgRogdZQTqf++IAUIaKQGXyJzLmScbK tX8u9rCoAxnRYWwSS/m585RamtVPIQE27OyPV9QwxejCNiAjqybnMt4aWTf0Blz5D+jr PlPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mm30-20020a170906cc5e00b006dfd81499c7si4209193ejb.828.2022.05.06.05.18.40; Fri, 06 May 2022 05:19:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376703AbiEES5f (ORCPT + 99 others); Thu, 5 May 2022 14:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351575AbiEES5a (ORCPT ); Thu, 5 May 2022 14:57:30 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165FD377D7; Thu, 5 May 2022 11:53:49 -0700 (PDT) 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.0.0) id 5a6eb3309ae26a11; Thu, 5 May 2022 20:53:48 +0200 Received: from kreacher.localnet (unknown [213.134.161.219]) (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 v370.home.net.pl (Postfix) with ESMTPSA id DA7C566C2F4; Thu, 5 May 2022 20:53:47 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML Subject: [PATCH v1] ACPI: glue: Rearrange find_child_checks() Date: Thu, 05 May 2022 20:52:57 +0200 Message-ID: <2630129.mvXUDI8C0e@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.161.219 X-CLIENT-HOSTNAME: 213.134.161.219 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfedugdduvdekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepffffffekgfehheffleetieevfeefvefhleetjedvvdeijeejledvieehueevueffnecukfhppedvudefrddufeegrdduiedurddvudelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudeiuddrvdduledphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepvddprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=2 Fuz1=2 Fuz2=2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 From: Rafael J. Wysocki Notice that it is not necessary to evaluate _STA in find_child_checks() if the device is expected to have children, but there are none, so move the children check to the front of the function. Also notice that FIND_CHILD_MIN_SCORE can be returned right away if _STA is missing, so make the function do so. Finally, replace the ternary operator in the return statement argument with an if () and a standalone return which is somewhat easier to follow. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/glue.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) Index: linux-pm/drivers/acpi/glue.c =================================================================== --- linux-pm.orig/drivers/acpi/glue.c +++ linux-pm/drivers/acpi/glue.c @@ -79,17 +79,17 @@ static struct acpi_bus_type *acpi_get_bu static int find_child_checks(struct acpi_device *adev, bool check_children) { - bool sta_present = true; unsigned long long sta; acpi_status status; + if (check_children && list_empty(&adev->children)) + return -ENODEV; + status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta); if (status == AE_NOT_FOUND) - sta_present = false; - else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED)) - return -ENODEV; + return FIND_CHILD_MIN_SCORE; - if (check_children && list_empty(&adev->children)) + if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED)) return -ENODEV; /* @@ -99,8 +99,10 @@ static int find_child_checks(struct acpi * matched going forward. [This means a second spec violation in a row, * so whatever we do here is best effort anyway.] */ - return sta_present && !adev->pnp.type.platform_id ? - FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE; + if (adev->pnp.type.platform_id) + return FIND_CHILD_MIN_SCORE; + + return FIND_CHILD_MAX_SCORE; } struct acpi_device *acpi_find_child_device(struct acpi_device *parent,