ntb: fix possible NULL dereference
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Thu, 10 Mar 2016 12:21:11 +0000 (17:51 +0530)
committerJon Mason <jdmason@kudzu.us>
Fri, 18 Mar 2016 00:52:15 +0000 (20:52 -0400)
kmalloc can fail and we should check for NULL before using the pointer
returned by kmalloc.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
Acked-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
drivers/ntb/test/ntb_perf.c

index f798beb01ac638e01a64027bae4ad4e7263f9c04..cf19ff07680dba12fbfe4935fd68869c44a671e8 100644 (file)
@@ -550,6 +550,8 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf,
                return 0;
 
        buf = kmalloc(64, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
        out_offset = snprintf(buf, 64, "%d\n", perf->run);
        ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
        kfree(buf);