From 3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 2 Sep 2026 15:31:14 -0700 Subject: treewide: refresh kmalloc_obj() conversions This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook --- tools/perf/util/cgroup.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/perf/util/cgroup.h (limited to 'tools/perf/util/cgroup.h') diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h new file mode 100644 index 000000000..7b1bda228 --- /dev/null +++ b/tools/perf/util/cgroup.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CGROUP_H__ +#define __CGROUP_H__ + +#include +#include +#include +#include "util/env.h" + +struct option; + +struct cgroup { + struct rb_node node; + u64 id; + char *name; + int fd; + refcount_t refcnt; +}; + +extern int nr_cgroups; /* number of explicit cgroups defined */ +extern bool cgrp_event_expanded; + +struct cgroup *cgroup__get(struct cgroup *cgroup); +void cgroup__put(struct cgroup *cgroup); + +struct evlist; +struct rblist; + +struct cgroup *cgroup__new(const char *name, bool do_open); +struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name); +int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups, bool open_cgroup); + +void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup); + +int parse_cgroups(const struct option *opt, const char *str, int unset); + +struct cgroup *cgroup__findnew(struct perf_env *env, uint64_t id, + const char *path); +struct cgroup *cgroup__find(struct perf_env *env, uint64_t id); +struct cgroup *__cgroup__find(struct rb_root *root, uint64_t id); + +void perf_env__purge_cgroups(struct perf_env *env); + +#ifdef HAVE_FILE_HANDLE +int read_cgroup_id(struct cgroup *cgrp); +#else +static inline int read_cgroup_id(struct cgroup *cgrp __maybe_unused) +{ + return -1; +} +#endif /* HAVE_FILE_HANDLE */ + +/* read all cgroups in the system and save them in the rbtree */ +void read_all_cgroups(struct rb_root *root); + +int cgroup_is_v2(const char *subsys); + +#endif /* __CGROUP_H__ */ -- cgit v1.3.1