mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
cxl/test: Add check after kzalloc() memory in alloc_mock_res()
alloc_mock_res() calls kzalloc() without checking the return value.
Add scope based resource management to deal with the allocated memory
cleanly.
Reported-by: sashiko-bot
Fixes: 67dcdd4d3b ("tools/testing/cxl: Introduce a mocked-up CXL port hierarchy")
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Link: https://patch.msgid.link/20260611230305.197390-1-dave.jiang@intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
This commit is contained in:
parent
50cc34be04
commit
dfe28c8592
|
|
@ -433,12 +433,16 @@ static void depopulate_all_mock_resources(void)
|
|||
|
||||
static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align)
|
||||
{
|
||||
struct cxl_mock_res *res = kzalloc(sizeof(*res), GFP_KERNEL);
|
||||
struct genpool_data_align data = {
|
||||
.align = align,
|
||||
};
|
||||
unsigned long phys;
|
||||
|
||||
struct cxl_mock_res *res __free(kfree) = kzalloc(sizeof(*res),
|
||||
GFP_KERNEL);
|
||||
if (!res)
|
||||
return NULL;
|
||||
|
||||
INIT_LIST_HEAD(&res->list);
|
||||
phys = gen_pool_alloc_algo(cxl_mock_pool, size,
|
||||
gen_pool_first_fit_align, &data);
|
||||
|
|
@ -453,7 +457,7 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align)
|
|||
list_add(&res->list, &mock_res);
|
||||
mutex_unlock(&mock_res_lock);
|
||||
|
||||
return res;
|
||||
return no_free_ptr(res);
|
||||
}
|
||||
|
||||
/* Only update CFMWS0 as this is used by the auto region. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user