Skip to content

Commit

Permalink
crypto: move 'opaque' parameter to (nearly) the end of parameter list
Browse files Browse the repository at this point in the history
Previous commit moved 'opaque' to be the 2nd parameter in the list:

  commit 3750923
  Author: Fam Zheng <[email protected]>
  Date:   Fri Apr 21 20:27:02 2017 +0800

    crypto: Make errp the last parameter of functions

    Move opaque to 2nd instead of the 2nd to last, so that compilers help
    check with the conversion.

this puts it back to the 2nd to last position.

Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Fam Zheng <[email protected]>
Signed-off-by: Daniel P. Berrange <[email protected]>
  • Loading branch information
berrange committed May 9, 2017
1 parent 899833c commit e4a3507
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions block/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format,


static ssize_t block_crypto_read_func(QCryptoBlock *block,
void *opaque,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
BlockDriverState *bs = opaque;
Expand All @@ -83,10 +83,10 @@ struct BlockCryptoCreateData {


static ssize_t block_crypto_write_func(QCryptoBlock *block,
void *opaque,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
Expand All @@ -102,8 +102,8 @@ static ssize_t block_crypto_write_func(QCryptoBlock *block,


static ssize_t block_crypto_init_func(QCryptoBlock *block,
void *opaque,
size_t headerlen,
void *opaque,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
Expand Down
13 changes: 8 additions & 5 deletions crypto/block-luks.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ qcrypto_block_luks_load_key(QCryptoBlock *block,
* then encrypted.
*/
rv = readfunc(block,
opaque,
slot->key_offset * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE,
splitkey, splitkeylen,
opaque,
errp);
if (rv < 0) {
goto cleanup;
Expand Down Expand Up @@ -676,9 +676,10 @@ qcrypto_block_luks_open(QCryptoBlock *block,

/* Read the entire LUKS header, minus the key material from
* the underlying device */
rv = readfunc(block, opaque, 0,
rv = readfunc(block, 0,
(uint8_t *)&luks->header,
sizeof(luks->header),
opaque,
errp);
if (rv < 0) {
ret = rv;
Expand Down Expand Up @@ -1245,7 +1246,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
QCRYPTO_BLOCK_LUKS_SECTOR_SIZE;

/* Reserve header space to match payload offset */
initfunc(block, opaque, block->payload_offset, &local_err);
initfunc(block, block->payload_offset, opaque, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto error;
Expand All @@ -1267,9 +1268,10 @@ qcrypto_block_luks_create(QCryptoBlock *block,


/* Write out the partition header and key slot headers */
writefunc(block, opaque, 0,
writefunc(block, 0,
(const uint8_t *)&luks->header,
sizeof(luks->header),
opaque,
&local_err);

/* Delay checking local_err until we've byte-swapped */
Expand All @@ -1295,10 +1297,11 @@ qcrypto_block_luks_create(QCryptoBlock *block,

/* Write out the master key material, starting at the
* sector immediately following the partition header. */
if (writefunc(block, opaque,
if (writefunc(block,
luks->header.key_slots[0].key_offset *
QCRYPTO_BLOCK_LUKS_SECTOR_SIZE,
splitkey, splitkeylen,
opaque,
errp) != splitkeylen) {
goto error;
}
Expand Down
6 changes: 3 additions & 3 deletions include/crypto/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ typedef struct QCryptoBlock QCryptoBlock;
* and QCryptoBlockOpenOptions in qapi/crypto.json */

typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block,
void *opaque,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);

typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block,
void *opaque,
size_t headerlen,
void *opaque,
Error **errp);

typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block,
void *opaque,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/test-crypto-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ static struct QCryptoBlockTestData {


static ssize_t test_block_read_func(QCryptoBlock *block,
void *opaque,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
Expand All @@ -204,8 +204,8 @@ static ssize_t test_block_read_func(QCryptoBlock *block,


static ssize_t test_block_init_func(QCryptoBlock *block,
void *opaque,
size_t headerlen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
Expand All @@ -219,10 +219,10 @@ static ssize_t test_block_init_func(QCryptoBlock *block,


static ssize_t test_block_write_func(QCryptoBlock *block,
void *opaque,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
Expand Down

0 comments on commit e4a3507

Please sign in to comment.