From patchwork Wed Oct 2 20:21:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13820341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83B9CCF31BA for ; Wed, 2 Oct 2024 20:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=10Ete0eASbyrDKTfZvxGKRPjMfOwNNJQDe6fYsjfOVs=; b=utytW/u/8yGcSyzRq11oRgoQDe Aqbk3DA0jZbLBmHhOJP9ClHuNyFRh6cIQfLbKAMpoU3yajecyUksnBmEsPNgDDQ+ASsLa2bMET28+ E4N34o5BrQVEfG8jbZ8xNlurxdgpUxUPH1/f1TBBdtWT+GBNRmIYBwoMMny4IIiusveRoWMI1RqAD I/e+kaaRK6GEPOuQLccPNSUhNh7uOKVVelCKK8eutxkxn/zBmVoBba5ZmA0dcguRNUtyk0kKkX4aE JVbD4UZ6WIl74QI9OdEGV4R50BQ/1OJCOTxcFw2g6+aoy4rHM0npZoIn7Wybu+v6RFvONvjsf0ojY qpHZQwXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sw5sT-00000007OeK-1VXp; Wed, 02 Oct 2024 20:23:17 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sw5rD-00000007OTa-3fdq for linux-arm-kernel@lists.infradead.org; Wed, 02 Oct 2024 20:22:01 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-37cdac05af9so213222f8f.0 for ; Wed, 02 Oct 2024 13:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727900518; x=1728505318; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=10Ete0eASbyrDKTfZvxGKRPjMfOwNNJQDe6fYsjfOVs=; b=ebUGp8C0/I46MEU4AB+sMWO+l8LrrKFbBAtVt3Zp2Pcc/xWM8FZnyHQOc49bdkxSYu M2vaKBD6ph3ZVXMQQ6M7uL27kH9ajknDYyrY6v/7ZyiPeZRjvyFXUMijIvre3XQUbz6i sYgzvhKo+Djb94Givfez/m4UmSXbF5vy1ZURC+B6swqQDlbRv2S4rP3izjbgLAvcYQXO vXG7UWoO0zagzBwPeljsUU8b8zB++YOH0vVmU2B781cag7F42TqoMEcQs/K03xqp/X6w Uv0ueHy9Dm/PrRpCtsuwbgph7dIuPImRQFneF0+PjxOIoUEEYzNBEnALRsDz3MFWZLvP 5l4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727900518; x=1728505318; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=10Ete0eASbyrDKTfZvxGKRPjMfOwNNJQDe6fYsjfOVs=; b=faQaPDWdUUOwhMmd3T87DVTIjv930W8RcfVkMH0Q5d3+oqQhRDwnqsgCD08RM93+ff /wPe6GrhO4UM/RUInGDaxvoTdKZ2HrIVk4HOJ+ilctqz2YxB8fsZeKe2iONC34rOU3Q9 U/ebfbpupFkQnpPne5YemE+/6cOUhiKbpoF698D06j1Q+VeNS0ec2Y7xLnGsLHoh3TZB Nyw9k5L/75nvvH6lafr+YoXknzcS7xxy892EsYBzK69QXDqYIqMuGtwDTCm29+d3mkyp eOkzoA2h5mAZ9SoshhBMP+JZO+TILCVtWa1wj2w9NG+BIyCHpD+BfUJ7cMol/jxjnpMK xIjA== X-Forwarded-Encrypted: i=1; AJvYcCVC87f+jhKK12yi96C9ilbSRvSFQ5APNqYSvChttPbQcgclw81Zqm/KCSScYjOvNgIjyGu6dUUGLwSigOjEDCOB@lists.infradead.org X-Gm-Message-State: AOJu0YxT7COCBTD/LLLYqEhmPobb+s6kegcHFh6872K5YnpKqPutWhsL ceY9Enn9HMDfmX6woP2orQyQCa7SOzs3iDIKZVtAdIEEh53b2bwK X-Google-Smtp-Source: AGHT+IFoAq4Ph8jiDRYgIEa71gIMuyXdNHKKqBbTh6+oyGjpqdo81GEjyoal0nyN5Ul0h29juLMdlA== X-Received: by 2002:a5d:58ee:0:b0:374:c7a5:d610 with SMTP id ffacd0b85a97d-37cfba0a4fbmr3562525f8f.43.1727900517427; Wed, 02 Oct 2024 13:21:57 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-28a8-6b99-3729-0965.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:28a8:6b99:3729:965]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd572fb5dsm14703947f8f.88.2024.10.02.13.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 13:21:56 -0700 (PDT) From: Javier Carrasco Date: Wed, 02 Oct 2024 22:21:51 +0200 Subject: [PATCH] soc: fsl: cpm1: tsa: switch to for_each_available_child_of_node_scoped() MIME-Version: 1.0 Message-Id: <20241002-tsa-scoped-v1-1-ba6a6d657f82@gmail.com> X-B4-Tracking: v=1; b=H4sIAF6r/WYC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxNDAwMj3ZLiRN3i5PyC1BRdc1Mz0zRzk7RU42QDJaCGgqLUtMwKsGHRsbW 1AM/O5BdcAAAA To: Herve Codina , Qiang Zhao , Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727900514; l=5467; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=rKJz0hao9xUpcsffGX5ZoN2ju/z7QmSDWhPXF7YCt+8=; b=Etx2qoaGCIabzk/U64d9Sqti+QbXieObYLBdJ6sdh4HrFIOI6H1/inwqehWshOTHicrQmUIRM 8pnW+dWmNRRDzA9jRw33np5cwayHwZsmuYTEi4+1M70RhscG15sJDi/ X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241002_132159_960702_38574530 X-CRM114-Status: GOOD ( 14.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The non-scoped variant of this macro turns error-prone as soon as error paths are included, because explicit calls to of_node_put() are required to avoid leaking memory. Using its scoped counterpart simplifies the code by removing the need of explicit calls to of_node_put(), as they are automatically triggered as soon as the child node goes out of scope. Moreover, it is more robust as it accounts for new error paths without having to worry about decrementing the object's refcount. Note that the device_node is declared within the macro, and its explicit declaration can be dropped as well if it is not used anywhere else. Signed-off-by: Javier Carrasco Acked-by: Herve Codina --- drivers/soc/fsl/qe/tsa.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) --- base-commit: fe21733536749bb1b31c9c84e0b8d2ab8d82ce13 change-id: 20241002-tsa-scoped-7565f74fe3c0 Best regards, diff --git a/drivers/soc/fsl/qe/tsa.c b/drivers/soc/fsl/qe/tsa.c index f0889b3fcaf2..a1140aadfd6c 100644 --- a/drivers/soc/fsl/qe/tsa.c +++ b/drivers/soc/fsl/qe/tsa.c @@ -680,7 +680,6 @@ static inline int tsa_of_parse_tdm_tx_route(struct tsa *tsa, static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) { - struct device_node *tdm_np; struct tsa_tdm *tdm; struct clk *clk; u32 tdm_id, val; @@ -691,11 +690,10 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) for (i = 0; i < ARRAY_SIZE(tsa->tdm); i++) tsa->tdm[i].is_enable = false; - for_each_available_child_of_node(np, tdm_np) { + for_each_available_child_of_node_scoped(np, tdm_np) { ret = of_property_read_u32(tdm_np, "reg", &tdm_id); if (ret) { dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np); - of_node_put(tdm_np); return ret; } switch (tdm_id) { @@ -719,16 +717,14 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) invalid_tdm: dev_err(tsa->dev, "%pOF: Invalid tdm_id (%u)\n", tdm_np, tdm_id); - of_node_put(tdm_np); return -EINVAL; } } - for_each_available_child_of_node(np, tdm_np) { + for_each_available_child_of_node_scoped(np, tdm_np) { ret = of_property_read_u32(tdm_np, "reg", &tdm_id); if (ret) { dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np); - of_node_put(tdm_np); return ret; } @@ -742,14 +738,12 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) dev_err(tsa->dev, "%pOF: failed to read fsl,rx-frame-sync-delay-bits\n", tdm_np); - of_node_put(tdm_np); return ret; } if (val > 3) { dev_err(tsa->dev, "%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n", tdm_np, val); - of_node_put(tdm_np); return -EINVAL; } tdm->simode_tdm |= TSA_SIMODE_TDM_RFSD(val); @@ -761,14 +755,12 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) dev_err(tsa->dev, "%pOF: failed to read fsl,tx-frame-sync-delay-bits\n", tdm_np); - of_node_put(tdm_np); return ret; } if (val > 3) { dev_err(tsa->dev, "%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n", tdm_np, val); - of_node_put(tdm_np); return -EINVAL; } tdm->simode_tdm |= TSA_SIMODE_TDM_TFSD(val); @@ -792,13 +784,11 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "rsync" : "l1rsync"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - of_node_put(tdm_np); goto err; } ret = clk_prepare_enable(clk); if (ret) { clk_put(clk); - of_node_put(tdm_np); goto err; } tdm->l1rsync_clk = clk; @@ -806,13 +796,11 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "rclk" : "l1rclk"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - of_node_put(tdm_np); goto err; } ret = clk_prepare_enable(clk); if (ret) { clk_put(clk); - of_node_put(tdm_np); goto err; } tdm->l1rclk_clk = clk; @@ -821,13 +809,11 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "tsync" : "l1tsync"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - of_node_put(tdm_np); goto err; } ret = clk_prepare_enable(clk); if (ret) { clk_put(clk); - of_node_put(tdm_np); goto err; } tdm->l1tsync_clk = clk; @@ -835,13 +821,11 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "tclk" : "l1tclk"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - of_node_put(tdm_np); goto err; } ret = clk_prepare_enable(clk); if (ret) { clk_put(clk); - of_node_put(tdm_np); goto err; } tdm->l1tclk_clk = clk; @@ -859,16 +843,12 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np) } ret = tsa_of_parse_tdm_rx_route(tsa, tdm_np, tsa->tdms, tdm_id); - if (ret) { - of_node_put(tdm_np); + if (ret) goto err; - } ret = tsa_of_parse_tdm_tx_route(tsa, tdm_np, tsa->tdms, tdm_id); - if (ret) { - of_node_put(tdm_np); + if (ret) goto err; - } tdm->is_enable = true; }