1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

rdcpuid: handle errors

This commit is contained in:
The Tumultuous Unicorn Of Darkness 2024-07-10 20:18:03 +02:00
parent 0d71be934e
commit 4d6cc787fe
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A
4 changed files with 10 additions and 3 deletions

View file

@ -2247,6 +2247,7 @@ const char* cpuid_error(void)
{ ERR_INVRANGE , "Invalid given range"},
{ ERR_NOT_FOUND, "Requested type not found"},
{ ERR_IOCTL, "Error on ioctl"},
{ ERR_REQUEST, "Invalid request"},
};
unsigned i;
for (i = 0; i < COUNT_OF(matchtable); i++)

View file

@ -1203,6 +1203,7 @@ typedef enum {
ERR_INVRANGE = -16, /*!< Invalid given range */
ERR_NOT_FOUND= -17, /*!< Requested type not found */
ERR_IOCTL = -18, /*!< Error on ioctl */
ERR_REQUEST = -19, /*!< Invalid request */
} cpu_error_t;
/**

View file

@ -120,7 +120,6 @@ struct read_reg_t {
uint32_t value_32b;
uint64_t value_64b;
};
int err;
};
typedef struct read_reg_t read_reg_t;

View file

@ -110,9 +110,12 @@ int cpu_read_arm_register_32b(struct cpuid_driver_t* driver, reg_request_t reque
if (!driver || driver->fd < 0)
return cpuid_set_error(ERR_HANDLE);
if(ioctl(driver->fd, ARM_IOC_READ_REG, &read_reg))
if (ioctl(driver->fd, ARM_IOC_READ_REG, &read_reg))
return cpuid_set_error(ERR_IOCTL);
if (read_reg.request == REQ_INVALID)
return cpuid_set_error(ERR_REQUEST);
*result = read_reg.value_32b;
return 0;
}
@ -125,9 +128,12 @@ int cpu_read_arm_register_64b(struct cpuid_driver_t* driver, reg_request_t reque
if (!driver || driver->fd < 0)
return cpuid_set_error(ERR_HANDLE);
if(ioctl(driver->fd, ARM_IOC_READ_REG, &read_reg))
if (ioctl(driver->fd, ARM_IOC_READ_REG, &read_reg))
return cpuid_set_error(ERR_IOCTL);
if (read_reg.request == REQ_INVALID)
return cpuid_set_error(ERR_REQUEST);
*result = read_reg.value_64b;
return 0;
}