From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-renesas-soc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Jassi Brar <jassisinghbrar@gmail.com>
Subject: Re: [PATCH v3] mailbox: test: really ignore optional memory resources
Date: Tue, 3 Mar 2026 22:29:44 +0100 [thread overview]
Message-ID: <aadSyJduOzrzRV8-@shikoro> (raw)
In-Reply-To: <20260303212738.12769-2-wsa+renesas@sang-engineering.com>
[-- Attachment #1: Type: text/plain, Size: 3179 bytes --]
On Tue, Mar 03, 2026 at 10:27:39PM +0100, Wolfram Sang 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>
> ---
Changes since v2:
* refactored mbox_test_ioremap() to have multiple exits which makes the
logic easier to understand IMHO (Thanks, Geert, for the suggestions!)
> 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 cfd5429df17e..df53d918d9fa 100644
> --- a/drivers/mailbox/mailbox-test.c
> +++ b/drivers/mailbox/mailbox-test.c
> @@ -356,11 +356,27 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name)
> return channel;
> }
>
> +static void *mbox_test_ioremap(struct platform_device *pdev, unsigned int res_num)
> +{
> + struct resource *res;
> + void *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);
> @@ -368,23 +384,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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-03-03 21:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 21:27 Wolfram Sang
2026-03-03 21:29 ` Wolfram Sang [this message]
2026-03-05 18:59 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aadSyJduOzrzRV8-@shikoro \
--to=wsa+renesas@sang-engineering.com \
--cc=jassisinghbrar@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®