Skip to content

Commit

Permalink
misc: pci_endpoint_test: Aggregate params checking for xfer
Browse files Browse the repository at this point in the history
Each transfer test functions have same parameter checking code. This patch
unites those to an introduced function.

Signed-off-by: Shunsuke Mie <[email protected]>
Cc: stable <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ShunsukeMie authored and gregkh committed Sep 9, 2022
1 parent eb3b3c9 commit 3e42dea
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions drivers/misc/pci_endpoint_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,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)
{
Expand Down Expand Up @@ -363,9 +374,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)
Expand Down Expand Up @@ -497,9 +510,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)
Expand Down Expand Up @@ -595,9 +610,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)
Expand Down

0 comments on commit 3e42dea

Please sign in to comment.