mailbox: omap: Reverse FIFO busy check logic
authorAndrew Davis <afd@ti.com>
Wed, 10 Apr 2024 13:59:41 +0000 (08:59 -0500)
committerJassi Brar <jassisinghbrar@gmail.com>
Mon, 20 May 2024 03:29:44 +0000 (22:29 -0500)
It is much more clear to check if the hardware FIFO is full and return
EBUSY if true. This allows us to also remove one level of indention
from the core of this function. It also makes the similarities between
omap_mbox_chan_send_noirq() and omap_mbox_chan_send() more obvious.

Signed-off-by: Andrew Davis <afd@ti.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
drivers/mailbox/omap-mailbox.c

index 8e2760d2c5b0cf0cc75270a3f2b365fddcb2d871..c5d4083125856051e58fd4043e3e2f651acf1e6a 100644 (file)
@@ -375,34 +375,33 @@ static void omap_mbox_chan_shutdown(struct mbox_chan *chan)
 
 static int omap_mbox_chan_send_noirq(struct omap_mbox *mbox, u32 msg)
 {
-       int ret = -EBUSY;
+       if (mbox_fifo_full(mbox))
+               return -EBUSY;
 
-       if (!mbox_fifo_full(mbox)) {
-               omap_mbox_enable_irq(mbox, IRQ_RX);
-               mbox_fifo_write(mbox, msg);
-               ret = 0;
-               omap_mbox_disable_irq(mbox, IRQ_RX);
+       omap_mbox_enable_irq(mbox, IRQ_RX);
+       mbox_fifo_write(mbox, msg);
+       omap_mbox_disable_irq(mbox, IRQ_RX);
 
-               /* we must read and ack the interrupt directly from here */
-               mbox_fifo_read(mbox);
-               ack_mbox_irq(mbox, IRQ_RX);
-       }
+       /* we must read and ack the interrupt directly from here */
+       mbox_fifo_read(mbox);
+       ack_mbox_irq(mbox, IRQ_RX);
 
-       return ret;
+       return 0;
 }
 
 static int omap_mbox_chan_send(struct omap_mbox *mbox, u32 msg)
 {
-       int ret = -EBUSY;
-
-       if (!mbox_fifo_full(mbox)) {
-               mbox_fifo_write(mbox, msg);
-               ret = 0;
+       if (mbox_fifo_full(mbox)) {
+               /* always enable the interrupt */
+               omap_mbox_enable_irq(mbox, IRQ_TX);
+               return -EBUSY;
        }
 
+       mbox_fifo_write(mbox, msg);
+
        /* always enable the interrupt */
        omap_mbox_enable_irq(mbox, IRQ_TX);
-       return ret;
+       return 0;
 }
 
 static int omap_mbox_chan_send_data(struct mbox_chan *chan, void *data)