Skip to content

Commit 64098e7

Browse files
ShunsukeMieSasha Levin
authored andcommitted
misc: pci_endpoint_test: Aggregate params checking for xfer
commit 3e42dea upstream. 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]>
1 parent fada947 commit 64098e7

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

drivers/misc/pci_endpoint_test.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
332332
return false;
333333
}
334334

335+
static int pci_endpoint_test_validate_xfer_params(struct device *dev,
336+
struct pci_endpoint_test_xfer_param *param, size_t alignment)
337+
{
338+
if (param->size > SIZE_MAX - alignment) {
339+
dev_dbg(dev, "Maximum transfer data size exceeded\n");
340+
return -EINVAL;
341+
}
342+
343+
return 0;
344+
}
345+
335346
static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
336347
unsigned long arg)
337348
{
@@ -363,9 +374,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
363374
return false;
364375
}
365376

377+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
378+
if (err)
379+
return false;
380+
366381
size = param.size;
367-
if (size > SIZE_MAX - alignment)
368-
goto err;
369382

370383
use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
371384
if (use_dma)
@@ -497,9 +510,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test,
497510
return false;
498511
}
499512

513+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
514+
if (err)
515+
return false;
516+
500517
size = param.size;
501-
if (size > SIZE_MAX - alignment)
502-
goto err;
503518

504519
use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
505520
if (use_dma)
@@ -595,9 +610,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test,
595610
return false;
596611
}
597612

613+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
614+
if (err)
615+
return false;
616+
598617
size = param.size;
599-
if (size > SIZE_MAX - alignment)
600-
goto err;
601618

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

0 commit comments

Comments
 (0)