* [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap()
@ 2024-07-31 23:31 Frank Li
2024-08-01 7:27 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-07-31 23:31 UTC (permalink / raw)
To: Arnd Bergmann, Jason Gunthorpe, Niklas Schnelle, Andrew Morton,
Alexei Starovoitov, Kent Overstreet, open list
Cc: imx
Add DEFINE_FREE for iounmap() and memunmap() to support scope based
cleanup.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
include/linux/io.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/io.h b/include/linux/io.h
index 59ec5eea696c4..7695d7973c8ff 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -163,6 +163,9 @@ enum {
void *memremap(resource_size_t offset, size_t size, unsigned long flags);
void memunmap(void *addr);
+DEFINE_FREE(iounmap, void __iomem *, if (!IS_ERR_OR_NULL(_T)) iounmap(_T))
+DEFINE_FREE(memunmap, void *, if (!IS_ERR_OR_NULL(_T)) memunmap(_T))
+
/*
* On x86 PAT systems we have memory tracking that keeps track of
* the allowed mappings on memory ranges. This tracking works for
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap()
2024-07-31 23:31 [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap() Frank Li
@ 2024-08-01 7:27 ` Arnd Bergmann
2024-08-01 15:15 ` Frank Li
0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2024-08-01 7:27 UTC (permalink / raw)
To: Frank Li, Jason Gunthorpe, Niklas Schnelle, Andrew Morton,
Alexei Starovoitov, Kent Overstreet, open list
Cc: imx
On Thu, Aug 1, 2024, at 01:31, Frank Li wrote:
> Add DEFINE_FREE for iounmap() and memunmap() to support scope based
> cleanup.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> include/linux/io.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/include/linux/io.h b/include/linux/io.h
> index 59ec5eea696c4..7695d7973c8ff 100644
> --- a/include/linux/io.h
> +++ b/include/linux/io.h
> @@ -163,6 +163,9 @@ enum {
> void *memremap(resource_size_t offset, size_t size, unsigned long flags);
> void memunmap(void *addr);
>
> +DEFINE_FREE(iounmap, void __iomem *, if (!IS_ERR_OR_NULL(_T)) iounmap(_T))
> +DEFINE_FREE(memunmap, void *, if (!IS_ERR_OR_NULL(_T)) memunmap(_T))
I don't like the use of IS_ERR_OR_NULL(), which tends
to indicate a problem in the interface design.
In which cases do you expect to need scope based cleanup
on an error pointer here? The only interfaces I see that
returns an __iomem error pointer are the devm_* ones, but
those have their own cleanup method.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap()
2024-08-01 7:27 ` Arnd Bergmann
@ 2024-08-01 15:15 ` Frank Li
2024-08-02 8:07 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-08-01 15:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jason Gunthorpe, Niklas Schnelle, Andrew Morton,
Alexei Starovoitov, Kent Overstreet, open list, imx
On Thu, Aug 01, 2024 at 09:27:40AM +0200, Arnd Bergmann wrote:
> On Thu, Aug 1, 2024, at 01:31, Frank Li wrote:
> > Add DEFINE_FREE for iounmap() and memunmap() to support scope based
> > cleanup.
> >
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> > include/linux/io.h | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/include/linux/io.h b/include/linux/io.h
> > index 59ec5eea696c4..7695d7973c8ff 100644
> > --- a/include/linux/io.h
> > +++ b/include/linux/io.h
> > @@ -163,6 +163,9 @@ enum {
> > void *memremap(resource_size_t offset, size_t size, unsigned long flags);
> > void memunmap(void *addr);
> >
> > +DEFINE_FREE(iounmap, void __iomem *, if (!IS_ERR_OR_NULL(_T)) iounmap(_T))
> > +DEFINE_FREE(memunmap, void *, if (!IS_ERR_OR_NULL(_T)) memunmap(_T))
>
> I don't like the use of IS_ERR_OR_NULL(), which tends
> to indicate a problem in the interface design.
Just !(_T) ? I just refer kfree()'s implementation.
>
> In which cases do you expect to need scope based cleanup
> on an error pointer here? The only interfaces I see that
> returns an __iomem error pointer are the devm_* ones, but
> those have their own cleanup method.
devm_* can help much especial in probe() function. but scope base cleanup
also useful.
Give a existed example:
drivers/clocksource/timer-fsl-ftm.c
static int __init ftm_timer_init(struct device_node *np) {
...
priv->clksrc_base = of_iomap(np, 1);
if (!priv->clksrc_base) {
pr_err("ftm: unable to map source timer registers\n");
goto err_clksrc;
}
...
err_clksrc:
iounmap(priv->clkevt_base);
}
If use scoped base cleanup it will be simple.
ftm_timer_init()
{
base __free(ioumap) = of_iomap(np, 1);
...
priv->clksrc_base = no_free_ptr(base);
return 0;
}
drivers/clocksource/arm_arch_timer.c
Some example need map and unmap in function such as:
arch_timer_mem_frame_get_cntfrq()
{
base = ioremap(frame->cntbase, frame->size);
...
iounmap(base);
}
of course this example is too simple. If there are many error branch
between ioremap() and iounmap(), scoped based clean up make code simple.
Frank
>
> Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap()
2024-08-01 15:15 ` Frank Li
@ 2024-08-02 8:07 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2024-08-02 8:07 UTC (permalink / raw)
To: Frank Li
Cc: Jason Gunthorpe, Niklas Schnelle, Andrew Morton,
Alexei Starovoitov, Kent Overstreet, open list, imx
On Thu, Aug 1, 2024, at 17:15, Frank Li wrote:
> On Thu, Aug 01, 2024 at 09:27:40AM +0200, Arnd Bergmann wrote:
>> On Thu, Aug 1, 2024, at 01:31, Frank Li wrote:
>> > diff --git a/include/linux/io.h b/include/linux/io.h
>> > index 59ec5eea696c4..7695d7973c8ff 100644
>> > --- a/include/linux/io.h
>> > +++ b/include/linux/io.h
>> > @@ -163,6 +163,9 @@ enum {
>> > void *memremap(resource_size_t offset, size_t size, unsigned long flags);
>> > void memunmap(void *addr);
>> >
>> > +DEFINE_FREE(iounmap, void __iomem *, if (!IS_ERR_OR_NULL(_T)) iounmap(_T))
>> > +DEFINE_FREE(memunmap, void *, if (!IS_ERR_OR_NULL(_T)) memunmap(_T))
>>
>> I don't like the use of IS_ERR_OR_NULL(), which tends
>> to indicate a problem in the interface design.
>
> Just !(_T) ? I just refer kfree()'s implementation.
Right, I think !(_T) is what we want here. I did see that kfree
has the same construct you are adding here, but did not read
up on how it got there.
>> In which cases do you expect to need scope based cleanup
>> on an error pointer here? The only interfaces I see that
>> returns an __iomem error pointer are the devm_* ones, but
>> those have their own cleanup method.
>
>
> devm_* can help much especial in probe() function. but scope base cleanup
> also useful.
Yes, that's fine. My only point here is that you can't combine
the cleanup function you added with devm_ioremap(), as that needs
to be paired with either implicit cleanup or with devm_iounmap() but
not plain iounmap().
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-02 8:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-31 23:31 [PATCH 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap() Frank Li
2024-08-01 7:27 ` Arnd Bergmann
2024-08-01 15:15 ` Frank Li
2024-08-02 8:07 ` Arnd Bergmann
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®