mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 03:11:11 -04:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user