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

Commit 06d7f9a2 authored by puneet's avatar puneet Committed by Gerrit - the friendly Code Review server
Browse files

drivers: iio: imu: Fixed minor bugs of IMU sensors



Fixed null pointer dereffering bugs of IMU sensors ASM330,
IAM20680 and SMI130 and initialised some of data types
and fixed ASM330 Flash back data delivering after 40 second of
boot time due to some wrong return value of functions.

Change-Id: I0f5ddc7b0b485c256ec1401f1ac83431c8f67493
Signed-off-by: default avatarpuneet <puneet@codeaurora.org>
parent 9da26550
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -348,7 +348,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	if (!st->inv_acc_cachepool) {
		pr_err("inv_acc_cachepool cache create failed\n");
		err = -ENOMEM;
		goto clean_exit1;
		return 0;
	}

	for (i = 0; i < INV_ACC_MAXSAMPLE; i++) {
@@ -357,7 +357,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
					GFP_KERNEL);
		if (!st->inv_acc_samplist[i]) {
			err = -ENOMEM;
			goto clean_exit2;
			goto clean_exit1;
		}
	}

@@ -367,7 +367,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	if (!st->inv_gyro_cachepool) {
		pr_err("inv_gyro_cachepool cache create failed\n");
		err = -ENOMEM;
		goto clean_exit3;
		goto clean_exit1;
	}

	for (i = 0; i < INV_GYRO_MAXSAMPLE; i++) {
@@ -376,7 +376,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
					GFP_KERNEL);
		if (!st->inv_gyro_samplist[i]) {
			err = -ENOMEM;
			goto clean_exit4;
			goto clean_exit2;
		}
	}

@@ -384,7 +384,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	if (!st->accbuf_dev) {
		err = -ENOMEM;
		pr_err("input device allocation failed\n");
		goto clean_exit5;
		goto clean_exit2;
	}
	st->accbuf_dev->name = "inv_accbuf";
	st->accbuf_dev->id.bustype = BUS_I2C;
@@ -405,14 +405,14 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	if (err) {
		pr_err("unable to register input device %s\n",
				st->accbuf_dev->name);
		goto clean_exit5;
		goto clean_exit3;
	}

	st->gyrobuf_dev = input_allocate_device();
	if (!st->gyrobuf_dev) {
		err = -ENOMEM;
		pr_err("input device allocation failed\n");
		goto clean_exit6;
		goto clean_exit4;
	}
	st->gyrobuf_dev->name = "inv_gyrobuf";
	st->gyrobuf_dev->id.bustype = BUS_I2C;
@@ -433,7 +433,7 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	if (err) {
		pr_err("unable to register input device %s\n",
				st->gyrobuf_dev->name);
		goto clean_exit6;
		goto clean_exit5;
	}

	st->acc_buffer_inv_samples = true;
@@ -442,23 +442,24 @@ static int inv_acc_gyro_early_buff_init(struct iio_dev *indio_dev)
	inv_enable_acc_gyro(st);

	return 1;
clean_exit6:

clean_exit5:
	input_free_device(st->gyrobuf_dev);
clean_exit4:
	input_unregister_device(st->accbuf_dev);
clean_exit5:
clean_exit3:
	input_free_device(st->accbuf_dev);
clean_exit4:
clean_exit2:
	for (i = 0; i < INV_GYRO_MAXSAMPLE; i++)
		kmem_cache_free(st->inv_gyro_cachepool,
				st->inv_gyro_samplist[i]);
clean_exit3:
	kmem_cache_destroy(st->inv_gyro_cachepool);
clean_exit2:
clean_exit1:
	for (i = 0; i < INV_ACC_MAXSAMPLE; i++)
		kmem_cache_free(st->inv_acc_cachepool,
				st->inv_acc_samplist[i]);
