Skip to contentSkip to conversation

nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

PATCH In review Wu Bo 3 participants 5 messages Jun 8, 2021 NVMe

lore
Share & tools
lore

Wu Bo

author
#0 lore raw

PATCH 1/1 nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

Hi,

Combine grpid and ANA state checks in nvme_parse_ana_log() to reduce repetitive code and more intuitive meaning.

---
 drivers/nvme/host/multipath.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/nvme/host/multipath.c +4 -6
index f81871c..19fe16d 100644
@@ -522,13 +522,11 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
 		nr_nsids = le32_to_cpu(desc->nnsids);
 		nsid_buf_size = nr_nsids * sizeof(__le32);
 
-		if (WARN_ON_ONCE(desc->grpid == 0))
+		if (WARN_ON_ONCE(desc->grpid == 0 ||
+			le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
 			return -EINVAL;
-		if (WARN_ON_ONCE(le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state == 0))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state > NVME_ANA_CHANGE))
+		if (WARN_ON_ONCE(desc->state == 0 ||
+			desc->state > NVME_ANA_CHANGE))
 			return -EINVAL;
 
 		offset += sizeof(*desc);
Signature · 7 lines
2.30.2


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#1 lore raw
Quoted 6 lines · Wu Bo

Hi,

Combine grpid and ANA state checks in nvme_parse_ana_log() to reduce repetitive code and more intuitive meaning.

Existing code just looks fine...

#2 lore raw
In reply to Wu Bo

drivers/nvme/host/multipath.c static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data, · line 529

Quoted 11 lines · Wu Bo
drivers/nvme/host/multipath.c +4 -6
-		if (WARN_ON_ONCE(desc->grpid == 0))
+		if (WARN_ON_ONCE(desc->grpid == 0 ||
+			le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
 			return -EINVAL;
-		if (WARN_ON_ONCE(le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state == 0))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state > NVME_ANA_CHANGE))
+		if (WARN_ON_ONCE(desc->state == 0 ||
+			desc->state > NVME_ANA_CHANGE))

So besides making the code impossibl to read due to the incorrect indentation this also makes each WARN_ON_ONCE cover multiple conditions. Not very useful for debugging.

author
#3 lore raw
Quoted 17 lines · Christoph Hellwig

drivers/nvme/host/multipath.c static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data, · line 529

Quoted 11 lines · Wu Bo
drivers/nvme/host/multipath.c +4 -6
-		if (WARN_ON_ONCE(desc->grpid == 0))
+		if (WARN_ON_ONCE(desc->grpid == 0 ||
+			le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
  			return -EINVAL;
-		if (WARN_ON_ONCE(le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state == 0))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state > NVME_ANA_CHANGE))
+		if (WARN_ON_ONCE(desc->state == 0 ||
+			desc->state > NVME_ANA_CHANGE))

So besides making the code impossibl to read due to the incorrect indentation this also makes each WARN_ON_ONCE cover multiple conditions. Not very useful for debugging.
Indeed, not very useful for debugging, please ignore this patch.

Thanks,
Wu Bo

Quoted 1 line
author
#4 lore raw
In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

drivers/nvme/host/multipath.c static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data, · line 529

Quoted 11 lines · Wu Bo
drivers/nvme/host/multipath.c +4 -6
-		if (WARN_ON_ONCE(desc->grpid == 0))
+		if (WARN_ON_ONCE(desc->grpid == 0 ||
+			le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
  			return -EINVAL;
-		if (WARN_ON_ONCE(le32_to_cpu(desc->grpid) > ctrl->anagrpmax))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state == 0))
-			return -EINVAL;
-		if (WARN_ON_ONCE(desc->state > NVME_ANA_CHANGE))
+		if (WARN_ON_ONCE(desc->state == 0 ||
+			desc->state > NVME_ANA_CHANGE))

So besides making the code impossibl to read due to the incorrect indentation this also makes each WARN_ON_ONCE cover multiple conditions. Not very useful for debugging.
.

Indeed, not very useful for debugging, please ignore this patch.

Thanks,
Wu Bo