請教一下兩個問題,如下
為什麼path分配空間後,最後面寫kfree(path)會導致crash,這樣寫法是錯的嗎?
另外code寫free_token = token,然後最後kfree(free_token),為什麼要多寫一個指標去free?
謝謝
int test(struct device *dev, const char *p_i8_buf, size_t count)
{
int i32_ret = 0;
char *temp_buf, *token, *path;
char *free_temp_buf, *free_token;
unsigned long fun = 0;
const char *delim = " ,";
temp_buf = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (temp_buf == NULL)
{
return -ENOMEM;
}
token = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (token == NULL) {
kfree(temp_buf);
return -ENOMEM;
}
path = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (path == NULL) {
kfree(temp_buf);
kfree(token);
return -ENOMEM;
}
free_token = token;
free_temp_buf = temp_buf;
strlcpy(temp_buf, p_i8_buf, count);
token = strsep(&temp_buf, delim);
if(token == NULL)
{
kfree(free_token);
kfree(free_temp_buf);
kfree(path);
return -EINVAL;
}
i32_ret = kstrtoul(token, 16, &fun);
if (i32_ret < 0) {
kfree(free_token);
kfree(free_temp_buf);
kfree(path);
return i32_ret;
}
path = strsep(&temp_buf, delim);//log path
parse(dev, fun, path);
kfree(free_token);
kfree(free_temp_buf);
//kfree(path); //will not crash <