clean_exit1:
	kmem_cache_destroy(st->inv_acc_cachepool);

	return 0;
}
static void inv_acc_gyro_input_cleanup(
+3 −5
Original line number Diff line number Diff line
@@ -374,7 +374,7 @@ ssize_t st_asm330lhh_set_watermark(struct device *dev,
	int err, val;

	if (asm330_check_acc_gyro_early_buff_enable_flag(sensor))
		return 0;
		return -EBUSY;

	mutex_lock(&iio_dev->mlock);
	if (iio_buffer_enabled(iio_dev)) {
@@ -504,10 +504,9 @@ static irqreturn_t st_asm330lhh_handler_thread(int irq, void *private)
static int st_asm330lhh_buffer_preenable(struct iio_dev *iio_dev)
{
	struct st_asm330lhh_sensor *sensor = iio_priv(iio_dev);
	int err = -1;

	if (asm330_check_acc_gyro_early_buff_enable_flag(sensor))
		return err;
		return 0;
	else
		return st_asm330lhh_update_fifo(iio_dev, true);
}
@@ -515,10 +514,9 @@ static int st_asm330lhh_buffer_preenable(struct iio_dev *iio_dev)
static int st_asm330lhh_buffer_postdisable(struct iio_dev *iio_dev)
{
	struct st_asm330lhh_sensor *sensor = iio_priv(iio_dev);
	int err = -1;

	if (asm330_check_acc_gyro_early_buff_enable_flag(sensor))
		return err;
		return 0;
	else
		return st_asm330lhh_update_fifo(iio_dev, false);
}
+15 −15
Original line number Diff line number Diff line
@@ -324,7 +324,7 @@ static int st_asm330lhh_read_oneshot(struct st_asm330lhh_sensor *sensor,
				     u8 addr, int *val)
{
	int err, delay;
	__le16 data;
	__le16 data = 0;

	if (sensor->id == ST_ASM330LHH_ID_TEMP) {
		u8 status;
@@ -885,7 +885,7 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
		dev_err(hw->dev,
				"asm_acc_cachepool cache create failed\n");
		err = -ENOMEM;
		goto clean_exit1;
		return 0;
	}

	for (i = 0; i < ASM_MAXSAMPLE; i++) {
@@ -894,7 +894,7 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
					GFP_KERNEL);
		if (!acc->asm_samplist[i]) {
			err = -ENOMEM;
			goto clean_exit2;
			goto clean_exit1;
		}
	}

@@ -905,7 +905,7 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
		dev_err(hw->dev,
				"asm_gyro_cachepool cache create failed\n");
		err = -ENOMEM;
		goto clean_exit3;
		goto clean_exit1;
	}

	for (i = 0; i < ASM_MAXSAMPLE; i++) {
@@ -914,7 +914,7 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
					GFP_KERNEL);
		if (!gyro->asm_samplist[i]) {
			err = -ENOMEM;
			goto clean_exit4;
			goto clean_exit2;
		}
	}

@@ -922,7 +922,7 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
	if (!acc->buf_dev) {
		err = -ENOMEM;
		dev_err(hw->dev, "input device allocation failed\n");
		goto clean_exit5;
		goto clean_exit2;
	}
	acc->buf_dev->name = "asm_accbuf";
	acc->buf_dev->id.bustype = BUS_I2C;
@@ -944,14 +944,14 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
		dev_err(hw->dev,
				"unable to register input device %s\n",
				acc->buf_dev->name);
		goto clean_exit5;
		goto clean_exit3;
	}

	gyro->buf_dev = input_allocate_device();
	if (!gyro->buf_dev) {
		err = -ENOMEM;
		dev_err(hw->dev, "input device allocation failed\n");
		goto clean_exit6;
		goto clean_exit4;
	}
	gyro->buf_dev->name = "asm_gyrobuf";
	gyro->buf_dev->id.bustype = BUS_I2C;
@@ -973,30 +973,30 @@ static int asm330_acc_gyro_early_buff_init(struct st_asm330lhh_hw *hw)
		dev_err(hw->dev,
				"unable to register input device %s\n",
				gyro->buf_dev->name);
		goto clean_exit6;
		goto clean_exit5;
	}

	acc->buffer_asm_samples = true;
	gyro->buffer_asm_samples = true;

	return 1;
clean_exit6:
clean_exit5:
	input_free_device(gyro->buf_dev);
clean_exit4:
	input_unregister_device(acc->buf_dev);
clean_exit5:
clean_exit3:
	input_free_device(acc->buf_dev);
clean_exit4:
clean_exit2:
	for (i = 0; i < ASM_MAXSAMPLE; i++)
		kmem_cache_free(gyro->asm_cachepool,
				gyro->asm_samplist[i]);
clean_exit3:
	kmem_cache_destroy(gyro->asm_cachepool);
clean_exit2:
clean_exit1:
	for (i = 0; i < ASM_MAXSAMPLE; i++)
		kmem_cache_free(acc->asm_cachepool,
				acc->asm_samplist[i]);
