]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mailbox: mailbox-test: Prevent memory leak
authorLee Jones <lee.jones@linaro.org>
Wed, 23 Mar 2016 14:43:42 +0000 (14:43 +0000)
committerJassi Brar <jaswinder.singh@linaro.org>
Tue, 12 Apr 2016 07:58:30 +0000 (13:28 +0530)
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>
drivers/mailbox/mailbox-test.c

index 5f4b439fd45abb12226eef0256ac6db76606a254..58d04726cdd7dc13f0faad15aeec89214ffce620 100644 (file)
@@ -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);