mailbox: mailbox-test: make data_ready a per-instance variable

While not the default case, multiple tests can be run simultaneously.
Then, data_ready being a global variable will be overwritten and the
per-instance lock will not help. Turn the global variable into a
per-instance one to avoid this problem.

Fixes: e339c80af9 ("mailbox: mailbox-test: don't rely on rx_buffer content to signal data ready")
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
master
Wolfram Sang 2026-04-17 09:42:36 +02:00 committed by Jassi Brar
parent bbcf9af68b
commit 6e937f4e76
1 changed files with 4 additions and 5 deletions

View File

@ -28,8 +28,6 @@
#define MBOX_HEXDUMP_MAX_LEN (MBOX_HEXDUMP_LINE_LEN * \ #define MBOX_HEXDUMP_MAX_LEN (MBOX_HEXDUMP_LINE_LEN * \
(MBOX_MAX_MSG_LEN / MBOX_BYTES_PER_LINE)) (MBOX_MAX_MSG_LEN / MBOX_BYTES_PER_LINE))
static bool mbox_data_ready;
struct mbox_test_device { struct mbox_test_device {
struct device *dev; struct device *dev;
void __iomem *tx_mmio; void __iomem *tx_mmio;
@ -42,6 +40,7 @@ struct mbox_test_device {
spinlock_t lock; spinlock_t lock;
struct mutex mutex; struct mutex mutex;
wait_queue_head_t waitq; wait_queue_head_t waitq;
bool data_ready;
struct fasync_struct *async_queue; struct fasync_struct *async_queue;
struct dentry *root_debugfs_dir; struct dentry *root_debugfs_dir;
}; };
@ -162,7 +161,7 @@ static bool mbox_test_message_data_ready(struct mbox_test_device *tdev)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&tdev->lock, flags); spin_lock_irqsave(&tdev->lock, flags);
data_ready = mbox_data_ready; data_ready = tdev->data_ready;
spin_unlock_irqrestore(&tdev->lock, flags); spin_unlock_irqrestore(&tdev->lock, flags);
return data_ready; return data_ready;
@ -227,7 +226,7 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
*(touser + l) = '\0'; *(touser + l) = '\0';
memset(tdev->rx_buffer, 0, MBOX_MAX_MSG_LEN); memset(tdev->rx_buffer, 0, MBOX_MAX_MSG_LEN);
mbox_data_ready = false; tdev->data_ready = false;
spin_unlock_irqrestore(&tdev->lock, flags); spin_unlock_irqrestore(&tdev->lock, flags);
@ -297,7 +296,7 @@ static void mbox_test_receive_message(struct mbox_client *client, void *message)
message, MBOX_MAX_MSG_LEN); message, MBOX_MAX_MSG_LEN);
memcpy(tdev->rx_buffer, message, MBOX_MAX_MSG_LEN); memcpy(tdev->rx_buffer, message, MBOX_MAX_MSG_LEN);
} }
mbox_data_ready = true; tdev->data_ready = true;
spin_unlock_irqrestore(&tdev->lock, flags); spin_unlock_irqrestore(&tdev->lock, flags);
wake_up_interruptible(&tdev->waitq); wake_up_interruptible(&tdev->waitq);