Skip to content

Commit c1c63a1

Browse files
lyakhVinod Koul
authored andcommitted
DMA: shdma: switch to managed resource allocation
Switch shdma to using devm_* managed functions for allocation of memory, requesting IRQs, mapping IO resources etc. Signed-off-by: Guennadi Liakhovetski <[email protected]> Signed-off-by: Vinod Koul <[email protected]>
1 parent ca8b387 commit c1c63a1

File tree

4 files changed

+15
-64
lines changed

4 files changed

+15
-64
lines changed

drivers/dma/sh/shdma-base.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -831,22 +831,15 @@ static irqreturn_t chan_irqt(int irq, void *dev)
831831
int shdma_request_irq(struct shdma_chan *schan, int irq,
832832
unsigned long flags, const char *name)
833833
{
834-
int ret = request_threaded_irq(irq, chan_irq, chan_irqt,
835-
flags, name, schan);
834+
int ret = devm_request_threaded_irq(schan->dev, irq, chan_irq,
835+
chan_irqt, flags, name, schan);
836836

837837
schan->irq = ret < 0 ? ret : irq;
838838

839839
return ret;
840840
}
841841
EXPORT_SYMBOL(shdma_request_irq);
842842

843-
void shdma_free_irq(struct shdma_chan *schan)
844-
{
845-
if (schan->irq >= 0)
846-
free_irq(schan->irq, schan);
847-
}
848-
EXPORT_SYMBOL(shdma_free_irq);
849-
850843
void shdma_chan_probe(struct shdma_dev *sdev,
851844
struct shdma_chan *schan, int id)
852845
{

drivers/dma/sh/shdma.c

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
515515
struct shdma_chan *schan;
516516
int err;
517517

518-
sh_chan = kzalloc(sizeof(struct sh_dmae_chan), GFP_KERNEL);
518+
sh_chan = devm_kzalloc(sdev->dma_dev.dev, sizeof(struct sh_dmae_chan),
519+
GFP_KERNEL);
519520
if (!sh_chan) {
520521
dev_err(sdev->dma_dev.dev,
521522
"No free memory for allocating dma channels!\n");
@@ -551,7 +552,6 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
551552
err_no_irq:
552553
/* remove from dmaengine device node */
553554
shdma_chan_remove(schan);
554-
kfree(sh_chan);
555555
return err;
556556
}
557557

@@ -562,14 +562,9 @@ static void sh_dmae_chan_remove(struct sh_dmae_device *shdev)
562562
int i;
563563

564564
shdma_for_each_chan(schan, &shdev->shdma_dev, i) {
565-
struct sh_dmae_chan *sh_chan = container_of(schan,
566-
struct sh_dmae_chan, shdma_chan);
567565
BUG_ON(!schan);
568566

569-
shdma_free_irq(&sh_chan->shdma_chan);
570-
571567
shdma_chan_remove(schan);
572-
kfree(sh_chan);
573568
}
574569
dma_dev->chancnt = 0;
575570
}
@@ -706,33 +701,22 @@ static int sh_dmae_probe(struct platform_device *pdev)
706701
if (!chan || !errirq_res)
707702
return -ENODEV;
708703

709-
if (!request_mem_region(chan->start, resource_size(chan), pdev->name)) {
710-
dev_err(&pdev->dev, "DMAC register region already claimed\n");
711-
return -EBUSY;
712-
}
713-
714-
if (dmars && !request_mem_region(dmars->start, resource_size(dmars), pdev->name)) {
715-
dev_err(&pdev->dev, "DMAC DMARS region already claimed\n");
716-
err = -EBUSY;
717-
goto ermrdmars;
718-
}
719-
720-
err = -ENOMEM;
721-
shdev = kzalloc(sizeof(struct sh_dmae_device), GFP_KERNEL);
704+
shdev = devm_kzalloc(&pdev->dev, sizeof(struct sh_dmae_device),
705+
GFP_KERNEL);
722706
if (!shdev) {
723707
dev_err(&pdev->dev, "Not enough memory\n");
724-
goto ealloc;
708+
return -ENOMEM;
725709
}
726710

