From nobody Thu Apr 9 21:50:52 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B7538642F for ; Thu, 5 Mar 2026 11:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772710724; cv=none; b=q/VgbItc05KBuGP4DcHwlLD0tNS3kZlDwenUhiqrJdRrun21e0s5HG3MdDzvQkNEkRMLwhR4L0MR6X/sNVwMjYJKUQpT2wHBqVsVMax5nKa1tr+8TPEfnZW5i2CoubPowE9AwxxsUObI4dlENS16dsLc4wG7+b4tdadXukejdUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772710724; c=relaxed/simple; bh=hS7vODF3DQIyet/2bI1xlwCCDpGlQ8TGjX7fz4ZYwzU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fTrBK9RSiLV0TVKtxEvp139gCzIJFbrVPOdFQGKW5/2dHDL5VQwaXQ9SF1scc9GxD2OQ0IG0BKcl2oUvKsFFfbeXlJv+7hRLc+OS9eFGWVqMXINsmLk1P7u6f4UpcXxzp01rQwsqY3UMOeUwAi3ROL+2e+HnOUdxZnu28UZ7uNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kfSdmYww; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="kfSdmYww" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772710719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=c4ZrF0xXthlDdfFn6ZdluOcER4YdQnfKjs2jmlZgnQ8=; b=kfSdmYwwp0qMlFqwoRteizsCWun7t76utQlgsTdlSEixKa7RmIRbeKWsUBRbeMQndvAOmS NP9JnVwIYAqHTEPOohN4Q9chQjuUpi4PGX09imJtofM91/ngkVjHfIRND/Z5+rTEqz4pJH ePOMxFdih5wnpjdvjDCaAGWKcCH3t/0= From: Thorsten Blum To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke Cc: Thorsten Blum , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-auth: use kzalloc_flex() in nvme_auth_alloc_key() Date: Thu, 5 Mar 2026 12:37:31 +0100 Message-ID: <20260305113730.201680-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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 --- drivers/nvme/common/auth.c | 14 +++----------- include/linux/nvme-auth.h | 1 - 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c index e07e7d4bf8b6..20aac5e29ca4 100644 --- a/drivers/nvme/common/auth.c +++ b/drivers/nvme/common/auth.c @@ -153,14 +153,6 @@ size_t nvme_auth_hmac_hash_len(u8 hmac_id) } EXPORT_SYMBOL_GPL(nvme_auth_hmac_hash_len); =20 -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); =20 struct nvme_dhchap_key *nvme_auth_alloc_key(u32 len, u8 hash) { - u32 num_bytes =3D nvme_auth_key_struct_size(len); - struct nvme_dhchap_key *key =3D kzalloc(num_bytes, GFP_KERNEL); + struct nvme_dhchap_key *key; =20 + key =3D kzalloc_flex(*key, key, len); if (key) { key->len =3D len; key->hash =3D hash; @@ -251,7 +243,7 @@ struct nvme_dhchap_key *nvme_auth_transform_key( return ERR_PTR(-ENOKEY); } if (key->hash =3D=3D 0) { - key_len =3D nvme_auth_key_struct_size(key->len); + key_len =3D struct_size(key, key, key->len); transformed_key =3D kmemdup(key, key_len, GFP_KERNEL); if (!transformed_key) return ERR_PTR(-ENOMEM); diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h index 60e069a6757f..f508cce5ed83 100644 --- a/include/linux/nvme-auth.h +++ b/include/linux/nvme-auth.h @@ -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); =20 -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 --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4