ssize_t scull_write ( struct file *filp, const char __user *buffer, size_t count , loff_t *offset)
{
struct ScullDev *lsculldev;
struct ScullQset *lscullqset;
int noq, nobsw,start_q,lcount,lv,ret;
int nobtw,noq_f,index,new_pos;
nobtw = count;
index = noq_f = 0;
lcount = noq = nobsw = start_q = lv = ret = 0;
#ifdef DEBUG
printk(KERN_INFO “Begin :%s\n”,__func__);
#endif
lsculldev = filp->private_data;
new_pos = filp->f_pos;
printk(KERN_INFO”value of filep=%d\n”,new_pos);
if(!lsculldev)
{
#ifdef DEBUG
printk(KERN_INFO “No Sculldev\n”);
#endif
goto OUT;
}
if(count size_of_device)
{
#ifdef DEBUG
printk(KERN_INFO “Not Enough Memory\n”);
#endif
goto OUT;
}
lscullqset = scull_follow(lsculldev);
if(!lscullqset)
{
lscullqset =(struct ScullQset *) kmalloc(sizeof(struct ScullQset),GFP_KERNEL);
if(!lscullqset)
{
#ifdef DEBUG
printk(KERN_INFO “Memory Allocation Failed\n”);
#endif
goto OUT;
}
lscullqset->data = kmalloc(sizeof(char*)*qset_size,GFP_KERNEL);
if(!lscullqset->data)
{
#ifdef DEBUG
printk(KERN_INFO “Memory Allocation Failed for qset array\n”);
#endif
goto OUT;
}
}
lsculldev->scullqset = lscullqset;
noq=count / quantum_size;
if(count % quantum_size)
{
noq++;
}
lsculldev->qset = noq;
printk(“noq = %d\n”,noq);
start_q = new_pos / quantum_size;
lv = start_q;
if(w_flag)
{
while(nobsw data[lv])
{
if(lv == start_q)
{
index = new_pos % quantum_size;
lcount = quantum_size – index;
ret = copy_from_user(lscullqset->data[lv]+index,buffer+nobsw,lcount);
#ifdef DEBUG
printk(KERN_INFO “data :%s\n”,(char*)lscullqset->data[lv]);
#endif
nobsw = nobsw + (lcount – ret);
lv++;
}
else
{
{
if(quantum_size count – nobsw)
lcount = count – nobsw;
printk(“ccc\n”);
ret = copy_from_user(lscullqset->data[lv],buffer+nobsw,lcount);
#ifdef DEBUG
printk(KERN_INFO “data :%s\n”,(char*)lscullqset->data[lv]);
#endif
nobsw = nobsw + (lcount – ret);
lv++;
}
printk(“~~~~\n\n”);
}
else
{
printk(“allocating memory for new quantum\n”);
noq_f++;
lscullqset->data[lv] = kmalloc(sizeof(char)*quantum_size,GFP_KERNEL);
if(!lscullqset->data[lv])
{
#ifdef DEBUG
printk(KERN_INFO “Memory Allocation Failed for new quantum\n”);
#endif
return -1;
}
#ifdef DEBUG
printk(KERN_INFO “Memory Allocated for new quantum\n”);
#endif
}
}
}
else
{
for(lv =0; lv data[lv] = kmalloc(sizeof(char)*quantum_size,GFP_KERNEL);
if(!lscullqset->data[lv])
{
#ifdef DEBUG
printk(KERN_INFO “Memory Allocation Failed for qset array\n”);
#endif
goto OUT;
}
}
for(lv=0; lv < noq; lv++)
{
if(quantum_size count – nobsw)
lcount = count – nobsw;
ret = copy_from_user(lscullqset->data[lv],buffer+nobsw,lcount);
#ifdef DEBUG
printk(KERN_INFO “data :%s\n”,(char*)lscullqset->data[lv]);
#endif
nobsw = nobsw + (lcount – ret);
w_flag = 1;
}
}
#ifdef DEBUG
printk(KERN_INFO “End :%s\n”,__func__);
#endif
return nobsw;
OUT:
#ifdef DEBUG
printk(KERN_INFO “End :%s\n”,__func__);
#endif
return -1;
}
Your issue hav resolved and your modified code i already send you . Your Code contains some silly mistakes like memset and NULL character .