Re: [PATCH v2] IB/mlx4: Fix refcount leak in add_port() error path

From: Guangshuo Li

Date: Tue Apr 28 2026 - 11:40:08 EST


Hi Jason,

Thanks for reviewing.

On Tue, 28 Apr 2026 at 22:35, Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>
>
> Sashiko says this will crash because this was skipped:
>
> p->pkey_group.attrs =
> alloc_group_attrs(show_port_pkey,
> is_eth ? NULL : store_port_pkey,
> dev->dev->caps.pkey_table_len[port_num]);
>
> Along with other problems.
>
> Jason

You are right! I missed that mlx4_port_release()
currently assumes pkey_group.attrs and gid_group.attrs are already
allocated. On the kobject_init_and_add() failure path they are still
NULL, so kobject_put(&p->kobj) can crash in the release callback.

I will respin v3 by making mlx4_port_release() tolerate NULL attribute
arrays and by dropping the parent reference taken before
kobject_init_and_add() before putting the embedded kobject.