linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ntb: fix possible NULL dereference
@ 2016-03-10 12:21 Sudip Mukherjee
  2016-03-10 16:24 ` Jiang, Dave
  0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2016-03-10 12:21 UTC (permalink / raw)
  To: Jon Mason, Dave Jiang, Allen Hubbe
  Cc: linux-kernel, linux-ntb, Sudip Mukherjee

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>
---
 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);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ntb: fix possible NULL dereference
  2016-03-10 12:21 [PATCH] ntb: fix possible NULL dereference Sudip Mukherjee
@ 2016-03-10 16:24 ` Jiang, Dave
  0 siblings, 0 replies; 2+ messages in thread
From: Jiang, Dave @ 2016-03-10 16:24 UTC (permalink / raw)
  To: Allen.Hubbe, sudipm.mukherjee, jdmason; +Cc: linux-kernel, linux-ntb

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@codethink.co.uk>
Acked-by: Dave Jiang <dave.jiang@intel.com>

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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-10 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 12:21 [PATCH] ntb: fix possible NULL dereference Sudip Mukherjee
2016-03-10 16:24 ` Jiang, Dave

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).