.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
7 | 4 | */ |
---|
8 | 5 | |
---|
9 | 6 | #include <linux/device.h> |
---|
.. | .. |
---|
257 | 254 | const struct firmware *fw_entry; |
---|
258 | 255 | struct device *dev = &cpt->pdev->dev; |
---|
259 | 256 | struct ucode_header *ucode; |
---|
| 257 | + unsigned int code_length; |
---|
260 | 258 | struct microcode *mcode; |
---|
261 | 259 | int j, ret = 0; |
---|
262 | 260 | |
---|
.. | .. |
---|
267 | 265 | ucode = (struct ucode_header *)fw_entry->data; |
---|
268 | 266 | mcode = &cpt->mcode[cpt->next_mc_idx]; |
---|
269 | 267 | 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) { |
---|
272 | 270 | ret = -EINVAL; |
---|
273 | 271 | goto fw_release; |
---|
274 | 272 | } |
---|
| 273 | + mcode->code_size = code_length * 2; |
---|
275 | 274 | |
---|
276 | 275 | mcode->is_ae = is_ae; |
---|
277 | 276 | mcode->core_mask = 0ULL; |
---|
278 | 277 | mcode->num_cores = is_ae ? 6 : 10; |
---|
279 | 278 | |
---|
280 | 279 | /* 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); |
---|
283 | 282 | if (!mcode->code) { |
---|
284 | 283 | dev_err(dev, "Unable to allocate space for microcode"); |
---|
285 | 284 | ret = -ENOMEM; |
---|