]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvme: target: allocate ana_state with port
authorRosen Penev <rosenp@gmail.com>
Mon, 8 Jun 2026 05:12:23 +0000 (22:12 -0700)
committerKeith Busch <kbusch@kernel.org>
Tue, 9 Jun 2026 18:18:03 +0000 (11:18 -0700)
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>
drivers/nvme/target/configfs.c
drivers/nvme/target/nvmet.h

index b88f897f06e25e3e604615c75dc55cc5b2a1f1a1..2b69ffcfc8dfb7ed53b5dccd3aed2d4e90cd0d99 100644 (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)) {
index 3305a88684ecab5d59c53d7f975d1b0a1cb213a2..aaba745e3c2145ca90f620e4955075389f5d70b9 100644 (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)