Skip to content

Commit

Permalink
scsi: block: Add a queue_max_bytes() helper
Browse files Browse the repository at this point in the history
Return the max_sectors value in bytes.  Lifted from scsi_ioctl.c.

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
Christoph Hellwig authored and martinkpetersen committed Jul 29, 2021
1 parent 2e27f57 commit 547e2f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
13 changes: 2 additions & 11 deletions block/scsi_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,9 @@ static int sg_set_timeout(struct request_queue *q, int __user *p)
return err;
}

static int max_sectors_bytes(struct request_queue *q)
{
unsigned int max_sectors = queue_max_sectors(q);

max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9);

return max_sectors << 9;
}

static int sg_get_reserved_size(struct request_queue *q, int __user *p)
{
int val = min_t(int, q->sg_reserved_size, max_sectors_bytes(q));
int val = min(q->sg_reserved_size, queue_max_bytes(q));

return put_user(val, p);
}
Expand All @@ -94,7 +85,7 @@ static int sg_set_reserved_size(struct request_queue *q, int __user *p)
if (size < 0)
return -EINVAL;

q->sg_reserved_size = min(size, max_sectors_bytes(q));
q->sg_reserved_size = min_t(unsigned int, size, queue_max_bytes(q));
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ static inline unsigned int queue_max_sectors(const struct request_queue *q)
return q->limits.max_sectors;
}

static inline unsigned int queue_max_bytes(struct request_queue *q)
{
return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9;
}

static inline unsigned int queue_max_hw_sectors(const struct request_queue *q)
{
return q->limits.max_hw_sectors;
Expand Down

0 comments on commit 547e2f7

Please sign in to comment.