bus_cfg.bus.mipi_csi2.num_data_lanes != 4) {
                dev_err(dev, "number of CSI2 data lanes %d is not supported",
                        bus_cfg.bus.mipi_csi2.num_data_lanes);
-               v4l2_fwnode_endpoint_free(&bus_cfg);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto check_hwcfg_error;
        }
 
        hi846->nr_lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
 
        if (!bus_cfg.nr_of_link_frequencies) {
                dev_err(dev, "link-frequency property not found in DT\n");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto check_hwcfg_error;
        }
 
        /* Check that link frequences for all the modes are in device tree */
        fq = hi846_check_link_freqs(hi846, &bus_cfg);
        if (fq) {
                dev_err(dev, "Link frequency of %lld is not supported\n", fq);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto check_hwcfg_error;
        }
 
        v4l2_fwnode_endpoint_free(&bus_cfg);
        }
 
        return 0;
+
+check_hwcfg_error:
+       v4l2_fwnode_endpoint_free(&bus_cfg);
+       return ret;
 }
 
 static int hi846_probe(struct i2c_client *client)