Re: [PATCH v2 net] ice: Fix freeing uninitialized pointers

From: Simon Horman
Date: Fri Mar 22 2024 - 08:57:40 EST


On Thu, Mar 21, 2024 at 05:42:12PM +0300, Dan Carpenter wrote:
> Automatically cleaned up pointers need to be initialized before exiting
> their scope. In this case, they need to be initialized to NULL before
> any return statement.
>
> Fixes: 90f821d72e11 ("ice: avoid unnecessary devm_ usage")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> ---
> v2: I missed a couple pointers in v1.
>
> The change to ice_update_link_info() isn't required because it's
> assigned on the very next line... But I did that because it's harmless
> and makes __free() stuff easier to verify. I felt like moving the
> declarations into the code would be controversial and it also ends up
> making the lines really long.
>
> goto goto err_unroll_sched;
>
> struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) =
> kzalloc(sizeof(*pcaps), GFP_KERNEL);

Thanks Dan,

I agree with the approach you have taken here.

And I apologise that it's quite likely that I skipped warnings regarding
these problems when reviewing patches that introduced them - I did not
understand the issue that this patch resolves.

Reviewed-by: Simon Horman <horms@xxxxxxxxxx>