Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c807dbed authored by Tero Kristo's avatar Tero Kristo
Browse files

clk: ti: fix ti_clk_get_reg_addr error handling



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: default avatarTero Kristo <t-kristo@ti.com>
Acked-by: default avatarMichael Turquette <mturquette@linaro.org>
parent c517d838
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;
	}
+4 −3
Original line number Diff line number Diff line
@@ -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)
{
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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;
	}

Loading