Skip to contentSkip to conversation

nvme: target: allocate ana_state with port

PATCH Applied Rosen Penev 3 participants 3 messages Jun 8 – Jun 10

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

PATCH 1/1 nvme: target: allocate ana_state with port

Use a flexible array member to remove one allocation. Simplifies code slightly.

---
 drivers/nvme/target/configfs.c | 9 +--------
 drivers/nvme/target/nvmet.h    | 2 +-
 2 files changed, 2 insertions(+), 9 deletions(-)
drivers/nvme/target/configfs.c +1 -8
index b88f897f06e2..2b69ffcfc8df 100644
@@ -2007,7 +2007,6 @@ static void nvmet_port_release(struct config_item *item)
 	list_del(&port->global_entry);
 
 	key_put(port->keyring);
-	kfree(port->ana_state);
 	kfree(port);
 }
 
@@ -2047,16 +2046,10 @@ static struct config_group *nvmet_ports_make(struct config_group *group,
 	if (kstrtou16(name, 0, &portid))
 		return ERR_PTR(-EINVAL);
 
-	port = kzalloc_obj(*port);
+	port = kzalloc_flex(*port, ana_state, NVMET_MAX_ANAGRPS + 1);
 	if (!port)
 		return ERR_PTR(-ENOMEM);
 
-	port->ana_state = kzalloc_objs(*port->ana_state, NVMET_MAX_ANAGRPS + 1);
-	if (!port->ana_state) {
-		kfree(port);
-		return ERR_PTR(-ENOMEM);
-	}
-
 	if (IS_ENABLED(CONFIG_NVME_TARGET_TCP_TLS) && nvme_keyring_id()) {
 		port->keyring = key_lookup(nvme_keyring_id());
 		if (IS_ERR(port->keyring)) {
drivers/nvme/target/nvmet.h +1 -1
index 3305a88684ec..aaba745e3c21 100644
@@ -208,7 +208,6 @@ struct nvmet_port {
 	struct list_head		global_entry;
 	struct config_group		ana_groups_group;
 	struct nvmet_ana_group		ana_default_group;
-	enum nvme_ana_state		*ana_state;
 	struct key			*keyring;
 	void				*priv;
 	bool				enabled;
@@ -217,6 +216,7 @@ struct nvmet_port {
 	int				mdts;
 	const struct nvmet_fabrics_ops	*tr_ops;
 	bool				pi_enable;
+	enum nvme_ana_state		ana_state[];
 };
 
 static inline struct nvmet_port *to_nvmet_port(struct config_item *item)
Signature · 1 line
2.54.0
maintainer Applied
#1 lore raw
Quoted 2 lines · Rosen Penev

Use a flexible array member to remove one allocation. Simplifies code slightly.

Thanks, applied to nvme-7.2.

#2 lore raw
Quoted 5 lines · Keith Busch
Quoted 2 lines · Rosen Penev

Use a flexible array member to remove one allocation. Simplifies code slightly.

Thanks, applied to nvme-7.2.

Btw, given that the array is of fixed size we don't even really the VLA here.