Skip to contentSkip to conversation

console+serial: don't open-code IRQ-safe locking primitives

PATCH In review Jan Beulich 2 participants 2 messages Jun 29

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 console+serial: don't open-code IRQ-safe locking primitives

xen/drivers/char/console.c +2 -4
@@ -1010,8 +1010,7 @@ vprintk_common(const char *fmt, va_list
     unsigned long flags;
 
     /* console_lock can be acquired recursively from __printk_ratelimit(). */
-    local_irq_save(flags);
-    rspin_lock(&console_lock);
+    flags = rspin_lock_irqsave(&console_lock);
     state = &this_cpu(state);
 
     (void)vsnprintf(buf, sizeof(buf), fmt, args);
@@ -1047,8 +1046,7 @@ vprintk_common(const char *fmt, va_list
         state->continued = 1;
     }
 
-    rspin_unlock(&console_lock);
-    local_irq_restore(flags);
+    rspin_unlock_irqrestore(&console_lock, flags);
 }
 
 void vprintk(const char *fmt, va_list args)
xen/drivers/char/serial.c +3 -8
@@ -76,17 +76,15 @@ void serial_tx_interrupt(struct serial_p
     int i, n;
     unsigned long flags;
 
-    local_irq_save(flags);
-
     /*
      * Avoid spinning for a long time: if there is a long-term lock holder
      * then we know that they'll be stuffing bytes into the transmitter which
      * will therefore not be empty for long.
      */
-    while ( !spin_trylock(&port->tx_lock) )
+    while ( !spin_trylock_irqsave(&port->tx_lock, flags) )
     {
         if ( port->driver->tx_ready(port) <= 0 )
-            goto out;
+            return;
         cpu_relax();
     }
 
@@ -94,7 +92,6 @@ void serial_tx_interrupt(struct serial_p
     {
         /* Disable TX. nothing to send */
         serial_stop_tx(port);
-        spin_unlock(&port->tx_lock);
         goto out;
     }
     else
@@ -112,10 +109,8 @@ void serial_tx_interrupt(struct serial_p
     if ( i && port->driver->flush )
         port->driver->flush(port);
 
-    spin_unlock(&port->tx_lock);
-
  out:
-    local_irq_restore(flags);
+    spin_unlock_irqrestore(&port->tx_lock, flags);
 }
 
 static void __serial_putc(struct serial_port *port, char c)