Skip to content

Commit 6dbd428

Browse files
Ryuwang3gregkh
authored andcommitted
nfp: Check resource mutex allocation
[ Upstream commit a61b4db ] nfp_cpp_resource_find() allocates a CPP mutex handle for the matching resource-table entry and then reports success. nfp_resource_try_acquire() immediately passes that handle to nfp_cpp_mutex_trylock(). However, nfp_cpp_mutex_alloc() returns NULL on failure. If that happens for a matching table entry, the resource lookup still returns success and the following trylock dereferences a NULL mutex pointer while opening the resource. nfp_resource_acquire() already treats failure to allocate the table mutex as -ENOMEM. Do the same for the resource mutex and fail the lookup before publishing the rest of the resource handle. This issue was found by a static analysis checker and confirmed by manual source review. Fixes: f01a216 ("nfp: add support for resources") Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20260708143408.3168425-1-ruoyuw560@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3295894 commit 6dbd428

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_resource.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res)
9696
res->mutex =
9797
nfp_cpp_mutex_alloc(cpp,
9898
NFP_RESOURCE_TBL_TARGET, addr, key);
99+
if (!res->mutex)
100+
return -ENOMEM;
101+
99102
res->cpp_id = NFP_CPP_ID(entry.region.cpp_target,
100103
entry.region.cpp_action,
101104
entry.region.cpp_token);

0 commit comments

Comments
 (0)