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

Commit a64c0bfe authored by Shantanu Jain's avatar Shantanu Jain Committed by Gerrit - the friendly Code Review server
Browse files

input: synaptics_dsx: remove array declaration in write function



Remove array declaration in i2c write function of Synaptics DSX
touch driver and use the malloc function to allocate the memory.
This change is added to use heap memory instead of stack memory.

CRs-Fixed: 1010986
Change-Id: I8f2f75744bb442191d7d4577795d986e10ea1cf6
Signed-off-by: default avatarShantanu Jain <shjain@codeaurora.org>
parent 8070c055
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3596,6 +3596,12 @@ static int synaptics_rmi4_probe(struct platform_device *pdev)
	rmi4_data->fingers_on_2d = false;
	rmi4_data->update_coords = true;

	rmi4_data->write_buf = devm_kzalloc(&pdev->dev, I2C_WRITE_BUF_MAX_LEN,
					GFP_KERNEL);
	if (!rmi4_data->write_buf)
		return -ENOMEM;
	rmi4_data->write_buf_len = I2C_WRITE_BUF_MAX_LEN;

	rmi4_data->irq_enable = synaptics_rmi4_irq_enable;
	rmi4_data->reset_device = synaptics_rmi4_reset_device;

+3 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@
#define PINCTRL_STATE_RELEASE   "pmx_ts_release"

#define SYNA_FW_NAME_MAX_LEN	50
#define I2C_WRITE_BUF_MAX_LEN	32

enum exp_fn {
	RMI_DEV = 0,
@@ -265,6 +266,8 @@ struct synaptics_rmi4_data {
	unsigned char no_sleep_setting;
	unsigned char intr_mask[MAX_INTR_REGISTERS];
	unsigned char *button_txrx_mapping;
	unsigned char *write_buf;
	unsigned short write_buf_len;
	unsigned short num_of_intr_regs;
	unsigned short f01_query_base_addr;
	unsigned short f01_cmd_base_addr;
+19 −4
Original line number Diff line number Diff line
@@ -134,18 +134,33 @@ static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
{
	int retval;
	unsigned char retry;
	unsigned char buf[length + 1];
	struct i2c_client *i2c = to_i2c_client(rmi4_data->pdev->dev.parent);
	struct i2c_msg msg[] = {
		{
			.addr = i2c->addr,
			.flags = 0,
			.len = length + 1,
			.buf = buf,
		}
	};

	mutex_lock(&rmi4_data->rmi4_io_ctrl_mutex);
	/*
	 * Reassign memory for write_buf in case length is greater than 32 bytes
	 */
	if (rmi4_data->write_buf_len < length + 1) {
		devm_kfree(rmi4_data->pdev->dev.parent, rmi4_data->write_buf);
		rmi4_data->write_buf = devm_kzalloc(rmi4_data->pdev->dev.parent,
					length + 1, GFP_KERNEL);
		if (!rmi4_data->write_buf) {
			rmi4_data->write_buf_len = 0;
			retval = -ENOMEM;
			goto exit;
		}
		rmi4_data->write_buf_len = length + 1;
	}

	/* Assign the write_buf of driver stucture to i2c_msg buf */
	msg[0].buf = rmi4_data->write_buf;

	retval = synaptics_rmi4_i2c_set_page(rmi4_data, addr);
	if (retval != PAGE_SELECT_LEN) {
@@ -153,8 +168,8 @@ static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
		goto exit;
	}

	buf[0] = addr & MASK_8BIT;
	memcpy(&buf[1], &data[0], length);
	rmi4_data->write_buf[0] = addr & MASK_8BIT;
	memcpy(&rmi4_data->write_buf[1], &data[0], length);

	for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
		if (i2c_transfer(i2c->adapter, msg, 1) == 1) {