Skip to content

Commit 9b00eb9

Browse files
committed
crypto: nx - Fix uninitialised hv_nxc on error
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 <[email protected]>
1 parent 9cf7928 commit 9b00eb9

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

drivers/crypto/nx/nx-common-pseries.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ static void __init nxcop_get_capabilities(void)
11451145
{
11461146
struct hv_vas_all_caps *hv_caps;
11471147
struct hv_nx_cop_caps *hv_nxc;
1148+
u64 feat;
11481149
int rc;
11491150

11501151
hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
@@ -1155,27 +1156,26 @@ static void __init nxcop_get_capabilities(void)
11551156
*/
11561157
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0,
11571158
(u64)virt_to_phys(hv_caps));
1159+
if (!rc)
1160+
feat = be64_to_cpu(hv_caps->feat_type);
1161+
kfree(hv_caps);
11581162
if (rc)
1159-
goto out;
1163+
return;
1164+
if (!(feat & VAS_NX_GZIP_FEAT_BIT))
1165+
return;
11601166

1161-
caps_feat = be64_to_cpu(hv_caps->feat_type);
11621167
/*
11631168
* NX-GZIP feature available
11641169
*/
1165-
if (caps_feat & VAS_NX_GZIP_FEAT_BIT) {
1166-
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
1167-
if (!hv_nxc)
1168-
goto out;
1169-
/*
1170-
* Get capabilities for NX-GZIP feature
1171-
*/
1172-
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
1173-
VAS_NX_GZIP_FEAT,
1174-
(u64)virt_to_phys(hv_nxc));
1175-
} else {
1176-
pr_err("NX-GZIP feature is not available\n");
1177-
rc = -EINVAL;
1178-
}
1170+
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
1171+
if (!hv_nxc)
1172+
return;
1173+
/*
1174+
* Get capabilities for NX-GZIP feature
1175+
*/
1176+
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
1177+
VAS_NX_GZIP_FEAT,
1178+
(u64)virt_to_phys(hv_nxc));
11791179

11801180
if (!rc) {
11811181
nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor);
@@ -1185,13 +1185,10 @@ static void __init nxcop_get_capabilities(void)
11851185
be64_to_cpu(hv_nxc->min_compress_len);
11861186
nx_cop_caps.min_decompress_len =
11871187
be64_to_cpu(hv_nxc->min_decompress_len);
1188-
} else {
1189-
caps_feat = 0;
1188+
caps_feat = feat;
11901189
}
11911190

11921191
kfree(hv_nxc);
1193-
out:
1194-
kfree(hv_caps);
11951192
}
11961193

11971194
static const struct vio_device_id nx842_vio_driver_ids[] = {

0 commit comments

Comments
 (0)