diff mbox

[3/3,Device] Verify zalloc returned valid pointer

Message ID 20150617082352.20710.69355.stgit@thinktux.in.ibm.com
State Accepted
Headers show

Commit Message

Ananth N Mavinakayanahalli June 17, 2015, 8:23 a.m. UTC
Else, we are dereferencing NULL

Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
---
 core/device.c |    3 +++
 1 file changed, 3 insertions(+)

Comments

Vasant Hegde June 18, 2015, 5:38 a.m. UTC | #1
On 06/17/2015 01:53 PM, Ananth N Mavinakayanahalli wrote:
> Else, we are dereferencing NULL
> 
> Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>

Looks good.

Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>

-Vasant


> ---
>  core/device.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/core/device.c b/core/device.c
> index 09f76d7..ba427de 100644
> --- a/core/device.c
> +++ b/core/device.c
> @@ -348,6 +348,9 @@ struct dt_property *dt_add_property_nstr(struct dt_node *node,
>  	struct dt_property *p;
>  	char *tmp = zalloc(vlen + 1);
>  
> +	if (!tmp)
> +		return NULL;
> +
>  	strncpy(tmp, value, vlen);
>  	p = dt_add_property(node, name, tmp, strlen(tmp)+1);
>  	free(tmp);
> 
> _______________________________________________
> Skiboot mailing list
> Skiboot@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
>
diff mbox

Patch

diff --git a/core/device.c b/core/device.c
index 09f76d7..ba427de 100644
--- a/core/device.c
+++ b/core/device.c
@@ -348,6 +348,9 @@  struct dt_property *dt_add_property_nstr(struct dt_node *node,
 	struct dt_property *p;
 	char *tmp = zalloc(vlen + 1);
 
+	if (!tmp)
+		return NULL;
+
 	strncpy(tmp, value, vlen);
 	p = dt_add_property(node, name, tmp, strlen(tmp)+1);
 	free(tmp);