diff mbox series

block: add a BUILD_BUG_ON() for adding more bio flags than we have space

Message ID da48fbb7-ec78-f382-919e-cdf23fa200db@kernel.dk (mailing list archive)
State New, archived
Headers show
Series block: add a BUILD_BUG_ON() for adding more bio flags than we have space | expand

Commit Message

Jens Axboe Jan. 9, 2023, 5:47 p.m. UTC
We have BIO_FLAG_LAST in the enum for bio specific flags, but it's
not used to check that we're not exceeding the size of them. Add
such a check.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

Comments

Damien Le Moal Jan. 9, 2023, 10:56 p.m. UTC | #1
On 1/10/23 02:47, Jens Axboe wrote:
> We have BIO_FLAG_LAST in the enum for bio specific flags, but it's
> not used to check that we're not exceeding the size of them. Add
> such a check.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> ---
> 
> diff --git a/block/bio.c b/block/bio.c
> index 5f96fcae3f75..633d1a2af785 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1785,6 +1785,8 @@ static int __init init_bio(void)
>  {
>  	int i;
>  
> +	BUILD_BUG_ON(BIO_FLAG_LAST > 8 * sizeof_field(struct bio, bi_flags));
> +
>  	bio_integrity_init();
>  
>  	for (i = 0; i < ARRAY_SIZE(bvec_slabs); i++) {
> 

Looks OK to me.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Johannes Thumshirn Jan. 10, 2023, 7:45 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index 5f96fcae3f75..633d1a2af785 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1785,6 +1785,8 @@  static int __init init_bio(void)
 {
 	int i;
 
+	BUILD_BUG_ON(BIO_FLAG_LAST > 8 * sizeof_field(struct bio, bi_flags));
+
 	bio_integrity_init();
 
 	for (i = 0; i < ARRAY_SIZE(bvec_slabs); i++) {