Skip to contentSkip to conversation

smc: Use flexible array for SMCD connections

PATCH Applied Rosen Penev 4 participants 6 messages May 19 – May 21

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

PATCH 1/1 smc: Use flexible array for SMCD connections

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Assisted-by Codex:GPT-5.5
---
 include/net/smc.h |  2 +-
 net/smc/smc_ism.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
include/net/smc.h +1 -1
index bfdc4c41f019..a2bc3ab88075 100644
@@ -40,7 +40,6 @@ struct smcd_dev {
 	struct dibs_dev *dibs;
 	struct list_head list;
 	spinlock_t lock;
-	struct smc_connection **conn;
 	struct list_head vlan;
 	struct workqueue_struct *event_wq;
 	u8 pnetid[SMC_MAX_PNETID_LEN];
@@ -50,6 +49,7 @@ struct smcd_dev {
 	atomic_t lgr_cnt;
 	wait_queue_head_t lgrs_deleted;
 	u8 going_away : 1;
+	struct smc_connection *conn[];
 };
 
 #define SMC_HS_CTRL_NAME_MAX 16
net/smc/smc_ism.c +2 -8
index e0dba2c7b6e3..bde938c5eb39 100644
@@ -467,17 +467,14 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 {
 	struct smcd_dev *smcd;
 
-	smcd = kzalloc_obj(*smcd);
+	smcd = kzalloc_flex(*smcd, conn, max_dmbs);
 	if (!smcd)
 		return NULL;
-	smcd->conn = kzalloc_objs(struct smc_connection *, max_dmbs);
-	if (!smcd->conn)
-		goto free_smcd;
 
 	smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
 						 WQ_MEM_RECLAIM, name);
 	if (!smcd->event_wq)
-		goto free_conn;
+		goto free_smcd;
 
 	spin_lock_init(&smcd->lock);
 	spin_lock_init(&smcd->lgr_lock);
@@ -486,8 +483,6 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 	init_waitqueue_head(&smcd->lgrs_deleted);
 	return smcd;
 
-free_conn:
-	kfree(smcd->conn);
 free_smcd:
 	kfree(smcd);
 	return NULL;
@@ -557,7 +552,6 @@ static void smcd_unregister_dev(struct dibs_dev *dibs)
 	list_del_init(&smcd->list);
 	mutex_unlock(&smcd_dev_list.mutex);
 	destroy_workqueue(smcd->event_wq);
-	kfree(smcd->conn);
 	kfree(smcd);
 }
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 9 lines · Rosen Penev

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Assisted-by Codex:GPT-5.5

---

I don't think GPT did a good job here.
There are many other instances, where smcd->conn is freed, those would need adoption as well afaiu.

I am also not sure that there is enough improvement in the idea to warrant a patch, but I leave that to the SMC maintainers.

Quoted 65 lines
 include/net/smc.h |  2 +-
 net/smc/smc_ism.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
include/net/smc.h +1 -1
index bfdc4c41f019..a2bc3ab88075 100644
@@ -40,7 +40,6 @@ struct smcd_dev {
 	struct dibs_dev *dibs;
 	struct list_head list;
 	spinlock_t lock;
-	struct smc_connection **conn;
 	struct list_head vlan;
 	struct workqueue_struct *event_wq;
 	u8 pnetid[SMC_MAX_PNETID_LEN];
@@ -50,6 +49,7 @@ struct smcd_dev {
 	atomic_t lgr_cnt;
 	wait_queue_head_t lgrs_deleted;
 	u8 going_away : 1;
+	struct smc_connection *conn[];
 };
 
 #define SMC_HS_CTRL_NAME_MAX 16
net/smc/smc_ism.c +2 -8
index e0dba2c7b6e3..bde938c5eb39 100644
@@ -467,17 +467,14 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 {
 	struct smcd_dev *smcd;
 
-	smcd = kzalloc_obj(*smcd);
+	smcd = kzalloc_flex(*smcd, conn, max_dmbs);
 	if (!smcd)
 		return NULL;
-	smcd->conn = kzalloc_objs(struct smc_connection *, max_dmbs);
-	if (!smcd->conn)
-		goto free_smcd;
 
 	smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
 						 WQ_MEM_RECLAIM, name);
 	if (!smcd->event_wq)
-		goto free_conn;
+		goto free_smcd;
 
 	spin_lock_init(&smcd->lock);
 	spin_lock_init(&smcd->lgr_lock);
@@ -486,8 +483,6 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 	init_waitqueue_head(&smcd->lgrs_deleted);
 	return smcd;
 
-free_conn:
-	kfree(smcd->conn);
 free_smcd:
 	kfree(smcd);
 	return NULL;
@@ -557,7 +552,6 @@ static void smcd_unregister_dev(struct dibs_dev *dibs)
 	list_del_init(&smcd->list);
 	mutex_unlock(&smcd_dev_list.mutex);
 	destroy_workqueue(smcd->event_wq);
-	kfree(smcd->conn);
 	kfree(smcd);
 }
 
