Skip to content

Commit 4d5a2a7

Browse files
mudongliangjwrdegoede
authored andcommitted
platform/x86/intel: tpmi: Fix double free in tpmi_create_device()
The previous commit 6a192c0 ("platform/x86/intel/tpmi: Fix double free reported by Smatch") incorrectly handle the deallocation of res variable. As shown in the comment, intel_vsec_add_aux handles all the deallocation of res and feature_vsec_dev. Therefore, kfree(res) can still cause double free if intel_vsec_add_aux returns error. Fix this by adjusting the error handling part in tpmi_create_device, following the function intel_vsec_add_dev. Fixes: 6a192c0 ("platform/x86/intel/tpmi: Fix double free reported by Smatch") Signed-off-by: Dongliang Mu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent da0ba0c commit 4d5a2a7

File tree

1 file changed

+5
-14
lines changed
  • drivers/platform/x86/intel

1 file changed

+5
-14
lines changed

drivers/platform/x86/intel/tpmi.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
203203
struct intel_vsec_device *feature_vsec_dev;
204204
struct resource *res, *tmp;
205205
const char *name;
206-
int ret, i;
206+
int i;
207207

208208
name = intel_tpmi_name(pfs->pfs_header.tpmi_id);
209209
if (!name)
@@ -215,8 +215,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
215215

216216
feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL);
217217
if (!feature_vsec_dev) {
218-
ret = -ENOMEM;
219-
goto free_res;
218+
kfree(res);
219+
return -ENOMEM;
220220
}
221221

222222
snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name);
@@ -242,17 +242,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
242242
* feature_vsec_dev memory is also freed as part of device
243243
* delete.
244244
*/
245-
ret = intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev,
246-
feature_vsec_dev, feature_id_name);
247-
if (ret)
248-
goto free_res;
249-
250-
return 0;
251-
252-
free_res:
253-
kfree(res);
254-
255-
return ret;
245+
return intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev,
246+
feature_vsec_dev, feature_id_name);
256247
}
257248

258249
static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info)

0 commit comments

Comments
 (0)