[PATCH] x86/kernel/cpu/resctrl: replace 'of->kn->priv' with of_rft()
From: zhouchuangao
Date: Mon Jan 04 2021 - 06:10:01 EST
The use of 'of->kn->priv' to get rftype can be found in several
places in arch/x86/kernel/cpu/resctrl/rdtgroup.c, which may reduce
readability.
So replace the direct use 'of->kn->priv' with inline function
of_rft(), which is more readable.
Signed-off-by: zhouchuangao <zhouchuangao@xxxxxxxxxx>
---
arch/x86/kernel/cpu/resctrl/internal.h | 5 +++++
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 6 +++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index ee71c47..f684b6d 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -409,6 +409,11 @@ struct rdt_membw {
u32 *mb_map;
};
+static inline struct rftype *of_rft(struct kernfs_open_file *of)
+{
+ return of->kn->priv;
+}
+
static inline bool is_llc_occupancy_enabled(void)
{
return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 29ffb95..b0ea6fc 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -222,7 +222,7 @@ static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)
static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
{
struct kernfs_open_file *of = m->private;
- struct rftype *rft = of->kn->priv;
+ struct rftype *rft = of_rft(of);
if (rft->seq_show)
return rft->seq_show(of, m, arg);
@@ -232,7 +232,7 @@ static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,
size_t nbytes, loff_t off)
{
- struct rftype *rft = of->kn->priv;
+ struct rftype *rft = of_rft(of);
if (rft->write)
return rft->write(of, buf, nbytes, off);
@@ -253,7 +253,7 @@ static const struct kernfs_ops kf_mondata_ops = {
static bool is_cpu_list(struct kernfs_open_file *of)
{
- struct rftype *rft = of->kn->priv;
+ struct rftype *rft = of_rft(of);
return rft->flags & RFTYPE_FLAGS_CPUS_LIST;
}
--
2.7.4