Skip to content

Commit 844d098

Browse files
javiercarrascocruzchleroy
authored andcommitted
soc: fsl: cpm1: tsa: switch to for_each_available_child_of_node_scoped()
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 <[email protected]> Acked-by: Herve Codina <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christophe Leroy <[email protected]>
1 parent 9852d85 commit 844d098

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

drivers/soc/fsl/qe/tsa.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ static inline int tsa_of_parse_tdm_tx_route(struct tsa *tsa,
680680

681681
static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
682682
{
683-
struct device_node *tdm_np;
684683
struct tsa_tdm *tdm;
685684
struct clk *clk;
686685
u32 tdm_id, val;
@@ -691,11 +690,10 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
691690
for (i = 0; i < ARRAY_SIZE(tsa->tdm); i++)
692691
tsa->tdm[i].is_enable = false;
693692

694-
for_each_available_child_of_node(np, tdm_np) {
693+
for_each_available_child_of_node_scoped(np, tdm_np) {
695694
ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
696695
if (ret) {
697696
dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
698-
of_node_put(tdm_np);
699697
return ret;
700698
}
701699
switch (tdm_id) {
@@ -719,16 +717,14 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
719717
invalid_tdm:
720718
dev_err(tsa->dev, "%pOF: Invalid tdm_id (%u)\n", tdm_np,
721719
tdm_id);
722-
of_node_put(tdm_np);
723720
return -EINVAL;
724721
}
725722
}
726723

727-
for_each_available_child_of_node(np, tdm_np) {
724+
for_each_available_child_of_node_scoped(np, tdm_np) {
728725
ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
729726
if (ret) {
730727
dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
731-
of_node_put(tdm_np);
732728
return ret;
733729
}
734730

@@ -742,14 +738,12 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
742738
dev_err(tsa->dev,
743739
"%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
744740
tdm_np);
745-
of_node_put(tdm_np);
746741
return ret;
747742
}
748743
if (val > 3) {
749744
dev_err(tsa->dev,
750745
"%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
751746
tdm_np, val);
752-
of_node_put(tdm_np);
753747
return -EINVAL;
754748
}
755749
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)
761755
dev_err(tsa->dev,
762756
"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n",
763757
tdm_np);
764-
of_node_put(tdm_np);
765758
return ret;
766759
}
767760
if (val > 3) {
768761
dev_err(tsa->dev,
769762
"%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
770763
tdm_np, val);
771-
of_node_put(tdm_np);
772764
return -EINVAL;
773765
}
774766
tdm->simode_tdm |= TSA_SIMODE_TDM_TFSD(val);
@@ -792,27 +784,23 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
792784
clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "rsync" : "l1rsync");
793785
if (IS_ERR(clk)) {
794786
ret = PTR_ERR(clk);
795-
of_node_put(tdm_np);
796787
goto err;
797788
}
798789
ret = clk_prepare_enable(clk);
799790
if (ret) {
800791
clk_put(clk);
801-
of_node_put(tdm_np);
802792
goto err;
803793
}
804794
tdm->l1rsync_clk = clk;
805795

806796
clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "rclk" : "l1rclk");
807797
if (IS_ERR(clk)) {
808798
ret = PTR_ERR(clk);
809-
of_node_put(tdm_np);
810799
goto err;
811800
}
812801
ret = clk_prepare_enable(clk);
813802
if (ret) {
814803
clk_put(clk);
815-
of_node_put(tdm_np);
816804
goto err;
817805
}
818806
tdm->l1rclk_clk = clk;
@@ -821,27 +809,23 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
821809
clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "tsync" : "l1tsync");
822810
if (IS_ERR(clk)) {
823811
ret = PTR_ERR(clk);
824-
of_node_put(tdm_np);
825812
goto err;
826813
}
827814
ret = clk_prepare_enable(clk);
828815
if (ret) {
829816
clk_put(clk);
830-
of_node_put(tdm_np);
831817
goto err;
832818
}
833819
tdm->l1tsync_clk = clk;
834820

835821
clk = of_clk_get_by_name(tdm_np, tsa_is_qe(tsa) ? "tclk" : "l1tclk");
836822
if (IS_ERR(clk)) {
837823
ret = PTR_ERR(clk);
838-
of_node_put(tdm_np);
839824
goto err;
840825
}
841826
ret = clk_prepare_enable(clk);
842827
if (ret) {
843828
clk_put(clk);
844-
of_node_put(tdm_np);
845829
goto err;
846830
}
847831
tdm->l1tclk_clk = clk;
@@ -859,16 +843,12 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
859843
}
860844

861845
ret = tsa_of_parse_tdm_rx_route(tsa, tdm_np, tsa->tdms, tdm_id);
862-
if (ret) {
863-
of_node_put(tdm_np);
846+
if (ret)
864847
goto err;
865-
}
866848

867849
ret = tsa_of_parse_tdm_tx_route(tsa, tdm_np, tsa->tdms, tdm_id);
868-
if (ret) {
869-
of_node_put(tdm_np);
850+
if (ret)
870851
goto err;
871-
}
872852

873853
tdm->is_enable = true;
874854
}

0 commit comments

Comments
 (0)