Commit 70f242c1 authored by Mario Limonciello's avatar Mario Limonciello Committed by Herbert Xu

crypto: ccp - Fix DBC sample application error handling

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: f40d42f1 ("crypto: ccp - Add a sample python script for Dynamic Boost Control")
Fixes: febe3ed3 ("crypto: ccp - Add a sample library for ioctl use")
Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7f71c3e0
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -22,16 +23,14 @@ int get_nonce(int fd, void *nonce_out, void *signature) ...@@ -22,16 +23,14 @@ int get_nonce(int fd, void *nonce_out, void *signature)
struct dbc_user_nonce tmp = { struct dbc_user_nonce tmp = {
.auth_needed = !!signature, .auth_needed = !!signature,
}; };
int ret;
assert(nonce_out); assert(nonce_out);
if (signature) if (signature)
memcpy(tmp.signature, signature, sizeof(tmp.signature)); memcpy(tmp.signature, signature, sizeof(tmp.signature));
ret = ioctl(fd, DBCIOCNONCE, &tmp); if (ioctl(fd, DBCIOCNONCE, &tmp))
if (ret) return errno;
return ret;
memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce)); memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce));
return 0; return 0;
...@@ -47,7 +46,9 @@ int set_uid(int fd, __u8 *uid, __u8 *signature) ...@@ -47,7 +46,9 @@ int set_uid(int fd, __u8 *uid, __u8 *signature)
memcpy(tmp.uid, uid, sizeof(tmp.uid)); memcpy(tmp.uid, uid, sizeof(tmp.uid));
memcpy(tmp.signature, signature, sizeof(tmp.signature)); 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) int process_param(int fd, int msg_index, __u8 *signature, int *data)
...@@ -63,9 +64,8 @@ int process_param(int fd, int msg_index, __u8 *signature, int *data) ...@@ -63,9 +64,8 @@ int process_param(int fd, int msg_index, __u8 *signature, int *data)
memcpy(tmp.signature, signature, sizeof(tmp.signature)); memcpy(tmp.signature, signature, sizeof(tmp.signature));
ret = ioctl(fd, DBCIOCPARAM, &tmp); if (ioctl(fd, DBCIOCPARAM, &tmp))
if (ret) return errno;
return ret;
*data = tmp.param; *data = tmp.param;
return 0; return 0;
......
...@@ -27,8 +27,7 @@ lib = ctypes.CDLL("./dbc_library.so", mode=ctypes.RTLD_GLOBAL) ...@@ -27,8 +27,7 @@ lib = ctypes.CDLL("./dbc_library.so", mode=ctypes.RTLD_GLOBAL)
def handle_error(code): def handle_error(code):
val = code * -1 raise OSError(code, os.strerror(code))
raise OSError(val, os.strerror(val))
def get_nonce(device, signature): def get_nonce(device, signature):
......
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