#2 lore raw
Quoted 10 lines · Alexandra Winter
Quoted 6 lines · Rosen Penev

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Quoted 7 lines
Quoted 3 lines
Assisted-by Codex:GPT-5.5

---

I don't think GPT did a good job here.
There are many other instances, where smcd->conn is freed, those would need adoption as well afaiu.

git grep kfree | grep \\\-\>conn\) drivers/media/dvb-core/dvbdev.c: kfree(dvbdev->adapter->conn); net/wireless/sme.c: kfree(wdev->conn); net/wireless/sme.c: kfree(wdev->conn);

I assume you mean net/wireless/sme.c

Quoted 72 lines

I am also not sure that there is enough improvement in the idea to warrant a patch, but I leave that to the SMC maintainers.

Quoted 65 lines
 include/net/smc.h |  2 +-
 net/smc/smc_ism.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
include/net/smc.h +1 -1
index bfdc4c41f019..a2bc3ab88075 100644
@@ -40,7 +40,6 @@ struct smcd_dev {
      struct dibs_dev *dibs;
      struct list_head list;
      spinlock_t lock;
-     struct smc_connection **conn;
      struct list_head vlan;
      struct workqueue_struct *event_wq;
      u8 pnetid[SMC_MAX_PNETID_LEN];
@@ -50,6 +49,7 @@ struct smcd_dev {
      atomic_t lgr_cnt;
      wait_queue_head_t lgrs_deleted;
      u8 going_away : 1;
+     struct smc_connection *conn[];
 };
 
 #define SMC_HS_CTRL_NAME_MAX 16
net/smc/smc_ism.c +2 -8
index e0dba2c7b6e3..bde938c5eb39 100644
@@ -467,17 +467,14 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 {
      struct smcd_dev *smcd;
 
-     smcd = kzalloc_obj(*smcd);
+     smcd = kzalloc_flex(*smcd, conn, max_dmbs);
      if (!smcd)
              return NULL;
-     smcd->conn = kzalloc_objs(struct smc_connection *, max_dmbs);
-     if (!smcd->conn)
-             goto free_smcd;
 
      smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
                                               WQ_MEM_RECLAIM, name);
      if (!smcd->event_wq)
-             goto free_conn;
+             goto free_smcd;
 
      spin_lock_init(&smcd->lock);
      spin_lock_init(&smcd->lgr_lock);
@@ -486,8 +483,6 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
      init_waitqueue_head(&smcd->lgrs_deleted);
      return smcd;
 
-free_conn:
-     kfree(smcd->conn);
 free_smcd:
      kfree(smcd);
      return NULL;
@@ -557,7 +552,6 @@ static void smcd_unregister_dev(struct dibs_dev *dibs)
      list_del_init(&smcd->list);
      mutex_unlock(&smcd_dev_list.mutex);
      destroy_workqueue(smcd->event_wq);
-     kfree(smcd->conn);
      kfree(smcd);
 }
 
