All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
@ 2014-09-24  6:30 Xiubo Li
       [not found] ` <1411540229-24915-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Xiubo Li @ 2014-09-24  6:30 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, Xiubo Li

Since we cannot make sure the 'n' 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-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/spi/spi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 95cfe3b..e19512f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -552,6 +552,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
 	struct boardinfo *bi;
 	int i;
 
+	if (!n)
+		return -EINVAL;
+
 	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 	if (!bi)
 		return -ENOMEM;
-- 
2.1.0.27.g96db324

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
       [not found] ` <1411540229-24915-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2014-09-24  8:52   ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2014-09-24  8:52 UTC (permalink / raw)
  To: Xiubo Li; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

On Wed, Sep 24, 2014 at 02:30:29PM +0800, Xiubo Li wrote:
> Since we cannot make sure the 'n' 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).

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2014-09-24  8:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24  6:30 [PATCH] spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error Xiubo Li
     [not found] ` <1411540229-24915-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-09-24  8:52   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.