i8k: allocate i8k_procbuf after opening /proc/i8k

this lets us simplify error handling
This commit is contained in:
bi4k8 2023-05-05 00:48:51 +00:00 committed by bi4k8
parent 48154e9805
commit 74de272dce
1 changed files with 1 additions and 4 deletions

View File

@ -56,17 +56,14 @@ static char *i8k_procbuf = nullptr;
int update_i8k(void) {
FILE *fp;
if (!i8k_procbuf) { i8k_procbuf = (char *)malloc(128 * sizeof(char)); }
if ((fp = fopen(PROC_I8K, "r")) == nullptr) {
free_and_zero(i8k_procbuf);
/*THREAD_CRIT_ERR(nullptr, NULL, "/proc/i8k doesn't exist! use insmod to
make sure the kernel " "driver is loaded...");*/
NORM_ERR(
"/proc/i8k doesn't exist! use insmod to make sure the kernel driver is "
"loaded...");
return 1;
}
if (!i8k_procbuf) { i8k_procbuf = (char *)malloc(128 * sizeof(char)); }
memset(&i8k_procbuf[0], 0, 128);
if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
NORM_ERR("something wrong with /proc/i8k...");