summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShantanu Jain <shjain@codeaurora.org>2016-04-29 17:11:04 +0530
committerShantanu Jain <shjain@codeaurora.org>2017-03-24 17:09:54 +0530
commitbcde95e2e69767fa1fa9702a4a52c56f2980a558 (patch)
tree4af1d9c851b077c2275acbd10e4ac391ca31bcdd
parentc1ef16be6d3c5606edb7a23398611d010b405aa8 (diff)
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: Shantanu Jain <shjain@codeaurora.org>
-rw-r--r--drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.c8
-rw-r--r--drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.h3
-rw-r--r--drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c23
3 files changed, 29 insertions, 5 deletions
diff --git a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.c b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.c
index 206941708141..3e85cb5e2ebc 100644
--- a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.c
+++ b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.c
@@ -3666,7 +3666,7 @@ static int synaptics_rmi4_probe(struct platform_device *pdev)
return -EINVAL;
}
- rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL);
+ rmi4_data = devm_kzalloc(&pdev->dev, sizeof(*rmi4_data), GFP_KERNEL);
if (!rmi4_data) {
dev_err(&pdev->dev,
"%s: Failed to alloc mem for rmi4_data\n",
@@ -3684,6 +3684,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;
diff --git a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.h b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.h
index 7d7e045d7917..a642092e2f63 100644
--- a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.h
+++ b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_core.h
@@ -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,
@@ -277,6 +278,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;
diff --git a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c
index 0b3fbaf9f462..0be7e0bc9045 100644
--- a/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c
+++ b/drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c
@@ -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 structure 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) {