LF-2860 media: mxc_capture: Fix Coverity Issue: 17691 Dereference before null check
authorRobby Cai <robby.cai@nxp.com>
Fri, 7 May 2021 10:11:00 +0000 (18:11 +0800)
committerRobby Cai <robby.cai@nxp.com>
Mon, 10 May 2021 03:46:12 +0000 (11:46 +0800)
Fix dereference before NULL check issue

Signed-off-by: Robby Cai <robby.cai@nxp.com>
Reviewed-by: G.n. Zhou <guoniu.zhou@nxp.com>
drivers/media/platform/mxc/capture/mxc_v4l2_capture.c

index 69e5284..a7444ce 100644 (file)
@@ -2999,20 +2999,24 @@ static struct platform_driver mxc_v4l2_driver = {
  */
 static int mxc_v4l2_master_attach(struct v4l2_int_device *slave)
 {
-       cam_data *cam = slave->u.slave->master->priv;
+       cam_data *cam;
        struct v4l2_format cam_fmt;
        int i;
-       struct sensor_data *sdata = slave->priv;
+       struct sensor_data *sdata;
 
        pr_debug("In MVC: mxc_v4l2_master_attach\n");
-       pr_debug("   slave.name = %s\n", slave->name);
-       pr_debug("   master.name = %s\n", slave->u.slave->master->name);
 
        if (slave == NULL) {
                pr_err("ERROR: v4l2 capture: slave parameter not valid.\n");
                return -1;
        }
 
+       pr_debug("   slave.name = %s\n", slave->name);
+       pr_debug("   master.name = %s\n", slave->u.slave->master->name);
+
+       cam = slave->u.slave->master->priv;
+       sdata = slave->priv;
+
        if (sdata->csi != cam->csi) {
                pr_debug("%s: csi doesn't match\n", __func__);
                return -1;