drivers: imx2xx: Fail probe if device unavailable
Bhanu Murthy V [Wed, 13 Jul 2016 01:40:38 +0000 (18:40 -0700)]
Return error if otp read or fuse id read fails
Turn off power before returning error and remove
check for device not available during power off as
it's already verified during power on.

Bug 1784114

Change-Id: Id217b87fb8352c426f68468b1520da9520b0dcc7
Signed-off-by: Bhanu Murthy V <bmurthyv@nvidia.com>
Reviewed-on: http://git-master/r/1180011
(cherry picked from commit 7ecab59b36e15224e0ea3901055be20794f61f6e)
Reviewed-on: http://git-master/r/1180977
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Jihoon Bang <jbang@nvidia.com>

drivers/media/i2c/imx2xx.c

index c0f87fb..c86ad8d 100644 (file)
@@ -1174,7 +1174,7 @@ static int imx2xx_read_otp_page(struct imx2xx *priv,
 
 static int imx2xx_otp_setup(struct imx2xx *priv)
 {
-       int err;
+       int err = 0;
        int i;
        struct v4l2_ctrl *ctrl;
        u8 otp_buf[IMX2XX_OTP_SIZE];
@@ -1192,6 +1192,7 @@ static int imx2xx_otp_setup(struct imx2xx *priv)
                if (err) {
                        dev_err(&priv->i2c_client->dev,
                                "otp page read error.\n");
+                       goto setup_error;
                }
        }
 
@@ -1199,7 +1200,8 @@ static int imx2xx_otp_setup(struct imx2xx *priv)
        if (!ctrl) {
                dev_err(&priv->i2c_client->dev,
                        "could not find device ctrl.\n");
-               return -EINVAL;
+               err = -EINVAL;
+               goto setup_error;
        }
 
        for (i = 0; i < IMX2XX_OTP_SIZE; i++)
@@ -1207,11 +1209,10 @@ static int imx2xx_otp_setup(struct imx2xx *priv)
                        otp_buf[i]);
        ctrl->cur.string = ctrl->string;
 
-       err = camera_common_s_power(priv->subdev, false);
-       if (err)
-               return -ENODEV;
+setup_error:
+       camera_common_s_power(priv->subdev, false);
 
-       return 0;
+       return err;
 }
 
 static int imx2xx_fuse_id_setup(struct imx2xx *priv)
@@ -1239,13 +1240,15 @@ static int imx2xx_fuse_id_setup(struct imx2xx *priv)
        if (err) {
                dev_err(&priv->i2c_client->dev,
                        "fuse id otp page read error.\n");
+               goto setup_error;
        }
 
        ctrl = v4l2_ctrl_find(&priv->ctrl_handler, V4L2_CID_FUSE_ID);
        if (!ctrl) {
                dev_err(&priv->i2c_client->dev,
                        "could not find device ctrl.\n");
-               return -EINVAL;
+               err = -EINVAL;
+               goto setup_error;
        }
 
        for (i = 0; i < IMX2XX_FUSE_ID_SIZE; i++) {
@@ -1256,11 +1259,10 @@ static int imx2xx_fuse_id_setup(struct imx2xx *priv)
        }
        ctrl->cur.string = ctrl->string;
 
-       err = camera_common_s_power(priv->subdev, false);
-       if (err)
-               return -ENODEV;
+setup_error:
+       camera_common_s_power(priv->subdev, false);
 
-       return 0;
+       return err;
 }
 
 static int imx2xx_g_volatile_ctrl(struct v4l2_ctrl *ctrl)