Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe50bc8a authored by Petar Sivenov's avatar Petar Sivenov
Browse files

msm: camera: isp: Replace unsafe bitwise operations



Using addition and substraction for bitwise operations is unsafe and
error prone. If some of operations are repeated, the mask can be
leaved in invalid state. Also, cleaning of masks relies upon stats
composite IRQ register, which value is invalid in case of preceeding
VFE hw reset. This fix uses bitwise AND and OR for mask operations and
cleans properly the mask irrespectively of VFE condition.

Change-Id: Iad4f7e18b10589de5c227babe89acecdd85fb885
Signed-off-by: default avatarPetar Sivenov <psiven@codeaurora.org>
parent d81481d4
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -1085,6 +1085,11 @@ static void msm_vfe44_stats_cfg_comp_mask(
	atomic_t *stats_comp;
	struct msm_vfe_stats_shared_data *stats_data = &vfe_dev->stats_data;


	if (vfe_dev->hw_info->stats_hw_info->num_stats_comp_mask < 1)
		/* no stats composite masks */
		return;

	if (vfe_dev->hw_info->stats_hw_info->num_stats_comp_mask >
			MAX_NUM_STATS_COMP_MASK) {
		pr_err("%s: num of comp masks %d exceed max %d\n",
@@ -1109,28 +1114,28 @@ static void msm_vfe44_stats_cfg_comp_mask(
				continue;

			reg_mask |= (mask_bf_scale << (16 + i*8));
			atomic_add(stats_mask, stats_comp);
			atomic_set(stats_comp, stats_mask |
					atomic_read(stats_comp));
			break;

		} else {

			if (!(atomic_read(stats_comp) & stats_mask))
				continue;
			if (stats_mask & (1 << STATS_IDX_BF_SCALE) &&
				atomic_read(stats_comp) &
					(1 << STATS_IDX_BF_SCALE))
				atomic_sub((1 << STATS_IDX_BF_SCALE),
					stats_comp);

			/*
			 * Check if comp mask in reg is valid
			 * and contains this stat
			 */

			if (!comp_stats_mask ||
				!((comp_stats_mask >> (16 + i*8)) &
					mask_bf_scale))
				continue;
				atomic_set(stats_comp,
						~(1 << STATS_IDX_BF_SCALE) &
						atomic_read(stats_comp));

			atomic_sub(stats_mask, stats_comp);
			atomic_set(stats_comp,
					~stats_mask & atomic_read(stats_comp));
			reg_mask &= ~(mask_bf_scale << (16 + i*8));
			break;
		}
	}

	ISP_DBG("%s: comp_mask: %x atomic stats[0]: %x %x\n",
		__func__, reg_mask,
		atomic_read(&stats_data->stats_comp_mask[0]),
@@ -1139,7 +1144,6 @@ static void msm_vfe44_stats_cfg_comp_mask(
	msm_camera_io_w(reg_mask, vfe_dev->vfe_base + 0x44);
	return;
}
}

static void msm_vfe44_stats_cfg_wm_irq_mask(
	struct vfe_device *vfe_dev,
+25 −21
Original line number Diff line number Diff line
@@ -1072,6 +1072,11 @@ static void msm_vfe46_stats_cfg_comp_mask(
	atomic_t *stats_comp;
	struct msm_vfe_stats_shared_data *stats_data = &vfe_dev->stats_data;


	if (vfe_dev->hw_info->stats_hw_info->num_stats_comp_mask < 1)
		/* no stats composite masks */
		return;

	if (vfe_dev->hw_info->stats_hw_info->num_stats_comp_mask >
			MAX_NUM_STATS_COMP_MASK) {
		pr_err("%s: num of comp masks %d exceed max %d\n",
@@ -1096,28 +1101,28 @@ static void msm_vfe46_stats_cfg_comp_mask(
				continue;

			reg_mask |= (mask_bf_scale << (16 + i*8));
			atomic_add(stats_mask, stats_comp);
			atomic_set(stats_comp, stats_mask |
					atomic_read(stats_comp));
			break;

		} else {

			if (!(atomic_read(stats_comp) & stats_mask))
				continue;
			if (stats_mask & (1 << STATS_IDX_BF_SCALE) &&
				atomic_read(stats_comp) &
					(1 << STATS_IDX_BF_SCALE))
				atomic_sub((1 << STATS_IDX_BF_SCALE),
					stats_comp);
				atomic_set(stats_comp,
						~(1 << STATS_IDX_BF_SCALE) &
						atomic_read(stats_comp));

			/*
			 * Check if comp mask in reg is valid
			 * and contains this stat
			 */

			if (!comp_stats_mask ||
				!((comp_stats_mask >> (16 + i*8)) &
					mask_bf_scale))
				continue;

			atomic_sub(stats_mask, stats_comp);
			atomic_set(stats_comp,
					~stats_mask & atomic_read(stats_comp));
			reg_mask &= ~(mask_bf_scale << (16 + i*8));
			break;
		}
	}

	ISP_DBG("%s: comp_mask: %x atomic stats[0]: %x %x\n",
		__func__, reg_mask,
		atomic_read(&stats_data->stats_comp_mask[0]),
@@ -1126,7 +1131,6 @@ static void msm_vfe46_stats_cfg_comp_mask(
	msm_camera_io_w(reg_mask, vfe_dev->vfe_base + 0x78);
	return;
}
}

static void msm_vfe46_stats_cfg_wm_irq_mask(
	struct vfe_device *vfe_dev,