1 | // SPDX-License-Identifier: GPL-2.0 |
---|---|
2 | /* |
3 | * Common Primitives for DAMON Modules |
4 | * |
5 | * Author: SeongJae Park <sj@kernel.org> |
6 | */ |
7 | |
8 | #include <linux/damon.h> |
9 | |
10 | #include "modules-common.h" |
11 | |
12 | /* |
13 | * Allocate, set, and return a DAMON context for the physical address space. |
14 | * @ctxp: Pointer to save the point to the newly created context |
15 | * @targetp: Pointer to save the point to the newly created target |
16 | */ |
17 | int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, |
18 | struct damon_target **targetp) |
19 | { |
20 | struct damon_ctx *ctx; |
21 | struct damon_target *target; |
22 | |
23 | ctx = damon_new_ctx(); |
24 | if (!ctx) |
25 | return -ENOMEM; |
26 | |
27 | if (damon_select_ops(ctx, id: DAMON_OPS_PADDR)) { |
28 | damon_destroy_ctx(ctx); |
29 | return -EINVAL; |
30 | } |
31 | |
32 | target = damon_new_target(); |
33 | if (!target) { |
34 | damon_destroy_ctx(ctx); |
35 | return -ENOMEM; |
36 | } |
37 | damon_add_target(ctx, t: target); |
38 | |
39 | *ctxp = ctx; |
40 | *targetp = target; |
41 | return 0; |
42 | } |
43 |