Unverified Commit 1cc2c113 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!11271 roh/core: Avoid null pointer access and optimize code.

Merge Pull Request from: @laodazhao 
 
Fix the exception handling process in the ROH during register sysfs
process, which may cause memory leak.
In this patch, we change the resourse free process and optimize
code to fix this issue;

bugzilla: https://gitee.com/openeuler/kernel/issues/IANDYO 
 
Link:https://gitee.com/openeuler/kernel/pulls/11271

 

Reviewed-by: default avatarKe Chen <chenke54@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parents 917b3f44 01ed9d99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -617,7 +617,7 @@ int roh_device_set_eid(struct roh_device *device, struct roh_eid_attr *attr)
		return ret;
	}

	device->eid = *attr;
	memcpy(&device->eid, attr, sizeof(device->eid));
	ret = roh_set_mac_by_eid(device, attr);
	mutex_unlock(&device->eid_mutex);

+6 −2
Original line number Diff line number Diff line
@@ -159,7 +159,9 @@ static struct attribute *alloc_hsa(const char *name,
static void free_hw_stats(struct roh_device *device)
{
	kfree(device->hw_private_stats);
	device->hw_private_stats = NULL;
	kfree(device->hw_public_stats);
	device->hw_public_stats = NULL;
}

static int alloc_and_get_hw_stats(struct roh_device *device)
@@ -203,7 +205,8 @@ static int alloc_and_get_hw_stats(struct roh_device *device)
	return 0;

err:
	free_hw_stats(device);
	kfree(privite_stats);
	kfree(public_stats);

	return ret;
}
@@ -309,7 +312,8 @@ int roh_device_register_sysfs(struct roh_device *device)

	return 0;
err:
	remove_device_sysfs(device);
	for (i = i - 1; i >= 0; i--)
		device_remove_file(&device->dev, roh_class_attr[i]);
	return ret;
}

+0 −2
Original line number Diff line number Diff line
@@ -536,8 +536,6 @@ static void hns3_roh_dfx_uninit(struct hns3_roh_device *hroh_dev)
static void hns3_roh_dfx_register_debugfs(const char *dir_name)
{
	hns3_roh_dfx_root = debugfs_create_dir(dir_name, NULL);
	if (IS_ERR_OR_NULL(hns3_roh_dfx_root))
		return;
}

static void hns3_roh_dfx_unregister_debugfs(void)