Skip to content

Commit 2e4de7b

Browse files
Bo Shenbroonie
authored andcommitted
ASoC: atmel-ssc: use devm_xxx() managed function
Using the devm_xxx() managed function to stripdown the error and remove code. Signed-off-by: Bo Shen <voice.shen@atmel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 6f0c058 commit 2e4de7b

1 file changed

Lines changed: 15 additions & 32 deletions

File tree

‎drivers/misc/atmel-ssc.c‎

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,33 @@ EXPORT_SYMBOL(ssc_free);
7070

7171
static int __init ssc_probe(struct platform_device *pdev)
7272
{
73-
int retval = 0;
7473
struct resource *regs;
7574
struct ssc_device *ssc;
7675

77-
ssc = kzalloc(sizeof(struct ssc_device), GFP_KERNEL);
76+
ssc = devm_kzalloc(&pdev->dev, sizeof(struct ssc_device), GFP_KERNEL);
7877
if (!ssc) {
7978
dev_dbg(&pdev->dev, "out of memory\n");
80-
retval = -ENOMEM;
81-
goto out;
79+
return -ENOMEM;
8280
}
8381

82+
ssc->pdev = pdev;
83+
8484
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8585
if (!regs) {
8686
dev_dbg(&pdev->dev, "no mmio resource defined\n");
87-
retval = -ENXIO;
88-
goto out_free;
87+
return -ENXIO;
8988
}
9089

91-
ssc->clk = clk_get(&pdev->dev, "pclk");
92-
if (IS_ERR(ssc->clk)) {
93-
dev_dbg(&pdev->dev, "no pclk clock defined\n");
94-
retval = -ENXIO;
95-
goto out_free;
96-
}
97-
98-
ssc->pdev = pdev;
99-
ssc->regs = ioremap(regs->start, resource_size(regs));
90+
ssc->regs = devm_request_and_ioremap(&pdev->dev, regs);
10091
if (!ssc->regs) {
10192
dev_dbg(&pdev->dev, "ioremap failed\n");
102-
retval = -EINVAL;
103-
goto out_clk;
93+
return -EINVAL;
94+
}
95+
96+
ssc->clk = devm_clk_get(&pdev->dev, "pclk");
97+
if (IS_ERR(ssc->clk)) {
98+
dev_dbg(&pdev->dev, "no pclk clock defined\n");
99+
return -ENXIO;
104100
}
105101

106102
/* disable all interrupts */
@@ -112,8 +108,7 @@ static int __init ssc_probe(struct platform_device *pdev)
112108
ssc->irq = platform_get_irq(pdev, 0);
113109
if (!ssc->irq) {
114110
dev_dbg(&pdev->dev, "could not get irq\n");
115-
retval = -ENXIO;
116-
goto out_unmap;
111+
return -ENXIO;
117112
}
118113

119114
spin_lock(&user_lock);
@@ -125,27 +120,15 @@ static int __init ssc_probe(struct platform_device *pdev)
125120
dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
126121
ssc->regs, ssc->irq);
127122

128-
goto out;
129-
130-
out_unmap:
131-
iounmap(ssc->regs);
132-
out_clk:
133-
clk_put(ssc->clk);
134-
out_free:
135-
kfree(ssc);
136-
out:
137-
return retval;
123+
return 0;
138124
}
139125

140126
static int __devexit ssc_remove(struct platform_device *pdev)
141127
{
142128
struct ssc_device *ssc = platform_get_drvdata(pdev);
143129

144130
spin_lock(&user_lock);
145-
iounmap(ssc->regs);
146-
clk_put(ssc->clk);
147131
list_del(&ssc->list);
148-
kfree(ssc);
149132
spin_unlock(&user_lock);
150133

151134
return 0;

0 commit comments

Comments
 (0)