Commit 1cedc186 authored by Shunsuke Mie's avatar Shunsuke Mie Committed by Jialin Zhang
Browse files

misc: pci_endpoint_test: Aggregate params checking for xfer

stable inclusion
from stable-v5.10.148
commit 40a29e58f6394963829bb1a26ff3bc9ef6c3aae5
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6D0WL

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



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

commit 3e42deaa upstream.

Each transfer test functions have same parameter checking code. This patch
unites those to an introduced function.

Signed-off-by: default avatarShunsuke Mie <mie@igel.co.jp>
Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/20220907020100.122588-1-mie@igel.co.jp


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
Reviewed-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d7d926cd
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -331,6 +331,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
	return false;
}

static int pci_endpoint_test_validate_xfer_params(struct device *dev,
		struct pci_endpoint_test_xfer_param *param, size_t alignment)
{
	if (param->size > SIZE_MAX - alignment) {
		dev_dbg(dev, "Maximum transfer data size exceeded\n");
		return -EINVAL;
	}

	return 0;
}

static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
				   unsigned long arg)
{
@@ -362,9 +373,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
		return false;
	}

	err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
	if (err)
		return false;

	size = param.size;
	if (size > SIZE_MAX - alignment)
		goto err;

	use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
	if (use_dma)
@@ -496,9 +509,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test,
		return false;
	}

	err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
	if (err)
		return false;

	size = param.size;
	if (size > SIZE_MAX - alignment)
		goto err;

	use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
	if (use_dma)
@@ -594,9 +609,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test,
		return false;
	}

	err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
	if (err)
		return false;

	size = param.size;
	if (size > SIZE_MAX - alignment)
		goto err;

	use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
	if (use_dma)