Skip to content

Commit 4890081

Browse files
Haibo Chenbroonie
authored andcommitted
spi: spi-nxp-fspi: remove the goto in probe
Remove all the goto in probe to simplify the driver. Signed-off-by: Haibo Chen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 92a09c4 commit 4890081

File tree

1 file changed

+27
-60
lines changed

1 file changed

+27
-60
lines changed

drivers/spi/spi-nxp-fspi.c

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,10 @@ static int nxp_fspi_probe(struct platform_device *pdev)
11611161
struct device_node *np = dev->of_node;
11621162
struct resource *res;
11631163
struct nxp_fspi *f;
1164-
int ret;
1164+
int ret, irq;
11651165
u32 reg;
11661166

1167-
ctlr = spi_alloc_host(&pdev->dev, sizeof(*f));
1167+
ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*f));
11681168
if (!ctlr)
11691169
return -ENOMEM;
11701170

@@ -1174,10 +1174,8 @@ static int nxp_fspi_probe(struct platform_device *pdev)
11741174
f = spi_controller_get_devdata(ctlr);
11751175
f->dev = dev;
11761176
f->devtype_data = (struct nxp_fspi_devtype_data *)device_get_match_data(dev);
1177-
if (!f->devtype_data) {
1178-
ret = -ENODEV;
1179-
goto err_put_ctrl;
1180-
}
1177+
if (!f->devtype_data)
1178+
return -ENODEV;
11811179

11821180
platform_set_drvdata(pdev, f);
11831181

@@ -1186,23 +1184,17 @@ static int nxp_fspi_probe(struct platform_device *pdev)
11861184
f->iobase = devm_platform_ioremap_resource(pdev, 0);
11871185
else
11881186
f->iobase = devm_platform_ioremap_resource_byname(pdev, "fspi_base");
1189-
1190-
if (IS_ERR(f->iobase)) {
1191-
ret = PTR_ERR(f->iobase);
1192-
goto err_put_ctrl;
1193-
}
1187+
if (IS_ERR(f->iobase))
1188+
return PTR_ERR(f->iobase);
11941189

11951190
/* find the resources - controller memory mapped space */
11961191
if (is_acpi_node(dev_fwnode(f->dev)))
11971192
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
11981193
else
11991194
res = platform_get_resource_byname(pdev,
12001195
IORESOURCE_MEM, "fspi_mmap");
1201-
1202-
if (!res) {
1203-
ret = -ENODEV;
1204-
goto err_put_ctrl;
1205-
}
1196+
if (!res)
1197+
return -ENODEV;
12061198

12071199
/* assign memory mapped starting address and mapped size. */
12081200
f->memmap_phy = res->start;
@@ -1211,69 +1203,46 @@ static int nxp_fspi_probe(struct platform_device *pdev)
12111203
/* find the clocks */
12121204
if (dev_of_node(&pdev->dev)) {
12131205
f->clk_en = devm_clk_get(dev, "fspi_en");
1214-
if (IS_ERR(f->clk_en)) {
1215-
ret = PTR_ERR(f->clk_en);
1216-
goto err_put_ctrl;
1217-
}
1206+
if (IS_ERR(f->clk_en))
1207+
return PTR_ERR(f->clk_en);
12181208

12191209
f->clk = devm_clk_get(dev, "fspi");
1220-
if (IS_ERR(f->clk)) {
1221-
ret = PTR_ERR(f->clk);
1222-
goto err_put_ctrl;
1223-
}
1224-
1225-
ret = nxp_fspi_clk_prep_enable(f);
1226-
if (ret) {
1227-
dev_err(dev, "can not enable the clock\n");
1228-
goto err_put_ctrl;
1229-
}
1210+
if (IS_ERR(f->clk))
1211+
return PTR_ERR(f->clk);
12301212
}
12311213

1214+
/* find the irq */
1215+
irq = platform_get_irq(pdev, 0);
1216+
if (irq < 0)
1217+
return dev_err_probe(dev, irq, "Failed to get irq source");
1218+
1219+
ret = nxp_fspi_clk_prep_enable(f);
1220+
if (ret)
1221+
return dev_err_probe(dev, ret, "Can't enable the clock\n");
1222+
12321223
/* Clear potential interrupts */
12331224
reg = fspi_readl(f, f->iobase + FSPI_INTR);
12341225
if (reg)
12351226
fspi_writel(f, reg, f->iobase + FSPI_INTR);
12361227

1237-
/* find the irq */
1238-
ret = platform_get_irq(pdev, 0);
1239-
if (ret < 0)
1240-
goto err_disable_clk;
1228+
nxp_fspi_default_setup(f);
12411229

1242-
ret = devm_request_irq(dev, ret,
1230+
ret = devm_request_irq(dev, irq,
12431231
nxp_fspi_irq_handler, 0, pdev->name, f);
12441232
if (ret) {
1245-
dev_err(dev, "failed to request irq: %d\n", ret);
1246-
goto err_disable_clk;
1233+
nxp_fspi_clk_disable_unprep(f);
1234+
return dev_err_probe(dev, ret, "Failed to request irq\n");
12471235
}
12481236

1249-
mutex_init(&f->lock);
1237+
devm_mutex_init(dev, &f->lock);
12501238

12511239
ctlr->bus_num = -1;
12521240
ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;
12531241
ctlr->mem_ops = &nxp_fspi_mem_ops;
12541242
ctlr->mem_caps = &nxp_fspi_mem_caps;
1255-
1256-
nxp_fspi_default_setup(f);
1257-
12581243
ctlr->dev.of_node = np;
12591244

1260-
ret = devm_spi_register_controller(&pdev->dev, ctlr);
1261-
if (ret)
1262-
goto err_destroy_mutex;
1263-
1264-
return 0;
1265-
1266-
err_destroy_mutex:
1267-
mutex_destroy(&f->lock);
1268-
1269-
err_disable_clk:
1270-
nxp_fspi_clk_disable_unprep(f);
1271-
1272-
err_put_ctrl:
1273-
spi_controller_put(ctlr);
1274-
1275-
dev_err(dev, "NXP FSPI probe failed\n");
1276-
return ret;
1245+
return devm_spi_register_controller(&pdev->dev, ctlr);
12771246
}
12781247

12791248
static void nxp_fspi_remove(struct platform_device *pdev)
@@ -1285,8 +1254,6 @@ static void nxp_fspi_remove(struct platform_device *pdev)
12851254

12861255
nxp_fspi_clk_disable_unprep(f);
12871256

1288-
mutex_destroy(&f->lock);
1289-
12901257
if (f->ahb_addr)
12911258
iounmap(f->ahb_addr);
12921259
}

0 commit comments

Comments
 (0)