Message ID | 20210712054816.4147559-13-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/24] bsg: remove support for SCSI_IOCTL_SEND_COMMAND | expand |
On 7/11/21 10:48 PM, Christoph Hellwig wrote: > +static inline int queue_max_sectors_bytes(struct request_queue *q) > +{ > + return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9; > +} Should this function return a signed or an unsigned integer? I'm asking because I see 'unsigned int' as the first argument for min_t(). Thanks, Bart.
Christoph, > +static inline int queue_max_sectors_bytes(struct request_queue *q) > +{ > + return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9; > +} > + Maybe simply queue_max_bytes()?
On Thu, Jul 22, 2021 at 10:37:36AM -0700, Bart Van Assche wrote: > On 7/11/21 10:48 PM, Christoph Hellwig wrote: >> +static inline int queue_max_sectors_bytes(struct request_queue *q) >> +{ >> + return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9; >> +} > > Should this function return a signed or an unsigned integer? I'm asking > because I see 'unsigned int' as the first argument for min_t(). Yes, it really should be unsigned.
On Thu, Jul 22, 2021 at 02:00:57PM -0400, Martin K. Petersen wrote:
> Maybe simply queue_max_bytes()?
Fine with me.
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index ca7b84452d9d..b46a04a40db4 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -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_t(int, q->sg_reserved_size, queue_max_sectors_bytes(q)); return put_user(val, p); } @@ -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(size, queue_max_sectors_bytes(q)); return 0; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e2b972a85012..c983cd8ecf98 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1373,6 +1373,11 @@ static inline unsigned int queue_max_sectors(const struct request_queue *q) return q->limits.max_sectors; } +static inline int queue_max_sectors_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;
Return the max_sectors value in bytes. Lifted from scsi_ioctl.c. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/scsi_ioctl.c | 13 ++----------- include/linux/blkdev.h | 5 +++++ 2 files changed, 7 insertions(+), 11 deletions(-)