interconnect: qcom: simplify allocation

Use a flexible array member to reduce allocation by 1.

Add __counted_by for extra runtime analysis. Move counting variable
assignment after allocation before any array access.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Link: https://patch.msgid.link/20260609222454.37352-1-rosenp@gmail.com
Signed-off-by: Georgi Djakov <djakov@kernel.org>
This commit is contained in:
Rosen Penev 2026-06-09 15:24:54 -07:00 committed by Georgi Djakov
parent c96fc14322
commit bd8a131fbe
2 changed files with 6 additions and 9 deletions

View File

@ -479,13 +479,11 @@ int qnoc_probe(struct platform_device *pdev)
cd_num = 0;
}
qp = devm_kzalloc(dev, sizeof(*qp), GFP_KERNEL);
qp = devm_kzalloc(dev, struct_size(qp, intf_clks, cd_num), GFP_KERNEL);
if (!qp)
return -ENOMEM;
qp->intf_clks = devm_kcalloc(dev, cd_num, sizeof(*qp->intf_clks), GFP_KERNEL);
if (!qp->intf_clks)
return -ENOMEM;
qp->num_intf_clks = cd_num;
if (desc->bus_clk_desc) {
qp->bus_clk_desc = devm_kzalloc(dev, sizeof(*qp->bus_clk_desc),
@ -507,7 +505,6 @@ int qnoc_probe(struct platform_device *pdev)
return -ENOMEM;
data->num_nodes = num_nodes;
qp->num_intf_clks = cd_num;
for (i = 0; i < cd_num; i++)
qp->intf_clks[i].id = cds[i];

View File

@ -40,7 +40,6 @@ struct rpm_clk_resource {
/**
* struct qcom_icc_provider - Qualcomm specific interconnect provider
* @provider: generic interconnect provider
* @num_intf_clks: the total number of intf_clks clk_bulk_data entries
* @type: the ICC provider type
* @regmap: regmap for QoS registers read/write access
* @qos_offset: offset to QoS registers
@ -49,13 +48,13 @@ struct rpm_clk_resource {
* @bus_clk_rate: bus clock rate in Hz
* @bus_clk_desc: a pointer to a rpm_clk_resource description of bus clocks
* @bus_clk: a pointer to a HLOS-owned bus clock
* @intf_clks: a clk_bulk_data array of interface clocks
* @keep_alive: whether to always keep a minimum vote on the bus clocks
* @ignore_enxio: whether to ignore ENXIO errors (for MSM8974)
* @num_intf_clks: the total number of intf_clks clk_bulk_data entries
* @intf_clks: a clk_bulk_data array of interface clocks
*/
struct qcom_icc_provider {
struct icc_provider provider;
int num_intf_clks;
enum qcom_icc_type type;
struct regmap *regmap;
unsigned int qos_offset;
@ -64,9 +63,10 @@ struct qcom_icc_provider {
u32 bus_clk_rate[QCOM_SMD_RPM_STATE_NUM];
const struct rpm_clk_resource *bus_clk_desc;
struct clk *bus_clk;
struct clk_bulk_data *intf_clks;
bool keep_alive;
bool ignore_enxio;
int num_intf_clks;
struct clk_bulk_data intf_clks[] __counted_by(num_intf_clks);
};
/**