mailbox: test: really ignore optional memory resources
PATCH v2 1/1 mailbox: test: really ignore optional memory resources
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.
---
Change since v1:
* don't fail if second region is empty but use the first region instead
* refactor into separate function for consistent handling of both regions and to make the logic in probe() more obvious
drivers/mailbox/mailbox-test.c | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-)
drivers/mailbox/mailbox-test.c +24 -16
@@ -355,11 +355,30 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name)return channel; } -static int mbox_test_probe (struct platform_device *pdev) +static void *mbox_test_ioremap (struct platform_device *pdev,unsigned int res_num) { -struct mbox_test_device *tdev;struct resource *res;resource_size_t size; +void *mmio =NULL ; + + res =platform_get_resource (pdev,IORESOURCE_MEM , res_num); +if (res) { + mmio =devm_ioremap_resource (&pdev->dev, res); +if (PTR_ERR (mmio) == -EBUSY ) { +dev_info (&pdev->dev,"trying workaround with plain ioremap\n" ); + size =resource_size (res); + mmio =devm_ioremap (&pdev->dev, res->start, size); + }else if (IS_ERR (mmio)) { + mmio =NULL ; + } + } + +return mmio; +} + +static int mbox_test_probe (struct platform_device *pdev) +{ +struct mbox_test_device *tdev;int ret; tdev =devm_kzalloc (&pdev->dev,sizeof (*tdev),GFP_KERNEL );
@@ -367,23 +386,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" );
Signature · 1 line
2.51.0
Hi Wolfram,
Quoted 9 lines · Wolfram Sang
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-EBUSYerror message ofioremap_resource()is still kept because it is correct. The comment which explains that a plainioremap()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 <[email protected]>
Thanks for your patch!
Quoted 6 lines
drivers/mailbox/mailbox-test.c +0
-0@@ -355,11 +355,30 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name)return channel; }
drivers/mailbox/mailbox-test.c mbox_test_request_channel(struct platform_device *pdev, const char *name) · line 365
Quoted 10 lines
drivers/mailbox/mailbox-test.c +5
-2-static int mbox_test_probe (struct platform_device *pdev) +static void *mbox_test_ioremap (struct platform_device *pdev,unsigned int res_num) { -struct mbox_test_device *tdev;struct resource *res;resource_size_t size; +void *mmio =NULL ; + + res =platform_get_resource (pdev,IORESOURCE_MEM , res_num); +if (res) {
if (!res)
return NULL;
drivers/mailbox/mailbox-test.c mbox_test_request_channel(struct platform_device *pdev, const char *name) · line 369
Quoted 4 lines
drivers/mailbox/mailbox-test.c +4
-0+ mmio =devm_ioremap_resource (&pdev->dev, res); +if (PTR_ERR (mmio) == -EBUSY ) { +dev_info (&pdev->dev,"trying workaround with plain ioremap\n" ); + size =resource_size (res);
With the reduced indentation, you don't need a temporary to avoid the next line being too long.
drivers/mailbox/mailbox-test.c mbox_test_request_channel(struct platform_device *pdev, const char *name) · line 370
Quoted 1 line
drivers/mailbox/mailbox-test.c +1
-0+ mmio =devm_ioremap (&pdev->dev, res->start, size);
return devm_ioremap(...);
drivers/mailbox/mailbox-test.c mbox_test_request_channel(struct platform_device *pdev, const char *name) · line 376
Quoted 6 lines
drivers/mailbox/mailbox-test.c +6
-0+ }else if (IS_ERR (mmio)) { + mmio =NULL ; + } + } + +return mmio;
return IS_ERR(mmio) ? NULL : mmio;
drivers/mailbox/mailbox-test.c mbox_test_request_channel(struct platform_device *pdev, const char *name) · line 377
Quoted 1 line
drivers/mailbox/mailbox-test.c +1
-0+}
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
thank you for the review!
Quoted 2 lines
if (!res)
return NULL;
I applied the 'single exit' paradigm, but your solution is a bit easier to understand, I think. Will send v3 soon.
Happy hacking,
Wolfram