fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe()
authorTobias Klauser <tklauser@distanz.ch>
Mon, 24 Apr 2017 21:34:20 +0000 (16:34 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Apr 2017 09:38:56 +0000 (11:38 +0200)
If either _alt_hps2fpga_enable_set() or fpga_bridge_register() fail in
alt_fpga_bridge_probe(), the clock remains enabled and prepared. Also,
in the error path for _alt_hps2fpga_enable_set() a call to
fpga_bridge_unregister() is made even though the bridge was not
registered yet.

Remove the unnecessary call to fpga_bridge_unregister() and call
clk_disable_unprepare() in both error paths in order to make sure the
clock gets properly disabled and unprepared.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Alan Tull <atull@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/fpga/altera-hps2fpga.c

index 4b354c79be31ad957d77d8d55435b01d2be303de..3066b805f2d072fd2731a785a6df408e42820dcd 100644 (file)
@@ -181,15 +181,18 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
                                 (enable ? "enabling" : "disabling"));
 
                        ret = _alt_hps2fpga_enable_set(priv, enable);
-                       if (ret) {
-                               fpga_bridge_unregister(&pdev->dev);
-                               return ret;
-                       }
+                       if (ret)
+                               goto err;
                }
        }
 
-       return fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops,
-                                   priv);
+       ret = fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops,
+                                  priv);
+err:
+       if (ret)
+               clk_disable_unprepare(priv->clk);
+
+       return ret;
 }
 
 static int alt_fpga_bridge_remove(struct platform_device *pdev)