clean_exit1:
	kmem_cache_destroy(acc->asm_cachepool);

	return 0;
}
static void asm330_acc_gyro_input_cleanup(
+12 −12
Original line number Diff line number Diff line
@@ -3869,7 +3869,7 @@ static int smi130_acc_read_accel_x(struct i2c_client *client,
				signed char sensor_type, short *a_x)
{
	int comres = 0;
	unsigned char data[2];
	unsigned char data[2] = {0};

	switch (sensor_type) {
	case 0:
@@ -3938,7 +3938,7 @@ static int smi130_acc_read_accel_y(struct i2c_client *client,
				signed char sensor_type, short *a_y)
{
	int comres = 0;
	unsigned char data[2];
	unsigned char data[2] = {0};

	switch (sensor_type) {
	case 0:
@@ -3996,7 +3996,7 @@ static int smi130_acc_read_accel_z(struct i2c_client *client,
				signed char sensor_type, short *a_z)
{
	int comres = 0;
	unsigned char data[2];
	unsigned char data[2] = {0};

	switch (sensor_type) {
	case 0:
@@ -5072,7 +5072,7 @@ static int smi130_acc_read_accel_xyz(struct i2c_client *client,
		signed char sensor_type, struct smi130_accacc *acc)
{
	int comres = 0;
	unsigned char data[6];
	unsigned char data[6] = {0};
	struct smi130_acc_data *client_data = i2c_get_clientdata(client);
#ifndef SMI_ACC2X2_SENSOR_IDENTIFICATION_ENABLE
	int bitwidth;
@@ -5366,7 +5366,7 @@ static ssize_t smi130_acc_register_show(struct device *dev,
	struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);

	size_t count = 0;
	u8 reg[0x40];
	u8 reg[0x40] = {0};
	int i;

	for (i = 0; i < 0x40; i++) {
@@ -6940,7 +6940,7 @@ static int smi130_acc_early_buff_init(struct i2c_client *client,
	if (!client_data->smi_acc_cachepool) {
		PERR("smi_acc_cachepool cache create failed\n");
		err = -ENOMEM;
		goto clean_exit1;
		return 0;
	}
	for (i = 0; i < SMI_ACC_MAXSAMPLE; i++) {
		client_data->smi130_acc_samplist[i] =
@@ -6948,7 +6948,7 @@ static int smi130_acc_early_buff_init(struct i2c_client *client,
					GFP_KERNEL);
		if (!client_data->smi130_acc_samplist[i]) {
			err = -ENOMEM;
			goto clean_exit2;
			goto clean_exit1;
		}
	}

@@ -6956,7 +6956,7 @@ static int smi130_acc_early_buff_init(struct i2c_client *client,
	if (!client_data->accbuf_dev) {
		err = -ENOMEM;
		PERR("input device allocation failed\n");
		goto clean_exit3;
		goto clean_exit1;
	}
	client_data->accbuf_dev->name = "smi130_accbuf";
	client_data->accbuf_dev->id.bustype = BUS_I2C;
@@ -6977,7 +6977,7 @@ static int smi130_acc_early_buff_init(struct i2c_client *client,
	if (err) {
		PERR("unable to register input device %s\n",
				client_data->accbuf_dev->name);
		goto clean_exit3;
		goto clean_exit2;
	}

	client_data->acc_buffer_smi130_samples = true;
@@ -6988,14 +6988,14 @@ static int smi130_acc_early_buff_init(struct i2c_client *client,

	return 1;

clean_exit3:
	input_free_device(client_data->accbuf_dev);
clean_exit2:
	input_free_device(client_data->accbuf_dev);
clean_exit1:
	for (i = 0; i < SMI_ACC_MAXSAMPLE; i++)
		kmem_cache_free(client_data->smi_acc_cachepool,
				client_data->smi130_acc_samplist[i]);
clean_exit1:
	kmem_cache_destroy(client_data->smi_acc_cachepool);

	return 0;
}

+2 −2
Original line number Diff line number Diff line
@@ -2879,7 +2879,7 @@ static ssize_t smi130_show_reg_val(struct device *dev
	struct smi_client_data *client_data = input_get_drvdata(input);

	ssize_t ret;
	u8 reg_data[128], i;
	u8 reg_data[128] = {0}, i;
	int pos;

	if (client_data == NULL) {
@@ -2913,7 +2913,7 @@ static ssize_t smi130_store_reg_val(struct device *dev
	struct input_dev *input = to_input_dev(dev);
	struct smi_client_data *client_data = input_get_drvdata(input);
	ssize_t ret;
	u8 reg_data[32];
	u8 reg_data[32] = {0};
	int i, j, status, digit;

	if (client_data == NULL) {
Loading