#3 lore raw
Quoted 18 lines · Rosen Penev
Quoted 10 lines · Alexandra Winter
Quoted 6 lines · Rosen Penev

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Quoted 7 lines
Quoted 3 lines
Assisted-by Codex:GPT-5.5

---

I don't think GPT did a good job here.
There are many other instances, where smcd->conn is freed, those would need adoption as well afaiu.

Quoted 7 lines

git grep kfree | grep \\\-\>conn\) drivers/media/dvb-core/dvbdev.c: kfree(dvbdev->adapter->conn); net/wireless/sme.c: kfree(wdev->conn); net/wireless/sme.c: kfree(wdev->conn);

I assume you mean net/wireless/sme.c

Quoted 1 line

I have to apologize. You are right, the patch is complete. I guess I was confused by smc_conn_free() or what else. I should have been more careful.

Quoted 4 lines
Quoted 4 lines

I am also not sure that there is enough improvement in the idea to warrant a patch, but I leave that to the SMC maintainers.

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Rosen Penev
Quoted 67 lines · Rosen Penev

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Assisted-by Codex:GPT-5.5
---
 include/net/smc.h |  2 +-
 net/smc/smc_ism.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
include/net/smc.h +1 -1
index bfdc4c41f019..a2bc3ab88075 100644
@@ -40,7 +40,6 @@ struct smcd_dev {
 	struct dibs_dev *dibs;
 	struct list_head list;
 	spinlock_t lock;
-	struct smc_connection **conn;
 	struct list_head vlan;
 	struct workqueue_struct *event_wq;
 	u8 pnetid[SMC_MAX_PNETID_LEN];
@@ -50,6 +49,7 @@ struct smcd_dev {
 	atomic_t lgr_cnt;
 	wait_queue_head_t lgrs_deleted;
 	u8 going_away : 1;
+	struct smc_connection *conn[];
 };
 
 #define SMC_HS_CTRL_NAME_MAX 16
net/smc/smc_ism.c +2 -7
index e0dba2c7b6e3..bde938c5eb39 100644
@@ -467,17 +467,14 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 {
 	struct smcd_dev *smcd;
 
-	smcd = kzalloc_obj(*smcd);
+	smcd = kzalloc_flex(*smcd, conn, max_dmbs);
 	if (!smcd)
 		return NULL;
-	smcd->conn = kzalloc_objs(struct smc_connection *, max_dmbs);
-	if (!smcd->conn)
-		goto free_smcd;
 
 	smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
 						 WQ_MEM_RECLAIM, name);
 	if (!smcd->event_wq)
-		goto free_conn;
+		goto free_smcd;
 
 	spin_lock_init(&smcd->lock);
 	spin_lock_init(&smcd->lgr_lock);
@@ -486,8 +483,6 @@ static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
 	init_waitqueue_head(&smcd->lgrs_deleted);
 	return smcd;
 
-free_conn:
-	kfree(smcd->conn);
 free_smcd:
 	kfree(smcd);
 	return NULL;

net/smc/smc_ism.c static void smcd_unregister_dev(struct dibs_dev *dibs) · line 557

Quoted 7 lines
net/smc/smc_ism.c +0 -1
@@ -557,7 +552,6 @@ static void smcd_unregister_dev(struct dibs_dev *dibs)
 	list_del_init(&smcd->list);
 	mutex_unlock(&smcd_dev_list.mutex);
 	destroy_workqueue(smcd->event_wq);
-	kfree(smcd->conn);
 	kfree(smcd);
 }
 

Code changes looks good to me.

#5 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 10 lines · On Mon, 18 May 2026 17:52:06 -0700 you wrote:

Store the per-DMB connection pointers in the SMCD device allocation instead of allocating a separate connection array.

This keeps the connection table tied to the SMCD device lifetime and simplifies the allocation and cleanup paths.

Assisted-by Codex:GPT-5.5

[...]

Here is the summary with links:
- smc: Use flexible array for SMCD connections

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

You are awesome, thank you!

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