From patchwork Tue Aug 27 07:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779048 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 613D8156C5E; Tue, 27 Aug 2024 07:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744675; cv=none; b=UDJ4WLn5YMMPTaF5NIWLGnAfavpvpcRpLDZGvGSMNj0WO/L90yy9AsHRZqcJB8nXNIgurBKrB28Cnqn5WadfZxKW3RHLO9VBDaOjvwQGOZL8K1oPE9WZwzgvUw9i1+vRMqn87nRQCBkEnAsdxczZOe5AfguBNGB5DFtT3rgeOP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744675; c=relaxed/simple; bh=8UyNLSsGP0E5k6oltSXFYCV+nNEVDb0t3FBVM3PNeDU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JbgplmIjIb2ss2ALzjZDxbZU5Bs41QAhSzynC8CAsKUI6J7m1pXAU+WN01nHqrgjtSzvvafbNC/lREa7LAfI4u+Npnch8dHthLIw6zYl7FyuqDy2QyOUFjGpnEmhd6PFO6cy+F97f7lmb8Xiil8a8WTSUCRwSWQ/F+BoE4ePX7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WtKLX1kzwz1S99K; Tue, 27 Aug 2024 15:44:20 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id A7A601A0188; Tue, 27 Aug 2024 15:44:30 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:29 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 1/7] net: stmmac: dwmac-sun8i: Use for_each_child_of_node_scoped() and __free() Date: Tue, 27 Aug 2024 15:52:13 +0800 Message-ID: <20240827075219.3793198-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Avoid need to manually handle of_node_put() by using for_each_child_of_node_scoped() and __free(), which can simplfy code. Signed-off-by: Jinjie Ruan --- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index cc93f73a380e..415a0d23b3a5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -774,46 +774,38 @@ static int sun8i_dwmac_reset(struct stmmac_priv *priv) static int get_ephy_nodes(struct stmmac_priv *priv) { struct sunxi_priv_data *gmac = priv->plat->bsp_priv; - struct device_node *mdio_mux, *iphynode; - struct device_node *mdio_internal; int ret; - mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux"); + struct device_node *mdio_mux __free(device_node) = + of_get_child_by_name(priv->device->of_node, "mdio-mux"); if (!mdio_mux) { dev_err(priv->device, "Cannot get mdio-mux node\n"); return -ENODEV; } - mdio_internal = of_get_compatible_child(mdio_mux, - "allwinner,sun8i-h3-mdio-internal"); - of_node_put(mdio_mux); + struct device_node *mdio_internal __free(device_node) = + of_get_compatible_child(mdio_mux, "allwinner,sun8i-h3-mdio-internal"); if (!mdio_internal) { dev_err(priv->device, "Cannot get internal_mdio node\n"); return -ENODEV; } /* Seek for internal PHY */ - for_each_child_of_node(mdio_internal, iphynode) { + for_each_child_of_node_scoped(mdio_internal, iphynode) { gmac->ephy_clk = of_clk_get(iphynode, 0); if (IS_ERR(gmac->ephy_clk)) continue; gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL); if (IS_ERR(gmac->rst_ephy)) { ret = PTR_ERR(gmac->rst_ephy); - if (ret == -EPROBE_DEFER) { - of_node_put(iphynode); - of_node_put(mdio_internal); + if (ret == -EPROBE_DEFER) return ret; - } continue; } dev_info(priv->device, "Found internal PHY node\n"); - of_node_put(iphynode); - of_node_put(mdio_internal); return 0; } - of_node_put(mdio_internal); return -ENODEV; } From patchwork Tue Aug 27 07:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779050 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 0066F158875; Tue, 27 Aug 2024 07:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744676; cv=none; b=OjW4c4Jjdj/qSPbnYBEixGZffNl7PtgOB153uBTZJiAZsLNc5CywfT2HKa/0/oPJkcOxmpQYLny/MPUMeyG2fqMzCJ1hG1eE3LHWq0bNSftOnAMZMoOgL5SZO8vaSng2VTLntvD0bZj4nnD/4mz20+z2tvoNvv0TXPH/ecZeE0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744676; c=relaxed/simple; bh=g9ZvAHk+N+rt85ClMjsz9HfcR2QjF4Ufi+FbhGOz9tY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gVssElx9lRT/WkqsvEQp53zIqfnhS6WKN7FsBhBSbSgtiyrslRQUJfxjsYT1m0JkWMyNVi6T6wlYUHG6n8ft51KNK6iH6L1lpewr0wAA5nT2O8eiudCW6RbBmvYxABPdW4oTwFO9B+FK47VQzrhL4xfxGbyWT9iaUjy+Sp2rvRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WtKLB3T2CzyRCS; Tue, 27 Aug 2024 15:44:02 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 8B15F140137; Tue, 27 Aug 2024 15:44:31 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:30 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 2/7] net: dsa: realtek: Use for_each_child_of_node_scoped() and __free() Date: Tue, 27 Aug 2024 15:52:14 +0800 Message-ID: <20240827075219.3793198-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Avoid need to manually handle of_node_put() by using for_each_child_of_node_scoped() and __free(), which can simplfy code. Signed-off-by: Jinjie Ruan Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl8366rb.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 9e821b42e5f3..0acdcdd93ea2 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1009,7 +1009,6 @@ static int rtl8366rb_setup_all_leds_off(struct realtek_priv *priv) static int rtl8366rb_setup_leds(struct realtek_priv *priv) { - struct device_node *leds_np, *led_np; struct dsa_switch *ds = &priv->ds; struct dsa_port *dp; int ret = 0; @@ -1018,23 +1017,21 @@ static int rtl8366rb_setup_leds(struct realtek_priv *priv) if (!dp->dn) continue; - leds_np = of_get_child_by_name(dp->dn, "leds"); + struct device_node *leds_np __free(device_node) = + of_get_child_by_name(dp->dn, "leds"); if (!leds_np) { dev_dbg(priv->dev, "No leds defined for port %d", dp->index); continue; } - for_each_child_of_node(leds_np, led_np) { + for_each_child_of_node_scoped(leds_np, led_np) { ret = rtl8366rb_setup_led(priv, dp, of_fwnode_handle(led_np)); - if (ret) { - of_node_put(led_np); + if (ret) break; - } } - of_node_put(leds_np); if (ret) return ret; } From patchwork Tue Aug 27 07:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779051 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 DF23B158218; Tue, 27 Aug 2024 07:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744677; cv=none; b=CNwvd2tKfvty8HUsaEIgAQMKbEg0riwhuHdIrZGo7amXoi5dwmlIpPo+BgQmb8g1gK91D5IqHy2Vbh3p//osFipDHAJx1Mu2XGXBL5aeyX4H0umGmaKE8w6bjwYxMgCzwj1WQo8GIL06aZTHPDPjmu2Lb3PW6QqbgM7kOw2tBH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744677; c=relaxed/simple; bh=xpQdtN/7TkKZDh5NKU1G4LJqTWkDaV8ddKqKicbmXxY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q6RHSymZWxavOXWUzkx9QNNcq5ihpBGMQqm4dbvUL5APKIKRxs5ODN/bSfiqdPFLAAG/w8cbKv9QkVhduQMIxGx5TzXQ17Noy2wyyYc7zLloQsZ1CdcGWQNm6i3Y+aP77C4mWPFeX5V4BcfKB650ktcQStTxcDE5z9YGMCFeT9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WtKKs5ltyz16PVw; Tue, 27 Aug 2024 15:43:45 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 7713E1401F1; Tue, 27 Aug 2024 15:44:32 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:31 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 3/7] net: phy: Fix missing of_node_put() for leds Date: Tue, 27 Aug 2024 15:52:15 +0800 Message-ID: <20240827075219.3793198-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org The call of of_get_child_by_name() will cause refcount incremented for leds, if it succeeds, it should call of_node_put() to decrease it. Fix it by using __free(). Also use for_each_available_child_of_node_scoped() to simplfy it. Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs") Signed-off-by: Jinjie Ruan --- drivers/net/phy/phy_device.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8f5314c1fecc..2fca33ff79e7 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3407,7 +3407,6 @@ static int of_phy_led(struct phy_device *phydev, static int of_phy_leds(struct phy_device *phydev) { struct device_node *node = phydev->mdio.dev.of_node; - struct device_node *leds, *led; int err; if (!IS_ENABLED(CONFIG_OF_MDIO)) @@ -3416,14 +3415,13 @@ static int of_phy_leds(struct phy_device *phydev) if (!node) return 0; - leds = of_get_child_by_name(node, "leds"); + struct device_node *leds __free(device_node) = of_get_child_by_name(node, "leds"); if (!leds) return 0; - for_each_available_child_of_node(leds, led) { + for_each_available_child_of_node_scoped(leds, led) { err = of_phy_led(phydev, led); if (err) { - of_node_put(led); phy_leds_unregister(phydev); return err; } From patchwork Tue Aug 27 07:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779053 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 D3E991714A3; Tue, 27 Aug 2024 07:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744678; cv=none; b=gj7LzNXOhFw9Yk14xrH1gJyMflm4WtlmBz5kfw+EJuImyF2sE31i31GEPE2DsO8ret4rgXerTkUfOQcnn48xobW02KavWh/+NAF+MbKF0iXbyU546R+hot/F9tp25VK0iaTFBTekkNHbmpiMn+JBSe2/ar1Lp5i20J6ZqDboEGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744678; c=relaxed/simple; bh=6oQfqsiOHa148ej6oqVjJ4ZyoSRmgAX54PXgsOHoj68=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DZCQIaD60DF+2CNWzea5ST/PZUdyxKF7kJpwt4gWBbU9KgLzBg9Sc6R+5fP1sGVUdg8vnfQqwCFep61KhlDOJILLVlM6sMcd0nilmp2tOjGEek6oCjIDy4xnXskplNxbLa6dB/RxfrpvB40JtA0QIle0VrUPq7fNfmbJ3spbpbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WtKGy6L3Hz1HFm4; Tue, 27 Aug 2024 15:41:14 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 60CF5140154; Tue, 27 Aug 2024 15:44:33 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:32 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 4/7] net: mdio: mux-mmioreg: Simplified with scoped function and dev_err_probe() Date: Tue, 27 Aug 2024 15:52:16 +0800 Message-ID: <20240827075219.3793198-5-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Avoids the need for manual cleanup of_node_put() in early exits from the loop by using for_each_available_child_of_node_scoped(). And use the dev_err_probe() helper to simplify error handling during probe. This also handle scenario, when EDEFER is returned and useless error is printed. Signed-off-by: Jinjie Ruan --- drivers/net/mdio/mdio-mux-mmioreg.c | 51 ++++++++++++----------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/drivers/net/mdio/mdio-mux-mmioreg.c b/drivers/net/mdio/mdio-mux-mmioreg.c index de08419d0c98..08c484ccdcbe 100644 --- a/drivers/net/mdio/mdio-mux-mmioreg.c +++ b/drivers/net/mdio/mdio-mux-mmioreg.c @@ -96,7 +96,7 @@ static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child, static int mdio_mux_mmioreg_probe(struct platform_device *pdev) { - struct device_node *np2, *np = pdev->dev.of_node; + struct device_node *np = pdev->dev.of_node; struct mdio_mux_mmioreg_state *s; struct resource res; const __be32 *iprop; @@ -109,52 +109,43 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev) return -ENOMEM; ret = of_address_to_resource(np, 0, &res); - if (ret) { - dev_err(&pdev->dev, "could not obtain memory map for node %pOF\n", - np); - return ret; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, + "could not obtain memory map for node %pOF\n", np); s->phys = res.start; s->iosize = resource_size(&res); if (s->iosize != sizeof(uint8_t) && s->iosize != sizeof(uint16_t) && s->iosize != sizeof(uint32_t)) { - dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); - return -EINVAL; + return dev_err_probe(&pdev->dev, -EINVAL, + "only 8/16/32-bit registers are supported\n"); } iprop = of_get_property(np, "mux-mask", &len); - if (!iprop || len != sizeof(uint32_t)) { - dev_err(&pdev->dev, "missing or invalid mux-mask property\n"); - return -ENODEV; - } - if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) { - dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); - return -EINVAL; - } + if (!iprop || len != sizeof(uint32_t)) + return dev_err_probe(&pdev->dev, -ENODEV, + "missing or invalid mux-mask property\n"); + if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) + return dev_err_probe(&pdev->dev, -EINVAL, + "only 8/16/32-bit registers are supported\n"); s->mask = be32_to_cpup(iprop); /* * Verify that the 'reg' property of each child MDIO bus does not * set any bits outside of the 'mask'. */ - for_each_available_child_of_node(np, np2) { + for_each_available_child_of_node_scoped(np, np2) { u64 reg; - if (of_property_read_reg(np2, 0, ®, NULL)) { - dev_err(&pdev->dev, "mdio-mux child node %pOF is " - "missing a 'reg' property\n", np2); - of_node_put(np2); - return -ENODEV; - } - if ((u32)reg & ~s->mask) { - dev_err(&pdev->dev, "mdio-mux child node %pOF has " - "a 'reg' value with unmasked bits\n", - np2); - of_node_put(np2); - return -ENODEV; - } + if (of_property_read_reg(np2, 0, ®, NULL)) + return dev_err_probe(&pdev->dev, -ENODEV, + "mdio-mux child node %pOF is missing a 'reg' property\n", + np2); + if ((u32)reg & ~s->mask) + return dev_err_probe(&pdev->dev, -ENODEV, + "mdio-mux child node %pOF has a 'reg' value with unmasked bits\n", + np2); } ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, From patchwork Tue Aug 27 07:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779052 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 5AF9317BEC1; Tue, 27 Aug 2024 07:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744678; cv=none; b=bTuZySPJNzPa5eTpTAUXGstWQ/oJ++j6oSG13SwAZTEEO8BAYjrTHfYxv1nUahSGPlE7ujDHmuck0ke0IUIjV0xL2vi1/2feVKc56C3Gi/nPGmA5io1VknpSX84DA9UXnWC4nkZ28X+3ngHvuji1Hp3IHGy8g0a7auRj4nHOz9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744678; c=relaxed/simple; bh=jv4XI5yACXeh2L/Tsbj6z0l+qxWAU6Sc3h6P+yEirmI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZATw3Qt6Q4vQ9Qk0pj+of2aqBW5ganq38td1E/HVAOBe3w2qrfmfS7xAAhttJoD/LBpGic6kYXwu+osvE2AuaQ5iDA3VVoVyTgGoRHZgAKmbmuNq5C/o0k8hG7clRdKzRBxEqMlVvV/JjoKacXQVLbsarRpBLeLyDNZGb1usUGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WtKLF1fMlzyRDk; Tue, 27 Aug 2024 15:44:05 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 4C38B140202; Tue, 27 Aug 2024 15:44:34 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:33 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 5/7] net: mv643xx_eth: Simplify with scoped for each OF child loop Date: Tue, 27 Aug 2024 15:52:17 +0800 Message-ID: <20240827075219.3793198-6-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Use scoped for_each_available_child_of_node_scoped() when iterating over device nodes to make code a bit simpler. Signed-off-by: Jinjie Ruan --- drivers/net/ethernet/marvell/mv643xx_eth.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c index f35ae2c88091..9e80899546d9 100644 --- a/drivers/net/ethernet/marvell/mv643xx_eth.c +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c @@ -2802,7 +2802,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) { struct mv643xx_eth_shared_platform_data *pd; - struct device_node *pnp, *np = pdev->dev.of_node; + struct device_node *np = pdev->dev.of_node; int ret; /* bail out if not registered from DT */ @@ -2816,10 +2816,9 @@ static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) mv643xx_eth_property(np, "tx-checksum-limit", pd->tx_csum_limit); - for_each_available_child_of_node(np, pnp) { + for_each_available_child_of_node_scoped(np, pnp) { ret = mv643xx_eth_shared_of_add_port(pdev, pnp); if (ret) { - of_node_put(pnp); mv643xx_eth_shared_of_remove(); return ret; } From patchwork Tue Aug 27 07:52:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779054 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 BF7E9194AEF; Tue, 27 Aug 2024 07:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744679; cv=none; b=dzABNQmaEC6qElGL0yydkIP+num7/sdRgf+MxliQeVBdxClZbe3FVJj67Ls5+mAAMZJCgETKDvYsllAP/PbwP4BK2KUWxHlWR/xbdjYYvg4X0c9lWoeT3XcVWjJIdlbxxI5ymcEloZruujzs+wvIY/lEm9bybNIE5ExKg8RlX0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744679; c=relaxed/simple; bh=8c4Tr1gcsgc3ABStWkW8rdW8bVsFRjz1eLq2j5zUSeI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PMPRKhwM2CP5jdpQm31AYUpNNeU7e2+vDaGbrozNdyDYe/Y89kRf+xGJqx3+8hTbNNUr/1OjxGH7dSP10p8GAK6RHvbeaWUFAi1j8EqGe3rnF8Qh9Ot7pmluonfQFfDZ6/N250DjtopigXSgkhV8OzYsXul3b0iFj0JchsLLpGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtKJt6h77zpTpP; Tue, 27 Aug 2024 15:42:54 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 3AD83140202; Tue, 27 Aug 2024 15:44:35 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:34 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 6/7] net: dsa: microchip: Use scoped function and __free() to simplfy code Date: Tue, 27 Aug 2024 15:52:18 +0800 Message-ID: <20240827075219.3793198-7-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Avoids the need for manual cleanup of_node_put() in early exits from the loop by using for_each_available_child_of_node_scoped() and __free(). Signed-off-by: Jinjie Ruan --- drivers/net/dsa/microchip/ksz_common.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index cd3991792b69..8058a0b7c161 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -4595,7 +4595,6 @@ static int ksz_parse_drive_strength(struct ksz_device *dev) int ksz_switch_register(struct ksz_device *dev) { const struct ksz_chip_data *info; - struct device_node *port, *ports; phy_interface_t interface; unsigned int port_num; int ret; @@ -4677,25 +4676,22 @@ int ksz_switch_register(struct ksz_device *dev) ret = of_get_phy_mode(dev->dev->of_node, &interface); if (ret == 0) dev->compat_interface = interface; - ports = of_get_child_by_name(dev->dev->of_node, "ethernet-ports"); + struct device_node *ports __free(device_node) = + of_get_child_by_name(dev->dev->of_node, "ethernet-ports"); if (!ports) ports = of_get_child_by_name(dev->dev->of_node, "ports"); if (ports) { - for_each_available_child_of_node(ports, port) { + for_each_available_child_of_node_scoped(ports, port) { if (of_property_read_u32(port, "reg", &port_num)) continue; - if (!(dev->port_mask & BIT(port_num))) { - of_node_put(port); - of_node_put(ports); + if (!(dev->port_mask & BIT(port_num))) return -EINVAL; - } of_get_phy_mode(port, &dev->ports[port_num].interface); ksz_parse_rgmii_delay(dev, port_num, port); } - of_node_put(ports); } dev->synclko_125 = of_property_read_bool(dev->dev->of_node, "microchip,synclko-125"); From patchwork Tue Aug 27 07:52:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13779055 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 9D0B019923A; Tue, 27 Aug 2024 07:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744680; cv=none; b=CmqRP4zeGg1/XZdok+NRsSDtDKTtgCTj6xGZZP951GVO2mMSgiNI/H9QTj2GYe8Z69xOwyr3iy8QQ0ZzaqiTfLie8H1/vdCnNTtvdL3Ud/p2+SoCwbcES33vtLm2em24lXk9gpD0YZYXAGMxKElngjET02wRfpxAgswFUdom9m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744680; c=relaxed/simple; bh=9WmcpDhjQpmGtaapVjGKh4LJjWs0+hFNOD0OuHPxsU8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IZG28SD6Z8LlUgCQfVnqoXEIgwv/juxYMRwFy2acmD26Qftsa3gd4dxbPSX7s1Gds62gTQnrB/YCBI8g/xA2BewGnYDYy5XA/oDmMU1Q/D7jsvoHb12+iXHt04wZAJHdbVM6HHm71WgO4nBFS0hy/roM8L6BaeEwF2v/tLs6GgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WtKFJ03pPz20mhj; Tue, 27 Aug 2024 15:39:48 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 19E411400F4; Tue, 27 Aug 2024 15:44:36 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:44:35 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next 7/7] net: bcmasp: Simplify with scoped for each OF child loop Date: Tue, 27 Aug 2024 15:52:19 +0800 Message-ID: <20240827075219.3793198-8-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827075219.3793198-1-ruanjinjie@huawei.com> References: <20240827075219.3793198-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemh500013.china.huawei.com (7.202.181.146) X-Patchwork-Delegate: kuba@kernel.org Use scoped for_each_available_child_of_node_scoped() and __free() when iterating over device nodes to make code a bit simpler. Signed-off-by: Jinjie Ruan --- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 20c6529ec135..73e767aada2f 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -1300,7 +1300,6 @@ static void bcmasp_remove_intfs(struct bcmasp_priv *priv) static int bcmasp_probe(struct platform_device *pdev) { - struct device_node *ports_node, *intf_node; const struct bcmasp_plat_data *pdata; struct device *dev = &pdev->dev; struct bcmasp_priv *priv; @@ -1367,21 +1366,20 @@ static int bcmasp_probe(struct platform_device *pdev) bcmasp_core_init(priv); bcmasp_core_init_filters(priv); - ports_node = of_find_node_by_name(dev->of_node, "ethernet-ports"); + struct device_node *ports_node __free(device_node) = + of_find_node_by_name(dev->of_node, "ethernet-ports"); if (!ports_node) { dev_warn(dev, "No ports found\n"); return -EINVAL; } i = 0; - for_each_available_child_of_node(ports_node, intf_node) { + for_each_available_child_of_node_scoped(ports_node, intf_node) { intf = bcmasp_interface_create(priv, intf_node, i); if (!intf) { - dev_err(dev, "Cannot create eth interface %d\n", i); bcmasp_remove_intfs(priv); - of_node_put(intf_node); - ret = -ENOMEM; - goto of_put_exit; + return dev_err_probe(dev, -ENOMEM, + "Cannot create eth interface %d\n", i); } list_add_tail(&intf->list, &priv->intfs); i++; @@ -1407,16 +1405,14 @@ static int bcmasp_probe(struct platform_device *pdev) "failed to register net_device: %d\n", ret); priv->destroy_wol(priv); bcmasp_remove_intfs(priv); - goto of_put_exit; + return ret; } count++; } dev_info(dev, "Initialized %d port(s)\n", count); -of_put_exit: - of_node_put(ports_node); - return ret; + return 0; } static void bcmasp_remove(struct platform_device *pdev)