727711
dma_dev = &shdev->shdma_dev.dma_dev;
728712

729-
shdev->chan_reg = ioremap(chan->start, resource_size(chan));
730-
if (!shdev->chan_reg)
731-
goto emapchan;
713+
shdev->chan_reg = devm_ioremap_resource(&pdev->dev, chan);
714+
if (IS_ERR(shdev->chan_reg))
715+
return PTR_ERR(shdev->chan_reg);
732716
if (dmars) {
733-
shdev->dmars = ioremap(dmars->start, resource_size(dmars));
734-
if (!shdev->dmars)
735-
goto emapdmars;
717+
shdev->dmars = devm_ioremap_resource(&pdev->dev, dmars);
718+
if (IS_ERR(shdev->dmars))
719+
return PTR_ERR(shdev->dmars);
736720
}
737721

738722
if (!pdata->slave_only)
@@ -793,8 +777,8 @@ static int sh_dmae_probe(struct platform_device *pdev)
793777

794778
errirq = errirq_res->start;
795779

796-
err = request_irq(errirq, sh_dmae_err, irqflags,
797-
"DMAC Address Error", shdev);
780+
err = devm_request_irq(&pdev->dev, errirq, sh_dmae_err, irqflags,
781+
"DMAC Address Error", shdev);
798782
if (err) {
799783
dev_err(&pdev->dev,
800784
"DMA failed requesting irq #%d, error %d\n",
@@ -872,7 +856,6 @@ static int sh_dmae_probe(struct platform_device *pdev)
872856
sh_dmae_chan_remove(shdev);
873857

874858
#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
875-
free_irq(errirq, shdev);
876859
eirq_err:
877860
#endif
878861
rst_err:
@@ -886,18 +869,7 @@ static int sh_dmae_probe(struct platform_device *pdev)
886869
platform_set_drvdata(pdev, NULL);
887870
shdma_cleanup(&shdev->shdma_dev);
888871
eshdma:
889-
if (dmars)
890-
iounmap(shdev->dmars);
891-
emapdmars:
892-
iounmap(shdev->chan_reg);
893872
synchronize_rcu();
894-
emapchan:
895-
kfree(shdev);
896-
ealloc:
897-
if (dmars)
898-
release_mem_region(dmars->start, resource_size(dmars));
899-
ermrdmars:
900-
release_mem_region(chan->start, resource_size(chan));
901873

902874
return err;
903875
}
@@ -923,21 +895,9 @@ static int sh_dmae_remove(struct platform_device *pdev)
923895
sh_dmae_chan_remove(shdev);
924896
shdma_cleanup(&shdev->shdma_dev);
925897

926-
if (shdev->dmars)
927-
iounmap(shdev->dmars);
928-
iounmap(shdev->chan_reg);
929-
930898
platform_set_drvdata(pdev, NULL);
931899

932900
synchronize_rcu();
933-
kfree(shdev);
934-
935-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
936-
if (res)
937-
release_mem_region(res->start, resource_size(res));
938-
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
939-
if (res)
940-
release_mem_region(res->start, resource_size(res));
941901

942902
return 0;
943903
}

drivers/dma/sh/sudmac.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ static void sudmac_chan_remove(struct sudmac_device *su_dev)
302302

303303
BUG_ON(!schan);
304304

305-
shdma_free_irq(&sc->shdma_chan);
306305
shdma_chan_remove(schan);
307306
}
308307
dma_dev->chancnt = 0;

include/linux/shdma-base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct shdma_dev {
116116

117117
int shdma_request_irq(struct shdma_chan *, int,
118118
unsigned long, const char *);
119-
void shdma_free_irq(struct shdma_chan *);
120119
bool shdma_reset(struct shdma_dev *sdev);
121120
void shdma_chan_probe(struct shdma_dev *sdev,
122121
struct shdma_chan *schan, int id);

0 commit comments

Comments
 (0)