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

Commit 84bc1704 authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron
Browse files

staging: iio: tsl2583: check return values from taos_chip_{on,off}



The return value from taos_chip_on() and taos_chip_off() was not
checked in taos_luxtable_store() and taos_probe(). This patch adds
proper error checking to these function calls.

Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 27f4fabd
Loading
Loading
Loading
Loading
+18 −8
Original line number Original line Diff line number Diff line
@@ -727,7 +727,7 @@ static ssize_t taos_luxtable_store(struct device *dev,
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct tsl2583_chip *chip = iio_priv(indio_dev);
	struct tsl2583_chip *chip = iio_priv(indio_dev);
	int value[ARRAY_SIZE(taos_device_lux) * 3 + 1];
	int value[ARRAY_SIZE(taos_device_lux) * 3 + 1];
	int n;
	int n, ret = -EINVAL;


	get_options(buf, ARRAY_SIZE(value), value);
	get_options(buf, ARRAY_SIZE(value), value);


@@ -739,23 +739,31 @@ static ssize_t taos_luxtable_store(struct device *dev,
	n = value[0];
	n = value[0];
	if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
	if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
		dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
		dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
		return -EINVAL;
		goto done;
	}
	}
	if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
	if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
		dev_info(dev, "LUX TABLE INPUT ERROR 2 Value[0]=%d\n", n);
		dev_info(dev, "LUX TABLE INPUT ERROR 2 Value[0]=%d\n", n);
		return -EINVAL;
		goto done;
	}
	}


	if (chip->taos_chip_status == TSL258X_CHIP_WORKING)
	if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
		taos_chip_off(indio_dev);
		ret = taos_chip_off(indio_dev);
		if (ret < 0)
			goto done;
	}


	/* Zero out the table */
	/* Zero out the table */
	memset(taos_device_lux, 0, sizeof(taos_device_lux));
	memset(taos_device_lux, 0, sizeof(taos_device_lux));
	memcpy(taos_device_lux, &value[1], (value[0] * 4));
	memcpy(taos_device_lux, &value[1], (value[0] * 4));


	taos_chip_on(indio_dev);
	ret = taos_chip_on(indio_dev);
	if (ret < 0)
		goto done;

	ret = len;


	return len;
done:
	return ret;
}
}


static DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR,
static DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR,
@@ -883,7 +891,9 @@ static int taos_probe(struct i2c_client *clientp,
	taos_defaults(chip);
	taos_defaults(chip);


	/* Make sure the chip is on */
	/* Make sure the chip is on */
	taos_chip_on(indio_dev);
	ret = taos_chip_on(indio_dev);
	if (ret < 0)
		return ret;


	dev_info(&clientp->dev, "Light sensor found.\n");
	dev_info(&clientp->dev, "Light sensor found.\n");
	return 0;
	return 0;