Skip to content

Commit 494fed6

Browse files
author
Andi Shyti
committed
i2c: qcom-geni: Simplify error handling in probe function
Avoid repeating the error handling pattern: geni_se_resources_off(&gi2c->se); clk_disable_unprepare(gi2c->core_clk); return; Introduce a single 'goto' exit label for cleanup in case of errors. While there are currently two distinct exit points, there is no overlap in their handling, allowing both branches to coexist cleanly. Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org> Link: https://lore.kernel.org/r/20241227223230.462395-3-andi.shyti@kernel.org Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent bfb3ddf commit 494fed6

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

drivers/i2c/busses/i2c-qcom-geni.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -867,14 +867,13 @@ static int geni_i2c_probe(struct platform_device *pdev)
867867

868868
ret = geni_se_resources_on(&gi2c->se);
869869
if (ret) {
870-
clk_disable_unprepare(gi2c->core_clk);
871-
return dev_err_probe(dev, ret, "Error turning on resources\n");
870+
dev_err_probe(dev, ret, "Error turning on resources\n");
871+
goto err_clk;
872872
}
873873
proto = geni_se_read_proto(&gi2c->se);
874874
if (proto != GENI_SE_I2C) {
875-
geni_se_resources_off(&gi2c->se);
876-
clk_disable_unprepare(gi2c->core_clk);
877-
return dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto);
875+
ret = dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto);
876+
goto err_resources;
878877
}
879878

880879
if (desc && desc->no_dma_support)
@@ -886,11 +885,8 @@ static int geni_i2c_probe(struct platform_device *pdev)
886885
/* FIFO is disabled, so we can only use GPI DMA */
887886
gi2c->gpi_mode = true;
888887
ret = setup_gpi_dma(gi2c);
889-
if (ret) {
890-
geni_se_resources_off(&gi2c->se);
891-
clk_disable_unprepare(gi2c->core_clk);
892-
return ret;
893-
}
888+
if (ret)
889+
goto err_resources;
894890

895891
dev_dbg(dev, "Using GPI DMA mode for I2C\n");
896892
} else {
@@ -902,10 +898,9 @@ static int geni_i2c_probe(struct platform_device *pdev)
902898
tx_depth = desc->tx_fifo_depth;
903899

904900
if (!tx_depth) {
905-
geni_se_resources_off(&gi2c->se);
906-
clk_disable_unprepare(gi2c->core_clk);
907-
return dev_err_probe(dev, -EINVAL,
908-
"Invalid TX FIFO depth\n");
901+
ret = dev_err_probe(dev, -EINVAL,
902+
"Invalid TX FIFO depth\n");
903+
goto err_resources;
909904
}
910905

911906
gi2c->tx_wm = tx_depth - 1;
@@ -942,10 +937,18 @@ static int geni_i2c_probe(struct platform_device *pdev)
942937

943938
dev_dbg(dev, "Geni-I2C adaptor successfully added\n");
944939

945-
return 0;
940+
return ret;
941+
942+
err_resources:
943+
geni_se_resources_off(&gi2c->se);
944+
err_clk:
945+
clk_disable_unprepare(gi2c->core_clk);
946+
947+
return ret;
946948

947949
err_dma:
948950
release_gpi_dma(gi2c);
951+
949952
return ret;
950953
}
951954

0 commit comments

Comments
 (0)