KNOWN CMD");
	}
}

static bool handle_install_package_init(struct hwaa_install_package_t *kdata,
	struct hwaa_install_package_t *kdata_store)
{
	if (memset_s(kdata, sizeof(struct hwaa_install_package_t), 0,
		sizeof(struct hwaa_install_package_t))!= EOK)
		return false;
	if (memset_s(kdata_store, sizeof(struct hwaa_install_package_t), 0,
		sizeof(struct hwaa_install_package_t))!= EOK)
		return false;
	return true;
}

static s32 handle_install_package(struct hwaa_install_package_t __user *udata)
{
	s32 ret = 0;

	struct hwaa_install_package_t kdata;
	struct hwaa_install_package_t kdata_store_addr;

	if (!udata)
		return -EINVAL;

	if (!handle_install_package_init(&kdata, &kdata_store_addr))
		return -EINVAL;

	if (copy_from_user(&kdata, udata, sizeof(struct hwaa_install_package_t))
	    || copy_from_user(&kdata_store_addr, udata,
	    sizeof(struct hwaa_install_package_t))) {
		hwaa_pr_err("Failed while copying from user space!");
		ret = -EFAULT;
		kdata.ret = HWAA_ERR_INTERNAL;
		goto do_copy_ret;
	}

	if (hwaa_utils_copy_package_info_from_user(&kdata.pinfo,
		&kdata_store_addr.pinfo, true)) {
		ret = -EINVAL;
		kdata.ret = HWAA_ERR_INVALID_ARGS;
		goto do_copy_ret;
	}

	hwaa_install_package(&kdata);
	hwaa_utils_free_package_info(&kdata.pinfo);

do_copy_ret:
	if (copy_to_user(&udata->ret, &kdata.ret, sizeof(hwaa_result_t))) {
		hwaa_pr_err("Failed while copying to user space!");
		if (!ret)
			ret = -EFAULT;
	}

	return ret;
}

static bool handle_uninstall_package_init(struct hwaa_uninstall_package_t *kdata,
	struct hwaa_uninstall_package_t *kdata_store)
{
	if (memset_s(kdata, sizeof(struct hwaa_uninstall_package_t), 0,
		sizeof(struct hwaa_uninstall_package_t))!= EOK)
		return false;
	if (memset_s(kdata_store, sizeof(struct hwaa_uninstall_package_t), 0,
		sizeof(struct hwaa_uninstall_package_t))!= EOK)
		return false;
	return true;
}

static s32 handle_uninstall_package(
	struct hwaa_uninstall_package_t __user *udata)
{
	s32 ret = 0;
	struct hwaa_uninstall_package_t kdata;
	struct hwaa_uninstall_package_t kdata_store_addr;

	if (!udata)
		return -EINVAL;
	if (!handle_uninstall_package_init(&kdata, &kdata_store_addr))
		return -EINVAL;
	if (copy_from_user(&kdata, udata,
		sizeof(struct hwaa_uninstall_package_t)) ||
		copy_from_user(&kdata_store_addr, udata,
		sizeof(struct hwaa_uninstall_package_t))) {
		hwaa_pr_err("Failed while copying from user space!");
		ret = -EFAULT;
		kdata.ret = HWAA_ERR_INTERNAL;
		goto do_copy_ret;
	}
	if (hwaa_utils_copy_package_info_from_user(&kdata.pinfo,
		&kdata_store_addr.pinfo, false)) {
		ret = -EINVAL;
		kdata.ret = HWAA_ERR_INVALID_ARGS;
		goto do_copy_ret;
	}

	hwaa_uninstall_package(&kdata);
	hwaa_utils_free_package_info(&kdata.pinfo);
do_copy_ret:
	if (copy_to_user(&udata->ret, &kdata.ret, sizeof(hwaa_result_t))) {
		hwaa_pr_err("Failed while copying to user space!");
		if (!ret)
			ret = -EFAULT;
	}

	return ret;
}

static void free_kdata_packages(struct hwaa_sync_installed_packages_t *kdata)
{
	s32 i;
	if (kdata->packages) {
		for (i = 0; i < kdata->package_count; i++)
			hwaa_utils_free_package_info(&kdata->packages[i]);
		kfree(kdata->packages);
	}
}

static s32 copy_sync_pkgs_level1(struct hwaa_sync_installed_packages_t *kdata,
	struct hwaa_sync_installed_packages_t __user *udata,
	struct hwaa_package_info_t **packages_user_addr)
{
	s32 ret = 0;

	if (memset_s(kdata, sizeof(*kdata), 0, sizeof(*kdata))!= EOK) {
		kdata->ret = HWAA_ERR_INTERNAL;
		kdata->package_count = 0;
		ret = -EFAULT;
		goto out;
	}
	if (copy_from_user(kdata, udata,
		sizeof(struct hwaa_sync_installed_packages_t))) {
		hwaa_pr_err("Failed while copying from user space!");
		kdata->ret = HWAA_ERR_INTERNAL;
		kdata->package_count = 0;
		ret = -EFAULT;
		goto out;
	}
	if ((kdata->package_count <= 0) ||
		(kdata->package_count > SYNC_PKG_CNT_MAX)) {
		kdata->ret = HWAA_ERR_INVALID_ARGS;
		kdata->package_count = 0;
		ret = -EFAULT;
		goto out;
	}
	*packages_user_addr = kdata->packages;
out:
	kdata->packages = NULL;
	return ret;
}

static s32 copy_sync_pkgs_level2(
	struct hwaa_package_info_t **packages_transform,
	struct hwaa_package_info_t *packages_user_addr,
	struct hwaa_sync_installed_packages_t *kdata)
{
	*packages_transform = kcalloc(kdata->package_count,
		sizeof(struct hwaa_package_info_t), GFP_KERNEL);// outside free
	if (!(*packages_transform)) {
		kdata->ret = HWAA_ERR_INVALID_ARGS;
		kdata->package_count = 0;
		return -ENOMEM;
	}
	if (copy_from_user(*packages_transform, packages_user_addr,
		sizeof(struct hwaa_package_info_t) * kdata->package_count)) {
		hwaa_pr_err("Failed while copying addr_pkgs from user space!");
		kdata->ret = HWAA_ERR_INVALID_ARGS;
		kdata->package_count = 0;
		return -EFAULT;
	}
	return 0;
}

static s32 copy_sync_pkgs_level3(struct hwaa_sync_installed_packages_t *kdata,
	struct hwaa_package_info_t *packages_transform)
{
	s32 ret;

	kdata->packages = kcalloc(kdata->package_count,
		sizeof(struct hwaa_package_info_t),GFP_KERNEL);
	if (!kdata->packages) {
		kdata->ret = HWAA_ERR_NO_MEMORY;
		kdata->package_count = 0;
		return -ENOMEM;
	}
	ret = hwaa_utils_copy_packages_from_user(kdata->packages,
		packages_transform, kdata->package_count);
	if (ret!= 0) {
		if (ret == -ENOMEM)
			