Skip to contentSkip to conversation

remoteproc: pru: remove always true check positive unsigned value

PATCH Applied Simon Horman 3 participants 3 messages Apr 4, 2023 – Apr 5, 2023 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: pru: remove always true check positive unsigned value

In both cases they type of da is u32. And PRU_PDRAM_DA is 0. So the check da >= PRU_PDRAM_DA is always true and can be removed.

Flagged by Smatch:

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

No functional changes intended.
Compile tested only.

---
 drivers/remoteproc/pru_rproc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/remoteproc/pru_rproc.c +2 -3
index b76db7fa693d..095f66130f48 100644
@@ -657,7 +657,7 @@ static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
 		swap(dram0, dram1);
 	shrd_ram = pruss->mem_regions[PRUSS_MEM_SHRD_RAM2];
 
-	if (da >= PRU_PDRAM_DA && da + len <= PRU_PDRAM_DA + dram0.size) {
+	if (da + len <= PRU_PDRAM_DA + dram0.size) {
 		offset = da - PRU_PDRAM_DA;
 		va = (__force void *)(dram0.va + offset);
 	} else if (da >= PRU_SDRAM_DA &&
@@ -706,8 +706,7 @@ static void *pru_i_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
 	 */
 	da &= 0xfffff;
 
-	if (da >= PRU_IRAM_DA &&
-	    da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
+	if (da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
 		offset = da - PRU_IRAM_DA;
 		va = (__force void *)(pru->mem_regions[PRU_IOMEM_IRAM].va +
 				      offset);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Simon Horman

In both cases they type of da is u32. And PRU_PDRAM_DA is 0. So the check da >= PRU_PDRAM_DA is always true and can be removed.

Flagged by Smatch:

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

No functional changes intended.
Compile tested only.

---
  drivers/remoteproc/pru_rproc.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/remoteproc/pru_rproc.c +1 -1
index b76db7fa693d..095f66130f48 100644
@@ -657,7 +657,7 @@ static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
  		swap(dram0, dram1);
  	shrd_ram = pruss->mem_regions[PRUSS_MEM_SHRD_RAM2];
 
-	if (da >= PRU_PDRAM_DA && da + len <= PRU_PDRAM_DA + dram0.size) {
+	if (da + len <= PRU_PDRAM_DA + dram0.size) {
  		offset = da - PRU_PDRAM_DA;
  		va = (__force void *)(dram0.va + offset);
  	} else if (da >= PRU_SDRAM_DA &&

drivers/remoteproc/pru_rproc.c static void *pru_i_da_to_va(struct pru_rproc *pru, u32 da, size_t len) · line 711

Quoted 8 lines
drivers/remoteproc/pru_rproc.c +1 -2
@@ -706,8 +706,7 @@ static void *pru_i_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
  	 */
  	da &= 0xfffff;
 
-	if (da >= PRU_IRAM_DA &&
-	    da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
+	if (da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
  		offset = da - PRU_IRAM_DA;
  		va = (__force void *)(pru->mem_regions[PRU_IOMEM_IRAM].va +

LGTM.

--Mukesh

Quoted 2 lines
drivers/remoteproc/pru_rproc.c +0 -0
  				      offset);
maintainer Applied
#2 lore raw
In reply to Simon Horman
Quoted 11 lines · Simon Horman

In both cases they type of da is u32. And PRU_PDRAM_DA is 0. So the check da >= PRU_PDRAM_DA is always true and can be removed.

Flagged by Smatch:

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

No functional changes intended.
Compile tested only.

Quoted 7 lines
---
 drivers/remoteproc/pru_rproc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Applied

Thanks,
Mathieu

Quoted 24 lines
drivers/remoteproc/pru_rproc.c +2 -3
index b76db7fa693d..095f66130f48 100644
@@ -657,7 +657,7 @@ static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
 		swap(dram0, dram1);
 	shrd_ram = pruss->mem_regions[PRUSS_MEM_SHRD_RAM2];
 
-	if (da >= PRU_PDRAM_DA && da + len <= PRU_PDRAM_DA + dram0.size) {
+	if (da + len <= PRU_PDRAM_DA + dram0.size) {
 		offset = da - PRU_PDRAM_DA;
 		va = (__force void *)(dram0.va + offset);
 	} else if (da >= PRU_SDRAM_DA &&
@@ -706,8 +706,7 @@ static void *pru_i_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
 	 */
 	da &= 0xfffff;
 
-	if (da >= PRU_IRAM_DA &&
-	    da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
+	if (da + len <= PRU_IRAM_DA + pru->mem_regions[PRU_IOMEM_IRAM].size) {
 		offset = da - PRU_IRAM_DA;
 		va = (__force void *)(pru->mem_regions[PRU_IOMEM_IRAM].va +
 				      offset);