crypto: nx - Fix uninitialised hv_nxc on error

[ Upstream commit 9b00eb923f3e60ca76cbc8b31123716f3a87ac6a ]

The compiler correctly warns that hv_nxc may be used uninitialised
as that will occur when NX-GZIP is unavailable.

Fix it by rearranging the code and delay setting caps_feat until
the final query succeeds.

Fixes: b4ba22114c ("crypto/nx: Get NX capabilities for GZIP coprocessor type")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Herbert Xu 2025-03-15 16:50:42 +08:00 committed by Greg Kroah-Hartman
parent 37a73de168
commit 837adafac3

View File

@ -1142,6 +1142,7 @@ static void __init nxcop_get_capabilities(void)
{ {
struct hv_vas_all_caps *hv_caps; struct hv_vas_all_caps *hv_caps;
struct hv_nx_cop_caps *hv_nxc; struct hv_nx_cop_caps *hv_nxc;
u64 feat;
int rc; int rc;
hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL); hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
@ -1152,27 +1153,26 @@ static void __init nxcop_get_capabilities(void)
*/ */
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0, rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0,
(u64)virt_to_phys(hv_caps)); (u64)virt_to_phys(hv_caps));
if (!rc)
feat = be64_to_cpu(hv_caps->feat_type);
kfree(hv_caps);
if (rc) if (rc)
goto out; return;
if (!(feat & VAS_NX_GZIP_FEAT_BIT))
return;
caps_feat = be64_to_cpu(hv_caps->feat_type);
/* /*
* NX-GZIP feature available * NX-GZIP feature available
*/ */
if (caps_feat & VAS_NX_GZIP_FEAT_BIT) { hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL); if (!hv_nxc)
if (!hv_nxc) return;
goto out; /*
/* * Get capabilities for NX-GZIP feature
* Get capabilities for NX-GZIP feature */
*/ rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, VAS_NX_GZIP_FEAT,
VAS_NX_GZIP_FEAT, (u64)virt_to_phys(hv_nxc));
(u64)virt_to_phys(hv_nxc));
} else {
pr_err("NX-GZIP feature is not available\n");
rc = -EINVAL;
}
if (!rc) { if (!rc) {
nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor); nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor);
@ -1182,13 +1182,10 @@ static void __init nxcop_get_capabilities(void)
be64_to_cpu(hv_nxc->min_compress_len); be64_to_cpu(hv_nxc->min_compress_len);
nx_cop_caps.min_decompress_len = nx_cop_caps.min_decompress_len =
be64_to_cpu(hv_nxc->min_decompress_len); be64_to_cpu(hv_nxc->min_decompress_len);
} else { caps_feat = feat;
caps_feat = 0;
} }
kfree(hv_nxc); kfree(hv_nxc);
out:
kfree(hv_caps);
} }
static const struct vio_device_id nx842_vio_driver_ids[] = { static const struct vio_device_id nx842_vio_driver_ids[] = {