[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <51F2991B.3060704@ti.com>
Date: Fri, 26 Jul 2013 11:43:23 -0400
From: Eduardo Valentin <eduardo.valentin@...com>
To: Wolfram Sang <wsa@...-dreams.de>
CC: <linux-kernel@...r.kernel.org>,
Eduardo Valentin <eduardo.valentin@...com>,
Zhang Rui <rui.zhang@...el.com>, <linux-pm@...r.kernel.org>
Subject: Re: [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation
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@...-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
Download attachment "signature.asc" of type "application/pgp-signature" (296 bytes)
Powered by blists - more mailing lists