Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipoctal: protect only the real critical section

In some conditions (echo or particular sequence of special
characters), on buffer push, the tty layer calls the write operation
while we are holding the spinlock. This means deadlock within the same
process on kernels version < 3.12. It seems not a problem on recent
kernel, but the patch still valid as locking optimization.

The protected variables by the spinlock are: xmit_buf, nb_bytes,
pointer_read and pointer_write. So, this patch reduces the locked area
in the IRQ handler only to these variables. Most of the code inside the
locked area in the IRQ handler is not protected elsewhere; it means
that it is not protected at all.

Signed-off-by: Federico Vaga <federico.vaga@cern.ch>
Acked-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Federico Vaga and committed by
Greg Kroah-Hartman
968d04e8 b86e1926

+2 -3
+2 -3
drivers/ipack/devices/ipoctal.c
··· 177 177 if (channel->nb_bytes == 0) 178 178 return; 179 179 180 + spin_lock(&channel->lock); 180 181 value = channel->tty_port.xmit_buf[*pointer_write]; 181 182 iowrite8(value, &channel->regs->w.thr); 182 183 channel->stats.tx++; 183 184 (*pointer_write)++; 184 185 *pointer_write = *pointer_write % PAGE_SIZE; 185 186 channel->nb_bytes--; 187 + spin_unlock(&channel->lock); 186 188 } 187 189 188 190 static void ipoctal_irq_channel(struct ipoctal_channel *channel) 189 191 { 190 192 u8 isr, sr; 191 193 192 - spin_lock(&channel->lock); 193 194 /* The HW is organized in pair of channels. See which register we need 194 195 * to read from */ 195 196 isr = ioread8(&channel->block_regs->r.isr); ··· 214 213 /* TX of each character */ 215 214 if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY)) 216 215 ipoctal_irq_tx(channel); 217 - 218 - spin_unlock(&channel->lock); 219 216 } 220 217 221 218 static irqreturn_t ipoctal_irq_handler(void *arg)