Introduce a helper to add an offset to the resource. This is helpful
in the cases when, for example) the resource has statically defined
the start and end fields, but the base of it is yet to be defined,
usually dynamically at run-time.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/ioport.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index e8b2d6aa4013..159e74284d0b 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -290,6 +290,12 @@ static inline resource_size_t resource_size(const struct resource *res)
{
return res->end - res->start + 1;
}
+
+static inline void resource_rebase(struct resource *res, resource_size_t start)
+{
+ resource_set_range(res, start + res->start, resource_size(res));
+}
+
static inline unsigned long resource_type(const struct resource *res)
{
return res->flags & IORESOURCE_TYPE_BITS;
--
2.50.1
On Wed, 3 Sep 2025, Andy Shevchenko wrote: > Introduce a helper to add an offset to the resource. This is helpful > in the cases when, for example) the resource has statically defined > the start and end fields, but the base of it is yet to be defined, > usually dynamically at run-time. > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > --- > include/linux/ioport.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > index e8b2d6aa4013..159e74284d0b 100644 > --- a/include/linux/ioport.h > +++ b/include/linux/ioport.h > @@ -290,6 +290,12 @@ static inline resource_size_t resource_size(const struct resource *res) > { > return res->end - res->start + 1; > } > + > +static inline void resource_rebase(struct resource *res, resource_size_t start) > +{ > + resource_set_range(res, start + res->start, resource_size(res)); > +} Hi Andy, This seems fine, it's nice to get rid of complex ->end calculations. But I wanted to mention another common case which is resetting the base to zero. Are we expected to use resource_rebase() for those cases too? I've been thinking of adding something like resource_reset(). resource_rebase(res, 0) would work for those cases but it doesn't then carry the intent of "removing" the base in its name. Opinions? -- i.
On Wed, Sep 03, 2025 at 03:29:00PM +0300, Ilpo Järvinen wrote: > On Wed, 3 Sep 2025, Andy Shevchenko wrote: ... > > +static inline void resource_rebase(struct resource *res, resource_size_t start) > > +{ > > + resource_set_range(res, start + res->start, resource_size(res)); > > +} > > This seems fine, it's nice to get rid of complex ->end calculations. But I > wanted to mention another common case which is resetting the base to zero. > Are we expected to use resource_rebase() for those cases too? I've been > thinking of adding something like resource_reset(). > > resource_rebase(res, 0) would work for those cases but it doesn't then > carry the intent of "removing" the base in its name. Opinions? Another case I have just realised is repeated "rebase" over the statically global resource (when driver is in but device is bind-unbind-and-repeat). Perhaps rebase has to be idempotent. That will do exactly, if I'm not mistaken, what you are telling as a _reset() by default. -- With Best Regards, Andy Shevchenko
© 2016 - 2025 Red Hat, Inc.