media: imx7-mipi-csis: Add a check for devm_regulator_get
authorChuhong Yuan <hslester96@gmail.com>
Tue, 15 Oct 2019 13:59:15 +0000 (10:59 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 15:44:18 +0000 (16:44 +0100)
[ Upstream commit a0219deefe9ee5006a28d48522f76b217d198c51 ]

devm_regulator_get may return an error but mipi_csis_phy_init misses
a check for it.
This may lead to problems when regulator_set_voltage uses the unchecked
pointer.
This patch adds a check for devm_regulator_get to avoid potential risk.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/staging/media/imx/imx7-mipi-csis.c

index 73d8354e618c47a99e1aa230510de70896df8f24..e50b1f88e25b579569c6afa91604e0b95eb205bc 100644 (file)
@@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
 static int mipi_csis_phy_init(struct csi_state *state)
 {
        state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
+       if (IS_ERR(state->mipi_phy_regulator))
+               return PTR_ERR(state->mipi_phy_regulator);
 
        return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
                                     1000000);
@@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
                return ret;
        }
 
-       mipi_csis_phy_init(state);
+       ret = mipi_csis_phy_init(state);
+       if (ret < 0)
+               return ret;
+
        mipi_csis_phy_reset(state);
 
        mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);