summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
diff options
context:
space:
mode:
authorJiri Pirko <jiri@mellanox.com>2015-12-22 11:43:07 +0300
committerDavid S. Miller <davem@davemloft.net>2015-12-23 00:25:09 +0300
commitf4cee3af0dedf3270e6d615d772e3fbfa3200769 (patch)
treedf31e4d939de5cc4c2817c72f7235a497d720d6f /drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
parent2010b93e9317cc12acd20c4aed385af7f9d1681e (diff)
downloadlinux-f4cee3af0dedf3270e6d615d772e3fbfa3200769.tar.xz
mlxsw: core: Use devm_kzalloc to allocate mlxsw_hwmon structure
KASan reported use-after-free for the hwmon structure. So fix this by using devm_kzalloc and let the core take care about freeing the memory during device dettach. Reported-by: Ido Schimmel <idosch@mellanox.com> Fixes: 89309da39 ("mlxsw: core: Implement temperature hwmon interface") Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c')
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
index 00ccf1c0dcda..5b9364f4837d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
@@ -334,7 +334,8 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
struct device *hwmon_dev;
int err;
- mlxsw_hwmon = kzalloc(sizeof(*mlxsw_hwmon), GFP_KERNEL);
+ mlxsw_hwmon = devm_kzalloc(mlxsw_bus_info->dev, sizeof(*mlxsw_hwmon),
+ GFP_KERNEL);
if (!mlxsw_hwmon)
return -ENOMEM;
mlxsw_hwmon->core = mlxsw_core;
@@ -367,11 +368,5 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
err_hwmon_register:
err_fans_init:
err_temp_init:
- kfree(mlxsw_hwmon);
return err;
}
-
-void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon)
-{
- kfree(mlxsw_hwmon);
-}