Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp445240pxb; Tue, 12 Apr 2022 05:40:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvUO1TzTmZXOhfWgE6fiAJYZttjIl6GYHCfKFOaSeCBvCkwvjOmJDLmstgVXZ8LzvpQsgE X-Received: by 2002:a17:906:7684:b0:6e8:5d05:196b with SMTP id o4-20020a170906768400b006e85d05196bmr17992641ejm.209.1649767205941; Tue, 12 Apr 2022 05:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649767205; cv=none; d=google.com; s=arc-20160816; b=Cb28dH/A6cHIqXwJ9aPh5/7mXIpLJcRtI63eQTIT7LomMWsV/ML7nEMFZHr7woJi9b DivCeb3TupSIK1lXxrXu3Olh4Wt0eqNrtGzG3FCq2+GZ3c01uyUFq2DNZJsenOjzbYt5 pinoT6Nml2y1nYOS6wQcFGrW5BqZOG+h/w0wVW4Eo61NS5jlxzPhP0ouyL8OKD3zv04B o3aT0ncplUJOChgFvQhTqWgLigIT02mto5eMSxk/iPQnm/P6L2m0fBHXYjvbIoC87CvU NxbF2wzMvUe7NCsy60Rt4NZ7ABpy6Zm8/PTaO17TuX65zP0pqmyfDwDg9MtbvpnSxU+G nioQ== 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=L5QIzQe/AwfNtTN3HYItNXihJumPQ2ZQraRYD+nSh7o=; b=oU8VrCnJZE5b/QSOCrAdphBEIQEZDhFthWeSGCLLidT3zFw5WFKSFdK5eDXbsTInGs 32lvIixhvQ5FNZp58vnWoT9X6z2PGxzii1AYweU1++0NjGL9a3nVOI6ep+DVF0/5oPSm whzN6ZpdLPWKXZMvdtos0LOwVUUsL3WbPgOrlItP9UFAW62clXHB/2uw8k/QifYUYiYg zK+IIDbSF86N0APX9iOtk150a2F153j9UNzt1WexhzBd1N6TcAzy38LhuK7MEhRm+8UC DhD8f69Ofx6xRlRgUjjIMXksGWZ40DlGoV1Vvex+8VuJZ1IN+NXuOfiNPotzOtLs/Gxl ArQg== 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 cw23-20020a056402229700b00418c2b5bf3dsi8498837edb.543.2022.04.12.05.39.41; Tue, 12 Apr 2022 05:40:05 -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 S1347335AbiDKOhD (ORCPT + 99 others); Mon, 11 Apr 2022 10:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347383AbiDKOgl (ORCPT ); Mon, 11 Apr 2022 10:36:41 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7199C60E1; Mon, 11 Apr 2022 07:34:11 -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 2ae36908047706f3; Mon, 11 Apr 2022 16:34:09 +0200 Received: from kreacher.localnet (unknown [213.134.175.113]) (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 1458D66BDD4; Mon, 11 Apr 2022 16:34:09 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PCI Cc: Linux PM , LKML , Bjorn Helgaas , Mika Westerberg Subject: [PATCH v2 3/9] PCI/PM: Rearrange pci_update_current_state() Date: Mon, 11 Apr 2022 16:21:04 +0200 Message-ID: <4721615.GXAFRqVoOG@kreacher> In-Reply-To: <11975904.O9o76ZdvQC@kreacher> References: <4419002.LvFx2qVVIh@kreacher> <11975904.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.175.113 X-CLIENT-HOSTNAME: 213.134.175.113 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvvddrudekiedgjeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvjeelgffhiedukedtleekkedvudfggefhgfegjefgueekjeelvefggfdvledutdenucfkphepvddufedrudefgedrudejhedruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddujeehrdduudefpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhvghlghgrrghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehm ihhkrgdrfigvshhtvghrsggvrhhgsehlihhnuhigrdhinhhtvghlrdgtohhm 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 --- v1 -> v2: No changes. --- 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; }