RDMA/core: Simplify how the gid_attrs sysfs is created
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 11 Jun 2021 16:00:24 +0000 (19:00 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 16 Jun 2021 23:58:29 +0000 (20:58 -0300)
commita4676388e2e21215b32f33b42ac5725e315a6680
treefdf8ca07541dac4169d5befaeb0e54e2c1bb3469
parenta32f433522c97d2f07c060517f1f0f4058aa211b
RDMA/core: Simplify how the gid_attrs sysfs is created

Instead of having an whole bunch of different allocations to create the
gid_attr kobjects reduce it to three, one for the kobj struct plus the
attributes, and one for the attribute list for each of the two
groups.

Move the freeing of all allocations to the release function.

Reorder the operations so all the allocations happen first then the
kobject & sysfs operations are last.

This removes the majority of the complicated error unwind since the
release function will always undo all the memory allocations. Freeing the
memory is also much simpler since there is a lot less of it.

Consolidate creating the "group of array indexes" pattern into one helper
function. Ensure kobject_del is used.

Link: https://lore.kernel.org/r/f4149d379db7178d37d11d75e3026bf550f818a1.1623427137.git.leonro@nvidia.com
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/sysfs.c