From 5f4eee5fc938a655710c18a9997dc5d780e46673 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Mon, 8 Jul 2024 11:31:11 +0300 Subject: [PATCH] scst_lib: use bdev_nr_bytes(bdev) instead of i_size_read(bdev->bd_inode) Use the helper to query the size of a block device in bytes. --- scst/include/backport.h | 12 ++++++++++++ scst/src/scst_lib.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index c54027707..7967508ef 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -329,6 +329,18 @@ static inline void bdev_release_backport(struct bdev_handle *handle) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) +/* + * See also commit 6436bd90f76e ("block: add a bdev_nr_bytes helper") # v5.16. + */ +static inline loff_t bdev_nr_bytes_backport(struct block_device *bdev) +{ + return i_size_read(bdev->bd_inode); +} + +#define bdev_nr_bytes bdev_nr_bytes_backport +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) && \ (!defined(RHEL_RELEASE_CODE) || \ RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 88239217e..ba776beac 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -6178,7 +6178,7 @@ loff_t scst_bdev_size(const char *path) if (rc) return rc; - res = i_size_read(bdev_desc.bdev->bd_inode); + res = bdev_nr_bytes(bdev_desc.bdev); scst_release_bdev(&bdev_desc); return res;