Skip to content

Commit

Permalink
crypto: nx - Fix uninitialised hv_nxc on error
Browse files Browse the repository at this point in the history
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: b4ba221 ("crypto/nx: Get NX capabilities for GZIP coprocessor type")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Herbert Xu committed Mar 21, 2025
1 parent 9cf7928 commit 9b00eb9
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions drivers/crypto/nx/nx-common-pseries.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ static void __init nxcop_get_capabilities(void)
{
struct hv_vas_all_caps *hv_caps;
struct hv_nx_cop_caps *hv_nxc;
u64 feat;
int rc;

hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
Expand All @@ -1155,27 +1156,26 @@ static void __init nxcop_get_capabilities(void)
*/
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0,
(u64)virt_to_phys(hv_caps));
if (!rc)
feat = be64_to_cpu(hv_caps->feat_type);
kfree(hv_caps);
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
*/
if (caps_feat & VAS_NX_GZIP_FEAT_BIT) {
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
if (!hv_nxc)
goto out;
/*
* Get capabilities for NX-GZIP feature
*/
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
VAS_NX_GZIP_FEAT,
(u64)virt_to_phys(hv_nxc));
} else {
pr_err("NX-GZIP feature is not available\n");
rc = -EINVAL;
}
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
if (!hv_nxc)
return;
/*
* Get capabilities for NX-GZIP feature
*/
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
VAS_NX_GZIP_FEAT,
(u64)virt_to_phys(hv_nxc));

if (!rc) {
nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor);
Expand All @@ -1185,13 +1185,10 @@ static void __init nxcop_get_capabilities(void)
be64_to_cpu(hv_nxc->min_compress_len);
nx_cop_caps.min_decompress_len =
be64_to_cpu(hv_nxc->min_decompress_len);
} else {
caps_feat = 0;
caps_feat = feat;
}

kfree(hv_nxc);
out:
kfree(hv_caps);
}

static const struct vio_device_id nx842_vio_driver_ids[] = {
Expand Down

0 comments on commit 9b00eb9

Please sign in to comment.