diff options
author | Tom Lendacky <thomas.lendacky@amd.com> | 2015-10-01 17:32:31 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-10-08 09:42:15 -0400 |
commit | 355eba5dda6984cbe10fa914e5cc8ef45a34cce2 (patch) | |
tree | cb5b8eb7a43f917ef7e982e0a24e7c1e79c8a8aa | |
parent | 9196d9676fe790975fdb1fc03230629139c6ea8e (diff) |
crypto: ccp - Replace BUG_ON with WARN_ON and a return code
Replace the usage of BUG_ON with WARN_ON and return an error.
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/ccp/ccp-crypto-aes-cmac.c | 20 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-crypto-main.c | 6 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-crypto-sha.c | 13 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-ops.c | 108 |
4 files changed, 105 insertions, 42 deletions
diff --git a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c index ea7e8446956a..d89f20c04266 100644 --- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c +++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c | |||
@@ -118,10 +118,19 @@ static int ccp_do_cmac_update(struct ahash_request *req, unsigned int nbytes, | |||
118 | if (rctx->buf_count) { | 118 | if (rctx->buf_count) { |
119 | sg_init_one(&rctx->buf_sg, rctx->buf, rctx->buf_count); | 119 | sg_init_one(&rctx->buf_sg, rctx->buf, rctx->buf_count); |
120 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->buf_sg); | 120 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->buf_sg); |
121 | if (!sg) { | ||
122 | ret = -EINVAL; | ||
123 | goto e_free; | ||
124 | } | ||
121 | } | 125 | } |
122 | 126 | ||
123 | if (nbytes) | 127 | if (nbytes) { |
124 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, req->src); | 128 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, req->src); |
129 | if (!sg) { | ||
130 | ret = -EINVAL; | ||
131 | goto e_free; | ||
132 | } | ||
133 | } | ||
125 | 134 | ||
126 | if (need_pad) { | 135 | if (need_pad) { |
127 | int pad_length = block_size - (len & (block_size - 1)); | 136 | int pad_length = block_size - (len & (block_size - 1)); |
@@ -132,6 +141,10 @@ static int ccp_do_cmac_update(struct ahash_request *req, unsigned int nbytes, | |||
132 | rctx->pad[0] = 0x80; | 141 | rctx->pad[0] = 0x80; |
133 | sg_init_one(&rctx->pad_sg, rctx->pad, pad_length); | 142 | sg_init_one(&rctx->pad_sg, rctx->pad, pad_length); |
134 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->pad_sg); | 143 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->pad_sg); |
144 | if (!sg) { | ||
145 | ret = -EINVAL; | ||
146 | goto e_free; | ||
147 | } | ||
135 | } | 148 | } |
136 | if (sg) { | 149 | if (sg) { |
137 | sg_mark_end(sg); | 150 | sg_mark_end(sg); |
@@ -163,6 +176,11 @@ static int ccp_do_cmac_update(struct ahash_request *req, unsigned int nbytes, | |||
163 | ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd); | 176 | ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd); |
164 | 177 | ||
165 | return ret; | 178 | return ret; |
179 | |||
180 | e_free: | ||
181 | sg_free_table(&rctx->data_sg); | ||
182 | |||
183 | return ret; | ||
166 | } | 184 | } |
167 | 185 | ||
168 | static int ccp_aes_cmac_init(struct ahash_request *req) | 186 | static int ccp_aes_cmac_init(struct ahash_request *req) |
diff --git a/drivers/crypto/ccp/ccp-crypto-main.c b/drivers/crypto/ccp/ccp-crypto-main.c index bdec01ec608f..e0380e59c361 100644 --- a/drivers/crypto/ccp/ccp-crypto-main.c +++ b/drivers/crypto/ccp/ccp-crypto-main.c | |||
@@ -305,14 +305,16 @@ struct scatterlist *ccp_crypto_sg_table_add(struct sg_table *table, | |||
305 | for (sg = table->sgl; sg; sg = sg_next(sg)) | 305 | for (sg = table->sgl; sg; sg = sg_next(sg)) |
306 | if (!sg_page(sg)) | 306 | if (!sg_page(sg)) |
307 | break; | 307 | break; |
308 | BUG_ON(!sg); | 308 | if (WARN_ON(!sg)) |
309 | return NULL; | ||
309 | 310 | ||
310 | for (; sg && sg_add; sg = sg_next(sg), sg_add = sg_next(sg_add)) { | 311 | for (; sg && sg_add; sg = sg_next(sg), sg_add = sg_next(sg_add)) { |
311 | sg_set_page(sg, sg_page(sg_add), sg_add->length, | 312 | sg_set_page(sg, sg_page(sg_add), sg_add->length, |
312 | sg_add->offset); | 313 | sg_add->offset); |
313 | sg_last = sg; | 314 | sg_last = sg; |
314 | } | 315 | } |
315 | BUG_ON(sg_add); | 316 | if (WARN_ON(sg_add)) |
317 | return NULL; | ||
316 | 318 | ||
317 | return sg_last; | 319 | return sg_last; |
318 | } | 320 | } |
diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c index 507b34e0cc19..d14b3f28e010 100644 --- a/drivers/crypto/ccp/ccp-crypto-sha.c +++ b/drivers/crypto/ccp/ccp-crypto-sha.c | |||
@@ -107,7 +107,15 @@ static int ccp_do_sha_update(struct ahash_request *req, unsigned int nbytes, | |||
107 | 107 | ||
108 | sg_init_one(&rctx->buf_sg, rctx->buf, rctx->buf_count); | 108 | sg_init_one(&rctx->buf_sg, rctx->buf, rctx->buf_count); |
109 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->buf_sg); | 109 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->buf_sg); |
110 | if (!sg) { | ||
111 | ret = -EINVAL; | ||
112 | goto e_free; | ||
113 | } | ||
110 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, req->src); | 114 | sg = ccp_crypto_sg_table_add(&rctx->data_sg, req->src); |
115 | if (!sg) { | ||
116 | ret = -EINVAL; | ||
117 | goto e_free; | ||
118 | } | ||
111 | sg_mark_end(sg); | 119 | sg_mark_end(sg); |
112 | 120 | ||
113 | sg = rctx->data_sg.sgl; | 121 | sg = rctx->data_sg.sgl; |
@@ -142,6 +150,11 @@ static int ccp_do_sha_update(struct ahash_request *req, unsigned int nbytes, | |||
142 | ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd); | 150 | ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd); |
143 | 151 | ||
144 | return ret; | 152 | return ret; |
153 | |||
154 | e_free: | ||
155 | sg_free_table(&rctx->data_sg); | ||
156 | |||
157 | return ret; | ||
145 | } | 158 | } |
146 | 159 | ||
147 | static int ccp_sha_init(struct ahash_request *req) | 160 | static int ccp_sha_init(struct ahash_request *req) |
diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index d09c6c4af4aa..c6e883b296a9 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c | |||
@@ -611,15 +611,16 @@ static void ccp_get_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset, | |||
611 | 1); | 611 | 1); |
612 | } | 612 | } |
613 | 613 | ||
614 | static void ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, | 614 | static int ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, |
615 | struct scatterlist *sg, | 615 | struct scatterlist *sg, |
616 | unsigned int len, unsigned int se_len, | 616 | unsigned int len, unsigned int se_len, |
617 | bool sign_extend) | 617 | bool sign_extend) |
618 | { | 618 | { |
619 | unsigned int nbytes, sg_offset, dm_offset, ksb_len, i; | 619 | unsigned int nbytes, sg_offset, dm_offset, ksb_len, i; |
620 | u8 buffer[CCP_REVERSE_BUF_SIZE]; | 620 | u8 buffer[CCP_REVERSE_BUF_SIZE]; |
621 | 621 | ||
622 | BUG_ON(se_len > sizeof(buffer)); | 622 | if (WARN_ON(se_len > sizeof(buffer))) |
623 | return -EINVAL; | ||
623 | 624 | ||
624 | sg_offset = len; | 625 | sg_offset = len; |
625 | dm_offset = 0; | 626 | dm_offset = 0; |
@@ -642,6 +643,8 @@ static void ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, | |||
642 | se_len - ksb_len); | 643 | se_len - ksb_len); |
643 | } | 644 | } |
644 | } | 645 | } |
646 | |||
647 | return 0; | ||
645 | } | 648 | } |
646 | 649 | ||
647 | static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa, | 650 | static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa, |
@@ -1606,8 +1609,10 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1606 | if (ret) | 1609 | if (ret) |
1607 | goto e_ksb; | 1610 | goto e_ksb; |
1608 | 1611 | ||
1609 | ccp_reverse_set_dm_area(&exp, rsa->exp, rsa->exp_len, CCP_KSB_BYTES, | 1612 | ret = ccp_reverse_set_dm_area(&exp, rsa->exp, rsa->exp_len, |
1610 | false); | 1613 | CCP_KSB_BYTES, false); |
1614 | if (ret) | ||
1615 | goto e_exp; | ||
1611 | ret = ccp_copy_to_ksb(cmd_q, &exp, op.jobid, op.ksb_key, | 1616 | ret = ccp_copy_to_ksb(cmd_q, &exp, op.jobid, op.ksb_key, |
1612 | CCP_PASSTHRU_BYTESWAP_NOOP); | 1617 | CCP_PASSTHRU_BYTESWAP_NOOP); |
1613 | if (ret) { | 1618 | if (ret) { |
@@ -1623,11 +1628,15 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1623 | if (ret) | 1628 | if (ret) |
1624 | goto e_exp; | 1629 | goto e_exp; |
1625 | 1630 | ||
1626 | ccp_reverse_set_dm_area(&src, rsa->mod, rsa->mod_len, CCP_KSB_BYTES, | 1631 | ret = ccp_reverse_set_dm_area(&src, rsa->mod, rsa->mod_len, |
1627 | false); | 1632 | CCP_KSB_BYTES, false); |
1633 | if (ret) | ||
1634 | goto e_src; | ||
1628 | src.address += o_len; /* Adjust the address for the copy operation */ | 1635 | src.address += o_len; /* Adjust the address for the copy operation */ |
1629 | ccp_reverse_set_dm_area(&src, rsa->src, rsa->src_len, CCP_KSB_BYTES, | 1636 | ret = ccp_reverse_set_dm_area(&src, rsa->src, rsa->src_len, |
1630 | false); | 1637 | CCP_KSB_BYTES, false); |
1638 | if (ret) | ||
1639 | goto e_src; | ||
1631 | src.address -= o_len; /* Reset the address to original value */ | 1640 | src.address -= o_len; /* Reset the address to original value */ |
1632 | 1641 | ||
1633 | /* Prepare the output area for the operation */ | 1642 | /* Prepare the output area for the operation */ |
@@ -1841,21 +1850,27 @@ static int ccp_run_ecc_mm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1841 | save = src.address; | 1850 | save = src.address; |
1842 | 1851 | ||
1843 | /* Copy the ECC modulus */ | 1852 | /* Copy the ECC modulus */ |
1844 | ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, | 1853 | ret = ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, |
1845 | CCP_ECC_OPERAND_SIZE, false); | 1854 | CCP_ECC_OPERAND_SIZE, false); |
1855 | if (ret) | ||
1856 | goto e_src; | ||
1846 | src.address += CCP_ECC_OPERAND_SIZE; | 1857 | src.address += CCP_ECC_OPERAND_SIZE; |
1847 | 1858 | ||
1848 | /* Copy the first operand */ | 1859 | /* Copy the first operand */ |
1849 | ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_1, | 1860 | ret = ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_1, |
1850 | ecc->u.mm.operand_1_len, | 1861 | ecc->u.mm.operand_1_len, |
1851 | CCP_ECC_OPERAND_SIZE, false); | 1862 | CCP_ECC_OPERAND_SIZE, false); |
1863 | if (ret) | ||
1864 | goto e_src; | ||
1852 | src.address += CCP_ECC_OPERAND_SIZE; | 1865 | src.address += CCP_ECC_OPERAND_SIZE; |
1853 | 1866 | ||
1854 | if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) { | 1867 | if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) { |
1855 | /* Copy the second operand */ | 1868 | /* Copy the second operand */ |
1856 | ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_2, | 1869 | ret = ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_2, |
1857 | ecc->u.mm.operand_2_len, | 1870 | ecc->u.mm.operand_2_len, |
1858 | CCP_ECC_OPERAND_SIZE, false); | 1871 | CCP_ECC_OPERAND_SIZE, false); |
1872 | if (ret) | ||
1873 | goto e_src; | ||
1859 | src.address += CCP_ECC_OPERAND_SIZE; | 1874 | src.address += CCP_ECC_OPERAND_SIZE; |
1860 | } | 1875 | } |
1861 | 1876 | ||
@@ -1960,18 +1975,24 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1960 | save = src.address; | 1975 | save = src.address; |
1961 | 1976 | ||
1962 | /* Copy the ECC modulus */ | 1977 | /* Copy the ECC modulus */ |
1963 | ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, | 1978 | ret = ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, |
1964 | CCP_ECC_OPERAND_SIZE, false); | 1979 | CCP_ECC_OPERAND_SIZE, false); |
1980 | if (ret) | ||
1981 | goto e_src; | ||
1965 | src.address += CCP_ECC_OPERAND_SIZE; | 1982 | src.address += CCP_ECC_OPERAND_SIZE; |
1966 | 1983 | ||
1967 | /* Copy the first point X and Y coordinate */ | 1984 | /* Copy the first point X and Y coordinate */ |
1968 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.x, | 1985 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.x, |
1969 | ecc->u.pm.point_1.x_len, | 1986 | ecc->u.pm.point_1.x_len, |
1970 | CCP_ECC_OPERAND_SIZE, false); | 1987 | CCP_ECC_OPERAND_SIZE, false); |
1988 | if (ret) | ||
1989 | goto e_src; | ||
1971 | src.address += CCP_ECC_OPERAND_SIZE; | 1990 | src.address += CCP_ECC_OPERAND_SIZE; |
1972 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.y, | 1991 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.y, |
1973 | ecc->u.pm.point_1.y_len, | 1992 | ecc->u.pm.point_1.y_len, |
1974 | CCP_ECC_OPERAND_SIZE, false); | 1993 | CCP_ECC_OPERAND_SIZE, false); |
1994 | if (ret) | ||
1995 | goto e_src; | ||
1975 | src.address += CCP_ECC_OPERAND_SIZE; | 1996 | src.address += CCP_ECC_OPERAND_SIZE; |
1976 | 1997 | ||
1977 | /* Set the first point Z coordianate to 1 */ | 1998 | /* Set the first point Z coordianate to 1 */ |
@@ -1980,13 +2001,17 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1980 | 2001 | ||
1981 | if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) { | 2002 | if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) { |
1982 | /* Copy the second point X and Y coordinate */ | 2003 | /* Copy the second point X and Y coordinate */ |
1983 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.x, | 2004 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.x, |
1984 | ecc->u.pm.point_2.x_len, | 2005 | ecc->u.pm.point_2.x_len, |
1985 | CCP_ECC_OPERAND_SIZE, false); | 2006 | CCP_ECC_OPERAND_SIZE, false); |
2007 | if (ret) | ||
2008 | goto e_src; | ||
1986 | src.address += CCP_ECC_OPERAND_SIZE; | 2009 | src.address += CCP_ECC_OPERAND_SIZE; |
1987 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.y, | 2010 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.y, |
1988 | ecc->u.pm.point_2.y_len, | 2011 | ecc->u.pm.point_2.y_len, |
1989 | CCP_ECC_OPERAND_SIZE, false); | 2012 | CCP_ECC_OPERAND_SIZE, false); |
2013 | if (ret) | ||
2014 | goto e_src; | ||
1990 | src.address += CCP_ECC_OPERAND_SIZE; | 2015 | src.address += CCP_ECC_OPERAND_SIZE; |
1991 | 2016 | ||
1992 | /* Set the second point Z coordianate to 1 */ | 2017 | /* Set the second point Z coordianate to 1 */ |
@@ -1994,16 +2019,21 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1994 | src.address += CCP_ECC_OPERAND_SIZE; | 2019 | src.address += CCP_ECC_OPERAND_SIZE; |
1995 | } else { | 2020 | } else { |
1996 | /* Copy the Domain "a" parameter */ | 2021 | /* Copy the Domain "a" parameter */ |
1997 | ccp_reverse_set_dm_area(&src, ecc->u.pm.domain_a, | 2022 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.domain_a, |
1998 | ecc->u.pm.domain_a_len, | 2023 | ecc->u.pm.domain_a_len, |
1999 | CCP_ECC_OPERAND_SIZE, false); | 2024 | CCP_ECC_OPERAND_SIZE, false); |
2025 | if (ret) | ||
2026 | goto e_src; | ||
2000 | src.address += CCP_ECC_OPERAND_SIZE; | 2027 | src.address += CCP_ECC_OPERAND_SIZE; |
2001 | 2028 | ||
2002 | if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) { | 2029 | if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) { |
2003 | /* Copy the scalar value */ | 2030 | /* Copy the scalar value */ |
2004 | ccp_reverse_set_dm_area(&src, ecc->u.pm.scalar, | 2031 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.scalar, |
2005 | ecc->u.pm.scalar_len, | 2032 | ecc->u.pm.scalar_len, |
2006 | CCP_ECC_OPERAND_SIZE, false); | 2033 | CCP_ECC_OPERAND_SIZE, |
2034 | false); | ||
2035 | if (ret) | ||
2036 | goto e_src; | ||
2007 | src.address += CCP_ECC_OPERAND_SIZE; | 2037 | src.address += CCP_ECC_OPERAND_SIZE; |
2008 | } | 2038 | } |
2009 | } | 2039 | } |