diff options
author | Thierry Reding <thierry.reding@avionic-design.de> | 2012-08-30 09:52:28 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@avionic-design.de> | 2012-10-05 14:56:41 -0400 |
commit | 5384e27317016bd30aa7a7a7513f76ce7caa3b09 (patch) | |
tree | 89cddff02878fac9146aef62ae438651353ffbd9 /arch/unicore32 | |
parent | e551fadef3650c34137e90f17963ca613b8f8610 (diff) |
unicore32: pwm: Use managed resource allocations
This commit uses the managed resource allocation functions to simplify
the cleanup paths on error and removal.
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Qin Rui <qinrui@mprc.pku.edu.cn>
Acked-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
Diffstat (limited to 'arch/unicore32')
-rw-r--r-- | arch/unicore32/kernel/pwm.c | 47 |
1 files changed, 9 insertions, 38 deletions
diff --git a/arch/unicore32/kernel/pwm.c b/arch/unicore32/kernel/pwm.c index 7e234700d80f..724e8603120b 100644 --- a/arch/unicore32/kernel/pwm.c +++ b/arch/unicore32/kernel/pwm.c | |||
@@ -160,19 +160,17 @@ static int __devinit pwm_probe(struct platform_device *pdev) | |||
160 | { | 160 | { |
161 | struct pwm_device *pwm; | 161 | struct pwm_device *pwm; |
162 | struct resource *r; | 162 | struct resource *r; |
163 | int ret = 0; | ||
164 | 163 | ||
165 | pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL); | 164 | pwm = devm_kzalloc(&pdev->dev, sizeof(struct pwm_device), GFP_KERNEL); |
166 | if (pwm == NULL) { | 165 | if (pwm == NULL) { |
167 | dev_err(&pdev->dev, "failed to allocate memory\n"); | 166 | dev_err(&pdev->dev, "failed to allocate memory\n"); |
168 | return -ENOMEM; | 167 | return -ENOMEM; |
169 | } | 168 | } |
170 | 169 | ||
171 | pwm->clk = clk_get(NULL, "OST_CLK"); | 170 | pwm->clk = devm_clk_get(&pdev->dev, "OST_CLK"); |
172 | if (IS_ERR(pwm->clk)) { | 171 | if (IS_ERR(pwm->clk)) |
173 | ret = PTR_ERR(pwm->clk); | 172 | return PTR_ERR(pwm->clk); |
174 | goto err_free; | 173 | |
175 | } | ||
176 | pwm->clk_enabled = 0; | 174 | pwm->clk_enabled = 0; |
177 | 175 | ||
178 | pwm->use_count = 0; | 176 | pwm->use_count = 0; |
@@ -182,41 +180,21 @@ static int __devinit pwm_probe(struct platform_device *pdev) | |||
182 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 180 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
183 | if (r == NULL) { | 181 | if (r == NULL) { |
184 | dev_err(&pdev->dev, "no memory resource defined\n"); | 182 | dev_err(&pdev->dev, "no memory resource defined\n"); |
185 | ret = -ENODEV; | 183 | return -ENODEV; |
186 | goto err_free_clk; | ||
187 | } | ||
188 | |||
189 | r = request_mem_region(r->start, resource_size(r), pdev->name); | ||
190 | if (r == NULL) { | ||
191 | dev_err(&pdev->dev, "failed to request memory resource\n"); | ||
192 | ret = -EBUSY; | ||
193 | goto err_free_clk; | ||
194 | } | 184 | } |
195 | 185 | ||
196 | pwm->base = ioremap_nocache(r->start, resource_size(r)); | 186 | pwm->base = devm_request_and_ioremap(&pdev->dev, r); |
197 | if (pwm->base == NULL) { | 187 | if (pwm->base == NULL) |
198 | dev_err(&pdev->dev, "failed to remap memory resource\n"); | 188 | return -EADDRNOTAVAIL; |
199 | ret = -EADDRNOTAVAIL; | ||
200 | goto err_release_mem; | ||
201 | } | ||
202 | 189 | ||
203 | __add_pwm(pwm); | 190 | __add_pwm(pwm); |
204 | platform_set_drvdata(pdev, pwm); | 191 | platform_set_drvdata(pdev, pwm); |
205 | return 0; | 192 | return 0; |
206 | |||
207 | err_release_mem: | ||
208 | release_mem_region(r->start, resource_size(r)); | ||
209 | err_free_clk: | ||
210 | clk_put(pwm->clk); | ||
211 | err_free: | ||
212 | kfree(pwm); | ||
213 | return ret; | ||
214 | } | 193 | } |
215 | 194 | ||
216 | static int __devexit pwm_remove(struct platform_device *pdev) | 195 | static int __devexit pwm_remove(struct platform_device *pdev) |
217 | { | 196 | { |
218 | struct pwm_device *pwm; | 197 | struct pwm_device *pwm; |
219 | struct resource *r; | ||
220 | 198 | ||
221 | pwm = platform_get_drvdata(pdev); | 199 | pwm = platform_get_drvdata(pdev); |
222 | if (pwm == NULL) | 200 | if (pwm == NULL) |
@@ -226,13 +204,6 @@ static int __devexit pwm_remove(struct platform_device *pdev) | |||
226 | list_del(&pwm->node); | 204 | list_del(&pwm->node); |
227 | mutex_unlock(&pwm_lock); | 205 | mutex_unlock(&pwm_lock); |
228 | 206 | ||
229 | iounmap(pwm->base); | ||
230 | |||
231 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
232 | release_mem_region(r->start, resource_size(r)); | ||
233 | |||
234 | clk_put(pwm->clk); | ||
235 | kfree(pwm); | ||
236 | return 0; | 207 | return 0; |
237 | } | 208 | } |
238 | 209 | ||