Unverified Commit c4795f4d authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!7308 iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC

parents c6c73ccb c51fa6be
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -538,6 +538,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
	struct rm3100_data *data;
	unsigned int tmp;
	int ret;
	int samp_rate_index;

	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
	if (!indio_dev)
@@ -596,9 +597,14 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
	ret = regmap_read(regmap, RM3100_REG_TMRC, &tmp);
	if (ret < 0)
		return ret;

	samp_rate_index = tmp - RM3100_TMRC_OFFSET;
	if (samp_rate_index < 0 || samp_rate_index >=  RM3100_SAMP_NUM) {
		dev_err(dev, "The value read from RM3100_REG_TMRC is invalid!\n");
		return -EINVAL;
	}
	/* Initializing max wait time, which is double conversion time. */
	data->conversion_time = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][2]
				* 2;
	data->conversion_time = rm3100_samp_rates[samp_rate_index][2] * 2;

	/* Cycle count values may not be what we want. */
	if ((tmp - RM3100_TMRC_OFFSET) == 0)