From patchwork Tue Aug 17 18:08:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 499634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F34EC4338F for ; Tue, 17 Aug 2021 18:08:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EF1060F5E for ; Tue, 17 Aug 2021 18:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233257AbhHQSJX (ORCPT ); Tue, 17 Aug 2021 14:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232807AbhHQSJV (ORCPT ); Tue, 17 Aug 2021 14:09:21 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D731C0613C1 for ; Tue, 17 Aug 2021 11:08:48 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id j9-20020a2581490000b02905897d81c63fso21146391ybm.8 for ; Tue, 17 Aug 2021 11:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kSH45SZMveG0CaWqBoMxwQKpfpniEhXxIOVkDYEW2gs=; b=etBTrfpzbs3cCZzDaZKPfBXIEycjxSXscCauYc6AWlisF9NEhS8ywPiPwTY/Wtj71Z mlPHKTapnrEoFTaKGh1QJEXGlBuHZchvm/cDjtVpnGJlY4UPdFgBGeMIXvnyvEiB3hRL b+keVDqVAz4Li0cYWHnFXicwcp13C8RMgw9c7Tcbe4/22AeafI/xWgVcoT+x81IAqy13 uwk6adK35YZVmXB7bbz+Wa2Vvk6+kFDIi1yFhCC3IuXeY0LOvtUlZL85J9SKxs8+juNa I/u7zRb3xSzn3J5LZUMJM8ZLRh6Bdl3tMCdepXJQ2NBrkquYBrm2rCvMJr/3nxAW6QMi AyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kSH45SZMveG0CaWqBoMxwQKpfpniEhXxIOVkDYEW2gs=; b=UOWBT4/gQWcqm76tDWGeKB5hiBDr9BUjtX8E/Cj5LnJEP4qU5WXqsvGHokfcxuZtgL PfabIx7s+vZkDDbrjfYhRI54LVS6Uskv1hj828qbRNMQd5ulyDGs4VJ2C8WKie35jS0U jgskjPlXzt6syuT/PahANfB5zSOR+NkG+58HmTu5Wv7MR6RNJOt+Mbfuv8LqsXYnd69L EPFBT3kz5hl8TfP11kE/nH73reIwfPGvQeYiCK0/XFml/ZGWEtZsKQnGic250xZRfVyB 4RTe+fha9Es9RDE9MIhZ8w8sT1/qjJDOKYDyVrn+8FJr2NuifkMagrD75dz7Fk4ltZpN KLXA== X-Gm-Message-State: AOAM531Et+8LGgcQ1/C55rZW4xR4GPbBFVJomxzsvseMMPsHgcorMaB+ XuBwg1BF6pks4ebQCLYa2L30/cXyRDXcHRs= X-Google-Smtp-Source: ABdhPJx7kwc2yf1NBmOlwG/p8RdAt1gPoF/4QEpryZEEDFOG4+07JBD9gcC3N93m0NSyNthhw2Af3wW+rR1Ihgg= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7750:a56d:5272:72cb]) (user=saravanak job=sendgmr) by 2002:a25:b948:: with SMTP id s8mr5947207ybm.281.1629223727760; Tue, 17 Aug 2021 11:08:47 -0700 (PDT) Date: Tue, 17 Aug 2021 11:08:39 -0700 In-Reply-To: <20210817180841.3210484-1-saravanak@google.com> Message-Id: <20210817180841.3210484-2-saravanak@google.com> Mime-Version: 1.0 References: <20210817180841.3210484-1-saravanak@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH net v2 1/3] net: mdio-mux: Delete unnecessary devm_kfree From: Saravana Kannan To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski Cc: Saravana Kannan , Marc Zyngier , Neil Armstrong , Kevin Hilman , kernel-team@android.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The whole point of devm_* APIs is that you don't have to undo them if you are returning an error that's going to get propagated out of a probe() function. So delete unnecessary devm_kfree() call in the error return path. Signed-off-by: Saravana Kannan Reviewed-by: Andrew Lunn Acked-by: Marc Zyngier Tested-by: Marc Zyngier Acked-by: Kevin Hilman Tested-by: Kevin Hilman --- drivers/net/mdio/mdio-mux.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index 110e4ee85785..5b37284f54d6 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/mdio-mux.c @@ -181,7 +181,6 @@ int mdio_mux_init(struct device *dev, } dev_err(dev, "Error: No acceptable child buses found\n"); - devm_kfree(dev, pb); err_pb_kz: put_device(&parent_bus->dev); err_parent_bus: From patchwork Tue Aug 17 18:08:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 498594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E048C4320A for ; Tue, 17 Aug 2021 18:08:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8281E60EFE for ; Tue, 17 Aug 2021 18:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233374AbhHQSJa (ORCPT ); Tue, 17 Aug 2021 14:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbhHQSJY (ORCPT ); Tue, 17 Aug 2021 14:09:24 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA96C061796 for ; Tue, 17 Aug 2021 11:08:51 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id s9-20020ad450090000b029034fef0edad8so117996qvo.21 for ; Tue, 17 Aug 2021 11:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SKq9HcdkybONWxbOYSXUnyicnjbklpyY3c0EANEvRv8=; b=Gs0/YqmYWclEEeTZV6R0wilhvUjUPDlIS/alZU0PkD0KPC860I53TUlJwRT2VfmdWs gVkyGiF+eaKIW0lluIAEjagyDa9dW75LUek/rBFKL+/bX97fU95KzJw78Pdo3ADvPl5R I72BjDAAjJWB5JyTxIssoUpda34lczkElPf9clOSKRPQBVKNQR2ijSl54LVmR4zL30JA M7KwKTdVDu5TdAj6gH3ONOh5k/QJL0kHDPvUZ+VGAmbwopsc3usYdmlk69IvKWWUHe4h hIELSWAWKSR2a+Mjo80PpmQYXeZa7dmFFA3Lv6po5JDvdPAa80UaRgq2ic9p4u3mHnCP 5qcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SKq9HcdkybONWxbOYSXUnyicnjbklpyY3c0EANEvRv8=; b=QzkbeU3Dt75HSzpAP5icFUrxkgRsHfcq2Mk4+sNgMvgrPzhwFem1P+NapjP7RbQViL xxrunXbwFOQHsfAI4TEucrR5j+KklaNqiJs4dxcHvICsqZdYAe4sSq4LwjZ6mfjjZ9z+ 0BoZbjaaSPYouepaBENkYxhoq2RopdorNZ25iAaP3TwLFaJk9K5z1PWB/hnuPA7NjoBX YL5hoZei+BmhGMT5LtmJ6gy3yrwt9YyUlarAKPbWa50yghyYwnhkoSunINnxoFwx/C2I geWOWNAMc+gk37haj2jno3ruQ4dLKWZS17iFmJWk5+ap7uk9+nhg8KAF+rrW/S4H6KFB ++SQ== X-Gm-Message-State: AOAM530W6+X55e1RskUlTaiZVh1EhTbjN3Y7lcQIUo3xC/jtWHxceN56 z4wYD9AMCSFWHH/AiulvIER9n+RHMZDJYZs= X-Google-Smtp-Source: ABdhPJzyMy1hBP0Fyod55lGFXARTq3Sr2eOkmHUhHKt/kEGuoSOplyPyBEAtyvjpSZqanFM3QC2V3dk1l0Mik9s= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7750:a56d:5272:72cb]) (user=saravanak job=sendgmr) by 2002:a0c:aac2:: with SMTP id g2mr4539726qvb.44.1629223730289; Tue, 17 Aug 2021 11:08:50 -0700 (PDT) Date: Tue, 17 Aug 2021 11:08:40 -0700 In-Reply-To: <20210817180841.3210484-1-saravanak@google.com> Message-Id: <20210817180841.3210484-3-saravanak@google.com> Mime-Version: 1.0 References: <20210817180841.3210484-1-saravanak@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH net v2 2/3] net: mdio-mux: Don't ignore memory allocation errors From: Saravana Kannan To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski Cc: Saravana Kannan , Marc Zyngier , Neil Armstrong , Kevin Hilman , kernel-team@android.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If we are seeing memory allocation errors, don't try to continue registering child mdiobus devices. It's unlikely they'll succeed. Signed-off-by: Saravana Kannan Reviewed-by: Andrew Lunn Acked-by: Marc Zyngier Tested-by: Marc Zyngier Acked-by: Kevin Hilman Tested-by: Kevin Hilman --- drivers/net/mdio/mdio-mux.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index 5b37284f54d6..13035e2685c4 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/mdio-mux.c @@ -82,6 +82,17 @@ static int mdio_mux_write(struct mii_bus *bus, int phy_id, static int parent_count; +static void mdio_mux_uninit_children(struct mdio_mux_parent_bus *pb) +{ + struct mdio_mux_child_bus *cb = pb->children; + + while (cb) { + mdiobus_unregister(cb->mii_bus); + mdiobus_free(cb->mii_bus); + cb = cb->next; + } +} + int mdio_mux_init(struct device *dev, struct device_node *mux_node, int (*switch_fn)(int cur, int desired, void *data), @@ -144,7 +155,7 @@ int mdio_mux_init(struct device *dev, cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL); if (!cb) { ret_val = -ENOMEM; - continue; + goto err_loop; } cb->bus_number = v; cb->parent = pb; @@ -152,8 +163,7 @@ int mdio_mux_init(struct device *dev, cb->mii_bus = mdiobus_alloc(); if (!cb->mii_bus) { ret_val = -ENOMEM; - devm_kfree(dev, cb); - continue; + goto err_loop; } cb->mii_bus->priv = cb; @@ -181,6 +191,10 @@ int mdio_mux_init(struct device *dev, } dev_err(dev, "Error: No acceptable child buses found\n"); + +err_loop: + mdio_mux_uninit_children(pb); + of_node_put(child_bus_node); err_pb_kz: put_device(&parent_bus->dev); err_parent_bus: @@ -192,14 +206,8 @@ EXPORT_SYMBOL_GPL(mdio_mux_init); void mdio_mux_uninit(void *mux_handle) { struct mdio_mux_parent_bus *pb = mux_handle; - struct mdio_mux_child_bus *cb = pb->children; - - while (cb) { - mdiobus_unregister(cb->mii_bus); - mdiobus_free(cb->mii_bus); - cb = cb->next; - } + mdio_mux_uninit_children(pb); put_device(&pb->mii_bus->dev); } EXPORT_SYMBOL_GPL(mdio_mux_uninit); From patchwork Tue Aug 17 18:08:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 499633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02C73C4338F for ; Tue, 17 Aug 2021 18:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBD2760FE6 for ; Tue, 17 Aug 2021 18:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233316AbhHQSJf (ORCPT ); Tue, 17 Aug 2021 14:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233428AbhHQSJ1 (ORCPT ); Tue, 17 Aug 2021 14:09:27 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96A57C0613A3 for ; Tue, 17 Aug 2021 11:08:53 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id o11-20020ac85a4b0000b029028acd99a680so11566398qta.19 for ; Tue, 17 Aug 2021 11:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=D43/Ik0ZmeC2KyL3MoNeHEy/ITGcx5BeAMWxIqGpsKc=; b=KEZdX/0iZbepsW68H82kx3/2by5MhIJd17wC2teBdmixZjuUy/hsk6bvqa5UaB8RzR YcIt1kFEwpuR8dVnqRTsKYegEEgWzBDxQqB3udzDl3A6DpxZcuHzOCMRDeaJWPt98Hc3 x2v9gLSab7WqUENthjjzD7JH9n6Maqhl5QItfOltkmZq4mI4HRl94FyyNiZHHy3yHsvD JpCq/jjvnlBjLX+dSeAWvhcIeN9AA9RtUFYsAwvKQ62CPvddEuXOttgKEnnVMao6MCSo wY0GewoxzsqKB7hR/c5Zzxp5iOit4kBWDxJrxfgZNlEwjaheiTA4tgDyBDVRQ4vAKGPl xyaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=D43/Ik0ZmeC2KyL3MoNeHEy/ITGcx5BeAMWxIqGpsKc=; b=XapPXNW6tLk0u0jCuij+fT+6t9o4MKfpuzVyMN73X51JbWDOjak702Z6659EgxdST4 B8lySSkkiL2ixKUegXRo6VvsQKNOLrbZd06hjArIPIXDuk0kfryIFPsCdV0Uz6wR5T9t /lpt3yJaSEn9tl5tT5FDZ9TJCpUhFbfu3E2VlhfHDWDqkjtE48bn39SdYaBFljySZGDl gMNkU7+LEJXmD2fNiO1yqJ6NwT38CMhGiPP7N6OjNQ5INgtyoiPDqHSPdJsri7PcmeEQ mhfeV3ypblhbTtWFzPKIkcF880hV6B9vHzO3oRbsMgsJd1DHheG2c2gbup0YNGHSqfJ7 /MUA== X-Gm-Message-State: AOAM532c2fo6VB8q+HSrDYocspYRXib355ZPpi74xxx+qbxtcutI3EN3 2V5eKRO1eGWiOOb6eVjddf+/oGBYFela7u0= X-Google-Smtp-Source: ABdhPJzxK4tKOsKXmKq5tOjL/M2oVEZjC183UfLFYmDlQrxG7xgiGY7cFJGcvVq3rDvg/gLR8gKYI7rNVpCjnFY= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7750:a56d:5272:72cb]) (user=saravanak job=sendgmr) by 2002:a05:6214:923:: with SMTP id dk3mr4650090qvb.38.1629223732811; Tue, 17 Aug 2021 11:08:52 -0700 (PDT) Date: Tue, 17 Aug 2021 11:08:41 -0700 In-Reply-To: <20210817180841.3210484-1-saravanak@google.com> Message-Id: <20210817180841.3210484-4-saravanak@google.com> Mime-Version: 1.0 References: <20210817180841.3210484-1-saravanak@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH net v2 3/3] net: mdio-mux: Handle -EPROBE_DEFER correctly From: Saravana Kannan To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski Cc: Saravana Kannan , Marc Zyngier , Neil Armstrong , Kevin Hilman , kernel-team@android.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When registering mdiobus children, if we get an -EPROBE_DEFER, we shouldn't ignore it and continue registering the rest of the mdiobus children. This would permanently prevent the deferring child mdiobus from working instead of reattempting it in the future. So, if a child mdiobus needs to be reattempted in the future, defer the entire mdio-mux initialization. This fixes the issue where PHYs sitting under the mdio-mux aren't initialized correctly if the PHY's interrupt controller is not yet ready when the mdio-mux is being probed. Additional context in the link below. Link: https://lore.kernel.org/lkml/CAGETcx95kHrv8wA-O+-JtfH7H9biJEGJtijuPVN0V5dUKUAB3A@mail.gmail.com/#t Signed-off-by: Saravana Kannan Reviewed-by: Andrew Lunn Acked-by: Marc Zyngier Tested-by: Marc Zyngier Acked-by: Kevin Hilman Tested-by: Kevin Hilman --- drivers/net/mdio/mdio-mux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index 13035e2685c4..ebd001f0eece 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/mdio-mux.c @@ -175,11 +175,15 @@ int mdio_mux_init(struct device *dev, cb->mii_bus->write = mdio_mux_write; r = of_mdiobus_register(cb->mii_bus, child_bus_node); if (r) { + mdiobus_free(cb->mii_bus); + if (r == -EPROBE_DEFER) { + ret_val = r; + goto err_loop; + } + devm_kfree(dev, cb); dev_err(dev, "Error: Failed to register MDIO bus for child %pOF\n", child_bus_node); - mdiobus_free(cb->mii_bus); - devm_kfree(dev, cb); } else { cb->next = pb->children; pb->children = cb;