Commit d1c2f87c authored by Lee Jones's avatar Lee Jones Committed by Jassi Brar

mailbox: mailbox-test: Prevent memory leak

If we set the Signal twice or more, without using it as part of a message,
memory will be re-allocated and the pointer over-written.  Prevent this
potential leak by only allocating memory when there isn't any already.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
parent 17f5f28f
...@@ -59,9 +59,12 @@ static ssize_t mbox_test_signal_write(struct file *filp, ...@@ -59,9 +59,12 @@ static ssize_t mbox_test_signal_write(struct file *filp,
return -EINVAL; return -EINVAL;
} }
tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL); /* Only allocate memory if we need to */
if (!tdev->signal) if (!tdev->signal) {
return -ENOMEM; tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
if (!tdev->signal)
return -ENOMEM;
}
if (copy_from_user(tdev->signal, userbuf, count)) { if (copy_from_user(tdev->signal, userbuf, count)) {
kfree(tdev->signal); kfree(tdev->signal);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment