* [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex
@ 2026-03-06 2:54 Rosen Penev
2026-03-06 4:36 ` Gustavo A. R. Silva
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-06 2:54 UTC (permalink / raw)
To: netdev
Cc: Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Combining the allocations simplifies things, especially the free path.
Remove ofdpa_group_tbl_entry_free as a result. kfree is shorter.
Add __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/rocker/rocker_ofdpa.c | 31 +++++-----------------
1 file changed, 7 insertions(+), 24 deletions(-)
diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
index 50ea5f9ef63a..66a8ae67c3ea 100644
--- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
+++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
@@ -104,7 +104,6 @@ struct ofdpa_group_tbl_entry {
u32 cmd;
u32 group_id; /* key */
u16 group_count;
- u32 *group_ids;
union {
struct {
u8 pop_vlan;
@@ -123,6 +122,8 @@ struct ofdpa_group_tbl_entry {
u32 group_id;
} l3_unicast;
};
+
+ u32 group_ids[] __counted_by(group_count);
};
struct ofdpa_fdb_tbl_entry {
@@ -1059,19 +1060,6 @@ ofdpa_group_tbl_find(const struct ofdpa *ofdpa,
return NULL;
}
-static void ofdpa_group_tbl_entry_free(struct ofdpa_group_tbl_entry *entry)
-{
- switch (ROCKER_GROUP_TYPE_GET(entry->group_id)) {
- case ROCKER_OF_DPA_GROUP_TYPE_L2_FLOOD:
- case ROCKER_OF_DPA_GROUP_TYPE_L2_MCAST:
- kfree(entry->group_ids);
- break;
- default:
- break;
- }
- kfree(entry);
-}
-
static int ofdpa_group_tbl_add(struct ofdpa_port *ofdpa_port, int flags,
struct ofdpa_group_tbl_entry *match)
{
@@ -1085,7 +1073,7 @@ static int ofdpa_group_tbl_add(struct ofdpa_port *ofdpa_port, int flags,
if (found) {
hash_del(&found->entry);
- ofdpa_group_tbl_entry_free(found);
+ kfree(found);
found = match;
found->cmd = ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_MOD;
} else {
@@ -1122,14 +1110,14 @@ static int ofdpa_group_tbl_del(struct ofdpa_port *ofdpa_port, int flags,
spin_unlock_irqrestore(&ofdpa->group_tbl_lock, lock_flags);
- ofdpa_group_tbl_entry_free(match);
+ kfree(match);
if (found) {
err = rocker_cmd_exec(ofdpa_port->rocker_port,
ofdpa_flags_nowait(flags),
ofdpa_cmd_group_tbl_del,
found, NULL, NULL);
- ofdpa_group_tbl_entry_free(found);
+ kfree(found);
}
return err;
@@ -1166,18 +1154,13 @@ static int ofdpa_group_l2_fan_out(struct ofdpa_port *ofdpa_port,
{
struct ofdpa_group_tbl_entry *entry;
- entry = kzalloc_obj(*entry);
+ entry = kzalloc_flex(*entry, group_ids, group_count);
if (!entry)
return -ENOMEM;
- entry->group_id = group_id;
entry->group_count = group_count;
+ entry->group_id = group_id;
- entry->group_ids = kcalloc(group_count, sizeof(u32), GFP_KERNEL);
- if (!entry->group_ids) {
- kfree(entry);
- return -ENOMEM;
- }
memcpy(entry->group_ids, group_ids, group_count * sizeof(u32));
return ofdpa_group_tbl_do(ofdpa_port, flags, entry);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex
2026-03-06 2:54 [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex Rosen Penev
@ 2026-03-06 4:36 ` Gustavo A. R. Silva
2026-03-06 12:04 ` Jiri Pirko
2026-03-10 2:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-06 4:36 UTC (permalink / raw)
To: Rosen Penev, netdev
Cc: Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On 3/6/26 11:54, Rosen Penev wrote:
> Combining the allocations simplifies things, especially the free path.
>
> Remove ofdpa_group_tbl_entry_free as a result. kfree is shorter.
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
-Gustavo
> ---
> drivers/net/ethernet/rocker/rocker_ofdpa.c | 31 +++++-----------------
> 1 file changed, 7 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
> index 50ea5f9ef63a..66a8ae67c3ea 100644
> --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
> +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
> @@ -104,7 +104,6 @@ struct ofdpa_group_tbl_entry {
> u32 cmd;
> u32 group_id; /* key */
> u16 group_count;
> - u32 *group_ids;
> union {
> struct {
> u8 pop_vlan;
> @@ -123,6 +122,8 @@ struct ofdpa_group_tbl_entry {
> u32 group_id;
> } l3_unicast;
> };
> +
> + u32 group_ids[] __counted_by(group_count);
> };
>
> struct ofdpa_fdb_tbl_entry {
> @@ -1059,19 +1060,6 @@ ofdpa_group_tbl_find(const struct ofdpa *ofdpa,
> return NULL;
> }
>
> -static void ofdpa_group_tbl_entry_free(struct ofdpa_group_tbl_entry *entry)
> -{
> - switch (ROCKER_GROUP_TYPE_GET(entry->group_id)) {
> - case ROCKER_OF_DPA_GROUP_TYPE_L2_FLOOD:
> - case ROCKER_OF_DPA_GROUP_TYPE_L2_MCAST:
> - kfree(entry->group_ids);
> - break;
> - default:
> - break;
> - }
> - kfree(entry);
> -}
> -
> static int ofdpa_group_tbl_add(struct ofdpa_port *ofdpa_port, int flags,
> struct ofdpa_group_tbl_entry *match)
> {
> @@ -1085,7 +1073,7 @@ static int ofdpa_group_tbl_add(struct ofdpa_port *ofdpa_port, int flags,
>
> if (found) {
> hash_del(&found->entry);
> - ofdpa_group_tbl_entry_free(found);
> + kfree(found);
> found = match;
> found->cmd = ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_MOD;
> } else {
> @@ -1122,14 +1110,14 @@ static int ofdpa_group_tbl_del(struct ofdpa_port *ofdpa_port, int flags,
>
> spin_unlock_irqrestore(&ofdpa->group_tbl_lock, lock_flags);
>
> - ofdpa_group_tbl_entry_free(match);
> + kfree(match);
>
> if (found) {
> err = rocker_cmd_exec(ofdpa_port->rocker_port,
> ofdpa_flags_nowait(flags),
> ofdpa_cmd_group_tbl_del,
> found, NULL, NULL);
> - ofdpa_group_tbl_entry_free(found);
> + kfree(found);
> }
>
> return err;
> @@ -1166,18 +1154,13 @@ static int ofdpa_group_l2_fan_out(struct ofdpa_port *ofdpa_port,
> {
> struct ofdpa_group_tbl_entry *entry;
>
> - entry = kzalloc_obj(*entry);
> + entry = kzalloc_flex(*entry, group_ids, group_count);
> if (!entry)
> return -ENOMEM;
>
> - entry->group_id = group_id;
> entry->group_count = group_count;
> + entry->group_id = group_id;
>
> - entry->group_ids = kcalloc(group_count, sizeof(u32), GFP_KERNEL);
> - if (!entry->group_ids) {
> - kfree(entry);
> - return -ENOMEM;
> - }
> memcpy(entry->group_ids, group_ids, group_count * sizeof(u32));
>
> return ofdpa_group_tbl_do(ofdpa_port, flags, entry);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex
2026-03-06 2:54 [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex Rosen Penev
2026-03-06 4:36 ` Gustavo A. R. Silva
@ 2026-03-06 12:04 ` Jiri Pirko
2026-03-10 2:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2026-03-06 12:04 UTC (permalink / raw)
To: Rosen Penev
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Fri, Mar 06, 2026 at 03:54:49AM +0100, rosenp@gmail.com wrote:
>Combining the allocations simplifies things, especially the free path.
>
>Remove ofdpa_group_tbl_entry_free as a result. kfree is shorter.
>
>Add __counted_by for extra runtime analysis.
>
>Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex
2026-03-06 2:54 [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex Rosen Penev
2026-03-06 4:36 ` Gustavo A. R. Silva
2026-03-06 12:04 ` Jiri Pirko
@ 2026-03-10 2:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-10 2:00 UTC (permalink / raw)
To: Rosen Penev
Cc: netdev, jiri, andrew+netdev, davem, edumazet, kuba, pabeni, kees,
gustavoars, linux-kernel, linux-hardening
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 5 Mar 2026 18:54:49 -0800 you wrote:
> Combining the allocations simplifies things, especially the free path.
>
> Remove ofdpa_group_tbl_entry_free as a result. kfree is shorter.
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> [...]
Here is the summary with links:
- [net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex
https://git.kernel.org/netdev/net-next/c/692743073580
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-10 2:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 2:54 [PATCH net-next] net: rocker: kzalloc + kcalloc to kzalloc_flex Rosen Penev
2026-03-06 4:36 ` Gustavo A. R. Silva
2026-03-06 12:04 ` Jiri Pirko
2026-03-10 2:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox