staging: vme_user: added bound check to geoid
PATCH 1/1 staging: vme_user: added bound check to geoid
Added bound check for geoid in probe function because geoid will always be positive and less than VME_MAX_SLOTS
Signed-off-by Riyan Dhiman <[email protected]>
--- drivers/staging/vme_user/vme_fake.c | 7 +++++++ drivers/staging/vme_user/vme_tsi148.c | 7 +++++++ 2 files changed, 14 insertions(+)
drivers/staging/vme_user/vme_fake.c +7 -0
@@ -1059,6 +1059,13 @@ static int __init fake_init(void)struct vme_slave_resource *slave_image;struct vme_lm_resource *lm; +/* If geoid provided, validate it is positive and less than VME_MAX_SLOTS */ +if ((geoid) && (geoid <0 || geoid >=VME_MAX_SLOTS )) { +pr_err ("VME geographical address must be between 0 and %d (exclusive), but got %d\n" , +VME_MAX_SLOTS , geoid); +return -EINVAL ; + } +/* We need a fake parent device */ vme_root =root_device_register ("vme" );if (IS_ERR (vme_root))
drivers/staging/vme_user/vme_tsi148.c +7 -0
@@ -2252,6 +2252,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)struct vme_dma_resource *dma_ctrlr;struct vme_lm_resource *lm; +/* If geoid provided, validate it is positive and less than VME_MAX_SLOTS */ +if ((geoid) && (geoid <0 || geoid >=VME_MAX_SLOTS )) { +pr_err ("VME geographical address must be between 0 and %d (exclusive), but got %d\n" , +VME_MAX_SLOTS , geoid); +return -EINVAL ; + } +/* If we want to support more than one of each bridge, we need to * dynamically generate this so we get one per device */
Signature · 1 line
2.46.0
drivers/staging/vme_user/vme_fake.c static int __init fake_init(void) · line 1063
Quoted 10 lines · Riyan Dhiman
drivers/staging/vme_user/vme_fake.c +2
-0@@ -1059,6 +1059,13 @@ static int __init fake_init(void)struct vme_slave_resource *slave_image;struct vme_lm_resource *lm; +/* If geoid provided, validate it is positive and less than VME_MAX_SLOTS */ +if ((geoid) && (geoid <0 || geoid >=VME_MAX_SLOTS )) {
^^^^^^^
Too many parentheses, but really there is no need for this. Just write:
if (geoid < 0 || geoid >= VME_MAX_SLOTS) {Quoted 13 lines
drivers/staging/vme_user/vme_fake.c +5
-0+pr_err ("VME geographical address must be between 0 and %d (exclusive), but got %d\n" , +VME_MAX_SLOTS , geoid); +return -EINVAL ; + } +/* We need a fake parent device */ vme_root =root_device_register ("vme" );if (IS_ERR (vme_root))drivers/staging/vme_user/vme_tsi148.c +0
-0
drivers/staging/vme_user/vme_tsi148.c static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 2258
Quoted 7 lines
drivers/staging/vme_user/vme_tsi148.c +4
-0@@ -2252,6 +2252,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)struct vme_dma_resource *dma_ctrlr;struct vme_lm_resource *lm; +/* If geoid provided, validate it is positive and less than VME_MAX_SLOTS */ +if ((geoid) && (geoid <0 || geoid >=VME_MAX_SLOTS )) { +pr_err ("VME geographical address must be between 0 and %d (exclusive), but got %d\n" , +VME_MAX_SLOTS , geoid);
Here you have a device pointer so can use dev_err(&pdev->dev, ... instead of pr_err().
regards,
dan carpenter
Quoted 2 lines
drivers/staging/vme_user/vme_tsi148.c +2
-0+return -EINVAL ; + }