hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/crypto/cavium/cpt/cptpf_main.c
....@@ -1,9 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2016 Cavium, Inc.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of version 2 of the GNU General Public License
6
- * as published by the Free Software Foundation.
74 */
85
96 #include <linux/device.h>
....@@ -257,6 +254,7 @@
257254 const struct firmware *fw_entry;
258255 struct device *dev = &cpt->pdev->dev;
259256 struct ucode_header *ucode;
257
+ unsigned int code_length;
260258 struct microcode *mcode;
261259 int j, ret = 0;
262260
....@@ -267,19 +265,20 @@
267265 ucode = (struct ucode_header *)fw_entry->data;
268266 mcode = &cpt->mcode[cpt->next_mc_idx];
269267 memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ);
270
- mcode->code_size = ntohl(ucode->code_length) * 2;
271
- if (!mcode->code_size) {
268
+ code_length = ntohl(ucode->code_length);
269
+ if (code_length == 0 || code_length >= INT_MAX / 2) {
272270 ret = -EINVAL;
273271 goto fw_release;
274272 }
273
+ mcode->code_size = code_length * 2;
275274
276275 mcode->is_ae = is_ae;
277276 mcode->core_mask = 0ULL;
278277 mcode->num_cores = is_ae ? 6 : 10;
279278
280279 /* Allocate DMAable space */
281
- mcode->code = dma_zalloc_coherent(&cpt->pdev->dev, mcode->code_size,
282
- &mcode->phys_base, GFP_KERNEL);
280
+ mcode->code = dma_alloc_coherent(&cpt->pdev->dev, mcode->code_size,
281
+ &mcode->phys_base, GFP_KERNEL);
283282 if (!mcode->code) {
284283 dev_err(dev, "Unable to allocate space for microcode");
285284 ret = -ENOMEM;