Merge remote-tracking branch 'torvalds/master' into perf/core
[linux-2.6-microblaze.git] / drivers / spi / spi-fsl-spi.c
index e4a8d20..bdf94cc 100644 (file)
@@ -440,6 +440,7 @@ static int fsl_spi_setup(struct spi_device *spi)
 {
        struct mpc8xxx_spi *mpc8xxx_spi;
        struct fsl_spi_reg __iomem *reg_base;
+       bool initial_setup = false;
        int retval;
        u32 hw_mode;
        struct spi_mpc8xxx_cs *cs = spi_get_ctldata(spi);
@@ -452,6 +453,7 @@ static int fsl_spi_setup(struct spi_device *spi)
                if (!cs)
                        return -ENOMEM;
                spi_set_ctldata(spi, cs);
+               initial_setup = true;
        }
        mpc8xxx_spi = spi_master_get_devdata(spi->master);
 
@@ -475,6 +477,8 @@ static int fsl_spi_setup(struct spi_device *spi)
        retval = fsl_spi_setup_transfer(spi, NULL);
        if (retval < 0) {
                cs->hw_mode = hw_mode; /* Restore settings */
+               if (initial_setup)
+                       kfree(cs);
                return retval;
        }
 
@@ -707,6 +711,11 @@ static int of_fsl_spi_probe(struct platform_device *ofdev)
        struct resource mem;
        int irq, type;
        int ret;
+       bool spisel_boot = false;
+#if IS_ENABLED(CONFIG_FSL_SOC)
+       struct mpc8xxx_spi_probe_info *pinfo = NULL;
+#endif
+
 
        ret = of_mpc8xxx_spi_probe(ofdev);
        if (ret)
@@ -715,9 +724,8 @@ static int of_fsl_spi_probe(struct platform_device *ofdev)
        type = fsl_spi_get_type(&ofdev->dev);
        if (type == TYPE_FSL) {
                struct fsl_spi_platform_data *pdata = dev_get_platdata(dev);
-               bool spisel_boot = false;
 #if IS_ENABLED(CONFIG_FSL_SOC)
-               struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata);
+               pinfo = to_of_pinfo(pdata);
 
                spisel_boot = of_property_read_bool(np, "fsl,spisel_boot");
                if (spisel_boot) {
@@ -746,15 +754,24 @@ static int of_fsl_spi_probe(struct platform_device *ofdev)
 
        ret = of_address_to_resource(np, 0, &mem);
        if (ret)
-               return ret;
+               goto unmap_out;
 
        irq = platform_get_irq(ofdev, 0);
-       if (irq < 0)
-               return irq;
+       if (irq < 0) {
+               ret = irq;
+               goto unmap_out;
+       }
 
        master = fsl_spi_probe(dev, &mem, irq);
 
        return PTR_ERR_OR_ZERO(master);
+
+unmap_out:
+#if IS_ENABLED(CONFIG_FSL_SOC)
+       if (spisel_boot)
+               iounmap(pinfo->immr_spi_cs);
+#endif
+       return ret;
 }
 
 static int of_fsl_spi_remove(struct platform_device *ofdev)