Skip to content

Commit 9fb6fef

Browse files
ij-intelbjorn-helgaas
authored andcommitted
resource: Add resource set range and size helpers
Setting the end address for a resource with a given size lacks a helper and is therefore coded manually unlike the getter side which has a helper for resource size calculation. Also, almost all callsites that calculate the end address for a resource also set the start address right before it like this: res->start = start_addr; res->end = res->start + size - 1; Add resource_set_range(res, start_addr, size) that sets the start address and calculates the end address to simplify this often repeated fragment. Also add resource_set_size() for the cases where setting the start address of the resource is not necessary but mention in its kerneldoc that resource_set_range() is preferred when setting both addresses. Link: https://lore.kernel.org/r/20240614100606.15830-2-ilpo.jarvinen@linux.intel.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 9852d85 commit 9fb6fef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/linux/ioport.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,38 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
249249
int adjust_resource(struct resource *res, resource_size_t start,
250250
resource_size_t size);
251251
resource_size_t resource_alignment(struct resource *res);
252+
253+
/**
254+
* resource_set_size - Calculate resource end address from size and start
255+
* @res: Resource descriptor
256+
* @size: Size of the resource
257+
*
258+
* Calculate the end address for @res based on @size.
259+
*
260+
* Note: The start address of @res must be set when calling this function.
261+
* Prefer resource_set_range() if setting both the start address and @size.
262+
*/
263+
static inline void resource_set_size(struct resource *res, resource_size_t size)
264+
{
265+
res->end = res->start + size - 1;
266+
}
267+
268+
/**
269+
* resource_set_range - Set resource start and end addresses
270+
* @res: Resource descriptor
271+
* @start: Start address for the resource
272+
* @size: Size of the resource
273+
*
274+
* Set @res start address and calculate the end address based on @size.
275+
*/
276+
static inline void resource_set_range(struct resource *res,
277+
resource_size_t start,
278+
resource_size_t size)
279+
{
280+
res->start = start;
281+
resource_set_size(res, size);
282+
}
283+
252284
static inline resource_size_t resource_size(const struct resource *res)
253285
{
254286
return res->end - res->start + 1;

0 commit comments

Comments
 (0)