aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLadislav Michl <ladis@linux-mips.org>2018-01-15 15:25:05 -0500
committerLee Jones <lee.jones@linaro.org>2018-05-16 04:21:48 -0400
commit16c2004d9e4d6e5bc0a81fa811eb6ebab4fb6307 (patch)
treec17d95b953de0cbbd98bb5c54d7575d112c5a43d
parent46c8aa8e3fe61c7bb5dbbc9db379eeb01dc97472 (diff)
mfd: omap-usb-tll: Allocate driver data at once
Allocating memory to store clk array together with driver data simplifies error unwinding and allows deleting memory allocation failure message as there is now only single point of failure already covered by allocation failure report. Signed-off-by: Ladislav Michl <ladis@linux-mips.org> [Markus Elfring: simplified error unwinding, error message removal] Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r--drivers/mfd/omap-usb-tll.c60
1 files changed, 25 insertions, 35 deletions
diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
index 44a5d66314c6..446713dbee27 100644
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -108,9 +108,9 @@
108 (x) != OMAP_EHCI_PORT_MODE_PHY) 108 (x) != OMAP_EHCI_PORT_MODE_PHY)
109 109
110struct usbtll_omap { 110struct usbtll_omap {
111 int nch; /* num. of channels */ 111 void __iomem *base;
112 struct clk **ch_clk; 112 int nch; /* num. of channels */
113 void __iomem *base; 113 struct clk *ch_clk[0]; /* must be the last member */
114}; 114};
115 115
116/*-------------------------------------------------------------------------*/ 116/*-------------------------------------------------------------------------*/
@@ -216,53 +216,49 @@ static int usbtll_omap_probe(struct platform_device *pdev)
216 struct device *dev = &pdev->dev; 216 struct device *dev = &pdev->dev;
217 struct resource *res; 217 struct resource *res;
218 struct usbtll_omap *tll; 218 struct usbtll_omap *tll;
219 int ret = 0; 219 void __iomem *base;
220 int i, ver; 220 int i, nch, ver;
221 221
222 dev_dbg(dev, "starting TI HSUSB TLL Controller\n"); 222 dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
223 223
224 tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL);
225 if (!tll) {
226 dev_err(dev, "Memory allocation failed\n");
227 return -ENOMEM;
228 }
229
230 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 224 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
231 tll->base = devm_ioremap_resource(dev, res); 225 base = devm_ioremap_resource(dev, res);
232 if (IS_ERR(tll->base)) 226 if (IS_ERR(base))
233 return PTR_ERR(tll->base); 227 return PTR_ERR(base);
234 228
235 platform_set_drvdata(pdev, tll);
236 pm_runtime_enable(dev); 229 pm_runtime_enable(dev);
237 pm_runtime_get_sync(dev); 230 pm_runtime_get_sync(dev);
238 231
239 ver = usbtll_read(tll->base, OMAP_USBTLL_REVISION); 232 ver = usbtll_read(base, OMAP_USBTLL_REVISION);
240 switch (ver) { 233 switch (ver) {
241 case OMAP_USBTLL_REV1: 234 case OMAP_USBTLL_REV1:
242 case OMAP_USBTLL_REV4: 235 case OMAP_USBTLL_REV4:
243 tll->nch = OMAP_TLL_CHANNEL_COUNT; 236 nch = OMAP_TLL_CHANNEL_COUNT;
244 break; 237 break;
245 case OMAP_USBTLL_REV2: 238 case OMAP_USBTLL_REV2:
246 case OMAP_USBTLL_REV3: 239 case OMAP_USBTLL_REV3:
247 tll->nch = OMAP_REV2_TLL_CHANNEL_COUNT; 240 nch = OMAP_REV2_TLL_CHANNEL_COUNT;
248 break; 241 break;
249 default: 242 default:
250 tll->nch = OMAP_TLL_CHANNEL_COUNT; 243 nch = OMAP_TLL_CHANNEL_COUNT;
251 dev_dbg(dev, 244 dev_dbg(dev, "rev 0x%x not recognized, assuming %d channels\n",
252 "USB TLL Rev : 0x%x not recognized, assuming %d channels\n", 245 ver, nch);
253 ver, tll->nch);
254 break; 246 break;
255 } 247 }
256 248
257 tll->ch_clk = devm_kzalloc(dev, sizeof(struct clk *) * tll->nch, 249 tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]),
258 GFP_KERNEL); 250 GFP_KERNEL);
259 if (!tll->ch_clk) { 251 if (!tll) {
260 ret = -ENOMEM; 252 pm_runtime_put_sync(dev);
261 dev_err(dev, "Couldn't allocate memory for channel clocks\n"); 253 pm_runtime_disable(dev);
262 goto err_clk_alloc; 254 return -ENOMEM;
263 } 255 }
264 256
265 for (i = 0; i < tll->nch; i++) { 257 tll->base = base;
258 tll->nch = nch;
259 platform_set_drvdata(pdev, tll);
260
261 for (i = 0; i < nch; i++) {
266 char clkname[] = "usb_tll_hs_usb_chx_clk"; 262 char clkname[] = "usb_tll_hs_usb_chx_clk";
267 263
268 snprintf(clkname, sizeof(clkname), 264 snprintf(clkname, sizeof(clkname),
@@ -282,12 +278,6 @@ static int usbtll_omap_probe(struct platform_device *pdev)
282 spin_unlock(&tll_lock); 278 spin_unlock(&tll_lock);
283 279
284 return 0; 280 return 0;
285
286err_clk_alloc:
287 pm_runtime_put_sync(dev);
288 pm_runtime_disable(dev);
289
290 return ret;
291} 281}
292 282
293/** 283/**