Skip to contentSkip to conversation

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

PATCH In review Jens Axboe 3 participants 3 messages Jan 9, 2023 – Jan 10, 2023 Block layer

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

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

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.

---

block/bio.c +2 -0
index 5f96fcae3f75..633d1a2af785 100644
@@ -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++) {
Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jens Axboe

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.

---

block/bio.c +0 -0
index 5f96fcae3f75..633d1a2af785 100644

block/bio.c static int __init init_bio(void) · line 1792

Quoted 8 lines
block/bio.c +2 -0
@@ -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.

Signature · 2 lines
Damien Le Moal
Western Digital Research