misc: pci_endpoint_test: Aggregate params checking for xfer
JIRA: https://issues.redhat.com/browse/RHEL-59033 Upstream Status: 3e42deaac06567c7e86d287c305ccda24db4ae3d commit 3e42deaac06567c7e86d287c305ccda24db4ae3d Author: Shunsuke Mie <mie@igel.co.jp> Date: Wed Sep 7 11:00:59 2022 +0900 misc: pci_endpoint_test: Aggregate params checking for xfer Each transfer test functions have same parameter checking code. This patch unites those to an introduced function. Signed-off-by: Shunsuke 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Myron Stowe <mstowe@redhat.com>
This commit is contained in:
parent
13958f32d7
commit
902c7f0004
|
@ -337,6 +337,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
|
|||
return pci_irq_vector(pdev, msi_num - 1) == test->last_irq;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -368,9 +379,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
|
|||
return false;
|
||||
}
|
||||
|
||||
err = pci_endpoint_test_validate_xfer_params(dev, ¶m, 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)
|
||||
|
@ -502,9 +515,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test,
|
|||
return false;
|
||||
}
|
||||
|
||||
err = pci_endpoint_test_validate_xfer_params(dev, ¶m, 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)
|
||||
|
@ -600,9 +615,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test,
|
|||
return false;
|
||||
}
|
||||
|
||||
err = pci_endpoint_test_validate_xfer_params(dev, ¶m, 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)
|
||||
|
|
Loading…
Reference in New Issue