[PATCH v5] mailbox: test: really ignore optional memory resources

Wolfram Sang posted 1 patch 5 days, 22 hours ago
drivers/mailbox/mailbox-test.c | 37 +++++++++++++++++++---------------
1 file changed, 21 insertions(+), 16 deletions(-)
[PATCH v5] mailbox: test: really ignore optional memory resources
Posted by Wolfram Sang 5 days, 22 hours ago
Memory resources are optional but if the resource is empty
devm_platform_get_and_ioremap_resource() prints an error nonetheless.
Refactor the code to check the resources locally first and process them
only if they are present. The -EBUSY error message of ioremap_resource()
is still kept because it is correct. The comment which explains that a
plain ioremap() is tried as a workaround is turned into a info message.
So, a user will be informed about it, too.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---

Changes since v4:
* rebased to 7.0-rc5
* add tag (Thanks, Geert!)

 drivers/mailbox/mailbox-test.c | 37 +++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index 3a28ab5c42e5..058c0fe4b9c2 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -355,11 +355,27 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name)
 	return channel;
 }
 
+static void __iomem *mbox_test_ioremap(struct platform_device *pdev, unsigned int res_num)
+{
+	struct resource *res;
+	void __iomem *mmio;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, res_num);
+	if (!res)
+		return NULL;
+
+	mmio = devm_ioremap_resource(&pdev->dev, res);
+	if (PTR_ERR(mmio) == -EBUSY) {
+		dev_info(&pdev->dev, "trying workaround with plain ioremap\n");
+		return devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	}
+
+	return IS_ERR(mmio) ? NULL : mmio;
+}
+
 static int mbox_test_probe(struct platform_device *pdev)
 {
 	struct mbox_test_device *tdev;
-	struct resource *res;
-	resource_size_t size;
 	int ret;
 
 	tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL);
@@ -367,23 +383,12 @@ static int mbox_test_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	/* It's okay for MMIO to be NULL */
-	tdev->tx_mmio = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
-	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)) {
-		tdev->tx_mmio = NULL;
-	}
+	tdev->tx_mmio = mbox_test_ioremap(pdev, 0);
 
 	/* If specified, second reg entry is Rx MMIO */
-	tdev->rx_mmio = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
-	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)) {
+	tdev->rx_mmio = mbox_test_ioremap(pdev, 1);
+	if (!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");
-- 
2.51.0
Re: [PATCH v5] mailbox: test: really ignore optional memory resources
Posted by Jassi Brar 3 days, 21 hours ago
On Fri, Mar 27, 2026 at 10:12 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> Memory resources are optional but if the resource is empty
> devm_platform_get_and_ioremap_resource() prints an error nonetheless.
> Refactor the code to check the resources locally first and process them
> only if they are present. The -EBUSY error message of ioremap_resource()
> is still kept because it is correct. The comment which explains that a
> plain ioremap() is tried as a workaround is turned into a info message.
> So, a user will be informed about it, too.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>
> Changes since v4:
> * rebased to 7.0-rc5
> * add tag (Thanks, Geert!)
>
>  drivers/mailbox/mailbox-test.c | 37 +++++++++++++++++++---------------
>  1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
> index 3a28ab5c42e5..058c0fe4b9c2 100644
> --- a/drivers/mailbox/mailbox-test.c
> +++ b/drivers/mailbox/mailbox-test.c
> @@ -355,11 +355,27 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name)
>         return channel;
>  }
>
> +static void __iomem *mbox_test_ioremap(struct platform_device *pdev, unsigned int res_num)
> +{
> +       struct resource *res;
> +       void __iomem *mmio;
> +
> +       res = platform_get_resource(pdev, IORESOURCE_MEM, res_num);
> +       if (!res)
> +               return NULL;
> +
> +       mmio = devm_ioremap_resource(&pdev->dev, res);
> +       if (PTR_ERR(mmio) == -EBUSY) {
> +               dev_info(&pdev->dev, "trying workaround with plain ioremap\n");
> +               return devm_ioremap(&pdev->dev, res->start, resource_size(res));
> +       }
> +
> +       return IS_ERR(mmio) ? NULL : mmio;
> +}
> +
>  static int mbox_test_probe(struct platform_device *pdev)
>  {
>         struct mbox_test_device *tdev;
> -       struct resource *res;
> -       resource_size_t size;
>         int ret;
>
>         tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL);
> @@ -367,23 +383,12 @@ static int mbox_test_probe(struct platform_device *pdev)
>                 return -ENOMEM;
>
>         /* It's okay for MMIO to be NULL */
> -       tdev->tx_mmio = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> -       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)) {
> -               tdev->tx_mmio = NULL;
> -       }
> +       tdev->tx_mmio = mbox_test_ioremap(pdev, 0);
>
>         /* If specified, second reg entry is Rx MMIO */
> -       tdev->rx_mmio = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
> -       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)) {
> +       tdev->rx_mmio = mbox_test_ioremap(pdev, 1);
> +       if (!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");
> --
> 2.51.0
>
Applied to mailbox/for-next
Thanks
Jassi