nvme: target: allocate ana_state with port

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

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
Rosen Penev 2026-06-07 22:12:23 -07:00 committed by Keith Busch
parent 26acdaa357
commit 4fd1f5f6a6
2 changed files with 2 additions and 9 deletions

View File

@ -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)) {

View File

@ -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)