net: dsa: hellcreek: replace kcalloc with struct_size
PATCH 1/1 net: dsa: hellcreek: replace kcalloc with struct_size
One fewer allocation for the priv struct.
Signed-off-by Rosen Penev <[email protected]>
--- 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
@@ -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
@@ -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
Quoted 3 lines · Rosen Penev
One fewer allocation for the priv struct.
Signed-off-by Rosen Penev <[email protected]>
Acked-by Kurt Kanzenbach <[email protected]>
It looks correct, but i'm currently out of office. I'll test it next week on hardware.
Thanks,
Kurt
Kurt Kanzenbach
maintainerQuoted 9 lines · Kurt Kanzenbach
Quoted 3 lines · Rosen Penev
One fewer allocation for the priv struct.
Signed-off-by Rosen Penev <[email protected]>Acked-by Kurt Kanzenbach <[email protected]>It looks correct, but i'm currently out of office. I'll test it next week on hardware.
Tested on hardware. No issues found. Thanks!
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.
Signed-off-by Rosen Penev <[email protected]>--- 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