Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 775b057

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 473e488 commit 775b057

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
@@ -331,6 +331,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
331331
return false;
332332
}
333333

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

376+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
377+
if (err)
378+
return false;
379+
365380
size = param.size;
366-
if (size > SIZE_MAX - alignment)
367-
goto err;
368381

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

512+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
513+
if (err)
514+
return false;
515+
499516
size = param.size;
500-
if (size > SIZE_MAX - alignment)
501-
goto err;
502517

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

612+
err = pci_endpoint_test_validate_xfer_params(dev, &param, alignment);
613+
if (err)
614+
return false;
615+
597616
size = param.size;
598-
if (size > SIZE_MAX - alignment)
599-
goto err;
600617

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

0 commit comments

Comments
 (0)