Hi All,
I have written code to create ordinary file from Linux kernel
module. This code is working fine in normal execution, but its hangs
when this function called from hook function or ISR.
Please advice me, what should I do to solve this problem.
Suppose if I remove variable arguments from this function. Its give
error "Failed to write". This problem comes only when I call from hook
or ISR.
Please advise me.
#include"lwfw.h"
#include"log.h"
struct file *filp=NULL;
mm_segment_t log_fs;
int init_log()
{
log_fs = get_fs();
set_fs(get_ds());
filp = filp_open("/var/log/lwfw.log", O_RDWR | O_CREAT, 0666);
if (IS_ERR(filp)) {
printk(KERN_INFO "Unable to load .\n");
return FAIL;
}
printk("log file initalizec %s : %s\n", __MODULE__,
__FUNCTION__);
return SUCCESS;
}
int write_log(const char *logData,...)
{
loff_t pos;
char *data;
long len;
int n, size = 1024;
va_list ap;
data = vmalloc(size);
if (data == NULL) {
printk(KERN_INFO "Out of memory loading '%s'.\n", "a");
return FAIL;
}
va_start(ap,logData);
n = vsnprintf (data, size, logData, ap);
va_end(ap);
if(filp==NULL)
init_log();
pos = filp->f_dentry->d_inode->i_size;
len = vfs_write(filp, data, strlen(data), &pos);
if (len < 0) {
printk(KERN_INFO "Failed to write '%s'.\n", data);
vfree(data);
return FAIL;
}
printk("success to write '%s'.\n", data);
if(data!=NULL)
vfree(data);
cleanup_log();
return len;
}
void cleanup_log()
{
filp_close(filp, current->files);
set_fs(log_fs);
printk("cleanup logs\n");
}