mm/shmem: fix uninitialized scalar variable
Subsystems (2)
PATCH 1/1 mm/shmem: fix uninitialized scalar variable
int entry_order has the possibility of being uninitialized when returning. Initializing it to zero at declaration appeases coverity and reduces risk of returning nonsense.
--- mm/shmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/shmem.c +2 -1
@@ -2153,7 +2153,8 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index, {struct address_space *mapping = inode->i_mapping;XA_STATE_ORDER (xas, &mapping->i_pages, index,0 ); -int split_order =0 , entry_order; +int split_order =0 ; +int entry_order =0 ;int i;/* Convert user data gfp flags to xarray node gfp flags */
---
base-commit: c0eb65494e59d9834af7cbad983629e9017b25a1
change-id: 20250301-entry_order_uninit-129251b1ac9f
Best regards,
Signature · 1 line
Ethan Carter Edwards <[email protected]>
Quoted 3 lines · Ethan Carter Edwards
int
entry_orderhas the possibility of being uninitialized when returning. Initializing it to zero at declaration appeases coverity and reduces risk of returning nonsense.
How come?
After entry_order is declared, for (;;) begins. The first branch is "if (!xa_is_value(old) || swp_to_radix_entry(swap) != old)", in the then case, xas_set_err(&xas, -EEXIST), which makes
"if (!xas_nomem(&xas, gfp))" at the end of the for loop to break. Then "if (xas_error(&xas))" will return -EEXIST. If the first then branch is not taken, entry_order is assigned to xas_get_order(&xas).
Which code path would make entry_order uninitialized?
Thanks.
Quoted 27 lines
Fixes 6dbc440b79b6 ("mm/shmem: use xas_try_split() in shmem_split_large_entry()")Signed-off-by Ethan Carter Edwards <[email protected]>--- mm/shmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/shmem.c +2
-2@@ -2153,7 +2153,8 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index, {struct address_space *mapping = inode->i_mapping;XA_STATE_ORDER (xas, &mapping->i_pages, index,0 ); -int split_order =0 , entry_order; +int split_order =0 ; +int entry_order =0 ;int i;/* Convert user data gfp flags to xarray node gfp flags */ ---base-commit:
c0eb65494e59d9834af7cbad983629e9017b25a1
change-id: 20250301-entry_order_uninit-129251b1ac9f
Quoted 3 lines
Best regards,
Signature · 1 line
Ethan Carter Edwards <[email protected]>
--
Best Regards,
Yan, Zi