linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: core: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
@ 2014-09-18  8:21 Xiubo Li
  2014-10-06 21:14 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Xiubo Li @ 2014-09-18  8:21 UTC (permalink / raw)
  To: sameo, lee.jones; +Cc: linux-kernel, Xiubo Li

Since we cannot make sure the 'cell->num_resources' will always be none
zero here, and then if either equal to zero, the kzalloc() will return
ZERO_SIZE_PTR, which equals to ((void *)16).

So this patch fix this with just doing the zero check before calling
kzalloc().

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
 drivers/mfd/mfd-core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 892d343..54c7e35 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -89,6 +89,9 @@ static int mfd_add_device(struct device *parent, int id,
 	int ret = -ENOMEM;
 	int r;
 
+	if (!cell->num_resources)
+		return -EINVAL;
+
 	pdev = platform_device_alloc(cell->name, id + cell->id);
 	if (!pdev)
 		goto fail_alloc;
-- 
2.1.0.27.g96db324


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

* Re: [PATCH] mfd: core: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
  2014-09-18  8:21 [PATCH] mfd: core: Fix possible ZERO_SIZE_PTR pointer dereferencing error Xiubo Li
@ 2014-10-06 21:14 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2014-10-06 21:14 UTC (permalink / raw)
  To: Xiubo Li; +Cc: sameo, linux-kernel

On Thu, 18 Sep 2014, Xiubo Li wrote:

> Since we cannot make sure the 'cell->num_resources' will always be none
> zero here, and then if either equal to zero, the kzalloc() will return
> ZERO_SIZE_PTR, which equals to ((void *)16).
> 
> So this patch fix this with just doing the zero check before calling
> kzalloc().
> 
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
> ---
>  drivers/mfd/mfd-core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
> index 892d343..54c7e35 100644
> --- a/drivers/mfd/mfd-core.c
> +++ b/drivers/mfd/mfd-core.c
> @@ -89,6 +89,9 @@ static int mfd_add_device(struct device *parent, int id,
>  	int ret = -ENOMEM;
>  	int r;
>  
> +	if (!cell->num_resources)
> +		return -EINVAL;

Resources are not compulsory.

>  	pdev = platform_device_alloc(cell->name, id + cell->id);
>  	if (!pdev)
>  		goto fail_alloc;

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2014-10-06 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-18  8:21 [PATCH] mfd: core: Fix possible ZERO_SIZE_PTR pointer dereferencing error Xiubo Li
2014-10-06 21:14 ` Lee Jones

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