Skip to content

Commit

Permalink
Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/clk/linux

Pull clk fixes from Stephen Boyd:
 "A small set of fixes for problems found by smatch in new drivers that
  we added this rc and a handful of driver fixes that came in during the
  merge window"

* tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux:
  drivers: clk: st: Incorrect register offset used for lock_status
  clk: mediatek: mt8173: Fix enabling of critical clocks
  drivers: clk: st: Fix mux bit-setting for Cortex A9 clocks
  drivers: clk: st: Add CLK_GET_RATE_NOCACHE flag to clocks
  drivers: clk: st: Fix flexgen lock init
  drivers: clk: st: Fix FSYN channel values
  drivers: clk: st: Remove unused code
  clk: qcom: Use parent rate when set rate to pixel RCG clock
  clk: at91: do not leak resources
  clk: stm32: Fix out-by-one error path in the index lookup
  clk: iproc: fix bit manipulation arithmetic
  clk: iproc: fix memory leak from clock name
  • Loading branch information
Linus Torvalds committed Jul 11, 2015
2 parents 9cb1680 + 56551da commit 4322f02
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 50 deletions.
4 changes: 3 additions & 1 deletion drivers/clk/at91/clk-h32mx.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
h32mxclk->pmc = pmc;

clk = clk_register(NULL, &h32mxclk->hw);
if (!clk)
if (!clk) {
kfree(h32mxclk);
return;
}

of_clk_add_provider(np, of_clk_src_simple_get, clk);
}
4 changes: 3 additions & 1 deletion drivers/clk/at91/clk-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ at91_clk_register_main_osc(struct at91_pmc *pmc,
irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
ret = request_irq(osc->irq, clk_main_osc_irq_handler,
IRQF_TRIGGER_HIGH, name, osc);
if (ret)
if (ret) {
kfree(osc);
return ERR_PTR(ret);
}

if (bypass)
pmc_write(pmc, AT91_CKGR_MOR,
Expand Down
8 changes: 6 additions & 2 deletions drivers/clk/at91/clk-master.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq,
irq_set_status_flags(master->irq, IRQ_NOAUTOEN);
ret = request_irq(master->irq, clk_master_irq_handler,
IRQF_TRIGGER_HIGH, "clk-master", master);
if (ret)
if (ret) {
kfree(master);
return ERR_PTR(ret);
}

clk = clk_register(NULL, &master->hw);
if (IS_ERR(clk))
if (IS_ERR(clk)) {
free_irq(master->irq, master);
kfree(master);
}

return clk;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/clk/at91/clk-pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,16 @@ at91_clk_register_pll(struct at91_pmc *pmc, unsigned int irq, const char *name,
irq_set_status_flags(pll->irq, IRQ_NOAUTOEN);
ret = request_irq(pll->irq, clk_pll_irq_handler, IRQF_TRIGGER_HIGH,
id ? "clk-pllb" : "clk-plla", pll);
if (ret)
if (ret) {
kfree(pll);
return ERR_PTR(ret);
}

clk = clk_register(NULL, &pll->hw);
if (IS_ERR(clk))
if (IS_ERR(clk)) {
free_irq(pll->irq, pll);
kfree(pll);
}

return clk;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/clk/at91/clk-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ at91_clk_register_system(struct at91_pmc *pmc, const char *name,
irq_set_status_flags(sys->irq, IRQ_NOAUTOEN);
ret = request_irq(sys->irq, clk_system_irq_handler,
IRQF_TRIGGER_HIGH, name, sys);
if (ret)
if (ret) {
kfree(sys);
return ERR_PTR(ret);
}
}

clk = clk_register(NULL, &sys->hw);
if (IS_ERR(clk))
if (IS_ERR(clk)) {
free_irq(sys->irq, sys);
kfree(sys);
}

return clk;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/clk/at91/clk-utmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ at91_clk_register_utmi(struct at91_pmc *pmc, unsigned int irq,
irq_set_status_flags(utmi->irq, IRQ_NOAUTOEN);
ret = request_irq(utmi->irq, clk_utmi_irq_handler,
IRQF_TRIGGER_HIGH, "clk-utmi", utmi);
if (ret)
if (ret) {
kfree(utmi);
return ERR_PTR(ret);
}

clk = clk_register(NULL, &utmi->hw);
if (IS_ERR(clk))
if (IS_ERR(clk)) {
free_irq(utmi->irq, utmi);
kfree(utmi);
}

return clk;
}
Expand Down
6 changes: 1 addition & 5 deletions drivers/clk/bcm/clk-iproc-asiu.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ void __init iproc_asiu_setup(struct device_node *node,
struct iproc_asiu_clk *asiu_clk;
const char *clk_name;

clk_name = kzalloc(IPROC_CLK_NAME_LEN, GFP_KERNEL);
if (WARN_ON(!clk_name))
goto err_clk_register;

ret = of_property_read_string_index(node, "clock-output-names",
i, &clk_name);
if (WARN_ON(ret))
Expand Down Expand Up @@ -259,7 +255,7 @@ void __init iproc_asiu_setup(struct device_node *node,

err_clk_register:
for (i = 0; i < num_clks; i++)
kfree(asiu->clks[i].name);
clk_unregister(asiu->clk_data.clks[i]);
iounmap(asiu->gate_base);

err_iomap_gate:
Expand Down
13 changes: 4 additions & 9 deletions drivers/clk/bcm/clk-iproc-pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ static unsigned long iproc_pll_recalc_rate(struct clk_hw *hw,
val = readl(pll->pll_base + ctrl->ndiv_int.offset);
ndiv_int = (val >> ctrl->ndiv_int.shift) &
bit_mask(ctrl->ndiv_int.width);
ndiv = ndiv_int << ctrl->ndiv_int.shift;
ndiv = (u64)ndiv_int << ctrl->ndiv_int.shift;

if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
val = readl(pll->pll_base + ctrl->ndiv_frac.offset);
ndiv_frac = (val >> ctrl->ndiv_frac.shift) &
bit_mask(ctrl->ndiv_frac.width);

if (ndiv_frac != 0)
ndiv = (ndiv_int << ctrl->ndiv_int.shift) | ndiv_frac;
ndiv = ((u64)ndiv_int << ctrl->ndiv_int.shift) |
ndiv_frac;
}

val = readl(pll->pll_base + ctrl->pdiv.offset);
Expand Down Expand Up @@ -655,10 +656,6 @@ void __init iproc_pll_clk_setup(struct device_node *node,
memset(&init, 0, sizeof(init));
parent_name = node->name;

clk_name = kzalloc(IPROC_CLK_NAME_LEN, GFP_KERNEL);
if (WARN_ON(!clk_name))
goto err_clk_register;

ret = of_property_read_string_index(node, "clock-output-names",
i, &clk_name);
if (WARN_ON(ret))
Expand Down Expand Up @@ -690,10 +687,8 @@ void __init iproc_pll_clk_setup(struct device_node *node,
return;

err_clk_register:
for (i = 0; i < num_clks; i++) {
kfree(pll->clks[i].name);
for (i = 0; i < num_clks; i++)
clk_unregister(pll->clk_data.clks[i]);
}

err_pll_register:
if (pll->asiu_base)
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/clk-stm32f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary)
memcpy(table, stm32f42xx_gate_map, sizeof(table));

/* only bits set in table can be used as indices */
if (WARN_ON(secondary > 8 * sizeof(table) ||
if (WARN_ON(secondary >= BITS_PER_BYTE * sizeof(table) ||
0 == (table[BIT_ULL_WORD(secondary)] &
BIT_ULL_MASK(secondary))))
return -EINVAL;
Expand Down
26 changes: 21 additions & 5 deletions drivers/clk/mediatek/clk-mt8173.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,22 @@ static const struct mtk_composite peri_clks[] __initconst = {
MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents, 0x40c, 3, 1),
};

static struct clk_onecell_data *mt8173_top_clk_data __initdata;
static struct clk_onecell_data *mt8173_pll_clk_data __initdata;

static void __init mtk_clk_enable_critical(void)
{
if (!mt8173_top_clk_data || !mt8173_pll_clk_data)
return;

clk_prepare_enable(mt8173_pll_clk_data->clks[CLK_APMIXED_ARMCA15PLL]);
clk_prepare_enable(mt8173_pll_clk_data->clks[CLK_APMIXED_ARMCA7PLL]);
clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_MEM_SEL]);
clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_DDRPHYCFG_SEL]);
clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_CCI400_SEL]);
clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_RTC_SEL]);
}

