public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to check bio after __blkdev_issue_discard()
@ 2025-11-26  6:14 Chao Yu
  2025-11-26  6:41 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2025-11-26  6:14 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu, stable

Previously, __blkdev_issue_discard() will always returned valid bio,
after commit e8b4869bc78d ("block: add a blk_alloc_discard_bio helper"),
it can return bio w/ NULL value, which may trigger panic or warning
in __submit_discard_cmd(), let's fix to check bio instread of return
value after __blkdev_issue_discard().

Cc: stable@kernel.org
Fixes: e8b4869bc78d ("block: add a blk_alloc_discard_bio helper")
Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/segment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 8375dca7ed9e..44c0cefbb5a9 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1351,7 +1351,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 					SECTOR_FROM_BLOCK(len),
 					GFP_NOFS, &bio);
 		}
-		if (err) {
+		if (err || bio == NULL) {
 			spin_lock_irqsave(&dc->lock, flags);
 			if (dc->state == D_PARTIAL)
 				dc->state = D_SUBMIT;
-- 
2.49.0


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

* Re: [PATCH] f2fs: fix to check bio after __blkdev_issue_discard()
  2025-11-26  6:14 [PATCH] f2fs: fix to check bio after __blkdev_issue_discard() Chao Yu
@ 2025-11-26  6:41 ` Christoph Hellwig
  2025-11-28  3:34   ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2025-11-26  6:41 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel, stable

On Wed, Nov 26, 2025 at 02:14:37PM +0800, Chao Yu wrote:
> Previously, __blkdev_issue_discard() will always returned valid bio,
> after commit e8b4869bc78d ("block: add a blk_alloc_discard_bio helper"),
> it can return bio w/ NULL value, which may trigger panic or warning
> in __submit_discard_cmd(), let's fix to check bio instread of return
> value after __blkdev_issue_discard().

It can only return blk_alloc_discard_bio if the the gfp_mask doesn't
allow sleeping (which isn't the case here), or nr_sect is zero,
which I hope is also not the case as __submit_discard_cmd would
run into various other problems.  So no, I don't think this is
patch makes any sense.

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

* Re: [PATCH] f2fs: fix to check bio after __blkdev_issue_discard()
  2025-11-26  6:41 ` Christoph Hellwig
@ 2025-11-28  3:34   ` Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2025-11-28  3:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: chao, jaegeuk, linux-f2fs-devel, linux-kernel, stable

On 11/26/25 14:41, Christoph Hellwig wrote:
> It can only return blk_alloc_discard_bio if the the gfp_mask doesn't
> allow sleeping (which isn't the case here), or nr_sect is zero,
> which I hope is also not the case as __submit_discard_cmd would
> run into various other problems.  So no, I don't think this is
> patch makes any sense.

Oh, I checked details in bio_alloc_bioset() again, it seems I missed
something for mempool_alloc(), as you mentioned, it may only fail due
to caller is in non-sleep context passing gfp w/ GFP_ATOMIC or
GFP_NOWAIT, which is not the case for f2fs discard.

Thanks,

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

end of thread, other threads:[~2025-11-28  3:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  6:14 [PATCH] f2fs: fix to check bio after __blkdev_issue_discard() Chao Yu
2025-11-26  6:41 ` Christoph Hellwig
2025-11-28  3:34   ` Chao Yu

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