All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Valentin <eduardo.valentin@ti.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-kernel@vger.kernel.org,
	Eduardo Valentin <eduardo.valentin@ti.com>,
	Zhang Rui <rui.zhang@intel.com>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation
Date: Fri, 26 Jul 2013 11:43:23 -0400	[thread overview]
Message-ID: <51F2991B.3060704@ti.com> (raw)
In-Reply-To: <1374602524-3398-28-git-send-email-wsa@the-dreams.de>

[-- Attachment #1: Type: text/plain, Size: 2388 bytes --]

On 23-07-2013 14:02, Wolfram Sang wrote:
> When cleaning up usage of devm_ioremap_resource, I found that resource
> allocation in this driver is ugly and buggy. If resource[0] is not
> found, bgp->base will end up NULL, so OOPS. All other resources get
> ioremapped, but their pointers are discarded, so why bother. So, let's
> keep things simple. Just remap resource[0] and pass the error, if any.
> Compile tested only, due to no hardware.


Nack, this will actually break the driver. This device has several
sections of registers, and not a single io region. Check
Documentation/devicetree/bindings/thermal/ti_soc_thermal.txt for examples.

> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> ---
> Please apply via the subsystem-tree.
> 
>  drivers/thermal/ti-soc-thermal/ti-bandgap.c |   20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> index 9dfd471..416be5d 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> @@ -1130,7 +1130,6 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
>  	const struct of_device_id *of_id;
>  	struct ti_bandgap *bgp;
>  	struct resource *res;
> -	int i;
>  
>  	/* just for the sake */
>  	if (!node) {
> @@ -1156,21 +1155,10 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
>  		return ERR_PTR(-ENOMEM);
>  	}
>  
> -	i = 0;
> -	do {
> -		void __iomem *chunk;
> -
> -		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
> -		if (!res)
> -			break;
> -		chunk = devm_ioremap_resource(&pdev->dev, res);
> -		if (i == 0)
> -			bgp->base = chunk;
> -		if (IS_ERR(chunk))
> -			return ERR_CAST(chunk);

In case resource 0 is not found, the error will be repassed.

> -
> -		i++;
> -	} while (res);

And yes, other IORESOURCE_MEM resources are required, depending on chip
version.

> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	bgp->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(bgp->base))
> +		return bgp->base;
>  
>  	if (TI_BANDGAP_HAS(bgp, TSHUT)) {
>  		bgp->tshut_gpio = of_get_gpio(node, 0);
> 


-- 
You have got to be excited about what you are doing. (L. Lamport)

Eduardo Valentin


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 295 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Valentin <eduardo.valentin@ti.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: <linux-kernel@vger.kernel.org>,
	Eduardo Valentin <eduardo.valentin@ti.com>,
	Zhang Rui <rui.zhang@intel.com>, <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation
Date: Fri, 26 Jul 2013 11:43:23 -0400	[thread overview]
Message-ID: <51F2991B.3060704@ti.com> (raw)
In-Reply-To: <1374602524-3398-28-git-send-email-wsa@the-dreams.de>

[-- Attachment #1: Type: text/plain, Size: 2388 bytes --]

On 23-07-2013 14:02, Wolfram Sang wrote:
> When cleaning up usage of devm_ioremap_resource, I found that resource
> allocation in this driver is ugly and buggy. If resource[0] is not
> found, bgp->base will end up NULL, so OOPS. All other resources get
> ioremapped, but their pointers are discarded, so why bother. So, let's
> keep things simple. Just remap resource[0] and pass the error, if any.
> Compile tested only, due to no hardware.


Nack, this will actually break the driver. This device has several
sections of registers, and not a single io region. Check
Documentation/devicetree/bindings/thermal/ti_soc_thermal.txt for examples.

> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> ---
> Please apply via the subsystem-tree.
> 
>  drivers/thermal/ti-soc-thermal/ti-bandgap.c |   20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> index 9dfd471..416be5d 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> @@ -1130,7 +1130,6 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
>  	const struct of_device_id *of_id;
>  	struct ti_bandgap *bgp;
>  	struct resource *res;
> -	int i;
>  
>  	/* just for the sake */
>  	if (!node) {
> @@ -1156,21 +1155,10 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
>  		return ERR_PTR(-ENOMEM);
>  	}
>  
> -	i = 0;
> -	do {
> -		void __iomem *chunk;
> -
> -		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
> -		if (!res)
> -			break;
> -		chunk = devm_ioremap_resource(&pdev->dev, res);
> -		if (i == 0)
> -			bgp->base = chunk;
> -		if (IS_ERR(chunk))
> -			return ERR_CAST(chunk);

In case resource 0 is not found, the error will be repassed.

> -
> -		i++;
> -	} while (res);

And yes, other IORESOURCE_MEM resources are required, depending on chip
version.

> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	bgp->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(bgp->base))
> +		return bgp->base;
>  
>  	if (TI_BANDGAP_HAS(bgp, TSHUT)) {
>  		bgp->tshut_gpio = of_get_gpio(node, 0);
> 


-- 
You have got to be excited about what you are doing. (L. Lamport)

Eduardo Valentin


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 295 bytes --]

  reply	other threads:[~2013-07-26 15:43 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23 18:01 [PATCH 00/27] devm cleanup, part #1, take #3 Wolfram Sang
2013-07-23 18:01 ` Wolfram Sang
2013-07-23 18:01 ` Wolfram Sang
2013-07-23 18:01 ` Wolfram Sang
2013-07-23 18:01 ` [PATCH 01/27] arch/mips/lantiq/xway: don't check resource with devm_ioremap_resource Wolfram Sang
2013-07-23 18:02   ` John Crispin
2013-07-23 18:01 ` [PATCH 02/27] drivers/amba: " Wolfram Sang
     [not found]   ` <1374602524-3398-3-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2013-07-24  1:34     ` Stephen Warren
2013-07-24  1:34       ` Stephen Warren
2013-07-23 18:01 ` [PATCH 03/27] drivers/cpuidle: " Wolfram Sang
2013-07-23 21:26   ` Rafael J. Wysocki
2013-07-23 18:01 ` [PATCH 04/27] drivers/dma: " Wolfram Sang
2013-08-19  8:58   ` Vinod Koul
2013-08-19 10:03     ` Wolfram Sang
2013-07-23 18:01 ` [PATCH 05/27] drivers/gpu/host1x/drm: " Wolfram Sang
     [not found]   ` <1374602524-3398-6-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2013-08-01 10:20     ` Terje Bergström
2013-08-01 10:20       ` Terje Bergström
2013-07-23 18:01 ` [PATCH 06/27] drivers/i2c/busses: " Wolfram Sang
2013-07-23 18:01   ` Wolfram Sang
2013-07-29 16:39   ` Linus Walleij
2013-07-29 16:39     ` Linus Walleij
     [not found]   ` <1374602524-3398-7-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2013-08-07 15:38     ` Wolfram Sang
2013-08-07 15:38       ` Wolfram Sang
2013-08-07 15:38       ` Wolfram Sang
2013-07-23 18:01 ` [PATCH 07/27] drivers/input/serio: " Wolfram Sang
2013-07-23 18:01 ` [PATCH 08/27] drivers/iommu: " Wolfram Sang
     [not found]   ` <1374602524-3398-9-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2013-07-24  1:30     ` Stephen Warren
2013-07-24  1:30       ` Stephen Warren
2013-07-23 18:01 ` [PATCH 09/27] drivers/media/platform: " Wolfram Sang
2013-07-23 18:01 ` [PATCH 10/27] drivers/memory: " Wolfram Sang
     [not found]   ` <1374602524-3398-11-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2013-07-23 18:25     ` Joe Perches
2013-07-23 18:25       ` Joe Perches
2013-07-24  1:27       ` Stephen Warren
2013-07-24  1:27         ` Stephen Warren
     [not found]         ` <51EF2D9D.8030904-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-07-24  1:38           ` Joe Perches
2013-07-24  1:38             ` Joe Perches
2013-07-24  1:32     ` Stephen Warren
2013-07-24  1:32       ` Stephen Warren
2013-07-24  1:50   ` Joe Perches
2013-07-24 15:28     ` Wolfram Sang
2013-07-24 15:51       ` Joe Perches
2013-07-23 18:01 ` [PATCH 11/27] drivers/mtd/nand: " Wolfram Sang
2013-07-23 18:01   ` Wolfram Sang
2013-07-23 18:09   ` Fabio Estevam
2013-07-23 18:09     ` Fabio Estevam
2013-07-23 18:01 ` [PATCH 12/27] drivers/net/ethernet/stmicro/stmmac: " Wolfram Sang
2013-07-25  6:59   ` David Miller
2013-07-23 18:01 ` [PATCH 13/27] drivers/pci/host: " Wolfram Sang
2013-07-23 18:12   ` Bjorn Helgaas
2013-07-23 23:17     ` Jingoo Han
2013-07-23 18:01 ` [PATCH 14/27] drivers/pinctrl: " Wolfram Sang
2013-08-07 18:14   ` Linus Walleij
2013-07-23 18:01 ` [PATCH 15/27] drivers/pwm: " Wolfram Sang
2013-08-14  9:43   ` Thierry Reding
2013-07-23 18:01 ` [PATCH 16/27] drivers/scsi/ufs: " Wolfram Sang
2013-07-23 18:01 ` [PATCH 17/27] drivers/spi: " Wolfram Sang
2013-07-24 14:29   ` Mark Brown
2013-07-24 15:30     ` Wolfram Sang
2013-07-23 18:01 ` [PATCH 18/27] drivers/staging/imx-drm: " Wolfram Sang
2013-07-23 18:01 ` [PATCH 19/27] drivers/usb/phy: " Wolfram Sang
2013-07-23 18:01 ` [PATCH 20/27] drivers/watchdog: " Wolfram Sang
2013-07-23 18:01   ` Wolfram Sang
2013-07-23 18:01 ` [PATCH 21/27] sound/soc/au1x: " Wolfram Sang
2013-07-24 14:31   ` Mark Brown
2013-07-24 14:31     ` Mark Brown
2013-07-23 18:01 ` [PATCH 22/27] sound/soc/cirrus: " Wolfram Sang
2013-07-24 14:33   ` Mark Brown
2013-07-24 14:33     ` Mark Brown
2013-07-23 18:01 ` [PATCH 23/27] sound/soc/nuc900: " Wolfram Sang
2013-07-24 14:34   ` Mark Brown
2013-07-23 18:01 ` [PATCH 24/27] sound/soc/pxa: " Wolfram Sang
2013-07-23 18:01   ` Wolfram Sang
2013-07-24 14:35   ` Mark Brown
2013-07-24 14:35     ` Mark Brown
2013-07-23 18:01 ` [PATCH 25/27] sound/soc/tegra: " Wolfram Sang
2013-07-24 14:37   ` Mark Brown
2013-07-24 14:37     ` Mark Brown
2013-07-23 18:01 ` [PATCH 26/27] sound/soc/txx9: " Wolfram Sang
2013-07-24 14:37   ` Mark Brown
2013-07-24 14:37     ` Mark Brown
2013-07-23 18:02 ` [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation Wolfram Sang
2013-07-26 15:43   ` Eduardo Valentin [this message]
2013-07-26 15:43     ` Eduardo Valentin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51F2991B.3060704@ti.com \
    --to=eduardo.valentin@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.