From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH] nvme-auth: Fixup kernel test robot warnings
Date: Fri, 15 Jul 2022 13:40:44 +0200 [thread overview]
Message-ID: <20220715114044.104782-1-hare@suse.de> (raw)
The linux kernel test robot complained that some checks in
nvme_auth_hmac_{len,name,id} and nvme_auth_dhgroup_{name,kpp,id}
always evaluate to 'true'. So simplify the conditions to get
rid of those warnings.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/common/auth.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
index 0c86ebce59d2..94cc7cafbb9d 100644
--- a/drivers/nvme/common/auth.c
+++ b/drivers/nvme/common/auth.c
@@ -55,9 +55,7 @@ static struct nvme_auth_dhgroup_map {
const char *nvme_auth_dhgroup_name(u8 dhgroup_id)
{
- if ((dhgroup_id > ARRAY_SIZE(dhgroup_map)) ||
- !dhgroup_map[dhgroup_id].name ||
- !strlen(dhgroup_map[dhgroup_id].name))
+ if (dhgroup_id > ARRAY_SIZE(dhgroup_map))
return NULL;
return dhgroup_map[dhgroup_id].name;
}
@@ -65,9 +63,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_dhgroup_name);
const char *nvme_auth_dhgroup_kpp(u8 dhgroup_id)
{
- if ((dhgroup_id > ARRAY_SIZE(dhgroup_map)) ||
- !dhgroup_map[dhgroup_id].kpp ||
- !strlen(dhgroup_map[dhgroup_id].kpp))
+ if (dhgroup_id > ARRAY_SIZE(dhgroup_map))
return NULL;
return dhgroup_map[dhgroup_id].kpp;
}
@@ -77,9 +73,10 @@ u8 nvme_auth_dhgroup_id(const char *dhgroup_name)
{
int i;
+ if (!dhgroup_name || !strlen(dhgroup_name))
+ return NVME_AUTH_DHGROUP_INVALID;
for (i = 0; i < ARRAY_SIZE(dhgroup_map); i++) {
- if (!dhgroup_map[i].name ||
- !strlen(dhgroup_map[i].name))
+ if (!strlen(dhgroup_map[i].name))
continue;
if (!strncmp(dhgroup_map[i].name, dhgroup_name,
strlen(dhgroup_map[i].name)))
@@ -113,9 +110,7 @@ static struct nvme_dhchap_hash_map {
const char *nvme_auth_hmac_name(u8 hmac_id)
{
- if ((hmac_id > ARRAY_SIZE(hash_map)) ||
- !hash_map[hmac_id].hmac ||
- !strlen(hash_map[hmac_id].hmac))
+ if (hmac_id > ARRAY_SIZE(hash_map))
return NULL;
return hash_map[hmac_id].hmac;
}
@@ -123,9 +118,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_hmac_name);
const char *nvme_auth_digest_name(u8 hmac_id)
{
- if ((hmac_id > ARRAY_SIZE(hash_map)) ||
- !hash_map[hmac_id].digest ||
- !strlen(hash_map[hmac_id].digest))
+ if (hmac_id > ARRAY_SIZE(hash_map))
return NULL;
return hash_map[hmac_id].digest;
}
@@ -135,8 +128,11 @@ u8 nvme_auth_hmac_id(const char *hmac_name)
{
int i;
+ if (!hmac_name || !strlen(hmac_name))
+ return NVME_AUTH_HASH_INVALID;
+
for (i = 0; i < ARRAY_SIZE(hash_map); i++) {
- if (!hash_map[i].hmac || !strlen(hash_map[i].hmac))
+ if (!strlen(hash_map[i].hmac))
continue;
if (!strncmp(hash_map[i].hmac, hmac_name,
strlen(hash_map[i].hmac)))
@@ -148,9 +144,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_hmac_id);
size_t nvme_auth_hmac_hash_len(u8 hmac_id)
{
- if ((hmac_id > ARRAY_SIZE(hash_map)) ||
- !hash_map[hmac_id].hmac ||
- !strlen(hash_map[hmac_id].hmac))
+ if (hmac_id > ARRAY_SIZE(hash_map))
return 0;
return hash_map[hmac_id].len;
}
--
2.29.2
next reply other threads:[~2022-07-15 11:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 11:40 Hannes Reinecke [this message]
2022-07-18 4:59 ` [PATCH] nvme-auth: Fixup kernel test robot warnings 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=20220715114044.104782-1-hare@suse.de \
--to=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