Commit 6a192c0c authored by Srinivas Pandruvada's avatar Srinivas Pandruvada Committed by Hans de Goede

platform/x86/intel/tpmi: Fix double free reported by Smatch

Fix warning:
drivers/platform/x86/intel/tpmi.c:253 tpmi_create_device()
	warn: 'feature_vsec_dev' was already freed.

If there is some error, feature_vsec_dev memory is freed as part
of resource managed call intel_vsec_add_aux(). So, additional
kfree() call is not required.

Reordered res allocation and feature_vsec_dev, so that on error
only res is freed.
Reported-by: default avatarDan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/platform-driver-x86/Y%2FxYR7WGiPayZu%2FR@kili/T/#u
Fixes: 47731fd2 ("platform/x86/intel: Intel TPMI enumeration driver")
Signed-off-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://lore.kernel.org/r/20230227140614.2913474-1-srinivas.pandruvada@linux.intel.comSigned-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 95ecf901
...@@ -209,14 +209,14 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, ...@@ -209,14 +209,14 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
if (!name) if (!name)
return -EOPNOTSUPP; return -EOPNOTSUPP;
feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL); res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL);
if (!feature_vsec_dev) if (!res)
return -ENOMEM; return -ENOMEM;
res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL); feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL);
if (!res) { if (!feature_vsec_dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_vsec; goto free_res;
} }
snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name); snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name);
...@@ -239,6 +239,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, ...@@ -239,6 +239,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
/* /*
* intel_vsec_add_aux() is resource managed, no explicit * intel_vsec_add_aux() is resource managed, no explicit
* delete is required on error or on module unload. * delete is required on error or on module unload.
* feature_vsec_dev memory is also freed as part of device
* delete.
*/ */
ret = intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev, ret = intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev,
feature_vsec_dev, feature_id_name); feature_vsec_dev, feature_id_name);
...@@ -249,8 +251,6 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, ...@@ -249,8 +251,6 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
free_res: free_res:
kfree(res); kfree(res);
free_vsec:
kfree(feature_vsec_dev);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment