mailbox: mailbox-test: don't rely on rx_buffer content to signal data ready
authorSudeep Holla <sudeep.holla@arm.com>
Thu, 28 Sep 2017 10:18:53 +0000 (11:18 +0100)
committerJassi Brar <jaswinder.singh@linaro.org>
Tue, 14 Nov 2017 14:51:32 +0000 (20:21 +0530)
Currently we rely on the first byte of the Rx buffer to check if there's
any data available to be read. If the first byte of the received buffer
is zero (i.e. null character), then we fail to signal that data is
available even when it's available.

Instead introduce a boolean variable to track the data availability and
update it in the channel receive callback as ready and clear it when the
data is read.

Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
drivers/mailbox/mailbox-test.c

index 97fb956bb6e04a328b12abdf37eb9db3fb321bb3..93f3d4d61fa7a6289819b68980e6df9c438a2790 100644 (file)
@@ -30,6 +30,7 @@
 #define MBOX_HEXDUMP_MAX_LEN   (MBOX_HEXDUMP_LINE_LEN *                \
                                 (MBOX_MAX_MSG_LEN / MBOX_BYTES_PER_LINE))
 
+static bool mbox_data_ready;
 static struct dentry *root_debugfs_dir;
 
 struct mbox_test_device {
@@ -152,16 +153,14 @@ out:
 
 static bool mbox_test_message_data_ready(struct mbox_test_device *tdev)
 {
-       unsigned char data;
+       bool data_ready;
        unsigned long flags;
 
        spin_lock_irqsave(&tdev->lock, flags);
-       data = tdev->rx_buffer[0];
+       data_ready = mbox_data_ready;
        spin_unlock_irqrestore(&tdev->lock, flags);
 
-       if (data != '\0')
-               return true;
-       return false;
+       return data_ready;
 }
 
 static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
@@ -223,6 +222,7 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
        *(touser + l) = '\0';
 
        memset(tdev->rx_buffer, 0, MBOX_MAX_MSG_LEN);
+       mbox_data_ready = false;
 
        spin_unlock_irqrestore(&tdev->lock, flags);
 
@@ -292,6 +292,7 @@ static void mbox_test_receive_message(struct mbox_client *client, void *message)
                                     message, MBOX_MAX_MSG_LEN);
                memcpy(tdev->rx_buffer, message, MBOX_MAX_MSG_LEN);
        }
+       mbox_data_ready = true;
        spin_unlock_irqrestore(&tdev->lock, flags);
 
        wake_up_interruptible(&tdev->waitq);