Skip to content

Commit f388412

Browse files
committed
Input: zforce_ts - remove unneeded locking
There is no need to have a lock around calls to i2c_master_send() and i2c_master_recv() as they are not issued concurrently and they are not sharing any buffers. Also there is no need for command_mutex as all commands are issued sequentially. Remove both. Tested-by: Andreas Kemnade <andreas@kemnade.info> # Tolino Shine2HD Link: https://lore.kernel.org/r/20240824055047.1706392-7-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 6244559 commit f388412

1 file changed

Lines changed: 9 additions & 38 deletions

File tree

drivers/input/touchscreen/zforce_ts.c

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ struct zforce_point {
9595
* @suspending in the process of going to suspend (don't emit wakeup
9696
* events for commands executed to suspend the device)
9797
* @suspended device suspended
98-
* @access_mutex serialize i2c-access, to keep multipart reads together
9998
* @command_done completion to wait for the command result
100-
* @command_mutex serialize commands sent to the ic
10199
* @command_waiting the id of the command that is currently waiting
102100
* for a result
103101
* @command_result returned result of the command
@@ -123,10 +121,7 @@ struct zforce_ts {
123121
u16 version_build;
124122
u16 version_rev;
125123

126-
struct mutex access_mutex;
127-
128124
struct completion command_done;
129-
struct mutex command_mutex;
130125
int command_waiting;
131126
int command_result;
132127
};
@@ -143,9 +138,7 @@ static int zforce_command(struct zforce_ts *ts, u8 cmd)
143138
buf[1] = 1; /* data size, command only */
144139
buf[2] = cmd;
145140

146-
mutex_lock(&ts->access_mutex);
147141
ret = i2c_master_send(client, &buf[0], ARRAY_SIZE(buf));
148-
mutex_unlock(&ts->access_mutex);
149142
if (ret < 0) {
150143
dev_err(&client->dev, "i2c send data request error: %d\n", ret);
151144
return ret;
@@ -169,37 +162,24 @@ static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len)
169162
struct i2c_client *client = ts->client;
170163
int ret;
171164

172-
ret = mutex_trylock(&ts->command_mutex);
173-
if (!ret) {
174-
dev_err(&client->dev, "already waiting for a command\n");
175-
return -EBUSY;
176-
}
177-
178165
dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n",
179166
buf[1], buf[2]);
180167

181168
ts->command_waiting = buf[2];
182169

183-
mutex_lock(&ts->access_mutex);
184170
ret = i2c_master_send(client, buf, len);
185-
mutex_unlock(&ts->access_mutex);
186171
if (ret < 0) {
187172
dev_err(&client->dev, "i2c send data request error: %d\n", ret);
188-
goto unlock;
173+
return ret;;
189174
}
190175

191176
dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]);
192177

193-
if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) {
194-
ret = -ETIME;
195-
goto unlock;
196-
}
178+
if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0)
179+
return -ETIME;
197180

198181
ret = ts->command_result;
199-
200-
unlock:
201-
mutex_unlock(&ts->command_mutex);
202-
return ret;
182+
return 0;
203183
}
204184

205185
static int zforce_command_wait(struct zforce_ts *ts, u8 cmd)
@@ -412,41 +392,35 @@ static int zforce_read_packet(struct zforce_ts *ts, u8 *buf)
412392
struct i2c_client *client = ts->client;
413393
int ret;
414394

415-
mutex_lock(&ts->access_mutex);
416-
417395
/* read 2 byte message header */
418396
ret = i2c_master_recv(client, buf, 2);
419397
if (ret < 0) {
420398
dev_err(&client->dev, "error reading header: %d\n", ret);
421-
goto unlock;
399+
return ret;
422400
}
423401

424402
if (buf[PAYLOAD_HEADER] != FRAME_START) {
425403
dev_err(&client->dev, "invalid frame start: %d\n", buf[0]);
426-
ret = -EIO;
427-
goto unlock;
404+
return -EIO;
428405
}
429406

430407
if (buf[PAYLOAD_LENGTH] == 0) {
431408
dev_err(&client->dev, "invalid payload length: %d\n",
432409
buf[PAYLOAD_LENGTH]);
433-
ret = -EIO;
434-
goto unlock;
410+
return -EIO;
435411
}
436412

437413
/* read the message */
438414
ret = i2c_master_recv(client, &buf[PAYLOAD_BODY], buf[PAYLOAD_LENGTH]);
439415
if (ret < 0) {
440416
dev_err(&client->dev, "error reading payload: %d\n", ret);
441-
goto unlock;
417+
return ret;
442418
}
443419

444420
dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n",
445421
buf[PAYLOAD_LENGTH], buf[PAYLOAD_BODY]);
446422

447-
unlock:
448-
mutex_unlock(&ts->access_mutex);
449-
return ret;
423+
return 0;
450424
}
451425

452426
static void zforce_complete(struct zforce_ts *ts, int cmd, int result)
@@ -801,9 +775,6 @@ static int zforce_probe(struct i2c_client *client)
801775
return -ENOMEM;
802776
}
803777

804-
mutex_init(&ts->access_mutex);
805-
mutex_init(&ts->command_mutex);
806-
807778
ts->client = client;
808779
ts->input = input_dev;
809780

0 commit comments

Comments
 (0)