nvme-auth: use kzalloc_flex() in nvme_auth_alloc_key()
Subsystems (2)
PATCH 1/1 nvme-auth: use kzalloc_flex() in nvme_auth_alloc_key()
Use kzalloc_flex() in nvme_auth_alloc_key() and remove the helper nvme_auth_key_struct_size(). In nvme_auth_transform_key(), use struct_size() directly.
Signed-off-by Thorsten Blum <[email protected]>
--- drivers/nvme/common/auth.c | 14 +++----------- include/linux/nvme-auth.h | 1 - 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/nvme/common/auth.c +3 -11
@@ -153,14 +153,6 @@ size_t nvme_auth_hmac_hash_len(u8 hmac_id) }EXPORT_SYMBOL_GPL (nvme_auth_hmac_hash_len); -u32 nvme_auth_key_struct_size (u32 key_len) -{ -struct nvme_dhchap_key key; - -return struct_size (&key, key, key_len); -} -EXPORT_SYMBOL_GPL (nvme_auth_key_struct_size); -struct nvme_dhchap_key *nvme_auth_extract_key (unsigned char *secret,u8 key_hash) {
@@ -218,9 +210,9 @@ EXPORT_SYMBOL_GPL(nvme_auth_extract_key);struct nvme_dhchap_key *nvme_auth_alloc_key (u32 len,u8 hash) { -u32 num_bytes =nvme_auth_key_struct_size (len); -struct nvme_dhchap_key *key =kzalloc (num_bytes,GFP_KERNEL ); +struct nvme_dhchap_key *key; + key =kzalloc_flex (*key, key, len);if (key) { key->len = len; key->hash = hash;
@@ -251,7 +243,7 @@ struct nvme_dhchap_key *nvme_auth_transform_key(return ERR_PTR (-ENOKEY ); }if (key->hash ==0 ) { - key_len =nvme_auth_key_struct_size (key->len); + key_len =struct_size (key, key, key->len); transformed_key =kmemdup (key, key_len,GFP_KERNEL );if (!transformed_key)return ERR_PTR (-ENOMEM );
include/linux/nvme-auth.h +0 -1
@@ -24,7 +24,6 @@ const char *nvme_auth_digest_name(u8 hmac_id);size_t nvme_auth_hmac_hash_len (u8 hmac_id);u8 nvme_auth_hmac_id (const char *hmac_name); -u32 nvme_auth_key_struct_size (u32 key_len);struct nvme_dhchap_key *nvme_auth_extract_key (unsigned char *secret,u8 key_hash);void nvme_auth_free_key (struct nvme_dhchap_key *key);
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4