Skip to content

Commit 356749a

Browse files
committed
Improve error handling in Rockchip SPI drivers
Merge series from Dragan Simic <[email protected]>: This is a small series that improves error handling in the probe path of the Rockchip SPI drivers, by using dev_err_probe() properly in multiple places. It also performs a bunch of small, rather trivial code cleanups, to make the code neater and a bit easier to read.
2 parents 9e3dfbc + 1482c40 commit 356749a

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

drivers/spi/spi-rockchip-sfc.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -580,19 +580,16 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
580580
return PTR_ERR(sfc->regbase);
581581

582582
sfc->clk = devm_clk_get(&pdev->dev, "clk_sfc");
583-
if (IS_ERR(sfc->clk)) {
584-
dev_err(&pdev->dev, "Failed to get sfc interface clk\n");
585-
return PTR_ERR(sfc->clk);
586-
}
583+
if (IS_ERR(sfc->clk))
584+
return dev_err_probe(&pdev->dev, PTR_ERR(sfc->clk),
585+
"Failed to get sfc interface clk\n");
587586

588587
sfc->hclk = devm_clk_get(&pdev->dev, "hclk_sfc");
589-
if (IS_ERR(sfc->hclk)) {
590-
dev_err(&pdev->dev, "Failed to get sfc ahb clk\n");
591-
return PTR_ERR(sfc->hclk);
592-
}
588+
if (IS_ERR(sfc->hclk))
589+
return dev_err_probe(&pdev->dev, PTR_ERR(sfc->hclk),
590+
"Failed to get sfc ahb clk\n");
593591

594-
sfc->use_dma = !of_property_read_bool(sfc->dev->of_node,
595-
"rockchip,sfc-no-dma");
592+
sfc->use_dma = !of_property_read_bool(sfc->dev->of_node, "rockchip,sfc-no-dma");
596593

597594
if (sfc->use_dma) {
598595
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
@@ -602,8 +599,7 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
602599
}
603600

604601
sfc->buffer = dmam_alloc_coherent(dev, SFC_MAX_IOSIZE_VER3,
605-
&sfc->dma_buffer,
606-
GFP_KERNEL);
602+
&sfc->dma_buffer, GFP_KERNEL);
607603
if (!sfc->buffer)
608604
return -ENOMEM;
609605
}
@@ -629,7 +625,6 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
629625
0, pdev->name, sfc);
630626
if (ret) {
631627
dev_err(dev, "Failed to request irq\n");
632-
633628
goto err_irq;
634629
}
635630

drivers/spi/spi-rockchip.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -742,22 +742,20 @@ static int rockchip_spi_setup(struct spi_device *spi)
742742

743743
static int rockchip_spi_probe(struct platform_device *pdev)
744744
{
745-
int ret;
746-
struct rockchip_spi *rs;
745+
struct device_node *np = pdev->dev.of_node;
747746
struct spi_controller *ctlr;
747+
struct rockchip_spi *rs;
748748
struct resource *mem;
749-
struct device_node *np = pdev->dev.of_node;
750749
u32 rsd_nsecs, num_cs;
751750
bool target_mode;
751+
int ret;
752752

753753
target_mode = of_property_read_bool(np, "spi-slave");
754754

755755
if (target_mode)
756-
ctlr = spi_alloc_target(&pdev->dev,
757-
sizeof(struct rockchip_spi));
756+
ctlr = spi_alloc_target(&pdev->dev, sizeof(struct rockchip_spi));
758757
else
759-
ctlr = spi_alloc_host(&pdev->dev,
760-
sizeof(struct rockchip_spi));
758+
ctlr = spi_alloc_host(&pdev->dev, sizeof(struct rockchip_spi));
761759

762760
if (!ctlr)
763761
return -ENOMEM;
@@ -769,7 +767,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
769767
/* Get basic io resource and map it */
770768
rs->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
771769
if (IS_ERR(rs->regs)) {
772-
ret = PTR_ERR(rs->regs);
770+
ret = PTR_ERR(rs->regs);
773771
goto err_put_ctlr;
774772
}
775773

@@ -794,7 +792,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
794792
goto err_put_ctlr;
795793

796794
ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL,
797-
IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
795+
IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
798796
if (ret)
799797
goto err_put_ctlr;
800798

@@ -804,16 +802,15 @@ static int rockchip_spi_probe(struct platform_device *pdev)
804802
if (!of_property_read_u32(pdev->dev.of_node, "rx-sample-delay-ns",
805803
&rsd_nsecs)) {
806804
/* rx sample delay is expressed in parent clock cycles (max 3) */
807-
u32 rsd = DIV_ROUND_CLOSEST(rsd_nsecs * (rs->freq >> 8),
808-
1000000000 >> 8);
805+
u32 rsd = DIV_ROUND_CLOSEST(rsd_nsecs * (rs->freq >> 8), 1000000000 >> 8);
809806
if (!rsd) {
810807
dev_warn(rs->dev, "%u Hz are too slow to express %u ns delay\n",
811-
rs->freq, rsd_nsecs);
808+
rs->freq, rsd_nsecs);
812809
} else if (rsd > CR0_RSD_MAX) {
813810
rsd = CR0_RSD_MAX;
814-
dev_warn(rs->dev, "%u Hz are too fast to express %u ns delay, clamping at %u ns\n",
815-
rs->freq, rsd_nsecs,
816-
CR0_RSD_MAX * 1000000000U / rs->freq);
811+
dev_warn(rs->dev,
812+
"%u Hz are too fast to express %u ns delay, clamping at %u ns\n",
813+
rs->freq, rsd_nsecs, CR0_RSD_MAX * 1000000000U / rs->freq);
817814
}
818815
rs->rsd = rsd;
819816
}

0 commit comments

Comments
 (0)