Skip to content

Commit 93c177f

Browse files
committed
kernel/range: Uplevel the cxl subsystem's range_contains() helper
In support of the CXL subsystem's use of 'struct range' to track decode address ranges, add a common range_contains() implementation with identical semantics as resource_contains(); The existing 'range_contains()' in lib/stackinit_kunit.c is namespaced with a 'stackinit_' prefix. Cc: Kees Cook <[email protected]> Reviewed-by: Vishal Verma <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Gregory Price <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Tested-by: Fan Ni <[email protected]> Link: https://lore.kernel.org/r/167601998163.1924368.6067392174077323935.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 9995576 commit 93c177f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/cxl/core/pci.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds)
214214
return devm_add_action_or_reset(host, clear_mem_enable, cxlds);
215215
}
216216

217-
static bool range_contains(struct range *r1, struct range *r2)
218-
{
219-
return r1->start <= r2->start && r1->end >= r2->end;
220-
}
221-
222217
/* require dvsec ranges to be covered by a locked platform window */
223218
static int dvsec_range_allowed(struct device *dev, void *arg)
224219
{

include/linux/range.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ static inline u64 range_len(const struct range *range)
1313
return range->end - range->start + 1;
1414
}
1515

16+
static inline bool range_contains(struct range *r1, struct range *r2)
17+
{
18+
return r1->start <= r2->start && r1->end >= r2->end;
19+
}
20+
1621
int add_range(struct range *range, int az, int nr_range,
1722
u64 start, u64 end);
1823

lib/stackinit_kunit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static volatile u8 forced_mask = 0xff;
3131
static void *fill_start, *target_start;
3232
static size_t fill_size, target_size;
3333

34-
static bool range_contains(char *haystack_start, size_t haystack_size,
35-
char *needle_start, size_t needle_size)
34+
static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,
35+
char *needle_start, size_t needle_size)
3636
{
3737
if (needle_start >= haystack_start &&
3838
needle_start + needle_size <= haystack_start + haystack_size)
@@ -175,7 +175,7 @@ static noinline void test_ ## name (struct kunit *test) \
175175
\
176176
/* Validate that compiler lined up fill and target. */ \
177177
KUNIT_ASSERT_TRUE_MSG(test, \
178-
range_contains(fill_start, fill_size, \
178+
stackinit_range_contains(fill_start, fill_size, \
179179
target_start, target_size), \
180180
"stack fill missed target!? " \
181181
"(fill %zu wide, target offset by %d)\n", \

0 commit comments

Comments
 (0)