Skip to content

Commit

Permalink
clk: ti: fix ti_clk_get_reg_addr error handling
Browse files Browse the repository at this point in the history
There is a case where NULL can be a valid return value for
ti_clk_get_reg_addr, specifically the case where both the provider index
and register offsets are zero. In this case, the current error checking
against a NULL pointer will fail. Thus, change the API to return a
ERR_PTR value in an error case, and change all the users of this API to
check against IS_ERR instead.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
Acked-by: Michael Turquette <mturquette@linaro.org>
  • Loading branch information
Tero Kristo committed Mar 24, 2015
1 parent c517d83 commit c807dbe
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
5 changes: 3 additions & 2 deletions drivers/clk/ti/apll.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void __init of_dra7_apll_setup(struct device_node *node)
ad->control_reg = ti_clk_get_reg_addr(node, 0);
ad->idlest_reg = ti_clk_get_reg_addr(node, 1);

if (!ad->control_reg || !ad->idlest_reg)
if (IS_ERR(ad->control_reg) || IS_ERR(ad->idlest_reg))
goto cleanup;

ad->idlest_mask = 0x1;
Expand Down Expand Up @@ -384,7 +384,8 @@ static void __init of_omap2_apll_setup(struct device_node *node)
ad->autoidle_reg = ti_clk_get_reg_addr(node, 1);
ad->idlest_reg = ti_clk_get_reg_addr(node, 2);

if (!ad->control_reg || !ad->autoidle_reg || !ad->idlest_reg)
if (IS_ERR(ad->control_reg) || IS_ERR(ad->autoidle_reg) ||
IS_ERR(ad->idlest_reg))
goto cleanup;

clk = clk_register(NULL, &clk_hw->hw);
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/ti/autoidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int __init of_ti_clk_autoidle_setup(struct device_node *node)
clk->name = node->name;
clk->reg = ti_clk_get_reg_addr(node, 0);

if (!clk->reg) {
if (IS_ERR(clk->reg)) {
kfree(clk);
return -EINVAL;
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/clk/ti/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ int __init ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
* @index: register index from the clock node
*
* Builds clock register address from device tree information. This
* is a struct of type clk_omap_reg.
* is a struct of type clk_omap_reg. Returns a pointer to the register
* address, or a pointer error value in failure.
*/
void __iomem *ti_clk_get_reg_addr(struct device_node *node, int index)
{
Expand All @@ -121,14 +122,14 @@ void __iomem *ti_clk_get_reg_addr(struct device_node *node, int index)

if (i == CLK_MAX_MEMMAPS) {
pr_err("clk-provider not found for %s!\n", node->name);
return NULL;
return ERR_PTR(-ENOENT);
}

reg->index = i;

if (of_property_read_u32_index(node, "reg", index, &val)) {
pr_err("%s must have reg[%d]!\n", node->name, index);
return NULL;
return ERR_PTR(-EINVAL);
}

reg->offset = val;
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/ti/divider.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ static int __init ti_clk_divider_populate(struct device_node *node,
u32 val;

*reg = ti_clk_get_reg_addr(node, 0);
if (!*reg)
return -EINVAL;
if (IS_ERR(*reg))
return PTR_ERR(*reg);

if (!of_property_read_u32(node, "ti,bit-shift", &val))
*shift = val;
Expand Down
6 changes: 3 additions & 3 deletions drivers/clk/ti/dpll.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,18 @@ static void __init of_ti_dpll_setup(struct device_node *node,
#endif
} else {
dd->idlest_reg = ti_clk_get_reg_addr(node, 1);
if (!dd->idlest_reg)
if (IS_ERR(dd->idlest_reg))
goto cleanup;

dd->mult_div1_reg = ti_clk_get_reg_addr(node, 2);
}

if (!dd->control_reg || !dd->mult_div1_reg)
if (IS_ERR(dd->control_reg) || IS_ERR(dd->mult_div1_reg))
goto cleanup;

if (dd->autoidle_mask) {
dd->autoidle_reg = ti_clk_get_reg_addr(node, 3);
if (!dd->autoidle_reg)
if (IS_ERR(dd->autoidle_reg))
goto cleanup;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/ti/gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void __init _of_ti_gate_clk_setup(struct device_node *node,

if (ops != &omap_gate_clkdm_clk_ops) {
reg = ti_clk_get_reg_addr(node, 0);
if (!reg)
if (IS_ERR(reg))
return;

if (!of_property_read_u32(node, "ti,bit-shift", &val))
Expand Down Expand Up @@ -264,7 +264,7 @@ _of_ti_composite_gate_clk_setup(struct device_node *node,
return;

gate->enable_reg = ti_clk_get_reg_addr(node, 0);
if (!gate->enable_reg)
if (IS_ERR(gate->enable_reg))
goto cleanup;

of_property_read_u32(node, "ti,bit-shift", &val);
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/ti/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void __init _of_ti_interface_clk_setup(struct device_node *node,
u32 val;

reg = ti_clk_get_reg_addr(node, 0);
if (!reg)
if (IS_ERR(reg))
return;

if (!of_property_read_u32(node, "ti,bit-shift", &val))
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/ti/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void of_mux_clk_setup(struct device_node *node)

reg = ti_clk_get_reg_addr(node, 0);

if (!reg)
if (IS_ERR(reg))
goto cleanup;

of_property_read_u32(node, "ti,bit-shift", &shift);
Expand Down Expand Up @@ -283,7 +283,7 @@ static void __init of_ti_composite_mux_clk_setup(struct device_node *node)

mux->reg = ti_clk_get_reg_addr(node, 0);

if (!mux->reg)
if (IS_ERR(mux->reg))
goto cleanup;

if (!of_property_read_u32(node, "ti,bit-shift", &val))
Expand Down

0 comments on commit c807dbe

Please sign in to comment.