Skip to content

Commit 7e202ac

Browse files
hfreudeheicarst
authored andcommitted
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 <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 74ecbef commit 7e202ac

File tree

1 file changed

+92
-72
lines changed

1 file changed

+92
-72
lines changed

drivers/s390/crypto/zcrypt_api.c

Lines changed: 92 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,99 +1298,119 @@ static int zcrypt_requestq_count(void)
12981298
return requestq_count;
12991299
}
13001300

1301-
static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
1302-
unsigned long arg)
1301+
static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg)
13031302
{
13041303
int rc;
1305-
struct ap_perms *perms =
1306-
(struct ap_perms *) filp->private_data;
1304+
struct ica_rsa_modexpo mex;
1305+
struct ica_rsa_modexpo __user *umex = (void __user *) arg;
13071306

1308-
rc = zcrypt_check_ioctl(perms, cmd);
1309-
if (rc)
1310-
return rc;
1311-
1312-
switch (cmd) {
1313-
case ICARSAMODEXPO: {
1314-
struct ica_rsa_modexpo __user *umex = (void __user *) arg;
1315-
struct ica_rsa_modexpo mex;
1316-
1317-
if (copy_from_user(&mex, umex, sizeof(mex)))
1318-
return -EFAULT;
1307+
if (copy_from_user(&mex, umex, sizeof(mex)))
1308+
return -EFAULT;
1309+
do {
1310+
rc = zcrypt_rsa_modexpo(perms, &mex);
1311+
} while (rc == -EAGAIN);
1312+
/* on failure: retry once again after a requested rescan */
1313+
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
13191314
do {
13201315
rc = zcrypt_rsa_modexpo(perms, &mex);
13211316
} while (rc == -EAGAIN);
1322-
/* on failure: retry once again after a requested rescan */
1323-
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1324-
do {
1325-
rc = zcrypt_rsa_modexpo(perms, &mex);
1326-
} while (rc == -EAGAIN);
1327-
if (rc) {
1328-
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
1329-
return rc;
1330-
}
1331-
return put_user(mex.outputdatalength, &umex->outputdatalength);
1317+
if (rc) {
1318+
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
1319+
return rc;
13321320
}
1333-
case ICARSACRT: {
1334-
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
1335-
struct ica_rsa_modexpo_crt crt;
1321+
return put_user(mex.outputdatalength, &umex->outputdatalength);
1322+
}
13361323

1337-
if (copy_from_user(&crt, ucrt, sizeof(crt)))
1338-
return -EFAULT;
1324+
static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
1325+
{
1326+
int rc;
1327+
struct ica_rsa_modexpo_crt crt;
1328+
struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
1329+
1330+
if (copy_from_user(&crt, ucrt, sizeof(crt)))
1331+
return -EFAULT;
1332+
do {
1333+
rc = zcrypt_rsa_crt(perms, &crt);
1334+
} while (rc == -EAGAIN);
1335+
/* on failure: retry once again after a requested rescan */
1336+
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
13391337
do {
13401338
rc = zcrypt_rsa_crt(perms, &crt);
13411339
} while (rc == -EAGAIN);
1342-
/* on failure: retry once again after a requested rescan */
1343-
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1344-
do {
1345-
rc = zcrypt_rsa_crt(perms, &crt);
1346-
} while (rc == -EAGAIN);
1347-
if (rc) {
1348-
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
1349-
return rc;
1350-
}
1351-
return put_user(crt.outputdatalength, &ucrt->outputdatalength);
1340+
if (rc) {
1341+
ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
1342+
return rc;
13521343
}
1353-
case ZSECSENDCPRB: {
1354-
struct ica_xcRB __user *uxcRB = (void __user *) arg;
1355-
struct ica_xcRB xcRB;
1344+
return put_user(crt.outputdatalength, &ucrt->outputdatalength);
1345+
}
13561346

1357-
if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
1358-
return -EFAULT;
1347+
static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
1348+
{
1349+
int rc;
1350+
struct ica_xcRB xcRB;
1351+
struct ica_xcRB __user *uxcRB = (void __user *) arg;
1352+
1353+
if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
1354+
return -EFAULT;
1355+
do {
1356+
rc = _zcrypt_send_cprb(perms, &xcRB);
1357+
} while (rc == -EAGAIN);
1358+
/* on failure: retry once again after a requested rescan */
1359+
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
13591360
do {
13601361
rc = _zcrypt_send_cprb(perms, &xcRB);
13611362
} while (rc == -EAGAIN);
1362-
/* on failure: retry once again after a requested rescan */
1363-
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1364-
do {
1365-
rc = _zcrypt_send_cprb(perms, &xcRB);
1366-
} while (rc == -EAGAIN);
1367-
if (rc)
1368-
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n",
1369-
rc, xcRB.status);
1370-
if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
1371-
return -EFAULT;
1372-
return rc;
1373-
}
1374-
case ZSENDEP11CPRB: {
1375-
struct ep11_urb __user *uxcrb = (void __user *)arg;
1376-
struct ep11_urb xcrb;
1363+
if (rc)
1364+
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n",
1365+
rc, xcRB.status);
1366+
if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
1367+
return -EFAULT;
1368+
return rc;
1369+
}
13771370

1378-
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
1379-
return -EFAULT;
1371+
static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
1372+
{
1373+
int rc;
1374+
struct ep11_urb xcrb;
1375+
struct ep11_urb __user *uxcrb = (void __user *)arg;
1376+
1377+
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
1378+
return -EFAULT;
1379+
do {
1380+
rc = _zcrypt_send_ep11_cprb(perms, &xcrb);
1381+
} while (rc == -EAGAIN);
1382+
/* on failure: retry once again after a requested rescan */
1383+
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
13801384
do {
13811385
rc = _zcrypt_send_ep11_cprb(perms, &xcrb);
13821386
} while (rc == -EAGAIN);
1383-
/* on failure: retry once again after a requested rescan */
1384-
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1385-
do {
1386-
rc = _zcrypt_send_ep11_cprb(perms, &xcrb);
1387-
} while (rc == -EAGAIN);
1388-
if (rc)
1389-
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
1390-
if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
1391-
return -EFAULT;
1387+
if (rc)
1388+
ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
1389+
if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
1390+
return -EFAULT;
1391+
return rc;
1392+
}
1393+
1394+
static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
1395+
unsigned long arg)
1396+
{
1397+
int rc;
1398+
struct ap_perms *perms =
1399+
(struct ap_perms *) filp->private_data;
1400+
1401+
rc = zcrypt_check_ioctl(perms, cmd);
1402+
if (rc)
13921403
return rc;
1393-
}
1404+
1405+
switch (cmd) {
1406+
case ICARSAMODEXPO:
1407+
return icarsamodexpo_ioctl(perms, arg);
1408+
case ICARSACRT:
1409+
return icarsacrt_ioctl(perms, arg);
1410+
case ZSECSENDCPRB:
1411+
return zsecsendcprb_ioctl(perms, arg);
1412+
case ZSENDEP11CPRB:
1413+
return zsendep11cprb_ioctl(perms, arg);
13941414
case ZCRYPT_DEVICE_STATUS: {
13951415
struct zcrypt_device_status_ext *device_status;
13961416
size_t total_size = MAX_ZDEV_ENTRIES_EXT

0 commit comments

Comments
 (0)