Skip to content

Commit

Permalink
crypto: ccp - Fix DBC sample application error handling
Browse files Browse the repository at this point in the history
The sample application was taking values from ioctl() and treating
those as the error codes to present to a user.

This is incorrect when ret is non-zero, the error is stored to `errno`.
Use this value instead.

Fixes: f40d42f ("crypto: ccp - Add a sample python script for Dynamic Boost Control")
Fixes: febe3ed ("crypto: ccp - Add a sample library for ioctl use")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Mario Limonciello authored and Herbert Xu committed Sep 15, 2023
1 parent 7f71c3e commit 70f242c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions tools/crypto/ccp/dbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>

Expand All @@ -22,16 +23,14 @@ int get_nonce(int fd, void *nonce_out, void *signature)
struct dbc_user_nonce tmp = {
.auth_needed = !!signature,
};
int ret;

assert(nonce_out);

if (signature)
memcpy(tmp.signature, signature, sizeof(tmp.signature));

ret = ioctl(fd, DBCIOCNONCE, &tmp);
if (ret)
return ret;
if (ioctl(fd, DBCIOCNONCE, &tmp))
return errno;
memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce));

return 0;
Expand All @@ -47,7 +46,9 @@ int set_uid(int fd, __u8 *uid, __u8 *signature)
memcpy(tmp.uid, uid, sizeof(tmp.uid));
memcpy(tmp.signature, signature, sizeof(tmp.signature));

return ioctl(fd, DBCIOCUID, &tmp);
if (ioctl(fd, DBCIOCUID, &tmp))
return errno;
return 0;
}

int process_param(int fd, int msg_index, __u8 *signature, int *data)
Expand All @@ -63,9 +64,8 @@ int process_param(int fd, int msg_index, __u8 *signature, int *data)

memcpy(tmp.signature, signature, sizeof(tmp.signature));

ret = ioctl(fd, DBCIOCPARAM, &tmp);
if (ret)
return ret;
if (ioctl(fd, DBCIOCPARAM, &tmp))
return errno;

*data = tmp.param;
return 0;
Expand Down
3 changes: 1 addition & 2 deletions tools/crypto/ccp/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@


def handle_error(code):
val = code * -1
raise OSError(val, os.strerror(val))
raise OSError(code, os.strerror(code))


def get_nonce(device, signature):
Expand Down

0 comments on commit 70f242c

Please sign in to comment.