Skip to contentSkip to conversation

clk: st: NULL dereference on error in st_of_clkgen_vcc_setup()

PATCH In review Dan Carpenter 2 participants 2 messages Apr 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: st: NULL dereference on error in st_of_clkgen_vcc_setup()

There are two allocations where, if they fail, then we end up dereferencing the NULL pointer in the error handling code.

Fixes 94885faf9dbc ('clk: st: Support for DIVMUX and PreDiv Clocks')
drivers/clk/st/clkgen-mux.c +5 -4
index a329906..10899bc 100644
@@ -714,14 +714,14 @@ void __init st_of_clkgen_vcc_setup(struct device_node *np)
 
 	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
 	if (!clk_data)
-		goto err;
+		goto err_free_parents;
 
 	clk_data->clk_num = VCC_MAX_CHANNELS;
 	clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
 				 GFP_KERNEL);
 
 	if (!clk_data->clks)
-		goto err;
+		goto err_free_data;
 
 	for (i = 0; i < clk_data->clk_num; i++) {
 		struct clk *clk;
@@ -811,10 +811,11 @@ err:
 		kfree(container_of(composite->mux_hw, struct clk_mux, hw));
 	}
 
-	if (clk_data)
-		kfree(clk_data->clks);
+	kfree(clk_data->clks);
 
+err_free_data:
 	kfree(clk_data);
+err_free_parents:
 	kfree(parents);
 }
 CLK_OF_DECLARE(clkgen_vcc, "st,clkgen-vcc", st_of_clkgen_vcc_setup);
#1 lore raw

Thanks Dan,
i m agree with patch.

Best Regards.

Gabriel

Quoted 41 lines · Dan Carpenter

There are two allocations where, if they fail, then we end up dereferencing the NULL pointer in the error handling code.

Fixes 94885faf9dbc ('clk: st: Support for DIVMUX and PreDiv Clocks')
drivers/clk/st/clkgen-mux.c +5 -4
index a329906..10899bc 100644
@@ -714,14 +714,14 @@ void __init st_of_clkgen_vcc_setup(struct device_node *np)
 
  	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  	if (!clk_data)
-		goto err;
+		goto err_free_parents;
 
  	clk_data->clk_num = VCC_MAX_CHANNELS;
  	clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
  				 GFP_KERNEL);
 
  	if (!clk_data->clks)
-		goto err;
+		goto err_free_data;
 
  	for (i = 0; i < clk_data->clk_num; i++) {
  		struct clk *clk;
@@ -811,10 +811,11 @@ err:
  		kfree(container_of(composite->mux_hw, struct clk_mux, hw));
  	}
 
-	if (clk_data)
-		kfree(clk_data->clks);
+	kfree(clk_data->clks);
 
+err_free_data:
  	kfree(clk_data);
+err_free_parents:
  	kfree(parents);
  }
  CLK_OF_DECLARE(clkgen_vcc, "st,clkgen-vcc", st_of_clkgen_vcc_setup);