thermal: rcar_gen3_thermal: check that TSC exists before memory allocation
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Wed, 29 Mar 2017 18:43:52 +0000 (20:43 +0200)
committerEduardo Valentin <edubezval@gmail.com>
Fri, 31 Mar 2017 04:41:48 +0000 (21:41 -0700)
Move the check for a TSC resource before allocating memory for a new
TSC. If no TSC is found there is little point in allocating memory for
it.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
drivers/thermal/rcar_gen3_thermal.c

index cb5c362c00009921b21bca54a76e252525e2c91f..9b6bc03dd142a8dd42165657b07b7475c8ff4b93 100644 (file)
@@ -276,16 +276,16 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
        for (i = 0; i < TSC_MAX_NUM; i++) {
                struct rcar_gen3_thermal_tsc *tsc;
 
+               res = platform_get_resource(pdev, IORESOURCE_MEM, i);
+               if (!res)
+                       break;
+
                tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL);
                if (!tsc) {
                        ret = -ENOMEM;
                        goto error_unregister;
                }
 
-               res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-               if (!res)
-                       break;
-
                tsc->base = devm_ioremap_resource(dev, res);
                if (IS_ERR(tsc->base)) {
                        ret = PTR_ERR(tsc->base);