diff options
author | Dan Carpenter <[email protected]> | 2023-06-14 16:07:15 +0300 |
---|---|---|
committer | Hans Verkuil <[email protected]> | 2023-07-25 09:44:26 +0200 |
commit | b19c347b123cd68d6208474194947bdb6dbc1227 (patch) | |
tree | 5fc71db039a01fc0a6fb9bfafc86d4d4c00ce7c7 | |
parent | 5bd28eae48589694ff4e5badb03bf75dae695b3f (diff) |
media: mediatek: vcodec: Fix potential crash in mtk_vcodec_dbgfs_remove()
The list iterator "dbgfs_inst" is always non-NULL. This means that the
test for NULL inside the loop is unnecessary and it also means that the
test for NULL outside the loop will not work. If we do not find the item
on the list with the correct the ctx_id then it will free invalid memory
leading to a crash.
Fixes: cd403a6a0419 ("media: mediatek: vcodec: Add a debugfs file to get different useful information")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: Nicolas Dufresne <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
-rw-r--r-- | drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c index b5cdbbfcc388..2ebf68d33d57 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c @@ -168,14 +168,11 @@ void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id) list_for_each_entry(dbgfs_inst, &vcodec_dev->dbgfs.dbgfs_head, node) { if (dbgfs_inst->inst_id == ctx_id) { vcodec_dev->dbgfs.inst_count--; - break; + list_del(&dbgfs_inst->node); + kfree(dbgfs_inst); + return; } } - - if (dbgfs_inst) { - list_del(&dbgfs_inst->node); - kfree(dbgfs_inst); - } } EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_remove); |