Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp218703pxb; Mon, 11 Apr 2022 23:36:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcM5QGnAldIRM4D0lmat/z89OOUBAooCgkXiYi+pDaW6pqzEnZMyEptOt4vQvmLX20KpN8 X-Received: by 2002:a63:d64d:0:b0:374:6edc:989c with SMTP id d13-20020a63d64d000000b003746edc989cmr29492584pgj.434.1649745396007; Mon, 11 Apr 2022 23:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649745396; cv=none; d=google.com; s=arc-20160816; b=p9waGXxwbfAH3Bw9iWZ0LazdQGMypZ0IU11Qg6Q68T/w9okc16wvgXBO88sO6AS9Dj tvyw93PNRgbtJaMhnsMQtFGzH5zqmLuYTVb2/chRJ0UyReSOjA4dHcpBNEtSb9kKSNiX gT2mp5AIM5VqhQ+0nymuD1KNdOc+t4shwp/NDO+l7jvCi5Xa+5VeIXsbC7sf49m/uRlh WjFm6qbxHru57ffWqK/OVrWlArouk3AhUAv1lo7o9Ai6IajIXGHyaVLzgReCq/aiA4F4 U3kuWOUSQ3k49kKPPDR5enOyUqrd1xIpmmuA7IcPgaKQEt/nbde45VQujCgEP0cJY8pe epVQ== 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=WtYuPy/JiOADmZgZ629awKeq8tUodyRUzyJ7GdROEp4=; b=GxXWsxy8csT0EIq4sZ7Dzk6Y6fD7SXg8rnWuwyKj+0kF3hdvcq9NIUakmx4ysWg0Ml A2GoI8QtV/0gGKISnUtkItmIYsErzT5ds6sfuMVGYBNuhB9iZtntuafGnZoSbt1hn5KT wF9+MbzlYvRwsNnm48mHtQ4q7JhFuDK0tO19D6EBgpNVjMFG0zfXFopISsDzjuRpd0fN AaQulqU6IZ+nok7muE0L83+6sFEMEBE6Rd4J7LW59GysTZtbLl+v8eLrTfHtKII1ixcr HB/jWZbZCV+TaWyDy4hbZ6tZFLkLH/RHDdbH+iUZobJv1m5uwCBNpzJ0xFaYqhBmwNOj /ohA== 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 i12-20020a17090332cc00b0015886a47d5esi1383898plr.582.2022.04.11.23.36.23; Mon, 11 Apr 2022 23:36:35 -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 S242180AbiDINbh (ORCPT + 99 others); Sat, 9 Apr 2022 09:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242114AbiDINbH (ORCPT ); Sat, 9 Apr 2022 09:31:07 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB93FB0A77; Sat, 9 Apr 2022 06:29:00 -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 774345feafbd1fe9; Sat, 9 Apr 2022 15:28:59 +0200 Received: from kreacher.localnet (89-77-51-84.dynamic.chello.pl [89.77.51.84]) (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 7BE1266BCD0; Sat, 9 Apr 2022 15:28:58 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PCI Cc: Linux PM , LKML , Bjorn Helgaas , Mika Westerberg Subject: [PATCH v1 3/7] PCI/PM: Rearrange pci_update_current_state() Date: Sat, 09 Apr 2022 15:08:39 +0200 Message-ID: <3191989.aeNJFYEL58@kreacher> In-Reply-To: <4419002.LvFx2qVVIh@kreacher> References: <4419002.LvFx2qVVIh@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.77.51.84 X-CLIENT-HOSTNAME: 89-77-51-84.dynamic.chello.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvvddrudekvddgfeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvjeelgffhiedukedtleekkedvudfggefhgfegjefgueekjeelvefggfdvledutdenucfkphepkeelrdejjedrhedurdekgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrjeejrdehuddrkeegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhvghlghgrrghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihhkrgdrfigvshht vghrsggvrhhgsehlihhnuhigrdhinhhtvghlrdgtohhm 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,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 Save one config space access in pci_update_current_state() by testing the retireved PCI_PM_CTRL register value against PCI_POSSIBLE_ERROR() instead of invoking pci_device_is_present() separately. While at it, drop a pair of unnecessary parens. No expected functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1201,14 +1201,17 @@ static int pci_raw_set_power_state(struc */ void pci_update_current_state(struct pci_dev *dev, pci_power_t state) { - if (platform_pci_get_power_state(dev) == PCI_D3cold || - !pci_device_is_present(dev)) { + if (platform_pci_get_power_state(dev) == PCI_D3cold) { dev->current_state = PCI_D3cold; } else if (dev->pm_cap) { u16 pmcsr; pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); - dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); + if (PCI_POSSIBLE_ERROR(pmcsr)) { + dev->current_state = PCI_D3cold; + return; + } + dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK; } else { dev->current_state = state; }