Re: mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.

From: Zi Yan
Date: Wed Jun 18 2025 - 13:55:58 EST


On 18 Jun 2025, at 13:47, Matthew Wilcox wrote:

> On Wed, Jun 18, 2025 at 08:42:17PM +0300, Dan Carpenter wrote:
>> smatch warnings:
>> mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.
>
> ...
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2169 if (!xa_is_value(old) || swp_to_radix_entry(swap) != old) {
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2170 xas_set_err(&xas, -EEXIST);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2171 goto unlock;
>>
>> Imagine we hit this goto on the first iteration
>
> That can happen (but if it does, we set -EEXIST in the xa_state).
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2213 unlock:
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2214 xas_unlock_irq(&xas);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2215
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2216 if (!xas_nomem(&xas, gfp))
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2217 break;
>>
>> And we hit this break.
>
> That's guaranteed. If there's an errno in the xa_state that isn't
> -ENOMEM, xas_nomem() will fail.
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2218 }
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2219
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2220 if (xas_error(&xas))
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2221 return xas_error(&xas);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12 2222
>> d53c78fffe7ad3 Zi Yan 2025-03-14 @2223 return entry_order;
>
> but if this does happen, then xas_error() will be true and we'll return
> -EEXIST here instead of returning entry_order.
Hi Matthew,

Thank you for the explanation.

Hi Dan,

I got a similar report 3 months ago and explained it already.
See https://lore.kernel.org/linux-mm/B024C29C-96D4-4F92-B2EF-F01CB06B27DF@xxxxxxxxxx/

Best Regards,
Yan, Zi