Commit 7e202acb authored by Harald Freudenberger's avatar Harald Freudenberger Committed by Heiko Carstens

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: default avatarHarald Freudenberger <freude@linux.ibm.com>
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
parent 74ecbef7
...@@ -1298,99 +1298,119 @@ static int zcrypt_requestq_count(void) ...@@ -1298,99 +1298,119 @@ 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 ica_rsa_modexpo mex;
(struct ap_perms *) filp->private_data; struct ica_rsa_modexpo __user *umex = (void __user *) arg;
rc = zcrypt_check_ioctl(perms, cmd); if (copy_from_user(&mex, umex, sizeof(mex)))
if (rc) return -EFAULT;
return rc; do {
rc = zcrypt_rsa_modexpo(perms, &mex);
switch (cmd) { } while (rc == -EAGAIN);
case ICARSAMODEXPO: { /* on failure: retry once again after a requested rescan */
struct ica_rsa_modexpo __user *umex = (void __user *) arg; if ((rc == -ENODEV) && (zcrypt_process_rescan()))
struct ica_rsa_modexpo mex;
if (copy_from_user(&mex, umex, sizeof(mex)))
return -EFAULT;
do { do {
rc = zcrypt_rsa_modexpo(perms, &mex); rc = zcrypt_rsa_modexpo(perms, &mex);
} while (rc == -EAGAIN); } while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */ if (rc) {
if ((rc == -ENODEV) && (zcrypt_process_rescan())) ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
do { return rc;
rc = zcrypt_rsa_modexpo(perms, &mex);
} while (rc == -EAGAIN);
if (rc) {
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
return rc;
}
return put_user(mex.outputdatalength, &umex->outputdatalength);
} }
case ICARSACRT: { return put_user(mex.outputdatalength, &umex->outputdatalength);
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg; }
struct ica_rsa_modexpo_crt crt;
if (copy_from_user(&crt, ucrt, sizeof(crt))) static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
return -EFAULT; {
int rc;
struct ica_rsa_modexpo_crt crt;
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
if (copy_from_user(&crt, ucrt, sizeof(crt)))
return -EFAULT;
do {
rc = zcrypt_rsa_crt(perms, &crt);
} while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
do { do {
rc = zcrypt_rsa_crt(perms, &crt); rc = zcrypt_rsa_crt(perms, &crt);
} while (rc == -EAGAIN); } while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */ if (rc) {
if ((rc == -ENODEV) && (zcrypt_process_rescan())) ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
do { return rc;
rc = zcrypt_rsa_crt(perms, &crt);
} while (rc == -EAGAIN);
if (rc) {
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
return rc;
}
return put_user(crt.outputdatalength, &ucrt->outputdatalength);
} }
case ZSECSENDCPRB: { return put_user(crt.outputdatalength, &ucrt->outputdatalength);
struct ica_xcRB __user *uxcRB = (void __user *) arg; }
struct ica_xcRB xcRB;
if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB))) static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
return -EFAULT; {
int rc;
struct ica_xcRB xcRB;
struct ica_xcRB __user *uxcRB = (void __user *) arg;
if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
return -EFAULT;
do {
rc = _zcrypt_send_cprb(perms, &xcRB);
} while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
do { do {
rc = _zcrypt_send_cprb(perms, &xcRB); rc = _zcrypt_send_cprb(perms, &xcRB);
} while (rc == -EAGAIN); } while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */ if (rc)
if ((rc == -ENODEV) && (zcrypt_process_rescan())) ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n",
do { rc, xcRB.status);
rc = _zcrypt_send_cprb(perms, &xcRB); if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
} while (rc == -EAGAIN); return -EFAULT;
if (rc) return rc;
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n", }
rc, xcRB.status);
if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
return -EFAULT;
return rc;
}
case ZSENDEP11CPRB: {
struct ep11_urb __user *uxcrb = (void __user *)arg;
struct ep11_urb xcrb;
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb))) static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
return -EFAULT; {
int rc;
struct ep11_urb xcrb;
struct ep11_urb __user *uxcrb = (void __user *)arg;
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
return -EFAULT;
do {
rc = _zcrypt_send_ep11_cprb(perms, &xcrb);
} while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
do { do {
rc = _zcrypt_send_ep11_cprb(perms, &xcrb); rc = _zcrypt_send_ep11_cprb(perms, &xcrb);
} while (rc == -EAGAIN); } while (rc == -EAGAIN);
/* on failure: retry once again after a requested rescan */ if (rc)
if ((rc == -ENODEV) && (zcrypt_process_rescan())) ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
do { if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
rc = _zcrypt_send_ep11_cprb(perms, &xcrb); return -EFAULT;
} while (rc == -EAGAIN); return rc;
if (rc) }
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb))) static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT; 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; 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment