Skip to content

Commit c4db297

Browse files
herbertxgregkh
authored andcommitted
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: b4ba221 ("crypto/nx: Get NX capabilities for GZIP coprocessor type") Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a278a41 commit c4db297

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
@@ -1144,6 +1144,7 @@ static void __init nxcop_get_capabilities(void)
11441144
{
11451145
struct hv_vas_all_caps *hv_caps;
11461146
struct hv_nx_cop_caps *hv_nxc;
1147+
u64 feat;
11471148
int rc;
11481149

11491150
hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
@@ -1154,27 +1155,26 @@ static void __init nxcop_get_capabilities(void)
11541155
*/
11551156
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0,
11561157
(u64)virt_to_phys(hv_caps));
1158+
if (!rc)
1159+
feat = be64_to_cpu(hv_caps->feat_type);
1160+
kfree(hv_caps);
11571161
if (rc)
1158-
goto out;
1162+
return;
1163+
if (!(feat & VAS_NX_GZIP_FEAT_BIT))
1164+
return;
11591165

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

11791179
if (!rc) {
11801180
nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor);
@@ -1184,13 +1184,10 @@ static void __init nxcop_get_capabilities(void)
11841184
be64_to_cpu(hv_nxc->min_compress_len);
11851185
nx_cop_caps.min_decompress_len =
11861186
be64_to_cpu(hv_nxc->min_decompress_len);
1187-
} else {
1188-
caps_feat = 0;
1187+
caps_feat = feat;
11891188
}
11901189

11911190
kfree(hv_nxc);
1192-
out:
1193-
kfree(hv_caps);
11941191
}
11951192

11961193
static const struct vio_device_id nx842_vio_driver_ids[] = {

0 commit comments

Comments
 (0)