Skip to content

Commit 420b2d4

Browse files
committed
Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux
Pull clk fixes from Stephen Boyd: "Two clk driver fixes - Use devm_kasprintf() to avoid overflows when forming clk names in the Microchip PolarFire driver - Fix the pretty broken Ingenic JZ4760 M/N/OD calculation to actually work and find proper divisors" * tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux: clk: ingenic: jz4760: Update M/N/OD calculation algorithm clk: microchip: mpfs-ccc: Use devm_kasprintf() for allocating formatted strings
2 parents 545c80a + ecfb9f4 commit 420b2d4

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

drivers/clk/ingenic/jz4760-cgu.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,25 @@ jz4760_cgu_calc_m_n_od(const struct ingenic_cgu_pll_info *pll_info,
5858
unsigned long rate, unsigned long parent_rate,
5959
unsigned int *pm, unsigned int *pn, unsigned int *pod)
6060
{
61-
unsigned int m, n, od, m_max = (1 << pll_info->m_bits) - 2;
61+
unsigned int m, n, od, m_max = (1 << pll_info->m_bits) - 1;
6262

6363
/* The frequency after the N divider must be between 1 and 50 MHz. */
6464
n = parent_rate / (1 * MHZ);
6565

6666
/* The N divider must be >= 2. */
6767
n = clamp_val(n, 2, 1 << pll_info->n_bits);
6868

69-
for (;; n >>= 1) {
70-
od = (unsigned int)-1;
69+
rate /= MHZ;
70+
parent_rate /= MHZ;
7171

72-
do {
73-
m = (rate / MHZ) * (1 << ++od) * n / (parent_rate / MHZ);
74-
} while ((m > m_max || m & 1) && (od < 4));
75-
76-
if (od < 4 && m >= 4 && m <= m_max)
77-
break;
72+
for (m = m_max; m >= m_max && n >= 2; n--) {
73+
m = rate * n / parent_rate;
74+
od = m & 1;
75+
m <<= od;
7876
}
7977

8078
*pm = m;
81-
*pn = n;
79+
*pn = n + 1;
8280
*pod = 1 << od;
8381
}
8482

drivers/clk/microchip/clk-mpfs-ccc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,11 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_
164164

165165
for (unsigned int i = 0; i < num_clks; i++) {
166166
struct mpfs_ccc_out_hw_clock *out_hw = &out_hws[i];
167-
char *name = devm_kzalloc(dev, 23, GFP_KERNEL);
167+
char *name = devm_kasprintf(dev, GFP_KERNEL, "%s_out%u", parent->name, i);
168168

169169
if (!name)
170170
return -ENOMEM;
171171

172-
snprintf(name, 23, "%s_out%u", parent->name, i);
173172
out_hw->divider.hw.init = CLK_HW_INIT_HW(name, &parent->hw, &clk_divider_ops, 0);
174173
out_hw->divider.reg = data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] +
175174
out_hw->reg_offset;
@@ -201,14 +200,13 @@ static int mpfs_ccc_register_plls(struct device *dev, struct mpfs_ccc_pll_hw_clo
201200

202201
for (unsigned int i = 0; i < num_clks; i++) {
203202
struct mpfs_ccc_pll_hw_clock *pll_hw = &pll_hws[i];
204-
char *name = devm_kzalloc(dev, 18, GFP_KERNEL);
205203

206-
if (!name)
204+
pll_hw->name = devm_kasprintf(dev, GFP_KERNEL, "ccc%s_pll%u",
205+
strchrnul(dev->of_node->full_name, '@'), i);
206+
if (!pll_hw->name)
207207
return -ENOMEM;
208208

209209
pll_hw->base = data->pll_base[i];
210-
snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'), i);
211-
pll_hw->name = (const char *)name;
212210
pll_hw->hw.init = CLK_HW_INIT_PARENTS_DATA_FIXED_SIZE(pll_hw->name,
213211
pll_hw->parents,
214212
&mpfs_ccc_pll_ops, 0);

0 commit comments

Comments
 (0)