Skip to content

Commit

Permalink
LFU-362 cpu: imx8_cpu: fix the mpidr check
Browse files Browse the repository at this point in the history
CID 22311217 (SolidRun#1 of 1): Operands don't affect result
(CONSTANT_EXPRESSION_RESULT) result_independent_of_operands:
plat->mpidr == 18446744073709551615UL /* (ulong)-1 */ is always false
regardless of the values of its operands. This occurs as the
logical operand of if.

The mpidr's type is u32, however dev_read_addr returns a value with type
fdt_addr_t(phys_addr_t) which is 64bit long. So the check never fail.

This patch we still keep mpidr as u32 type, because i.MX8 only has max
two cluster, the higher 32bit will always be 0. Use a variable addr
to do the check, if check pass, assign the lower 32 bit to plat->mpidr.

Reported-by: Coverity
Reviewed-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
  • Loading branch information
MrVan committed Jul 20, 2022
1 parent f05e92c commit 6498883
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/cpu/imx8_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,22 @@ static int imx8_cpu_probe(struct udevice *dev)
{
struct cpu_imx_plat *plat = dev_get_plat(dev);
u32 cpurev;
fdt_addr_t addr;

set_core_data(dev);
cpurev = get_cpu_rev();
plat->cpurev = cpurev;
plat->rev = get_imx8_rev(cpurev & 0xFFF);
plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
plat->mpidr = dev_read_addr(dev);
if (plat->mpidr == FDT_ADDR_T_NONE) {
addr = dev_read_addr(dev);
if (addr == FDT_ADDR_T_NONE) {
printf("%s: Failed to get CPU reg property\n", __func__);
return -EINVAL;
}

plat->mpidr = (u32)addr;

return 0;
}

Expand Down

0 comments on commit 6498883

Please sign in to comment.