[09/12] hdata/vpd: Fix possible NULL dereference (CID 144258)

Message ID 20170803064551.3439-9-cyril.bur@au1.ibm.com
State Accepted
Headers show

Commit Message

Cyril Bur Aug. 3, 2017, 6:45 a.m.
Only use devicetree model if there was one.

Fixes: CID 144258
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 hdata/vpd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Vasant Hegde Aug. 7, 2017, 5:01 a.m. | #1
On 08/03/2017 12:15 PM, Cyril Bur wrote:
> Only use devicetree model if there was one.
>
> Fixes: CID 144258
> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>

Looks good.  Thanks for the fix.

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

-Vasant

Patch

diff --git a/hdata/vpd.c b/hdata/vpd.c
index 9a0e0da9..d7d57cda 100644
--- a/hdata/vpd.c
+++ b/hdata/vpd.c
@@ -510,8 +510,6 @@  static void dt_add_model_name(void)
 	const struct dt_property *model;
 
 	model = dt_find_property(dt_root, "model");
-	if (!model)
-		goto def_model;
 
 	iplp = get_hdif(&spira.ntuples.ipl_parms, "IPLPMS");
 	if (!iplp)
@@ -525,7 +523,7 @@  static void dt_add_model_name(void)
 		model_name = p->sys_type_str;
 
 def_model:
-	if (!model_name || model_name[0] == '\0') {
+	if ((!model_name || model_name[0] == '\0') && model) {
 		mi = machine_info_lookup(model->prop);
 		if (mi)
 			model_name = mi->name;