Skip to contentSkip to conversation

xa_load() needs a NULL check before locking check

PATCH In review void0red 2 participants 2 messages Feb 15, 2023

Subsystems (2)
lore
Share & tools
lore

void0red

author
#0 lore raw

PATCH 1/1 xa_load() needs a NULL check before locking check

---
 include/linux/pagemap.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/pagemap.h +4 -0
index bbccb4044222..f1ddee3571de 100644
@@ -1250,6 +1250,10 @@ static inline struct folio *__readahead_folio(struct readahead_control *ractl)
 	}
 
 	folio = xa_load(&ractl->mapping->i_pages, ractl->_index);
+	if (!folio) {
+		VM_BUG_ON(!folio);
+		return NULL;
+	}
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 	ractl->_batch_count = folio_nr_pages(folio);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

include/linux/pagemap.h static inline struct folio *__readahead_folio(struct readahead_control *ractl) · line 1257

Quoted 6 lines · On Wed, Feb 15, 2023 at 09:14:17PM +0800, void0red wrote:
include/linux/pagemap.h +4 -0
 	folio = xa_load(&ractl->mapping->i_pages, ractl->_index);
+	if (!folio) {
+		VM_BUG_ON(!folio);
+		return NULL;
+	}
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);

Why does this need to happen? The caller has inserted all these folios into the xarray. They're locked, so they can't be removed. If they're not there, something has gone horribly wrong and crashing is a good response.

Quoted 5 lines

ractl->_batch_count = folio_nr_pages(folio);

Signature · 1 line
2.34.1