linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xa_load() needs a NULL check before locking check
@ 2023-02-15 13:14 void0red
  2023-02-15 13:31 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: void0red @ 2023-02-15 13:14 UTC (permalink / raw)
  To: willy; +Cc: linux-fsdevel, linux-kernel, void0red

Signed-off-by: void0red <void0red@gmail.com>
---
 include/linux/pagemap.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index bbccb4044222..f1ddee3571de 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -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);
 
-- 
2.34.1


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

* Re: [PATCH] xa_load() needs a NULL check before locking check
  2023-02-15 13:14 [PATCH] xa_load() needs a NULL check before locking check void0red
@ 2023-02-15 13:31 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2023-02-15 13:31 UTC (permalink / raw)
  To: void0red; +Cc: linux-fsdevel, linux-kernel

On Wed, Feb 15, 2023 at 09:14:17PM +0800, void0red wrote:
>  	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.

>  	ractl->_batch_count = folio_nr_pages(folio);
>  
> -- 
> 2.34.1
> 

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

end of thread, other threads:[~2023-02-15 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-15 13:14 [PATCH] xa_load() needs a NULL check before locking check void0red
2023-02-15 13:31 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).