Skip to contentSkip to conversation

net: dsa: hellcreek: replace kcalloc with struct_size

PATCH Applied Rosen Penev 3 participants 4 messages Jun 8 – Jun 15

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: hellcreek: replace kcalloc with struct_size

One fewer allocation for the priv struct.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 14 +++++---------
 drivers/net/dsa/hirschmann/hellcreek.h |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)
drivers/net/dsa/hirschmann/hellcreek.c +5 -9
index b369c1cc89e8..2c6cabf61143 100644
@@ -1932,29 +1932,25 @@ static const struct dsa_switch_ops hellcreek_ds_ops = {
 
 static int hellcreek_probe(struct platform_device *pdev)
 {
+	const struct hellcreek_platform_data *data;
 	struct device *dev = &pdev->dev;
 	struct hellcreek *hellcreek;
 	struct resource *res;
 	int ret, i;
 
-	hellcreek = devm_kzalloc(dev, sizeof(*hellcreek), GFP_KERNEL);
+	data = of_device_get_match_data(dev);
+	hellcreek = devm_kzalloc(dev, struct_size(hellcreek, ports, data->num_ports), GFP_KERNEL);
 	if (!hellcreek)
 		return -ENOMEM;
 
+	hellcreek->pdata = data;
+
 	hellcreek->vidmbrcfg = devm_kcalloc(dev, VLAN_N_VID,
 					    sizeof(*hellcreek->vidmbrcfg),
 					    GFP_KERNEL);
 	if (!hellcreek->vidmbrcfg)
 		return -ENOMEM;
 
-	hellcreek->pdata = of_device_get_match_data(dev);
-
-	hellcreek->ports = devm_kcalloc(dev, hellcreek->pdata->num_ports,
-					sizeof(*hellcreek->ports),
-					GFP_KERNEL);
-	if (!hellcreek->ports)
-		return -ENOMEM;
-
 	for (i = 0; i < hellcreek->pdata->num_ports; ++i) {
 		struct hellcreek_port *port = &hellcreek->ports[i];
 
drivers/net/dsa/hirschmann/hellcreek.h +1 -1
index bebf0d3ff330..851822adb09e 100644
@@ -280,7 +280,6 @@ struct hellcreek {
 	struct dsa_switch *ds;
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_clock_info;
-	struct hellcreek_port *ports;
 	struct delayed_work overflow_work;
 	struct led_classdev led_is_gm;
 	struct led_classdev led_sync_good;
@@ -297,6 +296,7 @@ struct hellcreek {
 	u64 last_ts;		/* Used for overflow detection */
 	u16 status_out;		/* ptp.status_out shadow */
 	size_t fdb_entries;
+	struct hellcreek_port ports[];
 };
 
 /* A Qbv schedule can only started up to 8 seconds in the future. If the delta
Signature · 1 line
2.54.0
#3 lore raw
In reply to Rosen Penev
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 7 lines · On Sun, 7 Jun 2026 21:56:40 -0700 you wrote:

One fewer allocation for the priv struct.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 14 +++++---------
 drivers/net/dsa/hirschmann/hellcreek.h |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)

Here is the summary with links:
- net: dsa: hellcreek: replace kcalloc with struct_size

    https://git.kernel.org/netdev/net-next/c/e3d202a1ed7c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html