projects/linux·blob master · refs

40 lines · 824 B

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