n_gsm.c: add tx_lock in gsm_send
PATCH 1/1 n_gsm.c: add tx_lock in gsm_send
From: xiaojin <[email protected]>
Date: Wed, 19 Dec 2012 11:53:43 +0800
Subject: [PATCH] n_gsm.c: add tx_lock in gsm_send
All the call to gsm->output should be in the tx_lock, that could avoid potential race from MUX level. But we have no tx_lock in gsm_send.
This patch is to add tx_lock in gsm_send.
--- drivers/tty/n_gsm.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/tty/n_gsm.c +0 -0
@@ -573,6 +573,7 @@ static void gsm_send(struct gsm_mux *gsm, int addr,
int cr, int control)
int len;
u8 cbuf[10];
u8 ibuf[3];
+ unsigned long flags;
switch (gsm->encoding) {
case 0:
@@ -602,7 +603,9 @@ static void gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
WARN_ON(1);
return;
}
+ spin_lock_irqsave(&gsm->tx_lock, flags);
gsm->output(gsm, cbuf, len);
+ spin_unlock_irqrestore(&gsm->tx_lock, flags);
gsm_print_packet("-->", addr, cr, control, NULL, 0);
}
Signature · 1 line
1.7.1
Quoted 9 lines · On Thu, 20 Dec 2012 08:38:40 +0800 Xiao Jin <[email protected]> wrote:
From: xiaojin <[email protected]>
Date: Wed, 19 Dec 2012 11:53:43 +0800
Subject: [PATCH]n_gsm.c: addtx_lockingsm_sendAll the call to
gsm->outputshould be in thetx_lock, that could avoid potential race from MUX level. But we have notx_lockingsm_send.This patch is to add
tx_lockingsm_send.
gsm->output calls the transmit method of the underlying tty driver. We can't do that with interrupts off as some drivers expect to be able to sleep in their output paths.
Alan
Alan,
Thanks. But the comment makes me confused. As we see, gsm->output is called by gsm_data_kick too, and it's in the tx_lock...
Best regards,
Jin Xiao
Quoted 8 lines
From: xiaojin <[email protected]>
Date: Wed, 19 Dec 2012 11:53:43 +0800
Subject: [PATCH]n_gsm.c: addtx_lockingsm_sendAll the call to
gsm->outputshould be in thetx_lock, that could avoid potential race from MUX level. But we have notx_lockingsm_send.This patch is to add
tx_lockingsm_send.
gsm->output calls the transmit method of the underlying tty driver. We
can't do that with interrupts off as some drivers expect to be able to sleep in their output paths.
Alan
Quoted 3 lines · Jin
Alan,
Thanks. But the comment makes me confused. As we see,
gsm->outputis called bygsm_data_kicktoo, and it's in thetx_lock...
That would be a bug too or I guess we could finally give in on trying to keep tty write paths not using spin_lock_irq and fix any oddments that blow up. That might actually be the right thing to do as its caused problems in other places too, and the USB tty drivers are now well behaved.
Your patch doesn't make it any worse however so I agree it might as well go in.
Alan