diff mbox series

[01/12] block-backend: blk_check_byte_request(): int64_t bytes

Message ID 20211006131718.214235-2-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series block: 64bit blk io | expand

Commit Message

Vladimir Sementsov-Ogievskiy Oct. 6, 2021, 1:17 p.m. UTC
Rename size and make it int64_t to correspond to modern block layer,
which always uses int64_t for offset and bytes (not in blk layer yet,
which is a task for following commits).

All callers pass int or unsigned int.

So, for bytes in [0, INT_MAX] nothing is changed, for negative bytes we
now fail on "bytes < 0" check instead of "bytes > INT_MAX" check.

Note, that blk_check_byte_request() still doesn't allow requests
exceeding INT_MAX.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/block-backend.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Eric Blake Oct. 6, 2021, 3:09 p.m. UTC | #1
On Wed, Oct 06, 2021 at 03:17:07PM +0200, Vladimir Sementsov-Ogievskiy wrote:
> Rename size and make it int64_t to correspond to modern block layer,
> which always uses int64_t for offset and bytes (not in blk layer yet,
> which is a task for following commits).
> 
> All callers pass int or unsigned int.
> 
> So, for bytes in [0, INT_MAX] nothing is changed, for negative bytes we
> now fail on "bytes < 0" check instead of "bytes > INT_MAX" check.
> 
> Note, that blk_check_byte_request() still doesn't allow requests
> exceeding INT_MAX.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/block-backend.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox series

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 6140d133e2..d121ca3868 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1161,11 +1161,11 @@  void blk_set_disable_request_queuing(BlockBackend *blk, bool disable)
 }
 
 static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
-                                  size_t size)
+                                  int64_t bytes)
 {
     int64_t len;
 
-    if (size > INT_MAX) {
+    if (bytes < 0 || bytes > INT_MAX) {
         return -EIO;
     }
 
@@ -1183,7 +1183,7 @@  static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
             return len;
         }
 
-        if (offset > len || len - offset < size) {
+        if (offset > len || len - offset < bytes) {
             return -EIO;
         }
     }