* [PATCH v2] mm/damon/paddr: initialize 'folio' variables to NULL for safety and clarity
@ 2026-01-04 1:32 Aaron Yang
2026-01-04 23:07 ` SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: Aaron Yang @ 2026-01-04 1:32 UTC (permalink / raw)
To: sj; +Cc: linux-mm, damon, Aaron Yang
In damon_pa_mark_accessed_or_deactivate(), damon_pa_pageout(),
damon_pa_migrate(), and damon_pa_stat(), the local variable 'folio' is
declared but not initialized.
Initialize 'folio' to NULL to:
- Follow kernel convention: uninitialized pointers should be
explicitly NULL
- Improve code readability and maintainability
- Provide safe fallback (NULL assignment to s->last_applied is harmless
and callers check for NULL before dereference)
Signed-off-by: Aaron Yang <yangqixiao@inspur.com>
---
mm/damon/paddr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 07a8aead439e..7d887a3c0866 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -156,7 +156,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
LIST_HEAD(folio_list);
bool install_young_filter = true;
struct damos_filter *filter;
- struct folio *folio;
+ struct folio *folio = NULL;
/* check access in page level again by default */
damos_for_each_ops_filter(filter, s) {
@@ -212,7 +212,7 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
unsigned long *sz_filter_passed)
{
phys_addr_t addr, applied = 0;
- struct folio *folio;
+ struct folio *folio = NULL;
addr = damon_pa_phys_addr(r->ar.start, addr_unit);
while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) {
@@ -262,7 +262,7 @@ static unsigned long damon_pa_migrate(struct damon_region *r,
{
phys_addr_t addr, applied;
LIST_HEAD(folio_list);
- struct folio *folio;
+ struct folio *folio = NULL;
addr = damon_pa_phys_addr(r->ar.start, addr_unit);
while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) {
@@ -295,7 +295,7 @@ static unsigned long damon_pa_stat(struct damon_region *r,
unsigned long *sz_filter_passed)
{
phys_addr_t addr;
- struct folio *folio;
+ struct folio *folio = NULL;
if (!damos_ops_has_filter(s))
return 0;
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mm/damon/paddr: initialize 'folio' variables to NULL for safety and clarity
2026-01-04 1:32 [PATCH v2] mm/damon/paddr: initialize 'folio' variables to NULL for safety and clarity Aaron Yang
@ 2026-01-04 23:07 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2026-01-04 23:07 UTC (permalink / raw)
To: Aaron Yang; +Cc: SeongJae Park, linux-mm, damon
On Sun, 4 Jan 2026 09:32:55 +0800 Aaron Yang <yangqixiao@inspur.com> wrote:
> In damon_pa_mark_accessed_or_deactivate(), damon_pa_pageout(),
> damon_pa_migrate(), and damon_pa_stat(), the local variable 'folio' is
> declared but not initialized.
>
> Initialize 'folio' to NULL to:
> - Follow kernel convention: uninitialized pointers should be
> explicitly NULL
Technically speaking, this is required only if it avoids unsafe code such as
use of the uninitialized pointers. Because zero-length DAMON region is not
allowed, this is not the main reason of this change that we discussed on v1 of
this patch [1].
> - Improve code readability and maintainability
This is the main goal of this change. This change allows readers be able to
know the function is safe, without have to know the fact that length DAMON
regions is disallowed.
> - Provide safe fallback (NULL assignment to s->last_applied is harmless
> and callers check for NULL before dereference)
>
> Signed-off-by: Aaron Yang <yangqixiao@inspur.com>
Because my above comments are for only clarifications of minor details:
Reviewed-by: SeongJae Park <sj@kernel.org>
> ---
FYI, this is a good place to summarize changes you made from the previous
version. For more details, please refer to the doc [2].
[1] https://lore.kernel.org/20251231055737.73325-1-yangqixiao@inspur.com
[2] https://origin.kernel.org/doc/html/latest/process/submitting-patches.html#commentary
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-04 23:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-04 1:32 [PATCH v2] mm/damon/paddr: initialize 'folio' variables to NULL for safety and clarity Aaron Yang
2026-01-04 23:07 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox