[PATCH v2 3/3] block: use pi_tuple_size in bi_offload_capable()

Caleb Sander Mateos posted 3 patches 1 month ago
[PATCH v2 3/3] block: use pi_tuple_size in bi_offload_capable()
Posted by Caleb Sander Mateos 1 month ago
bi_offload_capable() returns whether a block device's metadata size
matches its PI tuple size. Use pi_tuple_size instead of switching on
csum_type. This makes the code considerably simpler and less branchy.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 block/bio-integrity-auto.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/block/bio-integrity-auto.c b/block/bio-integrity-auto.c
index 605403b52c90..626bbe17eb23 100644
--- a/block/bio-integrity-auto.c
+++ b/block/bio-integrity-auto.c
@@ -50,23 +50,11 @@ static bool bip_should_check(struct bio_integrity_payload *bip)
 	return bip->bip_flags & BIP_CHECK_FLAGS;
 }
 
 static bool bi_offload_capable(struct blk_integrity *bi)
 {
-	switch (bi->csum_type) {
-	case BLK_INTEGRITY_CSUM_CRC64:
-		return bi->metadata_size == sizeof(struct crc64_pi_tuple);
-	case BLK_INTEGRITY_CSUM_CRC:
-	case BLK_INTEGRITY_CSUM_IP:
-		return bi->metadata_size == sizeof(struct t10_pi_tuple);
-	default:
-		pr_warn_once("%s: unknown integrity checksum type:%d\n",
-			__func__, bi->csum_type);
-		fallthrough;
-	case BLK_INTEGRITY_CSUM_NONE:
-		return false;
-	}
+	return bi->metadata_size == bi->pi_tuple_size;
 }
 
 /**
  * __bio_integrity_endio - Integrity I/O completion function
  * @bio:	Protected bio
-- 
2.45.2
Re: [PATCH v2 3/3] block: use pi_tuple_size in bi_offload_capable()
Posted by Christoph Hellwig 1 month ago
On Thu, Jan 08, 2026 at 10:22:12AM -0700, Caleb Sander Mateos wrote:
> bi_offload_capable() returns whether a block device's metadata size
> matches its PI tuple size. Use pi_tuple_size instead of switching on
> csum_type. This makes the code considerably simpler and less branchy.
> 
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Re: [PATCH v2 3/3] block: use pi_tuple_size in bi_offload_capable()
Posted by Anuj gupta 1 month ago
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>