Commit 09a17c4b authored by Yongzhi Liu's avatar Yongzhi Liu Committed by Ma Wupeng
Browse files

net: pds_core: Fix possible double free in error handling path

stable inclusion
from stable-v6.6.22
commit 995f802abff209514ac2ee03b96224237646cec3
bugzilla: https://gitee.com/openeuler/kernel/issues/I99TJK

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=995f802abff209514ac2ee03b96224237646cec3



--------------------------------

[ Upstream commit ba18deddd6d502da71fd6b6143c53042271b82bd ]

When auxiliary_device_add() returns error and then calls
auxiliary_device_uninit(), Callback function pdsc_auxbus_dev_release
calls kfree(padev) to free memory. We shouldn't call kfree(padev)
again in the error handling path.

Fix this by cleaning up the redundant kfree() and putting
the error handling back to where the errors happened.

Fixes: 4569cce4 ("pds_core: add auxiliary_bus devices")
Signed-off-by: default avatarYongzhi Liu <hyperlyzcs@gmail.com>
Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Reviewed-by: default avatarShannon Nelson <shannon.nelson@amd.com>
Link: https://lore.kernel.org/r/20240306105714.20597-1-hyperlyzcs@gmail.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent 79d1257e
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -160,23 +160,19 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
	if (err < 0) {
		dev_warn(cf->dev, "auxiliary_device_init of %s failed: %pe\n",
			 name, ERR_PTR(err));
		goto err_out;
		kfree(padev);
		return ERR_PTR(err);
	}

	err = auxiliary_device_add(aux_dev);
	if (err) {
		dev_warn(cf->dev, "auxiliary_device_add of %s failed: %pe\n",
			 name, ERR_PTR(err));
		goto err_out_uninit;
		auxiliary_device_uninit(aux_dev);
		return ERR_PTR(err);
	}

	return padev;

err_out_uninit:
	auxiliary_device_uninit(aux_dev);
err_out:
	kfree(padev);
	return ERR_PTR(err);
}

int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)