aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-sh.c
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2012-07-30 10:43:42 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-10 15:04:09 -0400
commita926e298b66a7a2d70a95810efdb0e64f3f24ae0 (patch)
treed7feec87e974e846df58114aa35d97d9ea0ad779 /drivers/usb/host/ehci-sh.c
parent6c40f5ee0f6213705eb6d3b706fc103b9dba72fb (diff)
drivers/usb/host/ehci-sh.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. 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-sh.c')
-rw-r--r--drivers/usb/host/ehci-sh.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index b3f1e3650da0..6081e1ed3ac9 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -125,33 +125,27 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
125 hcd->rsrc_start = res->start; 125 hcd->rsrc_start = res->start;
126 hcd->rsrc_len = resource_size(res); 126 hcd->rsrc_len = resource_size(res);
127 127
128 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 128 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
129 driver->description)) {
130 dev_dbg(&pdev->dev, "controller already in use\n");
131 ret = -EBUSY;
132 goto fail_request_resource;
133 }
134
135 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
136 if (hcd->regs == NULL) { 129 if (hcd->regs == NULL) {
137 dev_dbg(&pdev->dev, "error mapping memory\n"); 130 dev_dbg(&pdev->dev, "error mapping memory\n");
138 ret = -ENXIO; 131 ret = -ENXIO;
139 goto fail_ioremap; 132 goto fail_request_resource;
140 } 133 }
141 134
142 priv = kmalloc(sizeof(struct ehci_sh_priv), GFP_KERNEL); 135 priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv),
136 GFP_KERNEL);
143 if (!priv) { 137 if (!priv) {
144 dev_dbg(&pdev->dev, "error allocating priv data\n"); 138 dev_dbg(&pdev->dev, "error allocating priv data\n");
145 ret = -ENOMEM; 139 ret = -ENOMEM;
146 goto fail_alloc; 140 goto fail_request_resource;
147 } 141 }
148 142
149 /* These are optional, we don't care if they fail */ 143 /* These are optional, we don't care if they fail */
150 priv->fclk = clk_get(&pdev->dev, "usb_fck"); 144 priv->fclk = devm_clk_get(&pdev->dev, "usb_fck");
151 if (IS_ERR(priv->fclk)) 145 if (IS_ERR(priv->fclk))
152 priv->fclk = NULL; 146 priv->fclk = NULL;
153 147
154 priv->iclk = clk_get(&pdev->dev, "usb_ick"); 148 priv->iclk = devm_clk_get(&pdev->dev, "usb_ick");
155 if (IS_ERR(priv->iclk)) 149 if (IS_ERR(priv->iclk))
156 priv->iclk = NULL; 150 priv->iclk = NULL;
157 151
@@ -176,14 +170,6 @@ fail_add_hcd:
176 clk_disable(priv->iclk); 170 clk_disable(priv->iclk);
177 clk_disable(priv->fclk); 171 clk_disable(priv->fclk);
178 172
179 clk_put(priv->iclk);
180 clk_put(priv->fclk);
181
182 kfree(priv);
183fail_alloc:
184 iounmap(hcd->regs);
185fail_ioremap:
186 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
187fail_request_resource: 173fail_request_resource:
188 usb_put_hcd(hcd); 174 usb_put_hcd(hcd);
189fail_create_hcd: 175fail_create_hcd:
@@ -198,19 +184,12 @@ static int __exit ehci_hcd_sh_remove(struct platform_device *pdev)
198 struct usb_hcd *hcd = priv->hcd; 184 struct usb_hcd *hcd = priv->hcd;
199 185
200 usb_remove_hcd(hcd); 186 usb_remove_hcd(hcd);
201 iounmap(hcd->regs);
202 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
203 usb_put_hcd(hcd); 187 usb_put_hcd(hcd);
204 platform_set_drvdata(pdev, NULL); 188 platform_set_drvdata(pdev, NULL);
205 189
206 clk_disable(priv->fclk); 190 clk_disable(priv->fclk);
207 clk_disable(priv->iclk); 191 clk_disable(priv->iclk);
208 192
209 clk_put(priv->fclk);
210 clk_put(priv->iclk);
211
212 kfree(priv);
213
214 return 0; 193 return 0;
215} 194}
216 195