static void __init mtk_topckgen_init(struct device_node *node)
{
struct clk_onecell_data *clk_data;
Expand All @@ -712,19 +728,19 @@ static void __init mtk_topckgen_init(struct device_node *node)
return;
}

clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
mt8173_top_clk_data = clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);

mtk_clk_register_factors(root_clk_alias, ARRAY_SIZE(root_clk_alias), clk_data);
mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
&mt8173_clk_lock, clk_data);

clk_prepare_enable(clk_data->clks[CLK_TOP_CCI400_SEL]);

r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
pr_err("%s(): could not register clock provider: %d\n",
__func__, r);

mtk_clk_enable_critical();
}
CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt8173-topckgen", mtk_topckgen_init);

Expand Down Expand Up @@ -818,13 +834,13 @@ static void __init mtk_apmixedsys_init(struct device_node *node)
{
struct clk_onecell_data *clk_data;

clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
mt8173_pll_clk_data = clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
if (!clk_data)
return;

mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);

clk_prepare_enable(clk_data->clks[CLK_APMIXED_ARMCA15PLL]);
mtk_clk_enable_critical();
}
CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt8173-apmixedsys",
mtk_apmixedsys_init);
9 changes: 3 additions & 6 deletions drivers/clk/qcom/clk-rcg2.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,16 @@ static int clk_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
struct freq_tbl f = *rcg->freq_tbl;
const struct frac_entry *frac = frac_table_pixel;
unsigned long request, src_rate;
unsigned long request;
int delta = 100000;
u32 mask = BIT(rcg->hid_width) - 1;
u32 hid_div;
int index = qcom_find_src_index(hw, rcg->parent_map, f.src);
struct clk *parent = clk_get_parent_by_index(hw->clk, index);

