Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: qcom: clk-rpm: Fix clk_hw references

Fix the clk_hw references to the actual clocks and add a xlate function
to return the hw pointers from the already existing static array.

Reported-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Georgi Djakov and committed by
Stephen Boyd
c260524a 81b7667a

+22 -14
+22 -14
drivers/clk/qcom/clk-rpm.c
··· 127 127 128 128 struct rpm_cc { 129 129 struct qcom_rpm *rpm; 130 - struct clk_hw_onecell_data data; 131 - struct clk_hw *hws[]; 130 + struct clk_rpm **clks; 131 + size_t num_clks; 132 132 }; 133 133 134 134 struct rpm_clk_desc { ··· 391 391 }; 392 392 MODULE_DEVICE_TABLE(of, rpm_clk_match_table); 393 393 394 + static struct clk_hw *qcom_rpm_clk_hw_get(struct of_phandle_args *clkspec, 395 + void *data) 396 + { 397 + struct rpm_cc *rcc = data; 398 + unsigned int idx = clkspec->args[0]; 399 + 400 + if (idx >= rcc->num_clks) { 401 + pr_err("%s: invalid index %u\n", __func__, idx); 402 + return ERR_PTR(-EINVAL); 403 + } 404 + 405 + return rcc->clks[idx] ? &rcc->clks[idx]->hw : ERR_PTR(-ENOENT); 406 + } 407 + 394 408 static int rpm_clk_probe(struct platform_device *pdev) 395 409 { 396 - struct clk_hw **hws; 397 410 struct rpm_cc *rcc; 398 - struct clk_hw_onecell_data *data; 399 411 int ret; 400 412 size_t num_clks, i; 401 413 struct qcom_rpm *rpm; ··· 427 415 rpm_clks = desc->clks; 428 416 num_clks = desc->num_clks; 429 417 430 - rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc) + sizeof(*hws) * num_clks, 431 - GFP_KERNEL); 418 + rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc), GFP_KERNEL); 432 419 if (!rcc) 433 420 return -ENOMEM; 434 421 435 - hws = rcc->hws; 436 - data = &rcc->data; 437 - data->num = num_clks; 422 + rcc->clks = rpm_clks; 423 + rcc->num_clks = num_clks; 438 424 439 425 for (i = 0; i < num_clks; i++) { 440 426 if (!rpm_clks[i]) ··· 446 436 } 447 437 448 438 for (i = 0; i < num_clks; i++) { 449 - if (!rpm_clks[i]) { 450 - data->hws[i] = ERR_PTR(-ENOENT); 439 + if (!rpm_clks[i]) 451 440 continue; 452 - } 453 441 454 442 ret = devm_clk_hw_register(&pdev->dev, &rpm_clks[i]->hw); 455 443 if (ret) 456 444 goto err; 457 445 } 458 446 459 - ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get, 460 - data); 447 + ret = of_clk_add_hw_provider(pdev->dev.of_node, qcom_rpm_clk_hw_get, 448 + rcc); 461 449 if (ret) 462 450 goto err; 463 451