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; }