[RFC PATCH v4 01/13] ptrace: Use regset_size() for dynamic regset size.

From: Greentime Hu
Date: Tue May 26 2020 - 03:02:54 EST


It uses regset_size() instead of using regset->n and regset->size directly.
In this case, it will call the get_size() ported by arch dynamically to
support dynamic regset size case.

Signed-off-by: Greentime Hu <greentime.hu@xxxxxxxxxx>
---
kernel/ptrace.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 43d6179508d6..6877105e1b1e 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -882,13 +882,18 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
const struct user_regset_view *view = task_user_regset_view(task);
const struct user_regset *regset = find_regset(view, type);
int regset_no;
+ unsigned int size;

- if (!regset || (kiov->iov_len % regset->size) != 0)
+ if (!regset)
return -EINVAL;

regset_no = regset - view->regsets;
- kiov->iov_len = min(kiov->iov_len,
- (__kernel_size_t) (regset->n * regset->size));
+ size = regset_size(task, regset);
+
+ if ((kiov->iov_len % size) != 0)
+ return -EINVAL;
+
+ kiov->iov_len = min(kiov->iov_len, (__kernel_size_t) size);

if (req == PTRACE_GETREGSET)
return copy_regset_to_user(task, view, regset_no, 0,
--
2.26.2