Skip to content

Commit be0e8f3

Browse files
paravmellanoxdledford
authored andcommitted
IB/core: Reuse gid_table_release_one() in table allocation failure
_gid_table_setup_one() only performs GID table cache memory allocation, marks entries as invalid (free) and marks the reserved entries. At this point GID table is empty and no entries are added. On dual port device if _gid_table_setup_one() fails to allocate the gid table for 2nd port, there is no need to perform cleanup_gid_table_port() to delete GID entries, as GID table is empty. Therefore make use of existing gid_table_release_one() routine which frees the GID table memory and avoid code duplication. Reviewed-by: Daniel Jurgens <[email protected]> Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Dennis Dalessandro <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 25a1cd3 commit be0e8f3

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

drivers/infiniband/core/cache.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -778,50 +778,40 @@ static void gid_table_reserve_default(struct ib_device *ib_dev, u8 port,
778778
}
779779
}
780780

781+
782+
static void gid_table_release_one(struct ib_device *ib_dev)
783+
{
784+
struct ib_gid_table *table;
785+
u8 port;
786+
787+
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
788+
table = ib_dev->cache.ports[port].gid;
789+
release_gid_table(table);
790+
ib_dev->cache.ports[port].gid = NULL;
791+
}
792+
}
793+
781794
static int _gid_table_setup_one(struct ib_device *ib_dev)
782795
{
783796
u8 port;
784797
struct ib_gid_table *table;
785-
int err = 0;
786798

787799
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
788800
u8 rdma_port = port + rdma_start_port(ib_dev);
789801

790802
table = alloc_gid_table(
791803
ib_dev->port_immutable[rdma_port].gid_tbl_len);
792-
if (!table) {
793-
err = -ENOMEM;
804+
if (!table)
794805
goto rollback_table_setup;
795-
}
796806

797807
gid_table_reserve_default(ib_dev, rdma_port, table);
798808
ib_dev->cache.ports[port].gid = table;
799809
}
800-
801810
return 0;
802811

803812
rollback_table_setup:
804-
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
805-
table = ib_dev->cache.ports[port].gid;
806-
807-
cleanup_gid_table_port(ib_dev, port + rdma_start_port(ib_dev),
808-
table);
809-
release_gid_table(table);
810-
}
811-
812-
return err;
813-
}
814-
815-
static void gid_table_release_one(struct ib_device *ib_dev)
816-
{
817-
struct ib_gid_table *table;
818-
u8 port;
819-
820-
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
821-
table = ib_dev->cache.ports[port].gid;
822-
release_gid_table(table);
823-
ib_dev->cache.ports[port].gid = NULL;
824-
}
813+
gid_table_release_one(ib_dev);
814+
return -ENOMEM;
825815
}
826816

827817
static void gid_table_cleanup_one(struct ib_device *ib_dev)

0 commit comments

Comments
 (0)