Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1308779pxb; Sun, 22 Aug 2021 12:34:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgRilcHtBeAxkSKuWN22782g9B4wzgPViCuZ6fppoFQODfqa5c5HhgJNCWHlNReU5K2lxp X-Received: by 2002:a17:906:6bc5:: with SMTP id t5mr5327899ejs.340.1629660867418; Sun, 22 Aug 2021 12:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629660867; cv=none; d=google.com; s=arc-20160816; b=otCt0Vb7/w7DNLCx+55JUuU1b0/d3B/b9ZJCuKKGCixn8UaJp/7J1rgURBc/qrkWHH 0LabxwRvITizy8blkuIzhrGweVq0akFtn9q055xRz0pvxnr2Esz7bLH2CcA0x98HNYSb w9r4aM9I54Ri0pLDpUjGRbMCz3NdLgDjNwrmpc8WY8Z8e5y3ynKVcXFsmz0RcZhMJdpM 76HNMx/7N4dNK00yjQiP2vCer2FeHpv4P1YMm2Gz2fYgK/d3E9H4IFVxwxRhK0bzBNqY uyB93YvFhUx3GG3zDo+p4Ceyyh3cp7v9KEZ1a07eNXCIt3rtZkak1JX6s4sqYAyHaa+X Ch5g== 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 :dkim-signature; bh=t/57/7Ra/e8dihd9Z1Y6uUjnPgEzQmajUXKvHAVuv2o=; b=xK0tGtSL3C+KmOow5duTGNeLwtErl/wErqgNxes/UdsOtCcveJG/LG8szFXE1sqThP 19vGfM9KAnPOz+aGrfvMFwaxjlGF0D75P5tmZhWFIN9y+5xHLXg14UYLuucBMUoUgghy FaOGEAUWvsFjHbNlwOFl7MUJnJpkhM8SnKNk4mEoAn7mePQEEI11ON4EUMu7n/uEHFHe U2e9OaCeCmekCR21cWovxJT1jlAaq6UegsQzyml3c8nEveQVGBjW9jVSlL6Tg+UMFzBI R/fJ6vxyddQIpWU3Z1n8NMJKD+5OhxgL4T0j+8/1bqICXCGYCodhq4k2KAbIbrsmN6qr hxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@pqrs.dk header.s=google header.b=KskLkgGD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd15si13246516ejc.463.2021.08.22.12.34.04; Sun, 22 Aug 2021 12:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@pqrs.dk header.s=google header.b=KskLkgGD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbhHVTd1 (ORCPT + 99 others); Sun, 22 Aug 2021 15:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232763AbhHVTdZ (ORCPT ); Sun, 22 Aug 2021 15:33:25 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A941CC061756 for ; Sun, 22 Aug 2021 12:32:43 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id n12so22735263edx.8 for ; Sun, 22 Aug 2021 12:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t/57/7Ra/e8dihd9Z1Y6uUjnPgEzQmajUXKvHAVuv2o=; b=KskLkgGD8JaNGD7ASOLh1s3nv+GQU/By7BGMuPpogHKd98UmycDTDIp+JL52TOseZj KSonxBFgsSDlnwdUFw/bXEAZ59NcjEBqJoaEqYuTTyfRL1rfM98dcAKuqwUcuCwcgl1J PN4qN2J1RbDUKZofcxhYZEYxXW+OIFtDC5Mkg= 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:mime-version:content-transfer-encoding; bh=t/57/7Ra/e8dihd9Z1Y6uUjnPgEzQmajUXKvHAVuv2o=; b=ZfbiXRDXJleLPvnZH8oy5UFyx0QZGJsukauz4qfSkXb8G/h51Zmv7VWPgxYgeNdSfW QpvFZ2Bx2Nnj9biiDgnF3pigzBo3fg+d3FJdSBp1okMpRhtavkpvjT5yaKnhaf6rWx3d i5YzxdMFYh0jhSnF557pJ2rngfbHOqAKdWaDPfbIuQL+LktNwNYLTWD8IMMf5w2tsQ8B pzymiUBPW65JMZWm4an+V05ILvJf1o3kIyJVKHupmPBFtK1CRRNCmaeGQlVetHnAREUH 5K4LQzaJvKvG0Y+VpBHSeUPZZ9N2JtN8S17RJWEri6ohyPRs6tTHAB2zWT29K/X9T3dA mV9A== X-Gm-Message-State: AOAM531pbStB2UrZ1FEeNmUe0Oo1dGBZVI4a4akgaAGEchrNgBY0INQl rxSWwhZnPJ8Wyg88lQ9nARglBA== X-Received: by 2002:a05:6402:4406:: with SMTP id y6mr32848397eda.242.1629660762281; Sun, 22 Aug 2021 12:32:42 -0700 (PDT) Received: from capella.. (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id cn16sm7780053edb.9.2021.08.22.12.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Aug 2021 12:32:41 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: Linus Walleij , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Rob Herring , Heiner Kallweit , Russell King Cc: mir@bang-olufsen.dk, alvin@pqrs.dk, =?UTF-8?q?Alvin=20=C5=A0ipraga?= , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next 1/5] net: dsa: realtek-smi: fix mdio_free bug on module unload Date: Sun, 22 Aug 2021 21:31:39 +0200 Message-Id: <20210822193145.1312668-2-alvin@pqrs.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210822193145.1312668-1-alvin@pqrs.dk> References: <20210822193145.1312668-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin Šipraga realtek-smi-core fails to unregister the slave MII bus on module unload, raising the following BUG warning: mdio_bus.c:650: BUG_ON(bus->state != MDIOBUS_UNREGISTERED); kernel BUG at drivers/net/phy/mdio_bus.c:650! Internal error: Oops - BUG: 0 [#1] PREEMPT_RT SMP Call trace: mdiobus_free+0x4c/0x50 devm_mdiobus_free+0x18/0x20 release_nodes.isra.0+0x1c0/0x2b0 devres_release_all+0x38/0x58 device_release_driver_internal+0x124/0x1e8 driver_detach+0x54/0xe0 bus_remove_driver+0x60/0xd8 driver_unregister+0x34/0x60 platform_driver_unregister+0x18/0x20 realtek_smi_driver_exit+0x14/0x1c [realtek_smi] Fix this by duly unregistering the slave MII bus with mdiobus_unregister. We do this in the DSA teardown path, since registration is performed in the DSA setup path. Cc: Linus Walleij Fixes: d8652956cf37 ("net: dsa: realtek-smi: Add Realtek SMI driver") Signed-off-by: Alvin Šipraga --- drivers/net/dsa/realtek-smi-core.c | 6 ++++++ drivers/net/dsa/realtek-smi-core.h | 1 + drivers/net/dsa/rtl8366rb.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/drivers/net/dsa/realtek-smi-core.c b/drivers/net/dsa/realtek-smi-core.c index 8e49d4f85d48..6992b6b31db6 100644 --- a/drivers/net/dsa/realtek-smi-core.c +++ b/drivers/net/dsa/realtek-smi-core.c @@ -383,6 +383,12 @@ int realtek_smi_setup_mdio(struct realtek_smi *smi) return ret; } +void realtek_smi_teardown_mdio(struct realtek_smi *smi) +{ + if (smi->slave_mii_bus) + mdiobus_unregister(smi->slave_mii_bus); +} + static int realtek_smi_probe(struct platform_device *pdev) { const struct realtek_smi_variant *var; diff --git a/drivers/net/dsa/realtek-smi-core.h b/drivers/net/dsa/realtek-smi-core.h index fcf465f7f922..6cfa5f2df7ea 100644 --- a/drivers/net/dsa/realtek-smi-core.h +++ b/drivers/net/dsa/realtek-smi-core.h @@ -119,6 +119,7 @@ struct realtek_smi_variant { int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr, u32 data); int realtek_smi_setup_mdio(struct realtek_smi *smi); +void realtek_smi_teardown_mdio(struct realtek_smi *smi); /* RTL8366 library helpers */ int rtl8366_mc_is_used(struct realtek_smi *smi, int mc_index, int *used); diff --git a/drivers/net/dsa/rtl8366rb.c b/drivers/net/dsa/rtl8366rb.c index a89093bc6c6a..6537fac7aba4 100644 --- a/drivers/net/dsa/rtl8366rb.c +++ b/drivers/net/dsa/rtl8366rb.c @@ -982,6 +982,13 @@ static int rtl8366rb_setup(struct dsa_switch *ds) return 0; } +static void rtl8366rb_teardown(struct dsa_switch *ds) +{ + struct realtek_smi *smi = ds->priv; + + realtek_smi_teardown_mdio(smi); +} + static enum dsa_tag_protocol rtl8366_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -1505,6 +1512,7 @@ static int rtl8366rb_detect(struct realtek_smi *smi) static const struct dsa_switch_ops rtl8366rb_switch_ops = { .get_tag_protocol = rtl8366_get_tag_protocol, .setup = rtl8366rb_setup, + .teardown = rtl8366rb_teardown, .phylink_mac_link_up = rtl8366rb_mac_link_up, .phylink_mac_link_down = rtl8366rb_mac_link_down, .get_strings = rtl8366_get_strings, -- 2.32.0