]> git.ipfire.org Git - thirdparty/linux.git/commit
IB/mlx4: Fix refcount leak in add_port() error path
authorGuangshuo Li <lgs201920130244@gmail.com>
Mon, 18 May 2026 02:19:10 +0000 (10:19 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 25 May 2026 14:25:17 +0000 (11:25 -0300)
commit9a8826fdfbcd7ed2ccf745f5d54208358d939def
tree2252b8c5f63c3195c7f642e32b7d36cbe8bbb30e
parent35744ab3d03c5fca8c1752f53fc8fc674e14c561
IB/mlx4: Fix refcount leak in add_port() error path

After kobject_init_and_add(), the lifetime of the embedded struct
kobject is expected to be managed through the kobject core reference
counting.

In add_port(), failure paths after kobject_init_and_add() must not free
struct mlx4_port directly, because the embedded kobject is then managed
by the kobject core. Freeing it directly leaves the kobject reference
counting unbalanced and can lead to incorrect lifetime handling.

Allocate the pkey and gid attribute arrays before kobject_init_and_add(),
so failures before kobject initialization can be handled by directly
freeing the allocated memory. Once kobject_init_and_add() has been
called, unwind later failures by removing any successfully created sysfs
groups, calling kobject_del(), and then releasing the embedded kobject
with kobject_put().

Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device")
Link: https://patch.msgid.link/r/20260518021910.972900-1-lgs201920130244@gmail.com
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/mlx4/sysfs.c