diff mbox series

[2/3] Input: st1232 - do not read more bytes than needed

Message ID 20201229162601.2154566-3-geert+renesas@glider.be (mailing list archive)
State Accepted
Commit b999dbea06b9874c7724a410f47a6bac1e219e37
Headers show
Series Input: st1232 - fixes for resolution reading | expand

Commit Message

Geert Uytterhoeven Dec. 29, 2020, 4:26 p.m. UTC
st1232_ts_read_data() already reads ts->read_buf_len bytes (8 or 20
bytes) from the touchscreen controller.  This was fine when it was used
to read touch point coordinates only, but is overkill for reading the
touchscreen resolution, which just needs 3 bytes.

Optimize transfers by passing the wanted number of bytes.

Fixes: 3a54a215410b1650 ("Input: st1232 - add support resolution reading")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/input/touchscreen/st1232.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Dmitry Torokhov Jan. 4, 2021, 1:45 a.m. UTC | #1
On Tue, Dec 29, 2020 at 05:26:00PM +0100, Geert Uytterhoeven wrote:
> st1232_ts_read_data() already reads ts->read_buf_len bytes (8 or 20
> bytes) from the touchscreen controller.  This was fine when it was used
> to read touch point coordinates only, but is overkill for reading the
> touchscreen resolution, which just needs 3 bytes.
> 
> Optimize transfers by passing the wanted number of bytes.
> 
> Fixes: 3a54a215410b1650 ("Input: st1232 - add support resolution reading")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Applied, thank you.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index f18d4c7e03da17c6..459701056f2bda96 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -47,7 +47,8 @@  struct st1232_ts_data {
 	u8 *read_buf;
 };
 
-static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg)
+static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg,
+			       unsigned int n)
 {
 	struct i2c_client *client = ts->client;
 	struct i2c_msg msg[] = {
@@ -59,7 +60,7 @@  static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg)
 		{
 			.addr	= client->addr,
 			.flags	= I2C_M_RD | I2C_M_DMA_SAFE,
-			.len	= ts->read_buf_len,
+			.len	= n,
 			.buf	= ts->read_buf,
 		}
 	};
@@ -79,7 +80,7 @@  static int st1232_ts_read_resolution(struct st1232_ts_data *ts, u16 *max_x,
 	int error;
 
 	/* select resolution register */
-	error = st1232_ts_read_data(ts, REG_XY_RESOLUTION);
+	error = st1232_ts_read_data(ts, REG_XY_RESOLUTION, 3);
 	if (error)
 		return error;
 
@@ -140,7 +141,7 @@  static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
 	int count;
 	int error;
 
-	error = st1232_ts_read_data(ts, REG_XY_COORDINATES);
+	error = st1232_ts_read_data(ts, REG_XY_COORDINATES, ts->read_buf_len);
 	if (error)
 		goto out;