Re: [PATCH 06/20] misc: habanalabs: goya: Omit pointless check ensuring addr is >=0

Oded Gabbay
2020-06-29T18:38:15Z

On Mon, Jun 29, 2020 at 5:04 PM Lee Jones <lee.jones@linaro.org> wrote:
>
> Seeing as 'addr' is unsigned, it would be impossible for the assigned
> value to be anything other than zero or positive.
>
> Squashes the following W=1 warnings:
>
> drivers/misc/habanalabs/goya/goya.c: In function ‘goya_debugfs_read32’:
> drivers/misc/habanalabs/goya/goya.c:3945:19: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
> 3945 | } else if ((addr >= DRAM_PHYS_BASE) &&
> | ^~
> drivers/misc/habanalabs/goya/goya.c: In function ‘goya_debugfs_write32’:
> drivers/misc/habanalabs/goya/goya.c:4002:19: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
> 4002 | } else if ((addr >= DRAM_PHYS_BASE) &&
> | ^~
> drivers/misc/habanalabs/goya/goya.c: In function ‘goya_debugfs_read64’:
> drivers/misc/habanalabs/goya/goya.c:4047:19: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
> 4047 | } else if ((addr >= DRAM_PHYS_BASE) &&
> | ^~
> drivers/misc/habanalabs/goya/goya.c: In function ‘goya_debugfs_write64’:
> drivers/misc/habanalabs/goya/goya.c:4091:19: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
> 4091 | } else if ((addr >= DRAM_PHYS_BASE) &&
> | ^~
> drivers/misc/habanalabs/pci.c:328: warning: Excess function parameter 'dma_mask' description in 'hl_pci_set_dma_mask'
> drivers/misc/habanalabs/goya/goya_coresight.c: In function ‘goya_debug_coresight’:
> drivers/misc/habanalabs/goya/goya_coresight.c:643:6: warning: variable ‘val’ set but not used [-Wunused-but-set-variable]
> 643 | u32 val;
> | ^~~
>
> Cc: Oded Gabbay <oded.gabbay@gmail.com>
> Cc: Tomer Tayar <ttayar@habana.ai>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
> drivers/misc/habanalabs/goya/goya.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
> index 0d2952bb58dfb..a4a20e27ed3b4 100644
> --- a/drivers/misc/habanalabs/goya/goya.c
> +++ b/drivers/misc/habanalabs/goya/goya.c
> @@ -3942,8 +3942,7 @@ static int goya_debugfs_read32(struct hl_device *hdev, u64 addr, u32 *val)
> *val = readl(hdev->pcie_bar[SRAM_CFG_BAR_ID] +
> (addr - SRAM_BASE_ADDR));
>
> - } else if ((addr >= DRAM_PHYS_BASE) &&
> - (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size)) {
> + } else if (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size) {
>
> u64 bar_base_addr = DRAM_PHYS_BASE +
> (addr & ~(prop->dram_pci_bar_size - 0x1ull));
> @@ -3999,8 +3998,7 @@ static int goya_debugfs_write32(struct hl_device *hdev, u64 addr, u32 val)
> writel(val, hdev->pcie_bar[SRAM_CFG_BAR_ID] +
> (addr - SRAM_BASE_ADDR));
>
> - } else if ((addr >= DRAM_PHYS_BASE) &&
> - (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size)) {
> + } else if (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size) {
>
> u64 bar_base_addr = DRAM_PHYS_BASE +
> (addr & ~(prop->dram_pci_bar_size - 0x1ull));
> @@ -4044,9 +4042,8 @@ static int goya_debugfs_read64(struct hl_device *hdev, u64 addr, u64 *val)
> *val = readq(hdev->pcie_bar[SRAM_CFG_BAR_ID] +
> (addr - SRAM_BASE_ADDR));
>
> - } else if ((addr >= DRAM_PHYS_BASE) &&
> - (addr <=
> - DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64))) {
> + } else if (addr <=
> + DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64)) {
>
> u64 bar_base_addr = DRAM_PHYS_BASE +
> (addr & ~(prop->dram_pci_bar_size - 0x1ull));
> @@ -4088,9 +4085,8 @@ static int goya_debugfs_write64(struct hl_device *hdev, u64 addr, u64 val)
> writeq(val, hdev->pcie_bar[SRAM_CFG_BAR_ID] +
> (addr - SRAM_BASE_ADDR));
>
> - } else if ((addr >= DRAM_PHYS_BASE) &&
> - (addr <=
> - DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64))) {
> + } else if (addr <=
> + DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64)) {
>
> u64 bar_base_addr = DRAM_PHYS_BASE +
> (addr & ~(prop->dram_pci_bar_size - 0x1ull));
> --
> 2.25.1
>

This patch is:
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>