s390/zcrypt: split ioctl function into smaller code units

The zcrpyt_unlocked_ioctl() function has become large. So split away
into new static functions the 4 ioctl ICARSAMODEXPO, ICARSACRT,
ZSECSENDCPRB and ZSENDEP11CPRB. This makes the code more readable and
is a preparation step for further improvements needed on these ioctls.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
This commit is contained in:
Harald Freudenberger 2020-05-20 16:07:19 +02:00 committed by Heiko Carstens
parent 74ecbef7b9
commit 7e202acb5c
1 changed files with 101 additions and 81 deletions

View File

@ -1298,21 +1298,11 @@ static int zcrypt_requestq_count(void)
return requestq_count; return requestq_count;
} }
static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd, static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg)
unsigned long arg)
{ {
int rc; int rc;
struct ap_perms *perms =
(struct ap_perms *) filp->private_data;
rc = zcrypt_check_ioctl(perms, cmd);
if (rc)
return rc;
switch (cmd) {
case ICARSAMODEXPO: {
struct ica_rsa_modexpo __user *umex = (void __user *) arg;
struct ica_rsa_modexpo mex; struct ica_rsa_modexpo mex;
struct ica_rsa_modexpo __user *umex = (void __user *) arg;
if (copy_from_user(&mex, umex, sizeof(mex))) if (copy_from_user(&mex, umex, sizeof(mex)))
return -EFAULT; return -EFAULT;
@ -1330,9 +1320,12 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
} }
return put_user(mex.outputdatalength, &umex->outputdatalength); return put_user(mex.outputdatalength, &umex->outputdatalength);
} }
case ICARSACRT: {
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg; static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
{
int rc;
struct ica_rsa_modexpo_crt crt; struct ica_rsa_modexpo_crt crt;
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
if (copy_from_user(&crt, ucrt, sizeof(crt))) if (copy_from_user(&crt, ucrt, sizeof(crt)))
return -EFAULT; return -EFAULT;
@ -1350,9 +1343,12 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
} }
return put_user(crt.outputdatalength, &ucrt->outputdatalength); return put_user(crt.outputdatalength, &ucrt->outputdatalength);
} }
case ZSECSENDCPRB: {
struct ica_xcRB __user *uxcRB = (void __user *) arg; static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
{
int rc;
struct ica_xcRB xcRB; struct ica_xcRB xcRB;
struct ica_xcRB __user *uxcRB = (void __user *) arg;
if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB))) if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
return -EFAULT; return -EFAULT;
@ -1371,9 +1367,12 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT; return -EFAULT;
return rc; return rc;
} }
case ZSENDEP11CPRB: {
struct ep11_urb __user *uxcrb = (void __user *)arg; static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
{
int rc;
struct ep11_urb xcrb; struct ep11_urb xcrb;
struct ep11_urb __user *uxcrb = (void __user *)arg;
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb))) if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
return -EFAULT; return -EFAULT;
@ -1391,6 +1390,27 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT; return -EFAULT;
return rc; return rc;
} }
static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
int rc;
struct ap_perms *perms =
(struct ap_perms *) filp->private_data;
rc = zcrypt_check_ioctl(perms, cmd);
if (rc)
return rc;
switch (cmd) {
case ICARSAMODEXPO:
return icarsamodexpo_ioctl(perms, arg);
case ICARSACRT:
return icarsacrt_ioctl(perms, arg);
case ZSECSENDCPRB:
return zsecsendcprb_ioctl(perms, arg);
case ZSENDEP11CPRB:
return zsendep11cprb_ioctl(perms, arg);
case ZCRYPT_DEVICE_STATUS: { case ZCRYPT_DEVICE_STATUS: {
struct zcrypt_device_status_ext *device_status; struct zcrypt_device_status_ext *device_status;
size_t total_size = MAX_ZDEV_ENTRIES_EXT size_t total_size = MAX_ZDEV_ENTRIES_EXT