Prechádzať zdrojové kódy

power: max8925: Fix NULL ptr dereference on memory allocation failure

Check the return value of devm_kzalloc() to fix possible NULL pointer
dereference and properly exit the probe() on memory allocation failure.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Krzysztof Kozlowski 11 rokov pred
rodič
commit
920ac5be91
1 zmenil súbory, kde vykonal 4 pridanie a 1 odobranie
  1. 4 1
      drivers/power/max8925_power.c

+ 4 - 1
drivers/power/max8925_power.c

@@ -452,13 +452,14 @@ max8925_power_dt_init(struct platform_device *pdev)
 	pdata = devm_kzalloc(&pdev->dev,
 	pdata = devm_kzalloc(&pdev->dev,
 			sizeof(struct max8925_power_pdata),
 			sizeof(struct max8925_power_pdata),
 			GFP_KERNEL);
 			GFP_KERNEL);
+	if (!pdata)
+		goto ret;
 
 
 	of_property_read_u32(np, "topoff-threshold", &topoff_threshold);
 	of_property_read_u32(np, "topoff-threshold", &topoff_threshold);
 	of_property_read_u32(np, "batt-detect", &batt_detect);
 	of_property_read_u32(np, "batt-detect", &batt_detect);
 	of_property_read_u32(np, "fast-charge", &fast_charge);
 	of_property_read_u32(np, "fast-charge", &fast_charge);
 	of_property_read_u32(np, "no-insert-detect", &no_insert_detect);
 	of_property_read_u32(np, "no-insert-detect", &no_insert_detect);
 	of_property_read_u32(np, "no-temp-support", &no_temp_support);
 	of_property_read_u32(np, "no-temp-support", &no_temp_support);
-	of_node_put(np);
 
 
 	pdata->batt_detect = batt_detect;
 	pdata->batt_detect = batt_detect;
 	pdata->fast_charge = fast_charge;
 	pdata->fast_charge = fast_charge;
@@ -466,6 +467,8 @@ max8925_power_dt_init(struct platform_device *pdev)
 	pdata->no_insert_detect = no_insert_detect;
 	pdata->no_insert_detect = no_insert_detect;
 	pdata->no_temp_support = no_temp_support;
 	pdata->no_temp_support = no_temp_support;
 
 
+ret:
+	of_node_put(np);
 	return pdata;
 	return pdata;
 }
 }
 #else
 #else