Commit 51ad3d34 authored by Luis Ubieda's avatar Luis Ubieda Committed by Anas Nashif
Browse files

sensor: vcnl36825t: fix: Address CID 347083

Coverity found this legitimate issue: the datasheet specifies PS_IT
being 2-bits long (1, 2, 4, 8) and this driver assumes more steps are
available. Remove extraneous fields so the Proximity integration
setting fits in the expected 16-bit value.

Signed-off-by: default avatarLuis Ubieda <luisf@croxel.com>
parent 2258dcb7
Loading
Loading
Loading
Loading
+0 −16
Changes for drivers/sensor/vishay/vcnl36825t/vcnl36825t.c: 0 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -242,26 +242,10 @@ static int vcnl36825t_init_registers(const struct device *dev)
		reg_value |= VCNL36825T_PS_IT_1T;
		data->meas_timeout_us *= 1 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_1_5T:
		reg_value |= VCNL36825T_PS_IT_1_5T;
		data->meas_timeout_us *= 1.5 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_2T:
		reg_value |= VCNL36825T_PS_IT_2T;
		data->meas_timeout_us *= 2 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_2_5T:
		reg_value |= VCNL36825T_PS_IT_2_5T;
		data->meas_timeout_us *= 2.5 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_3T:
		reg_value |= VCNL36825T_PS_IT_3T;
		data->meas_timeout_us *= 3 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_3_5T:
		reg_value |= VCNL36825T_PS_IT_3_5T;
		data->meas_timeout_us *= 3.5 * VCNL36825T_FORCED_FACTOR_SCALE;
		break;
	case VCNL36825T_PROXIMITY_INTEGRATION_4T:
		reg_value |= VCNL36825T_PS_IT_4T;
		data->meas_timeout_us *= 4 * VCNL36825T_FORCED_FACTOR_SCALE;
+3 −11
Changes for drivers/sensor/vishay/vcnl36825t/vcnl36825t.h: 3 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -91,13 +91,9 @@
#define VCNL36825T_MPS_PULSES_8	(4 << VCNL36825T_PS_MPS_POS)

#define VCNL36825T_PS_IT_1T	(0 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_1_5T	(1 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_2T	(2 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_2_5T	(3 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_3T	(4 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_3_5T	(5 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_4T	(6 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_8T	(7 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_2T	(1 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_4T	(2 << VCNL36825T_PS_IT_POS)
#define VCNL36825T_PS_IT_8T	(3 << VCNL36825T_PS_IT_POS)

/* PS_CONF3 */
#define VCNL36825T_PS_SP_INT_POS	2
@@ -241,11 +237,7 @@ enum vcnl36825t_measurement_period {

enum vcnl36825t_proximity_integration_time {
	VCNL36825T_PROXIMITY_INTEGRATION_1T,
	VCNL36825T_PROXIMITY_INTEGRATION_1_5T,
	VCNL36825T_PROXIMITY_INTEGRATION_2T,
	VCNL36825T_PROXIMITY_INTEGRATION_2_5T,
	VCNL36825T_PROXIMITY_INTEGRATION_3T,
	VCNL36825T_PROXIMITY_INTEGRATION_3_5T,
	VCNL36825T_PROXIMITY_INTEGRATION_4T,
	VCNL36825T_PROXIMITY_INTEGRATION_8T,
};
+1 −1
Changes for dts/bindings/sensor/vishay,vcnl36825t.yaml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ properties:
  proximity-it:
    type: string
    default: "1"
    enum: ["1", "1.5", "2", "2.5", "3", "3.5", "4", "8"]
    enum: ["1", "2", "4", "8"]
    description: |
      Proximity integration time in T.
      Defaults to sensor reset value.
+1 −1
Changes for tests/drivers/build_all/sensor/i2c.dtsi: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -914,7 +914,7 @@ test_i2c_vishay_vcnl36825t: vcnl36825t@81 {
	compatible = "vishay,vcnl36825t";
	reg = <0x81>;

	proximity-it = "3.5";
	proximity-it = "1";
	multi-pulse = <8>;

	low-power;