linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <chaitanyak@nvidia.com>,
	"hare@suse.de" <hare@suse.de>
Cc: "kbusch@kernel.org" <kbusch@kernel.org>,
	"hch@lst.de" <hch@lst.de>,
	"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>
Subject: Re: [PATCH 1/3] nvme: add generic helper to store secret
Date: Wed, 17 May 2023 21:05:57 +0000	[thread overview]
Message-ID: <0c0dadfc-53aa-6131-2e0a-4985e19e464f@nvidia.com> (raw)
In-Reply-To: <05c40aed-755a-bbdf-4e22-c529ea4d6e17@grimberg.me>

On 5/17/23 00:31, Sagi Grimberg wrote:
>
>
> On 5/16/23 13:06, Chaitanya Kulkarni wrote:
>> Refactor code to avoid duplication and improve maintainability:
>>
>> Consolidate the shared code between the functions
>> nvme_ctrl_dhchap_secret_store() and
>> nvme_ctrl_dhchap_ctrl_secret_store(). This duplication not only
>> increases the likelihood of bugs but also requires additional effort for
>> maintenance and testing.
>>
>> Introduce a new generic helper function called
>> nvme_dhchap_secret_store_common() to handle the storage of the
>> dhchap secret. This helper function will be used by both
>> nvme_ctrl_dhchap_secret_store() and
>> nvme_ctrl_dhchap_ctrl_secret_store().
>>
>> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
>> ---
>>   drivers/nvme/host/sysfs.c | 59 ++++++++++++++++++++++++++-------------
>>   1 file changed, 39 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
>> index 796e1d373b7c..9ce3b16f06da 100644
>> --- a/drivers/nvme/host/sysfs.c
>> +++ b/drivers/nvme/host/sysfs.c
>> @@ -418,43 +418,53 @@ static ssize_t 
>> nvme_ctrl_dhchap_secret_show(struct device *dev,
>>       return sysfs_emit(buf, "%s\n", opts->dhchap_secret);
>>   }
>>   -static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
>> -        struct device_attribute *attr, const char *buf, size_t count)
>> +static ssize_t nvme_dhchap_secret_store_common(struct nvme_ctrl *ctrl,
>> +        const char *buf, size_t count, bool ctrl_secret)
>>   {
>> -    struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
>> -    struct nvmf_ctrl_options *opts = ctrl->opts;
>> -    char *dhchap_secret;
>> +    struct nvme_dhchap_key **orig_key;
>> +    char **dhchap_secret;
>> +    char *new_dhchap_secret;
>> +
>> +    if (ctrl_secret) {
>> +        if (!ctrl->opts->dhchap_ctrl_secret)
>> +            return -EINVAL;
>> +        dhchap_secret = &ctrl->opts->dhchap_ctrl_secret;
>> +        orig_key = &ctrl->ctrl_key;
>> +    } else {
>> +        if (!ctrl->opts->dhchap_secret)
>> +            return -EINVAL;
>> +        dhchap_secret = &ctrl->opts->dhchap_secret;
>> +        orig_key = &ctrl->host_key;
>> +    }
>>   -    if (!ctrl->opts->dhchap_secret)
>> -        return -EINVAL;
>>       if (count < 7)
>>           return -EINVAL;
>>       if (memcmp(buf, "DHHC-1:", 7))
>>           return -EINVAL;
>>   -    dhchap_secret = kzalloc(count + 1, GFP_KERNEL);
>> -    if (!dhchap_secret)
>> +    new_dhchap_secret = kzalloc(count + 1, GFP_KERNEL);
>> +    if (!new_dhchap_secret)
>>           return -ENOMEM;
>> -    memcpy(dhchap_secret, buf, count);
>> +    memcpy(new_dhchap_secret, buf, count);
>>       nvme_auth_stop(ctrl);
>> -    if (strcmp(dhchap_secret, opts->dhchap_secret)) {
>> -        struct nvme_dhchap_key *key, *host_key;
>> +    if (strcmp(new_dhchap_secret, *dhchap_secret)) {
>> +        struct nvme_dhchap_key *new_key, *prev_host_key;
>
> prev_host_key? or prev_key?


will fix it in the next version ..

-ck



  reply	other threads:[~2023-05-17 21:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 10:06 [PATCH 0/3] nvme-core: dhchap_secret code cleanup Chaitanya Kulkarni
2023-05-16 10:06 ` [PATCH 1/3] nvme: add generic helper to store secret Chaitanya Kulkarni
2023-05-17  7:31   ` Sagi Grimberg
2023-05-17 21:05     ` Chaitanya Kulkarni [this message]
2023-05-16 10:06 ` [PATCH 2/3] nvme: use generic helper to store ctrl secret Chaitanya Kulkarni
2023-05-17  7:32   ` Sagi Grimberg
2023-05-16 10:06 ` [PATCH 3/3] nvme-core: use macro defination to define dev attr Chaitanya Kulkarni
2023-05-17  7:35   ` Sagi Grimberg

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=0c0dadfc-53aa-6131-2e0a-4985e19e464f@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --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;
as well as URLs for NNTP newsgroup(s).