Skip to content

Commit a12bd67

Browse files
Jason-JH.Lingregkh
authored andcommitted
drm/mediatek: Fix coverity issue with unintentional integer overflow
commit b0b0d811eac6b4c52cb9ad632fa6384cf48869e7 upstream. 1. Instead of multiplying 2 variable of different types. Change to assign a value of one variable and then multiply the other variable. 2. Add a int variable for multiplier calculation instead of calculating different types multiplier with dma_addr_t variable directly. Fixes: 1a64a7a ("drm/mediatek: Fix cursor plane no update") Signed-off-by: Jason-JH.Lin <[email protected]> Reviewed-by: Alexandre Mergnat <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]> [ For certain code segments with coverity issue do not exist in function mtk_plane_update_new_state(), those not present in v6.1 are not back ported. ] Signed-off-by: Bin Lan <[email protected]> Signed-off-by: He Zhe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2d4a7a0 commit a12bd67

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

drivers/gpu/drm/mediatek/mtk_drm_gem.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
119119
int ret;
120120

121121
args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
122-
args->size = args->pitch * args->height;
122+
123+
/*
124+
* Multiply 2 variables of different types,
125+
* for example: args->size = args->spacing * args->height;
126+
* may cause coverity issue with unintentional overflow.
127+
*/
128+
args->size = args->pitch;
129+
args->size *= args->height;
123130

124131
mtk_gem = mtk_drm_gem_create(dev, args->size, false);
125132
if (IS_ERR(mtk_gem))

drivers/gpu/drm/mediatek/mtk_drm_plane.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,24 @@ static void mtk_plane_update_new_state(struct drm_plane_state *new_state,
120120
struct mtk_drm_gem_obj *mtk_gem;
121121
unsigned int pitch, format;
122122
dma_addr_t addr;
123+
int offset;
123124

124125
gem = fb->obj[0];
125126
mtk_gem = to_mtk_gem_obj(gem);
126127
addr = mtk_gem->dma_addr;
127128
pitch = fb->pitches[0];
128129
format = fb->format->format;
129130

130-
addr += (new_state->src.x1 >> 16) * fb->format->cpp[0];
131-
addr += (new_state->src.y1 >> 16) * pitch;
131+
/*
132+
* Using dma_addr_t variable to calculate with multiplier of different types,
133+
* for example: addr += (new_state->src.x1 >> 16) * fb->format->cpp[0];
134+
* may cause coverity issue with unintentional overflow.
135+
*/
136+
offset = (new_state->src.x1 >> 16) * fb->format->cpp[0];
137+
addr += offset;
138+
offset = (new_state->src.y1 >> 16) * pitch;
139+
addr += offset;
140+
132141

133142
mtk_plane_state->pending.enable = true;
134143
mtk_plane_state->pending.pitch = pitch;

0 commit comments

Comments
 (0)