[PATCH] target: iblock: Use flexible array for per-CPU plugs

Rosen Penev posted 1 patch 6 days, 3 hours ago
drivers/target/target_core_iblock.c | 11 +----------
drivers/target/target_core_iblock.h |  2 +-
2 files changed, 2 insertions(+), 11 deletions(-)
[PATCH] target: iblock: Use flexible array for per-CPU plugs
Posted by Rosen Penev 6 days, 3 hours ago
Store the per-CPU iblock plug array in the iblock_dev allocation
instead of allocating it separately.

This keeps the plug storage tied to the iblock device lifetime and
simplifies the allocation and RCU cleanup paths.

Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/target/target_core_iblock.c | 11 +----------
 drivers/target/target_core_iblock.h |  2 +-
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 1087d1d17c36..985197f0df26 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -59,24 +59,16 @@ static struct se_device *iblock_alloc_device(struct se_hba *hba, const char *nam
 {
 	struct iblock_dev *ib_dev = NULL;
 
-	ib_dev = kzalloc_obj(struct iblock_dev);
+	ib_dev = kzalloc_flex(*ib_dev, ibd_plug, nr_cpu_ids);
 	if (!ib_dev) {
 		pr_err("Unable to allocate struct iblock_dev\n");
 		return NULL;
 	}
 	ib_dev->ibd_exclusive = true;
 
-	ib_dev->ibd_plug = kzalloc_objs(*ib_dev->ibd_plug, nr_cpu_ids);
-	if (!ib_dev->ibd_plug)
-		goto free_dev;
-
 	pr_debug( "IBLOCK: Allocated ib_dev for %s\n", name);
 
 	return &ib_dev->dev;
-
-free_dev:
-	kfree(ib_dev);
-	return NULL;
 }
 
 static bool iblock_configure_unmap(struct se_device *dev)
@@ -189,7 +181,6 @@ static void iblock_dev_call_rcu(struct rcu_head *p)
 	struct se_device *dev = container_of(p, struct se_device, rcu_head);
 	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
 
-	kfree(ib_dev->ibd_plug);
 	kfree(ib_dev);
 }
 
diff --git a/drivers/target/target_core_iblock.h b/drivers/target/target_core_iblock.h
index e2f28a69a11c..849c948368bc 100644
--- a/drivers/target/target_core_iblock.h
+++ b/drivers/target/target_core_iblock.h
@@ -35,7 +35,7 @@ struct iblock_dev {
 	struct file *ibd_bdev_file;
 	bool ibd_readonly;
 	bool ibd_exclusive;
-	struct iblock_dev_plug *ibd_plug;
+	struct iblock_dev_plug ibd_plug[];
 } ____cacheline_aligned;
 
 #endif /* TARGET_CORE_IBLOCK_H */
-- 
2.54.0