linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmscan: Initialize dirty to prevent uninitialized use
@ 2025-03-25 19:49 Purva Yeshi
  2025-03-25 20:35 ` Yu Zhao
  0 siblings, 1 reply; 3+ messages in thread
From: Purva Yeshi @ 2025-03-25 19:49 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Purva Yeshi

Fix Smatch-detected error:
mm/vmscan.c:3509 walk_pte_range() error: uninitialized symbol 'dirty'.
mm/vmscan.c:3522 walk_pte_range() error: uninitialized symbol 'dirty'.
mm/vmscan.c:3600 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
mm/vmscan.c:3614 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
mm/vmscan.c:4220 lru_gen_look_around() error: uninitialized symbol 'dirty'.
mm/vmscan.c:4232 lru_gen_look_around() error: uninitialized symbol 'dirty'.

Smatch reports 'dirty' as uninitialized, leading to potential
undefined behavior.

Explicitly initialize dirty to 0 in walk_pte_range(),
walk_pmd_range_locked(), and lru_gen_look_around() in mm/vmscan.c
to fix Smatch error.

Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
 mm/vmscan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index c767d71c43d7..39c49fcd960c 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3456,7 +3456,7 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
 			   struct mm_walk *args)
 {
 	int i;
-	bool dirty;
+	bool dirty = 0;
 	pte_t *pte;
 	spinlock_t *ptl;
 	unsigned long addr;
@@ -3535,7 +3535,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
 				  struct mm_walk *args, unsigned long *bitmap, unsigned long *first)
 {
 	int i;
-	bool dirty;
+	bool dirty = 0;
 	pmd_t *pmd;
 	spinlock_t *ptl;
 	struct folio *last = NULL;
@@ -4147,7 +4147,7 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
 bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw)
 {
 	int i;
-	bool dirty;
+	bool dirty = 0;
 	unsigned long start;
 	unsigned long end;
 	struct lru_gen_mm_walk *walk;
-- 
2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/vmscan: Initialize dirty to prevent uninitialized use
  2025-03-25 19:49 [PATCH] mm/vmscan: Initialize dirty to prevent uninitialized use Purva Yeshi
@ 2025-03-25 20:35 ` Yu Zhao
  2025-03-26  6:48   ` Purva Yeshi
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Zhao @ 2025-03-25 20:35 UTC (permalink / raw)
  To: Purva Yeshi; +Cc: Andrew Morton, linux-mm, linux-kernel

On Tue, Mar 25, 2025 at 1:49 PM Purva Yeshi <purvayeshi550@gmail.com> wrote:
>
> Fix Smatch-detected error:
> mm/vmscan.c:3509 walk_pte_range() error: uninitialized symbol 'dirty'.
> mm/vmscan.c:3522 walk_pte_range() error: uninitialized symbol 'dirty'.
> mm/vmscan.c:3600 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
> mm/vmscan.c:3614 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
> mm/vmscan.c:4220 lru_gen_look_around() error: uninitialized symbol 'dirty'.
> mm/vmscan.c:4232 lru_gen_look_around() error: uninitialized symbol 'dirty'.
>
> Smatch reports 'dirty' as uninitialized, leading to potential
> undefined behavior.

Thanks -- this seems like false positives from Smatch, where the
problem should be fixed.

> Explicitly initialize dirty to 0 in walk_pte_range(),
> walk_pmd_range_locked(), and lru_gen_look_around() in mm/vmscan.c
> to fix Smatch error.
>
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/vmscan: Initialize dirty to prevent uninitialized use
  2025-03-25 20:35 ` Yu Zhao
@ 2025-03-26  6:48   ` Purva Yeshi
  0 siblings, 0 replies; 3+ messages in thread
From: Purva Yeshi @ 2025-03-26  6:48 UTC (permalink / raw)
  To: Yu Zhao; +Cc: Andrew Morton, linux-mm, linux-kernel

On 26/03/25 02:05, Yu Zhao wrote:
> On Tue, Mar 25, 2025 at 1:49 PM Purva Yeshi <purvayeshi550@gmail.com> wrote:
>>
>> Fix Smatch-detected error:
>> mm/vmscan.c:3509 walk_pte_range() error: uninitialized symbol 'dirty'.
>> mm/vmscan.c:3522 walk_pte_range() error: uninitialized symbol 'dirty'.
>> mm/vmscan.c:3600 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
>> mm/vmscan.c:3614 walk_pmd_range_locked() error: uninitialized symbol 'dirty'.
>> mm/vmscan.c:4220 lru_gen_look_around() error: uninitialized symbol 'dirty'.
>> mm/vmscan.c:4232 lru_gen_look_around() error: uninitialized symbol 'dirty'.
>>
>> Smatch reports 'dirty' as uninitialized, leading to potential
>> undefined behavior.
> 
> Thanks -- this seems like false positives from Smatch, where the
> problem should be fixed.

Should we make modifications to address this Smatch error, or is it safe 
to ignore?

> 
>> Explicitly initialize dirty to 0 in walk_pte_range(),
>> walk_pmd_range_locked(), and lru_gen_look_around() in mm/vmscan.c
>> to fix Smatch error.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-26  6:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-25 19:49 [PATCH] mm/vmscan: Initialize dirty to prevent uninitialized use Purva Yeshi
2025-03-25 20:35 ` Yu Zhao
2025-03-26  6:48   ` Purva Yeshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox