Skip to contentSkip to conversation

interconnect: qcom: simplify allocation

PATCH Superseded Rosen Penev 3 participants 3 messages Jun 8

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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,

---
 drivers/interconnect/qcom/icc-rpm.c | 7 ++-----
 drivers/interconnect/qcom/icc-rpm.h | 2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/interconnect/qcom/icc-rpm.c +2 -5
index 23a1d116e79a..ca4c8a944755 100644
@@ -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];
 
drivers/interconnect/qcom/icc-rpm.h +1 -1
index 7d1cb2efa9ee..b08821c2ef74 100644
@@ -64,9 +64,9 @@ 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;
+	struct clk_bulk_data intf_clks[] __counted_by(num_intf_clks);
 };
 
 /**

--
2.54.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Rosen Penev

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,

---
 drivers/interconnect/qcom/icc-rpm.c | 7 ++-----
 drivers/interconnect/qcom/icc-rpm.h | 2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#2 lore raw
In reply to Rosen Penev
Quoted 7 lines · Rosen Penev

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,

---

[...]

drivers/interconnect/qcom/icc-rpm.h struct qcom_icc_provider { · line 69

Quoted 12 lines
drivers/interconnect/qcom/icc-rpm.h +1 -1
index 7d1cb2efa9ee..b08821c2ef74 100644
@@ -64,9 +64,9 @@ 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;
+	struct clk_bulk_data intf_clks[] __counted_by(num_intf_clks);

nit: it's easier to visually track if these are kept together. I think you may also need to update the kerneldoc as the order changes

Konrad