2021-06-08 03:50:18

by Wu Bo

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Wu Bo <[email protected]>
---
drivers/nvme/host/multipath.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index f81871c..19fe16d 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -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);
--
2.30.2


2021-06-08 05:01:25

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: [PATCH] nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

On 6/7/21 20:59, Wu Bo wrote:
> Hi,
>
> Combine grpid and ANA state checks in nvme_parse_ana_log() to
> reduce repetitive code and more intuitive meaning.
>
> Signed-off-by: Wu Bo <[email protected]>

Existing code just looks fine...


2021-06-08 05:27:52

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

On Tue, Jun 08, 2021 at 12:13:36PM +0800, Wu Bo wrote:
> - 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.

2021-06-08 12:33:19

by Wu Bo

[permalink] [raw]
Subject: Re: [PATCH] nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

On 2021/6/8 13:23, Christoph Hellwig wrote:
> On Tue, Jun 08, 2021 at 12:13:36PM +0800, Wu Bo wrote:
>> - 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
>

2021-06-08 12:36:52

by Wu Bo

[permalink] [raw]
Subject: Re: [PATCH] nvme-multipath: combine grpid and ANA state checks in nvme_parse_ana_log()

On 2021/6/8 13:23, Christoph Hellwig wrote:
> On Tue, Jun 08, 2021 at 12:13:36PM +0800, Wu Bo wrote:
>> - 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