All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] file-posix: Fix crash on discard_granularity == 0
@ 2025-04-29 15:56 Kevin Wolf
  2025-04-29 21:09 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kevin Wolf @ 2025-04-29 15:56 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, stefanha, qemu-devel

Block devices that don't support discard have a discard_granularity of
0. Currently, this results in a division by zero when we try to make
sure that it's a multiple of request_alignment. Only try to update
bs->bl.pdiscard_alignment when we got a non-zero discard_granularity
from sysfs.

Fixes: f605796aae4 ('file-posix: probe discard alignment on Linux block devices')
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/file-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index 0d6e12f880..0d85123d0f 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1573,7 +1573,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
         int ret;
 
         ret = hdev_get_pdiscard_alignment(&st, &dalign);
-        if (ret == 0) {
+        if (ret == 0 && dalign != 0) {
             uint32_t ralign = bs->bl.request_alignment;
 
             /* Probably never happens, but handle it just in case */
-- 
2.49.0



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

end of thread, other threads:[~2025-04-30 15:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 15:56 [PATCH] file-posix: Fix crash on discard_granularity == 0 Kevin Wolf
2025-04-29 21:09 ` Eric Blake
2025-04-30 15:54   ` Kevin Wolf
2025-04-30 15:37 ` Stefan Hajnoczi
2025-04-30 15:40 ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.