Skip to content

Commit

Permalink
mailbox: mailbox-test: Prevent memory leak
Browse files Browse the repository at this point in the history
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: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
  • Loading branch information
Lee Jones authored and Jassi Brar committed Apr 12, 2016
1 parent 17f5f28 commit d1c2f87
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/mailbox/mailbox-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ static ssize_t mbox_test_signal_write(struct file *filp,
return -EINVAL;
}

tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
if (!tdev->signal)
return -ENOMEM;
/* Only allocate memory if we need to */
if (!tdev->signal) {
tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
if (!tdev->signal)
return -ENOMEM;
}

if (copy_from_user(tdev->signal, userbuf, count)) {
kfree(tdev->signal);
Expand Down

0 comments on commit d1c2f87

Please sign in to comment.