drivers/remoteproc/pru_rproc.c:145 pru_d_da_to_va() warn: always true condition '(da >= 0) => (0-u32max >= 0)'

From: kernel test robot
Date: Thu Mar 25 2021 - 17:23:56 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: e138138003eb3b3d06cc91cf2e8c5dec77e2a31e
commit: d4ce2de7e4af8b978eb816784d0eafc220336d52 remoteproc: pru: Add a PRU remoteproc driver
date: 4 months ago
config: arm64-randconfig-m031-20210325 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

smatch warnings:
drivers/remoteproc/pru_rproc.c:145 pru_d_da_to_va() warn: always true condition '(da >= 0) => (0-u32max >= 0)'
drivers/remoteproc/pru_rproc.c:176 pru_i_da_to_va() warn: always true condition '(da >= 0) => (0-u32max >= 0)'

vim +145 drivers/remoteproc/pru_rproc.c

118
119 /*
120 * Convert PRU device address (data spaces only) to kernel virtual address.
121 *
122 * Each PRU has access to all data memories within the PRUSS, accessible at
123 * different ranges. So, look through both its primary and secondary Data
124 * RAMs as well as any shared Data RAM to convert a PRU device address to
125 * kernel virtual address. Data RAM0 is primary Data RAM for PRU0 and Data
126 * RAM1 is primary Data RAM for PRU1.
127 */
128 static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
129 {
130 struct pruss_mem_region dram0, dram1, shrd_ram;
131 struct pruss *pruss = pru->pruss;
132 u32 offset;
133 void *va = NULL;
134
135 if (len == 0)
136 return NULL;
137
138 dram0 = pruss->mem_regions[PRUSS_MEM_DRAM0];
139 dram1 = pruss->mem_regions[PRUSS_MEM_DRAM1];
140 /* PRU1 has its local RAM addresses reversed */
141 if (pru->id == 1)
142 swap(dram0, dram1);
143 shrd_ram = pruss->mem_regions[PRUSS_MEM_SHRD_RAM2];
144
> 145 if (da >= PRU_PDRAM_DA && da + len <= PRU_PDRAM_DA + dram0.size) {
146 offset = da - PRU_PDRAM_DA;
147 va = (__force void *)(dram0.va + offset);
148 } else if (da >= PRU_SDRAM_DA &&
149 da + len <= PRU_SDRAM_DA + dram1.size) {
150 offset = da - PRU_SDRAM_DA;
151 va = (__force void *)(dram1.va + offset);
152 } else if (da >= PRU_SHRDRAM_DA &&
153 da + len <= PRU_SHRDRAM_DA + shrd_ram.size) {
154 offset = da - PRU_SHRDRAM_DA;
155 va = (__force void *)(shrd_ram.va + offset);
156 }
157
158 return va;
159 }
160
161 /*
162 * Convert PRU device address (instruction space) to kernel virtual address.
163 *
164 * A PRU does not have an unified address space. Each PRU has its very own
165 * private Instruction RAM, and its device address is identical to that of
166 * its primary Data RAM device address.
167 */
168 static void *pru_i_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
169 {
170 u32 offset;
171 void *va = NULL;
172
173 if (len == 0)
174 return NULL;
175
> 176 if (da >= PRU_IRAM_DA &&
177 da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
178 offset = da - PRU_IRAM_DA;
179 va = (__force void *)(pru->mem_regions[PRU_IOMEM_IRAM].va +
180 offset);
181 }
182
183 return va;
184 }
185

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip