Skip to content

Commit 7135673

Browse files
Xuanqiang LuoAndi Shyti
authored andcommitted
i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource()
If devm_platform_get_and_ioremap_resource() returns an error, mlxbf_i2c_init_resource() frees tmp_res before reading tmp_res->io to get the error code. This results in a use-after-free. Save the error code before freeing tmp_res. Fixes: b5b5b32 ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC") Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn> Cc: <stable@vger.kernel.org> # v5.10+ Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20260714150808.85045-1-xuanqiang.luo@linux.dev
1 parent 9db20d2 commit 7135673

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/i2c/busses/i2c-mlxbf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,10 @@ static int mlxbf_i2c_init_resource(struct platform_device *pdev,
10511051

10521052
tmp_res->io = devm_platform_get_and_ioremap_resource(pdev, type, &tmp_res->params);
10531053
if (IS_ERR(tmp_res->io)) {
1054+
int ret = PTR_ERR(tmp_res->io);
1055+
10541056
devm_kfree(dev, tmp_res);
1055-
return PTR_ERR(tmp_res->io);
1057+
return ret;
10561058
}
10571059

10581060
tmp_res->type = type;

0 commit comments

Comments
 (0)