for (; frac->num; frac++) {
request = (rate * frac->den) / frac->num;

src_rate = __clk_round_rate(parent, request);
if ((src_rate < (request - delta)) ||
(src_rate > (request + delta)))
if ((parent_rate < (request - delta)) ||
(parent_rate > (request + delta)))
continue;

regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
Expand Down
4 changes: 3 additions & 1 deletion drivers/clk/st/clk-flexgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static struct clk *clk_register_flexgen(const char *name,

init.name = name;
init.ops = &flexgen_ops;
init.flags = CLK_IS_BASIC | flexgen_flags;
init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE | flexgen_flags;
init.parent_names = parent_names;
init.num_parents = num_parents;

Expand Down Expand Up @@ -303,6 +303,8 @@ static void __init st_of_flexgen_setup(struct device_node *np)
if (!rlock)
goto err;

spin_lock_init(rlock);

for (i = 0; i < clk_data->clk_num; i++) {
struct clk *clk;
const char *clk_name;
Expand Down
12 changes: 4 additions & 8 deletions drivers/clk/st/clkgen-fsyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static const struct clkgen_quadfs_data st_fs660c32_C_407 = {
CLKGEN_FIELD(0x30c, 0xf, 20),
CLKGEN_FIELD(0x310, 0xf, 20) },
.lockstatus_present = true,
.lock_status = CLKGEN_FIELD(0x2A0, 0x1, 24),
.lock_status = CLKGEN_FIELD(0x2f0, 0x1, 24),
.powerup_polarity = 1,
.standby_polarity = 1,
.pll_ops = &st_quadfs_pll_c32_ops,
Expand Down Expand Up @@ -489,7 +489,7 @@ static int quadfs_pll_is_enabled(struct clk_hw *hw)
struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw);
u32 npda = CLKGEN_READ(pll, npda);

return !!npda;
return pll->data->powerup_polarity ? !npda : !!npda;
}

static int clk_fs660c32_vco_get_rate(unsigned long input, struct stm_fs *fs,
Expand Down Expand Up @@ -635,7 +635,7 @@ static struct clk * __init st_clk_register_quadfs_pll(

init.name = name;
init.ops = quadfs->pll_ops;
init.flags = CLK_IS_BASIC;
init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
init.parent_names = &parent_name;
init.num_parents = 1;

Expand Down Expand Up @@ -774,7 +774,7 @@ static void quadfs_fsynth_disable(struct clk_hw *hw)
if (fs->lock)
spin_lock_irqsave(fs->lock, flags);

CLKGEN_WRITE(fs, nsb[fs->chan], !fs->data->standby_polarity);
CLKGEN_WRITE(fs, nsb[fs->chan], fs->data->standby_polarity);

if (fs->lock)
spin_unlock_irqrestore(fs->lock, flags);
Expand Down Expand Up @@ -1082,10 +1082,6 @@ static const struct of_device_id quadfs_of_match[] = {
.compatible = "st,stih407-quadfs660-D",
.data = &st_fs660c32_D_407
},
{
.compatible = "st,stih407-quadfs660-D",
.data = (void *)&st_fs660c32_D_407
},
{}
};

Expand Down
10 changes: 6 additions & 4 deletions drivers/clk/st/clkgen-mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static struct clk *clk_register_genamux(const char *name,

init.name = name;
init.ops = &clkgena_divmux_ops;
init.flags = CLK_IS_BASIC;
init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
init.parent_names = parent_names;
init.num_parents = num_parents;

Expand Down Expand Up @@ -513,7 +513,8 @@ static void __init st_of_clkgena_prediv_setup(struct device_node *np)
0, &clk_name))
return;

clk = clk_register_divider_table(NULL, clk_name, parent_name, 0,
clk = clk_register_divider_table(NULL, clk_name, parent_name,
CLK_GET_RATE_NOCACHE,
reg + data->offset, data->shift, 1,
0, data->table, NULL);
if (IS_ERR(clk))
Expand Down Expand Up @@ -582,7 +583,7 @@ static struct clkgen_mux_data stih416_a9_mux_data = {
};
static struct clkgen_mux_data stih407_a9_mux_data = {
.offset = 0x1a4,
.shift = 1,
.shift = 0,
.width = 2,
};

Expand Down Expand Up @@ -786,7 +787,8 @@ static void __init st_of_clkgen_vcc_setup(struct device_node *np)
&mux->hw, &clk_mux_ops,
&div->hw, &clk_divider_ops,
&gate->hw, &clk_gate_ops,
data->clk_flags);
data->clk_flags |
CLK_GET_RATE_NOCACHE);
if (IS_ERR(clk)) {
kfree(gate);
kfree(div);
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/st/clkgen-pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ static struct clk * __init clkgen_pll_register(const char *parent_name,
init.name = clk_name;
init.ops = pll_data->ops;

init.flags = CLK_IS_BASIC;
init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
init.parent_names = &parent_name;
init.num_parents = 1;

Expand Down

0 comments on commit 4322f02

Please sign in to comment.