cxl/test: Add check after kzalloc() memory in alloc_mock_res()
Dave Jiang
maintainerPATCH 1/1 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 67dcdd4d3b83 ("tools/testing/cxl: Introduce a mocked-up CXL port hierarchy")
Signed-off-by Dave Jiang <[email protected]>
--- tools/testing/cxl/test/cxl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +6 -2
@@ -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. */
base-commit: 4549871118cf616eecdd2d939f78e3b9e1dddc48
Signature · 1 line
2.54.0
Quoted 3 lines · Dave Jiang
alloc_mock_res()callskzalloc()without checking the return value. Add scope based resource management to deal with the allocated memory cleanly.
Reviewed-by Alison Schofield <[email protected]>
Quoted 7 lines · Dave Jiang
alloc_mock_res()callskzalloc()without checking the return value. Add scope based resource management to deal with the allocated memory cleanly.Reported-by sashiko-botFixes 67dcdd4d3b83 ("tools/testing/cxl: Introduce a mocked-up CXL port hierarchy")Signed-off-by Dave Jiang <[email protected]>
Applied to cxl/nextdfe28c859253
Quoted 37 lines
--- tools/testing/cxl/test/cxl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)tools/testing/cxl/test/cxl.c +6
-2@@ -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. */ base-commit:
4549871118cf616eecdd2d939f78e3b9e1dddc48