Skip to content

Commit

Permalink
mailbox: mailbox-test: fix null pointer if no mmio
Browse files Browse the repository at this point in the history
Fix null pointer issue if resource_size is called with no ioresource.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Fabien Dessenne <fabien.dessenne@st.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
  • Loading branch information
Fabien Dessenne authored and JassiBrar committed Mar 7, 2019
1 parent 10cfc5a commit 6899b4f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/mailbox/mailbox-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,24 @@ static int mbox_test_probe(struct platform_device *pdev)

/* It's okay for MMIO to be NULL */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
size = resource_size(res);
tdev->tx_mmio = devm_ioremap_resource(&pdev->dev, res);
if (PTR_ERR(tdev->tx_mmio) == -EBUSY)
if (PTR_ERR(tdev->tx_mmio) == -EBUSY) {
/* if reserved area in SRAM, try just ioremap */
size = resource_size(res);
tdev->tx_mmio = devm_ioremap(&pdev->dev, res->start, size);
else if (IS_ERR(tdev->tx_mmio))
} else if (IS_ERR(tdev->tx_mmio)) {
tdev->tx_mmio = NULL;
}

/* If specified, second reg entry is Rx MMIO */
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
size = resource_size(res);
tdev->rx_mmio = devm_ioremap_resource(&pdev->dev, res);
if (PTR_ERR(tdev->rx_mmio) == -EBUSY)
if (PTR_ERR(tdev->rx_mmio) == -EBUSY) {
size = resource_size(res);
tdev->rx_mmio = devm_ioremap(&pdev->dev, res->start, size);
else if (IS_ERR(tdev->rx_mmio))
} else if (IS_ERR(tdev->rx_mmio)) {
tdev->rx_mmio = tdev->tx_mmio;
}

tdev->tx_channel = mbox_test_request_channel(pdev, "tx");
tdev->rx_channel = mbox_test_request_channel(pdev, "rx");
Expand Down

0 comments on commit 6899b4f

Please sign in to comment.