Re: [PATCH] ntb: fix possible NULL dereference

From: Jiang, Dave
Date: Thu Mar 10 2016 - 11:24:41 EST


On Thu, 2016-03-10 at 17:51 +0530, Sudip Mukherjee wrote:
> kmalloc can fail and we should check for NULL before using the
> pointer
> returned by kmalloc.
>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@xxxxxxxxxxxxxxx>
Acked-by: Dave Jiang <dave.jiang@xxxxxxxxx>

Thanks!

> ---
> Âdrivers/ntb/test/ntb_perf.c | 2 ++
> Â1 file changed, 2 insertions(+)
>
> diff --git a/drivers/ntb/test/ntb_perf.c
> b/drivers/ntb/test/ntb_perf.c
> index c8a37ba..b21e647 100644
> --- a/drivers/ntb/test/ntb_perf.c
> +++ b/drivers/ntb/test/ntb_perf.c
> @@ -541,6 +541,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);