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

Commit 3cdae817 authored by Puneet Yatnal's avatar Puneet Yatnal Committed by Gerrit - the friendly Code Review server
Browse files

drivers: iio: imu: fix memory leak in asm330 i2c driver



Fix memory leak by freeing the memory after i2c read and
write operation completed in asm330 i2c driver.

Change-Id: If62206eb4bb866285552970fe8db6adbb9ee1a34
Signed-off-by: default avatarPuneet Yatnal <puneet@codeaurora.org>
parent 7ca9b10b
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ static int st_asm330lhh_i2c_read(struct device *dev, u8 addr, int len, u8 *data)
	buf[0] = addr;
	ret = i2c_transfer(client->adapter, msg, 2);
	memcpy(data, buf + 1, len);
	kfree(buf);

	return ret;
}
@@ -49,6 +50,7 @@ static int st_asm330lhh_i2c_write(struct device *dev, u8 addr, int len, u8 *data
	struct i2c_client *client = to_i2c_client(dev);
	struct i2c_msg msg;
	uint8_t *send;
	int ret = 0;

	send = kmalloc(len + 1, GFP_KERNEL);
	if (!send)
@@ -62,7 +64,10 @@ static int st_asm330lhh_i2c_write(struct device *dev, u8 addr, int len, u8 *data
	msg.len = len + 1;
	msg.buf = send;

	return i2c_transfer(client->adapter, &msg, 1);
	ret = i2c_transfer(client->adapter, &msg, 1);
	kfree(send);

	return ret;
}

static const struct st_asm330lhh_transfer_function st_asm330lhh_transfer_fn = {