Skip to content

Commit 68e777e

Browse files
committed
Merge tag 'block-6.0-2022-09-16' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Two fixes for -rc6: - Fix a mixup of sectors and bytes in the secure erase ioctl (Mikulas) - Fix for a bad return value for a non-blocking bio/blk queue enter call (me)" * tag 'block-6.0-2022-09-16' of git://git.kernel.dk/linux-block: blk-lib: fix blkdev_issue_secure_erase block: blk_queue_enter() / __bio_queue_enter() must return -EAGAIN for nowait
2 parents 0158137 + c4fa368 commit 68e777e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

block/blk-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)
295295

296296
while (!blk_try_enter_queue(q, pm)) {
297297
if (flags & BLK_MQ_REQ_NOWAIT)
298-
return -EBUSY;
298+
return -EAGAIN;
299299

300300
/*
301301
* read pair of barrier in blk_freeze_queue_start(), we need to
@@ -325,7 +325,7 @@ int __bio_queue_enter(struct request_queue *q, struct bio *bio)
325325
if (test_bit(GD_DEAD, &disk->state))
326326
goto dead;
327327
bio_wouldblock_error(bio);
328-
return -EBUSY;
328+
return -EAGAIN;
329329
}
330330

331331
/*

block/blk-lib.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
309309
struct blk_plug plug;
310310
int ret = 0;
311311

312+
/* make sure that "len << SECTOR_SHIFT" doesn't overflow */
313+
if (max_sectors > UINT_MAX >> SECTOR_SHIFT)
314+
max_sectors = UINT_MAX >> SECTOR_SHIFT;
315+
max_sectors &= ~bs_mask;
316+
312317
if (max_sectors == 0)
313318
return -EOPNOTSUPP;
314319
if ((sector | nr_sects) & bs_mask)
@@ -322,10 +327,10 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
322327

323328
bio = blk_next_bio(bio, bdev, 0, REQ_OP_SECURE_ERASE, gfp);
324329
bio->bi_iter.bi_sector = sector;
325-
bio->bi_iter.bi_size = len;
330+
bio->bi_iter.bi_size = len << SECTOR_SHIFT;
326331

327-
sector += len << SECTOR_SHIFT;
328-
nr_sects -= len << SECTOR_SHIFT;
332+
sector += len;
333+
nr_sects -= len;
329334
if (!nr_sects) {
330335
ret = submit_bio_wait(bio);
331336
bio_put(bio);

0 commit comments

Comments
 (0)