Skip to contentSkip to conversation

drm/amdgpu: fix i2s_pdata out of bound array access

PATCH In review Vijendar Mukunda 2 participants 4 messages Jul 27, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix i2s_pdata out of bound array access

Fixed following Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:393 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:396 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -8
index bcc7ee02e0fc..6d72355ac492 100644
@@ -390,14 +390,6 @@ static int acp_hw_init(void *handle)
 		i2s_pdata[2].i2s_reg_comp1 = ACP_BT_COMP1_REG_OFFSET;
 		i2s_pdata[2].i2s_reg_comp2 = ACP_BT_COMP2_REG_OFFSET;
 
-		i2s_pdata[3].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
-		switch (adev->asic_type) {
-		case CHIP_STONEY:
-			i2s_pdata[3].quirks |= DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
-			break;
-		default:
-			break;
-		}
 		adev->acp.acp_res[0].name = "acp2x_dma";
 		adev->acp.acp_res[0].flags = IORESOURCE_MEM;
 		adev->acp.acp_res[0].start = acp_base;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Vijendar Mukunda

Fixed following Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:393 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:396 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -0
index bcc7ee02e0fc..6d72355ac492 100644
@@ -390,14 +390,6 @@ static int acp_hw_init(void *handle)
                i2s_pdata[2].i2s_reg_comp1 = ACP_BT_COMP1_REG_OFFSET;

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c static int acp_hw_init(void *handle) · line 400

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -8
                i2s_pdata[2].i2s_reg_comp2 = ACP_BT_COMP2_REG_OFFSET;
 
-               i2s_pdata[3].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
-               switch (adev->asic_type) {
-               case CHIP_STONEY:
-                       i2s_pdata[3].quirks |= DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
-                       break;
-               default:
-                       break;
-               }

Is this actually not used or should we just increase the allocation size?

Alex

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -1
                adev->acp.acp_res[0].name = "acp2x_dma";
                adev->acp.acp_res[0].flags = IORESOURCE_MEM;
                adev->acp.acp_res[0].start = acp_base;
--

2.25.1

#2 lore raw
Quoted 35 lines · Alex Deucher
Quoted 20 lines · Vijendar Mukunda

Fixed following Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:393 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:396 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -0
index bcc7ee02e0fc..6d72355ac492 100644
@@ -390,14 +390,6 @@ static int acp_hw_init(void *handle)
                i2s_pdata[2].i2s_reg_comp1 = ACP_BT_COMP1_REG_OFFSET;

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c static int acp_hw_init(void *handle) · line 400

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -8
                i2s_pdata[2].i2s_reg_comp2 = ACP_BT_COMP2_REG_OFFSET;
 
-               i2s_pdata[3].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
-               switch (adev->asic_type) {
-               case CHIP_STONEY:
-                       i2s_pdata[3].quirks |= DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
-                       break;
-               default:
-                       break;
-               }

Is this actually not used or should we just increase the allocation size?

Quoted 1 line

Alex

it's my bad. i2s_pdata array size is 3. when we recently included code changes for JD platform , this piece of code was added mistakenly for Stoney platform switch case.

--
Vijendar

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -1
                adev->acp.acp_res[0].name = "acp2x_dma";
                adev->acp.acp_res[0].flags = IORESOURCE_MEM;
                adev->acp.acp_res[0].start = acp_base;
--

2.25.1

Acked-by
#3 lore raw
Quoted 37 lines · Mukunda,Vijendar
Quoted 35 lines · Alex Deucher
Quoted 20 lines · Vijendar Mukunda

Fixed following Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:393 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c:396 acp_hw_init()
error: buffer overflow 'i2s_pdata' 3 <= 3

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -0
index bcc7ee02e0fc..6d72355ac492 100644
@@ -390,14 +390,6 @@ static int acp_hw_init(void *handle)
                i2s_pdata[2].i2s_reg_comp1 = ACP_BT_COMP1_REG_OFFSET;

drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c static int acp_hw_init(void *handle) · line 400

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -8
                i2s_pdata[2].i2s_reg_comp2 = ACP_BT_COMP2_REG_OFFSET;
 
-               i2s_pdata[3].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
-               switch (adev->asic_type) {
-               case CHIP_STONEY:
-                       i2s_pdata[3].quirks |= DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
-                       break;
-               default:
-                       break;
-               }

Is this actually not used or should we just increase the allocation size?

Quoted 4 lines
Quoted 1 line

Alex

it's my bad. i2s_pdata array size is 3. when we recently included code changes for JD platform , this piece of code was added mistakenly for Stoney platform switch case.

Thanks. Patch is:

Quoted 12 lines

--
Vijendar

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +0 -1
                adev->acp.acp_res[0].name = "acp2x_dma";
                adev->acp.acp_res[0].flags = IORESOURCE_MEM;
                adev->acp.acp_res[0].start = acp_base;
--

2.25.1