mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	Dennis Maisenbacher <Dennis.Maisenbacher@wdc.com>,
	"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>
Cc: Niklas Cassel <niklas.cassel@wdc.com>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] nvmet: fix mar and mor off-by-one errors
Date: Wed, 7 Sep 2022 02:43:47 +0000	[thread overview]
Message-ID: <36b16998-3720-cc30-3ee8-b4d92c3b266d@nvidia.com> (raw)
In-Reply-To: <8154fb0a-4cda-a4bc-29ef-8435a3edb264@opensource.wdc.com>


>>>    	if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
>>>    		req->error_loc = offsetof(struct nvme_identify, nsid);
>>> @@ -130,8 +131,20 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req)
>>>    	zsze = (bdev_zone_sectors(req->ns->bdev) << 9) >>
>>>    					req->ns->blksize_shift;
>>>    	id_zns->lbafe[0].zsze = cpu_to_le64(zsze);
>>> -	id_zns->mor = cpu_to_le32(bdev_max_open_zones(req->ns->bdev));
>>> -	id_zns->mar = cpu_to_le32(bdev_max_active_zones(req->ns->bdev));
>>> +
>>> +	mor = bdev_max_open_zones(req->ns->bdev);
>>> +	if (!mor)
>>> +		mor = U32_MAX;
>>> +	else
>>> +		--mor;
>>> +	id_zns->mor = cpu_to_le32(mor);
>>> +
>>> +	mar = bdev_max_active_zones(req->ns->bdev);
>>> +	if (!mar)
>>> +		mar = U32_MAX;
>>> +	else
>>> +		--mar;
>>> +	id_zns->mar = cpu_to_le32(mar);
>>>    
>>
>> above 14 lines of code can be simplified as in 4-5 lines :-
> 
> Simplified ? It is much harder to read in my opinion...
> 
>>

there are two if ... else ... doing identical things on same data
type u32 and its return type is also same le32,
if my suggestion is hard to read then common code needs
to be moved to the helper as it is not clear the need for
code duplication from commit message.

-ck


  reply	other threads:[~2022-09-07  2:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06  7:39 Dennis Maisenbacher
2022-09-06 21:53 ` Chaitanya Kulkarni
2022-09-06 22:35   ` Damien Le Moal
2022-09-07  2:43     ` Chaitanya Kulkarni [this message]
2022-09-07  7:04       ` Dennis Maisenbacher
2022-09-07  6:39 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=36b16998-3720-cc30-3ee8-b4d92c3b266d@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=Dennis.Maisenbacher@wdc.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=damien.lemoal@wdc.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=niklas.cassel@wdc.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®