From: Zhihao Cheng
ohos inclusion
category: bugfix
issue: #I3ZXZF
CVE: NA
-------------------------------------------------
Since commit b35fd7422c2f8("block: check queue's limits.discard_granularity
in __blkdev_issue_discard()") checks rq.limits.discard_granularity in
__blkdev_issue_discard(), we may get following warnings on formatted ftl:
WARNING: CPU: 2 PID: 7313 at block/blk-lib.c:51
__blkdev_issue_discard+0x2a7/0x390
Reproducer:
1. ftl_format /dev/mtd0
2. modprobe ftl
3. mkfs.vfat /dev/ftla
4. mount -odiscard /dev/ftla temp
5. dd if=/dev/zero of=temp/tst bs=1M count=10 oflag=direct
6. dd if=/dev/zero of=temp/tst bs=1M count=10 oflag=direct
Fix it by initializing rq.limits.discard_granularity if device supports
discard operation.
Signed-off-by: Zhihao Cheng
Reviewed-by: Tao Hou
Signed-off-by: Chen Jun
Link: https://lore.kernel.org/lkml/258a2366-0042-dc2b-0589-fe3a99851ded@huawei.com
Signed-off-by: Yu Changchun
---
drivers/mtd/mtd_blkdevs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 37f4e169d305..5b5504e123a6 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -447,6 +447,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
if (tr->discard) {
blk_queue_flag_set(QUEUE_FLAG_DISCARD, new->rq);
blk_queue_max_discard_sectors(new->rq, UINT_MAX);
+ new->rq->limits.discard_granularity = tr->blksize;
}
gd->queue = new->rq;
--
2.22.0