linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once
@ 2018-01-15 20:25 Ladislav Michl
  2018-01-17 15:22 ` Roger Quadros
  2018-01-23 12:55 ` Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Ladislav Michl @ 2018-01-15 20:25 UTC (permalink / raw)
  To: linux-omap
  Cc: SF Markus Elfring, Lee Jones, Tony Lindgren, Roger Quadros, LKML,
	kernel-janitors

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>
Link: https://lkml.org/lkml/2018/1/15/411
---
 Changes:
 - v2: reindent 'rev' debug message
       credit Markus Elfring

 drivers/mfd/omap-usb-tll.c | 60 +++++++++++++++++++---------------------------
 1 file 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 @@
 					 (x) != OMAP_EHCI_PORT_MODE_PHY)
 
 struct usbtll_omap {
-	int					nch;	/* num. of channels */
-	struct clk				**ch_clk;
-	void __iomem				*base;
+	void __iomem	*base;
+	int		nch;		/* num. of channels */
+	struct clk	*ch_clk[0];	/* must be the last member */
 };
 
 /*-------------------------------------------------------------------------*/
@@ -216,53 +216,49 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct resource				*res;
 	struct usbtll_omap			*tll;
-	int					ret = 0;
-	int					i, ver;
+	void __iomem				*base;
+	int					i, nch, ver;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
-	tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL);
-	if (!tll) {
-		dev_err(dev, "Memory allocation failed\n");
-		return -ENOMEM;
-	}
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	tll->base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(tll->base))
-		return PTR_ERR(tll->base);
+	base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
-	platform_set_drvdata(pdev, tll);
 	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
 
-	ver =  usbtll_read(tll->base, OMAP_USBTLL_REVISION);
+	ver = usbtll_read(base, OMAP_USBTLL_REVISION);
 	switch (ver) {
 	case OMAP_USBTLL_REV1:
 	case OMAP_USBTLL_REV4:
-		tll->nch = OMAP_TLL_CHANNEL_COUNT;
+		nch = OMAP_TLL_CHANNEL_COUNT;
 		break;
 	case OMAP_USBTLL_REV2:
 	case OMAP_USBTLL_REV3:
-		tll->nch = OMAP_REV2_TLL_CHANNEL_COUNT;
+		nch = OMAP_REV2_TLL_CHANNEL_COUNT;
 		break;
 	default:
-		tll->nch = OMAP_TLL_CHANNEL_COUNT;
-		dev_dbg(dev,
-		 "USB TLL Rev : 0x%x not recognized, assuming %d channels\n",
-			ver, tll->nch);
+		nch = OMAP_TLL_CHANNEL_COUNT;
+		dev_dbg(dev, "rev 0x%x not recognized, assuming %d channels\n",
+			ver, nch);
 		break;
 	}
 
-	tll->ch_clk = devm_kzalloc(dev, sizeof(struct clk *) * tll->nch,
-						GFP_KERNEL);
-	if (!tll->ch_clk) {
-		ret = -ENOMEM;
-		dev_err(dev, "Couldn't allocate memory for channel clocks\n");
-		goto err_clk_alloc;
+	tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]),
+			   GFP_KERNEL);
+	if (!tll) {
+		pm_runtime_put_sync(dev);
+		pm_runtime_disable(dev);
+		return -ENOMEM;
 	}
 
-	for (i = 0; i < tll->nch; i++) {
+	tll->base = base;
+	tll->nch = nch;
+	platform_set_drvdata(pdev, tll);
+
+	for (i = 0; i < nch; i++) {
 		char clkname[] = "usb_tll_hs_usb_chx_clk";
 
 		snprintf(clkname, sizeof(clkname),
@@ -282,12 +278,6 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	spin_unlock(&tll_lock);
 
 	return 0;
-
-err_clk_alloc:
-	pm_runtime_put_sync(dev);
-	pm_runtime_disable(dev);
-
-	return ret;
 }
 
 /**
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once
  2018-01-15 20:25 [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once Ladislav Michl
@ 2018-01-17 15:22 ` Roger Quadros
  2018-01-23 12:55 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Roger Quadros @ 2018-01-17 15:22 UTC (permalink / raw)
  To: Ladislav Michl, linux-omap
  Cc: SF Markus Elfring, Lee Jones, Tony Lindgren, LKML, kernel-janitors

On 15/01/18 22:25, Ladislav Michl wrote:
> 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>
> Link: https://lkml.org/lkml/2018/1/15/411

Acked-by: Roger Quadros <rogerq@ti.com>

-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once
  2018-01-15 20:25 [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once Ladislav Michl
  2018-01-17 15:22 ` Roger Quadros
@ 2018-01-23 12:55 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2018-01-23 12:55 UTC (permalink / raw)
  To: Ladislav Michl
  Cc: linux-omap, SF Markus Elfring, Tony Lindgren, Roger Quadros,
	LKML, kernel-janitors

On Mon, 15 Jan 2018, Ladislav Michl wrote:

> 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>
> Link: https://lkml.org/lkml/2018/1/15/411
> ---
>  Changes:
>  - v2: reindent 'rev' debug message
>        credit Markus Elfring
> 
>  drivers/mfd/omap-usb-tll.c | 60 +++++++++++++++++++---------------------------
>  1 file changed, 25 insertions(+), 35 deletions(-)

Applied, thanks.

-- 
Lee Jones
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-23 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-15 20:25 [PATCH v2] mfd: omap-usb-tll: Allocate driver data at once Ladislav Michl
2018-01-17 15:22 ` Roger Quadros
2018-01-23 12:55 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).