From patchwork Fri Jun 19 04:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1312558 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Sm2Ju+Yp; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49p5sb33XFz9sSf for ; Fri, 19 Jun 2020 14:48:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbgFSEsR (ORCPT ); Fri, 19 Jun 2020 00:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbgFSEsO (ORCPT ); Fri, 19 Jun 2020 00:48:14 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D84EC06174E; Thu, 18 Jun 2020 21:48:14 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id mb16so8775153ejb.4; Thu, 18 Jun 2020 21:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+V5Jgmnw6zPAxpFlqqIwG2UnRCpwzgUpgKhoqNVxZr0=; b=Sm2Ju+Ypyp2Nfkld/Cp7+WPbxFJUQI1+zxzblDcwbEAqnaBo5PCkAbI1S/Sb4YqgZN O5BOwYB/FzhHRcSo5QdK97qodlzmfntrJ9jujkyAPvH6PX8GiYqJ5yhBMzTdrJKgjjcU kkL+NTaaLGdhvHnkHI9Emyw4n8Po6ynvm2UtWkyULHKBxQD64mgN+cEmk7qU5+w2zqd3 TamN+xe3jZIa1fpKNG93VqKxTWYg7aqyPJe2CUWRdzFb3yQfmrezn0rXgHqBCuPJHkQy 7aZrwar0cf/ZsuN8jhK73ZzBRwyCkSQj8aFtO+WO9QyaV1ARnco6Qae//LC5atq88e+r uTEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+V5Jgmnw6zPAxpFlqqIwG2UnRCpwzgUpgKhoqNVxZr0=; b=reg0JEpilDtyl95sA0aebxRL+gVUX8QjCEdICkmkvfqO3wV6BDhrE410pW5DyQZJtt rXvbGnRux4y+CYryVzCfgCTWzVI2vAXYgv25krHHgJrvqjzy2ZbRY14Xoou+zBzIncwL Ygd3oTem5v84cWm5g3RD1/z9iC092DUXQ+wSDq9AMi4gHY1w2MfaYhy1GBcQp0WT8SJ4 R5Dr368SLHEhRRdMsfsGl0g6On/usxkTdBqDMU8Ty3VYmy90SH7fpFI7fV+we/tUU7Po vAFcXG0SqefSjNFqQ0p3mLSEyGO9YN7HhwmFcKpSfP46DajxelLEO1i2sB9vqepg/tnB tt0w== X-Gm-Message-State: AOAM5339oAO9yhoD8Fy5tClpZ8YcjUh//iv5k58y2em+KQxtYvbjRouM jNVm06dEzCmNst5DKOXCEfNtDhie X-Google-Smtp-Source: ABdhPJxxLNz8Fx8VDtqGD8X7i3DfiIprxWQvEFgNVWhrk0jYL3LKlgaFq3jgt9r7Gcbi6MVPhDfG+w== X-Received: by 2002:a17:907:94c4:: with SMTP id dn4mr1856569ejc.150.1592542092553; Thu, 18 Jun 2020 21:48:12 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id ew9sm3867852ejb.121.2020.06.18.21.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 21:48:11 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Rob Herring , Frank Rowand , Dajun Jin , Alexandre Belloni , linux-kernel@vger.kernel.org (open list), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE) Subject: [PATCH net 1/2] of: of_mdio: Correct loop scanning logic Date: Thu, 18 Jun 2020 21:47:58 -0700 Message-Id: <20200619044759.11387-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200619044759.11387-1-f.fainelli@gmail.com> References: <20200619044759.11387-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit 209c65b61d94 ("drivers/of/of_mdio.c:fix of_mdiobus_register()") introduced a break of the loop on the premise that a successful registration should exit the loop. The premise is correct but not to code, because rc && rc != -ENODEV is just a special error condition, that means we would exit the loop even with rc == -ENODEV which is absolutely not correct since this is the error code to indicate to the MDIO bus layer that scanning should continue. Fix this by explicitly checking for rc = 0 as the only valid condition to break out of the loop. Fixes: 209c65b61d94 ("drivers/of/of_mdio.c:fix of_mdiobus_register()") Signed-off-by: Florian Fainelli Reviewed-by: Andrew Lunn --- drivers/of/of_mdio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index a04afe79529c..7496dc64d6b5 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -315,9 +315,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) if (of_mdiobus_child_is_phy(child)) { rc = of_mdiobus_register_phy(mdio, child, addr); - if (rc && rc != -ENODEV) + if (!rc) + break; + if (rc != -ENODEV) goto unregister; - break; } } } From patchwork Fri Jun 19 04:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1312559 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EjhitqHw; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49p5sl2KFdz9sSJ for ; Fri, 19 Jun 2020 14:48:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbgFSEsV (ORCPT ); Fri, 19 Jun 2020 00:48:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726220AbgFSEsR (ORCPT ); Fri, 19 Jun 2020 00:48:17 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F491C06174E; Thu, 18 Jun 2020 21:48:17 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id cy7so29876edb.5; Thu, 18 Jun 2020 21:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z6pjZcvuC6hfoI30JKSQEs1lxYUwr1VGXrh+ISodyNY=; b=EjhitqHwM0Ddc1lu+b7bk7/9gwOyrLf50KXySN2IHjKuH90HwRdgaXJhtnkIAU1sbh hlSn+B1ZIN2iCaToSbDBIZ6YmgdUvjZ9gThOmkC4PrY9ZrHgpCRsj8ozR9E8gsR5mXnR /pqL99KNleodPg+XYOAMBFZU7B3v1v2ookoCOjD2/ozYx3xf17RdRFyDB1gSrJU7uJVz WU604RVnKVQ8G3YYLkyjiOxiATVfZl9U/OzFK0Bx0BiVhAejDK5QBNmbxyle6p8/nS4V 9eqoGXrFZUm/hFw/qCrlvtwVbhZ9FZNStqZBz3Ch2wf48Wp9dLB7zQAGFk7awGUmZYMh 1EGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z6pjZcvuC6hfoI30JKSQEs1lxYUwr1VGXrh+ISodyNY=; b=SIrjbM0nYP+nv1CaM/9dNCObH9k8f2JcKCHZZHkY9/ZqidPv0mW019mz2laq/YOgFw YhNHPBExmS+dEpxTzlBtvrcr3fLvSTn6B8PHEKD8lmAxJXycLV03RozUf5Zf2OIzj/zG redLlMNsktKpkaBkLVZ9hA01tcTgboGcVTKEi/YZo6M+SfHvYfX7U8j1giq+dZhvJ/n5 5pFYiYtuqIULqgteHHyqBOZIvApyAEMys6dUF+UBP29PtOjGr25FCYBvQ82JU7D6d6/r cXhOHZ3pasKH6L8jDOlPBOYLz+fqb68o71dV0joPY65VKc1e2S8ywDIUWAeE4uLgfcNH SKTw== X-Gm-Message-State: AOAM530EzwUCzmeW9aN0JpDmzL8oj4di+xM6jZ6Mvpagfa/0wDa3PqwF pxG4U5de7A2Fno7UcpE0QKUetoOI X-Google-Smtp-Source: ABdhPJz4RJRXfOqvp2LISkOtvFVlDLIIFMYK9X3zJZqq+YkzWTe+hOEXhgfqbMS5LOi76Wg/XgP+2w== X-Received: by 2002:aa7:d7cc:: with SMTP id e12mr1475006eds.70.1592542095630; Thu, 18 Jun 2020 21:48:15 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id ew9sm3867852ejb.121.2020.06.18.21.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 21:48:15 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Rob Herring , Frank Rowand , Dajun Jin , Alexandre Belloni , linux-kernel@vger.kernel.org (open list), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE) Subject: [PATCH net 2/2] net: phy: Check harder for errors in get_phy_id() Date: Thu, 18 Jun 2020 21:47:59 -0700 Message-Id: <20200619044759.11387-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200619044759.11387-1-f.fainelli@gmail.com> References: <20200619044759.11387-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit 02a6efcab675 ("net: phy: allow scanning busses with missing phys") added a special condition to return -ENODEV in case -ENODEV or -EIO was returned from the first read of the MII_PHYSID1 register. In case the MDIO bus data line pull-up is not strong enough, the MDIO bus controller will not flag this as a read error. This can happen when a pluggable daughter card is not connected and weak internal pull-ups are used (since that is the only option, otherwise the pins are floating). The second read of MII_PHYSID2 will be correctly flagged an error though, but now we will return -EIO which will be treated as a hard error, thus preventing MDIO bus scanning loops to continue succesfully. Apply the same logic to both register reads, thus allowing the scanning logic to proceed. Fixes: 02a6efcab675 ("net: phy: allow scanning busses with missing phys") Signed-off-by: Florian Fainelli Reviewed-by: Andrew Lunn --- drivers/net/phy/phy_device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 04946de74fa0..85ba95b598b5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -794,8 +794,10 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, /* Grab the bits from PHYIR2, and put them in the lower half */ phy_reg = mdiobus_read(bus, addr, MII_PHYSID2); - if (phy_reg < 0) - return -EIO; + if (phy_reg < 0) { + /* returning -ENODEV doesn't stop bus scanning */ + return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; + } *phy_id |= phy_reg;