Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2460134lqb; Mon, 27 May 2024 23:42:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWimOje0xYOWGciBbpb5M61xjv3iX3wd59q6i2lsK5Qcw2cIn/ZHy/EWyV9xGH6TZ2HnBApRijcW+waz7QqZGTQHR8l65/Xy5dK+NXlEw== X-Google-Smtp-Source: AGHT+IHfg9QuimFlFYRFqa9Uc3CiI7OSz7WBAf5UKAFWwbg1vFak4tu6VzHIMJmocyVEEAqVtmzH X-Received: by 2002:a17:90a:69e2:b0:2bd:ed86:aafc with SMTP id 98e67ed59e1d1-2bf5e568823mr10495749a91.21.1716878557923; Mon, 27 May 2024 23:42:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716878557; cv=pass; d=google.com; s=arc-20160816; b=QVa4YbeWc0P7L03voCOofJxXa85T3XkYhCARBDZZRsJIprrH8weOJ4DrmtT4sUDOt4 5Z2UPcOFkObpKkr24M4z+X47tnkh+CgTBAxUl8Qc2a+vOGBVvOuSgNdDjus0/rr1Ro7h locexP4vKjOTD6/ondX2im+Xe/Q9VGTFWvk/lR629I4vwYylZeSM3ncPOnvYhTdP3jsv ymM/ct2L9cuQy2ffQDf3LOG9Fx378Ec6TnPDitVj02n1+gruF+phoobzfhwCkg5QpATA u7DsJcnq9zOORRO1T4U3i9CZJMrZRm7GmxhT9qrqXa0KPy3Dd66BtouB+c7v8LDTE927 gYEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1TYz2MSLWTBADR4fMNQi+uyHDoesbuC11bnI7fbU/Nk=; fh=q7TbgsxxGaXtWjVyB7SuxMv7qAkbt2lnXZaKncW/9mw=; b=gsNIbd4PxAhk0RCCphglBgr9jMeVWFFOmsBueTsffrpEOly1lL3E0+hx64VLrbaf+m AvshWUROMMkZgr4KSwPL0g55/iwqwAZRXB0rz9p++1XvVCTe+SV9p4q2pomgsagtv1nQ PHJbMEVnxezqQwQt9eCCLHkH2ckOgn+VXMcuw17qY487cWnM091sjkg5xh/lNbNe12zT XpVoCj741FJtlORcarM5U5EP87eLHYvfF0oRhXlq7PKKuJ8iUt3M25fi27YNrjyCgFgp BXY4eKk/jgfKhxbC4u5rC48oWL0/ItSn90L3iG8vecxx6E3Ou/b4JqR01dEFHfKWZ1qE b1aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=YAYTy97C; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-191819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191819-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bf93705c4asi5120822a91.10.2024.05.27.23.42.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 23:42:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=YAYTy97C; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-191819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191819-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B5F10B218A1 for ; Tue, 28 May 2024 06:42:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1256B6D1A9; Tue, 28 May 2024 06:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="YAYTy97C" Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF95661FF6; Tue, 28 May 2024 06:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716878539; cv=none; b=jjTzwU0rtQMpLOkzlhghDm+7Yrj18qiJ9Z2QCwZj6li6NC/6eE+25/sQ2ZN9nJjQR7YiXxsl7VYP7cg+UqktyyFItn8dtkmGxC5M9+97Ntr7YJheHMVyg21aGDPQBKjjWM1lz//VKi+8iwQFkdhYl9Q38d5ArjRPO/F1ABbJqSo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716878539; c=relaxed/simple; bh=unp07GJmZ++P8y9G7R8jwpKp8WXsLs59UX5DVYR1qVw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UhClqjUMtGQgH/Y+97rw4u6NF1g+Froh0l+n/0qKUBfgqSAEqUMdqXEYuIUrLFWJb1EHdzXwRloWTJZ0ZsM0tASFksqxp+QA30l8Z9aixOrtHs8dURS6KsowSHUm3gT0mkrYVMOtKCkbn55nBZMVPMJL0KIyjnvGKxxZJfDCDS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=YAYTy97C; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716878527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=1TYz2MSLWTBADR4fMNQi+uyHDoesbuC11bnI7fbU/Nk=; b=YAYTy97C4//M7/wp5gTfEV1m6srNwHt4opTs6wNkGhDcH40omnnsn5qmYKEMSX56N9X24E1qQuDAqORUaDKh9Htf2MRDdw2EJfED6z/DxmbJDkA7L3t5H5ZXjai21AvU0GvBpdiOk+8IImfN7RqWQLEy3RTzvaFINOMnNgcNVHg= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067109;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0W7OiUf9_1716878524; Received: from localhost.localdomain(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W7OiUf9_1716878524) by smtp.aliyun-inc.com; Tue, 28 May 2024 14:42:06 +0800 From: Bitao Hu To: lukas@wunner.de, bhelgaas@google.com, weirongguang@kylinos.cn Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kanie@linux.alibaba.com, yaoma@linux.alibaba.com Subject: [PATCHv2] PCI: pciehp: Use appropriate conditions to check the hotplug controller status Date: Tue, 28 May 2024 14:42:00 +0800 Message-Id: <20240528064200.87762-1-yaoma@linux.alibaba.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20240524063023.77148-1-yaoma@linux.alibaba.com> References: <20240524063023.77148-1-yaoma@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit "present" and "link_active" can be 1 if the status is ready, and 0 if it is not. Both of them can be -ENODEV if reading the config space of the hotplug port failed. That's typically the case if the hotplug port itself was hot-removed. Therefore, this situation can occur: pciehp_card_present() may return 1 and pciehp_check_link_active() may return -ENODEV because the hotplug port was hot-removed in-between the two function calls. In that case we'll emit both "Card present" *and* "Link Up" since both 1 and -ENODEV are considered "true". This is not the expected behavior. Those messages should be emited when "present" and "link_active" are positive. Signed-off-by: Bitao Hu Reviewed-by: Lukas Wunner --- v1 -> v2: 1. Explain the rationale of the code change in the commit message more clearly. 2. Add the "Reviewed-by" tag of Lukas. --- drivers/pci/hotplug/pciehp_ctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index dcdbfcf404dd..6adfdbb70150 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -276,10 +276,10 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) case OFF_STATE: ctrl->state = POWERON_STATE; mutex_unlock(&ctrl->state_lock); - if (present) + if (present > 0) ctrl_info(ctrl, "Slot(%s): Card present\n", slot_name(ctrl)); - if (link_active) + if (link_active > 0) ctrl_info(ctrl, "Slot(%s): Link Up\n", slot_name(ctrl)); ctrl->request_result = pciehp_enable_slot(ctrl); -- 2.37.1 (Apple Git-137.1)