diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-07-29 15:46:12 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-10 15:01:34 -0400 |
commit | 35b55563dffd4a68988077e402ddd330e8cfa580 (patch) | |
tree | 8fedaf6f7c8685b1799116f5bf5671687987a867 /drivers/usb/host/ehci-mv.c | |
parent | df5eb3ffa8bfd23be8189cb0c58ed0c4902b6bfd (diff) |
drivers/usb/host/ehci-mv.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
A new label name is created in one case to better reflect the contents of
the error-handling code.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/host/ehci-mv.c')
-rw-r--r-- | drivers/usb/host/ehci-mv.c | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c index f6df1ccc9617..f7bfc0b898b9 100644 --- a/drivers/usb/host/ehci-mv.c +++ b/drivers/usb/host/ehci-mv.c | |||
@@ -161,7 +161,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
161 | return -ENOMEM; | 161 | return -ENOMEM; |
162 | 162 | ||
163 | size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; | 163 | size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; |
164 | ehci_mv = kzalloc(size, GFP_KERNEL); | 164 | ehci_mv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
165 | if (ehci_mv == NULL) { | 165 | if (ehci_mv == NULL) { |
166 | dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); | 166 | dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); |
167 | retval = -ENOMEM; | 167 | retval = -ENOMEM; |
@@ -175,12 +175,12 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
175 | ehci_mv->clknum = pdata->clknum; | 175 | ehci_mv->clknum = pdata->clknum; |
176 | for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { | 176 | for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { |
177 | ehci_mv->clk[clk_i] = | 177 | ehci_mv->clk[clk_i] = |
178 | clk_get(&pdev->dev, pdata->clkname[clk_i]); | 178 | devm_clk_get(&pdev->dev, pdata->clkname[clk_i]); |
179 | if (IS_ERR(ehci_mv->clk[clk_i])) { | 179 | if (IS_ERR(ehci_mv->clk[clk_i])) { |
180 | dev_err(&pdev->dev, "error get clck \"%s\"\n", | 180 | dev_err(&pdev->dev, "error get clck \"%s\"\n", |
181 | pdata->clkname[clk_i]); | 181 | pdata->clkname[clk_i]); |
182 | retval = PTR_ERR(ehci_mv->clk[clk_i]); | 182 | retval = PTR_ERR(ehci_mv->clk[clk_i]); |
183 | goto err_put_clk; | 183 | goto err_clear_drvdata; |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
@@ -188,34 +188,36 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
188 | if (r == NULL) { | 188 | if (r == NULL) { |
189 | dev_err(&pdev->dev, "no phy I/O memory resource defined\n"); | 189 | dev_err(&pdev->dev, "no phy I/O memory resource defined\n"); |
190 | retval = -ENODEV; | 190 | retval = -ENODEV; |
191 | goto err_put_clk; | 191 | goto err_clear_drvdata; |
192 | } | 192 | } |
193 | 193 | ||
194 | ehci_mv->phy_regs = ioremap(r->start, resource_size(r)); | 194 | ehci_mv->phy_regs = devm_ioremap(&pdev->dev, r->start, |
195 | resource_size(r)); | ||
195 | if (ehci_mv->phy_regs == 0) { | 196 | if (ehci_mv->phy_regs == 0) { |
196 | dev_err(&pdev->dev, "failed to map phy I/O memory\n"); | 197 | dev_err(&pdev->dev, "failed to map phy I/O memory\n"); |
197 | retval = -EFAULT; | 198 | retval = -EFAULT; |
198 | goto err_put_clk; | 199 | goto err_clear_drvdata; |
199 | } | 200 | } |
200 | 201 | ||
201 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "capregs"); | 202 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "capregs"); |
202 | if (!r) { | 203 | if (!r) { |
203 | dev_err(&pdev->dev, "no I/O memory resource defined\n"); | 204 | dev_err(&pdev->dev, "no I/O memory resource defined\n"); |
204 | retval = -ENODEV; | 205 | retval = -ENODEV; |
205 | goto err_iounmap_phyreg; | 206 | goto err_clear_drvdata; |
206 | } | 207 | } |
207 | 208 | ||
208 | ehci_mv->cap_regs = ioremap(r->start, resource_size(r)); | 209 | ehci_mv->cap_regs = devm_ioremap(&pdev->dev, r->start, |
210 | resource_size(r)); | ||
209 | if (ehci_mv->cap_regs == NULL) { | 211 | if (ehci_mv->cap_regs == NULL) { |
210 | dev_err(&pdev->dev, "failed to map I/O memory\n"); | 212 | dev_err(&pdev->dev, "failed to map I/O memory\n"); |
211 | retval = -EFAULT; | 213 | retval = -EFAULT; |
212 | goto err_iounmap_phyreg; | 214 | goto err_clear_drvdata; |
213 | } | 215 | } |
214 | 216 | ||
215 | retval = mv_ehci_enable(ehci_mv); | 217 | retval = mv_ehci_enable(ehci_mv); |
216 | if (retval) { | 218 | if (retval) { |
217 | dev_err(&pdev->dev, "init phy error %d\n", retval); | 219 | dev_err(&pdev->dev, "init phy error %d\n", retval); |
218 | goto err_iounmap_capreg; | 220 | goto err_clear_drvdata; |
219 | } | 221 | } |
220 | 222 | ||
221 | offset = readl(ehci_mv->cap_regs) & CAPLENGTH_MASK; | 223 | offset = readl(ehci_mv->cap_regs) & CAPLENGTH_MASK; |
@@ -239,7 +241,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
239 | ehci_mv->mode = pdata->mode; | 241 | ehci_mv->mode = pdata->mode; |
240 | if (ehci_mv->mode == MV_USB_MODE_OTG) { | 242 | if (ehci_mv->mode == MV_USB_MODE_OTG) { |
241 | #ifdef CONFIG_USB_OTG_UTILS | 243 | #ifdef CONFIG_USB_OTG_UTILS |
242 | ehci_mv->otg = usb_get_phy(USB_PHY_TYPE_USB2); | 244 | ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
243 | if (IS_ERR_OR_NULL(ehci_mv->otg)) { | 245 | if (IS_ERR_OR_NULL(ehci_mv->otg)) { |
244 | dev_err(&pdev->dev, | 246 | dev_err(&pdev->dev, |
245 | "unable to find transceiver\n"); | 247 | "unable to find transceiver\n"); |
@@ -252,7 +254,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
252 | dev_err(&pdev->dev, | 254 | dev_err(&pdev->dev, |
253 | "unable to register with transceiver\n"); | 255 | "unable to register with transceiver\n"); |
254 | retval = -ENODEV; | 256 | retval = -ENODEV; |
255 | goto err_put_transceiver; | 257 | goto err_disable_clk; |
256 | } | 258 | } |
257 | /* otg will enable clock before use as host */ | 259 | /* otg will enable clock before use as host */ |
258 | mv_ehci_disable(ehci_mv); | 260 | mv_ehci_disable(ehci_mv); |
@@ -286,22 +288,10 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
286 | err_set_vbus: | 288 | err_set_vbus: |
287 | if (pdata->set_vbus) | 289 | if (pdata->set_vbus) |
288 | pdata->set_vbus(0); | 290 | pdata->set_vbus(0); |
289 | #ifdef CONFIG_USB_OTG_UTILS | ||
290 | err_put_transceiver: | ||
291 | if (!IS_ERR_OR_NULL(ehci_mv->otg)) | ||
292 | usb_put_phy(ehci_mv->otg); | ||
293 | #endif | ||
294 | err_disable_clk: | 291 | err_disable_clk: |
295 | mv_ehci_disable(ehci_mv); | 292 | mv_ehci_disable(ehci_mv); |
296 | err_iounmap_capreg: | 293 | err_clear_drvdata: |
297 | iounmap(ehci_mv->cap_regs); | ||
298 | err_iounmap_phyreg: | ||
299 | iounmap(ehci_mv->phy_regs); | ||
300 | err_put_clk: | ||
301 | for (clk_i--; clk_i >= 0; clk_i--) | ||
302 | clk_put(ehci_mv->clk[clk_i]); | ||
303 | platform_set_drvdata(pdev, NULL); | 294 | platform_set_drvdata(pdev, NULL); |
304 | kfree(ehci_mv); | ||
305 | err_put_hcd: | 295 | err_put_hcd: |
306 | usb_put_hcd(hcd); | 296 | usb_put_hcd(hcd); |
307 | 297 | ||
@@ -317,10 +307,8 @@ static int mv_ehci_remove(struct platform_device *pdev) | |||
317 | if (hcd->rh_registered) | 307 | if (hcd->rh_registered) |
318 | usb_remove_hcd(hcd); | 308 | usb_remove_hcd(hcd); |
319 | 309 | ||
320 | if (!IS_ERR_OR_NULL(ehci_mv->otg)) { | 310 | if (!IS_ERR_OR_NULL(ehci_mv->otg)) |
321 | otg_set_host(ehci_mv->otg->otg, NULL); | 311 | otg_set_host(ehci_mv->otg->otg, NULL); |
322 | usb_put_phy(ehci_mv->otg); | ||
323 | } | ||
324 | 312 | ||
325 | if (ehci_mv->mode == MV_USB_MODE_HOST) { | 313 | if (ehci_mv->mode == MV_USB_MODE_HOST) { |
326 | if (ehci_mv->pdata->set_vbus) | 314 | if (ehci_mv->pdata->set_vbus) |
@@ -329,15 +317,8 @@ static int mv_ehci_remove(struct platform_device *pdev) | |||
329 | mv_ehci_disable(ehci_mv); | 317 | mv_ehci_disable(ehci_mv); |
330 | } | 318 | } |
331 | 319 | ||
332 | iounmap(ehci_mv->cap_regs); | ||
333 | iounmap(ehci_mv->phy_regs); | ||
334 | |||
335 | for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) | ||
336 | clk_put(ehci_mv->clk[clk_i]); | ||
337 | |||
338 | platform_set_drvdata(pdev, NULL); | 320 | platform_set_drvdata(pdev, NULL); |
339 | 321 | ||
340 | kfree(ehci_mv); | ||
341 | usb_put_hcd(hcd); | 322 | usb_put_hcd(hcd); |
342 | 323 | ||
343 | return 0; | 324 | return 0; |