@@ -616,6 +616,17 @@ static bool index_to_params(u64 id, struct coproc_params *params)
}
}
+const struct coproc_reg *
+find_coproc_reg_by_id(u64 id, struct coproc_params *params,
+ const struct coproc_reg table[],
+ unsigned int num)
+{
+ if (!index_to_params(id, params))
+ return NULL;
+
+ return find_reg(params, table, num);
+}
+
/* Decode an index value, and find the cp15 coproc_reg entry. */
static const struct coproc_reg *index_to_coproc_reg(struct kvm_vcpu *vcpu,
u64 id)
@@ -742,10 +753,8 @@ static int get_invariant_cp15(u64 id, void __user *uaddr)
const struct coproc_reg *r;
int ret;
- if (!index_to_params(id, ¶ms))
- return -ENOENT;
-
- r = find_reg(¶ms, invariant_cp15, ARRAY_SIZE(invariant_cp15));
+ r = find_coproc_reg_by_id(id, ¶ms, invariant_cp15,
+ ARRAY_SIZE(invariant_cp15));
if (!r)
return -ENOENT;
@@ -767,9 +776,8 @@ static int set_invariant_cp15(u64 id, void __user *uaddr)
int err;
u64 val;
- if (!index_to_params(id, ¶ms))
- return -ENOENT;
- r = find_reg(¶ms, invariant_cp15, ARRAY_SIZE(invariant_cp15));
+ r = find_coproc_reg_by_id(id, ¶ms, invariant_cp15,
+ ARRAY_SIZE(invariant_cp15));
if (!r)
return -ENOENT;
@@ -157,4 +157,8 @@ bool access_vm_reg(struct kvm_vcpu *vcpu,
struct coproc_params *p,
const struct coproc_reg *r);
+const struct coproc_reg *
+find_coproc_reg_by_id(u64 id, struct coproc_params *params,
+ const struct coproc_reg table[],
+ unsigned int num);
#endif /* __ARM_KVM_COPROC_LOCAL_H__ */