hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mailbox/mailbox-test.c
....@@ -12,6 +12,7 @@
1212 #include <linux/kernel.h>
1313 #include <linux/mailbox_client.h>
1414 #include <linux/module.h>
15
+#include <linux/mutex.h>
1516 #include <linux/of.h>
1617 #include <linux/platform_device.h>
1718 #include <linux/poll.h>
....@@ -38,6 +39,7 @@
3839 char *signal;
3940 char *message;
4041 spinlock_t lock;
42
+ struct mutex mutex;
4143 wait_queue_head_t waitq;
4244 struct fasync_struct *async_queue;
4345 struct dentry *root_debugfs_dir;
....@@ -95,6 +97,7 @@
9597 size_t count, loff_t *ppos)
9698 {
9799 struct mbox_test_device *tdev = filp->private_data;
100
+ char *message;
98101 void *data;
99102 int ret;
100103
....@@ -110,10 +113,13 @@
110113 return -EINVAL;
111114 }
112115
113
- tdev->message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
114
- if (!tdev->message)
116
+ message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
117
+ if (!message)
115118 return -ENOMEM;
116119
120
+ mutex_lock(&tdev->mutex);
121
+
122
+ tdev->message = message;
117123 ret = copy_from_user(tdev->message, userbuf, count);
118124 if (ret) {
119125 ret = -EFAULT;
....@@ -143,6 +149,8 @@
143149 kfree(tdev->signal);
144150 kfree(tdev->message);
145151 tdev->signal = NULL;
152
+
153
+ mutex_unlock(&tdev->mutex);
146154
147155 return ret < 0 ? ret : count;
148156 }
....@@ -392,6 +400,7 @@
392400 platform_set_drvdata(pdev, tdev);
393401
394402 spin_lock_init(&tdev->lock);
403
+ mutex_init(&tdev->mutex);
395404
396405 if (tdev->rx_channel) {
397406 tdev->rx_buffer = devm_kzalloc(&pdev->dev,