Input: elo - use guard notation when acquiring mutex

Guard notation simplifies code.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
Dmitry Torokhov
2024-08-17 17:20:30 -07:00
parent e5c79d9f65
commit cec3bcec6f

View File

@@ -219,40 +219,40 @@ static irqreturn_t elo_interrupt(struct serio *serio,
static int elo_command_10(struct elo *elo, unsigned char *packet)
{
int rc = -1;
int error;
int i;
unsigned char csum = 0xaa + ELO10_LEAD_BYTE;
mutex_lock(&elo->cmd_mutex);
guard(mutex)(&elo->cmd_mutex);
scoped_guard(serio_pause_rx, elo->serio) {
elo->expected_packet = toupper(packet[0]);
init_completion(&elo->cmd_done);
}
if (serio_write(elo->serio, ELO10_LEAD_BYTE))
goto out;
error = serio_write(elo->serio, ELO10_LEAD_BYTE);
if (error)
return error;
for (i = 0; i < ELO10_PACKET_LEN; i++) {
csum += packet[i];
if (serio_write(elo->serio, packet[i]))
goto out;
error = serio_write(elo->serio, packet[i]);
if (error)
return error;
}
if (serio_write(elo->serio, csum))
goto out;
error = serio_write(elo->serio, csum);
if (error)
return error;
wait_for_completion_timeout(&elo->cmd_done, HZ);
if (elo->expected_packet == ELO10_TOUCH_PACKET) {
/* We are back in reporting mode, the command was ACKed */
memcpy(packet, elo->response, ELO10_PACKET_LEN);
rc = 0;
}
if (elo->expected_packet != ELO10_TOUCH_PACKET)
return -EIO;
out:
mutex_unlock(&elo->cmd_mutex);
return rc;
/* We are back in reporting mode, the command was ACKed */
memcpy(packet, elo->response, ELO10_PACKET_LEN);
return 0;
}
static int elo_setup_10(struct elo *elo)