On Wed, Sep 15, 2010 at 5:39 PM, Tayade, Nilesh
<nilesh.tay...@netscout.com>wrote:

> Can't it be because you are using size = 1byte in copy_from_user? Make it
> 'count'.
>
> After your suggestion I tried changing

> ---------------------------------------------------------
>
>
> #include <linux/init.h>
> #include <linux/module.h>
> #include <linux/kernel.h> /* printk() */
> #include <linux/slab.h> /* kmalloc() */
> #include <linux/fs.h> /* everything... */
> #include <linux/errno.h> /* error codes */
> #include <linux/types.h> /* size_t */
> #include <linux/proc_fs.h>
> #include <linux/fcntl.h> /* O_ACCMODE */
> #include <asm/system.h> /* cli(), *_flags */
> #include <asm/uaccess.h> /* copy_from/to_user */
>
>
>
>
> /* Declaration of memory.c functions */
> int bond_open(struct inode *inode, struct file *filp) { return 0;};
> int bond_release(struct inode *inode, struct file *filp){ return 0;};
> ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t
> *f_pos)
> {
>
>   /* Transfering data to user space */
>   copy_to_user(buf,bond_buffer,1);
>
>
>   /* Changing reading position as best suits */
>   if (*f_pos == 0) {
>     *f_pos+=1;
>     return 1;
>   } else {
>     return 0;
>   }
> };
>
>
>
>
> ssize_t bond_write(struct file *filp, char *buf, size_t count, loff_t
> *f_pos)
>  {
>
>
>   char *tmp;
>
>
>   tmp=buf+count-1;
>   copy_from_user(bond_buffer,tmp,1);
>   return 1;
> } ;
> void bond_exit(void);
> int bond_init(void);
>
>
> /* Structure that declares the usual file */
> /* access functions */
> struct file_operations bond_fops = {
>   read: bond_read,
>   write: bond_write,
>   open: bond_open,
>   release: bond_release
> };
>
>
> /* Global variables of the driver */
> /* Major number */
> int bond_major = 60;
> /* Buffer to store data */
> char *bond_buffer;
>
> I am not sure if the above statement I wrote is supposed to be written like
that only.

>
> static int bond_init(void) {
>   printk("<1> Hello bond new driver!\n");
>      int result;
>
>
>       /* Registering device */
>       result = register_chrdev(bond_major, "bond", &bond_fops);
>       if (result < 0) {
>         printk(
>           "<1>memory: cannot obtain major number %d\n", bond_major);
>         return result;
>       }
>
>
>       /* Allocating memory for the buffer */
>       bond_buffer = kmalloc(1, GFP_KERNEL);
>
kmalloc here I passed on 10 (and compiled and checked there were same
results no change)
if any other changes let me know I will try.

>       if (!bond_buffer) {
>         result = -ENOMEM;
>         goto fail;
>       }
>       memset(bond_buffer, 0, 1);
>
> Changed the value of 1 to 10 here recompiled (did not worked same problem)
Are you referring to this area to be changed.

>       printk("<1>Inserting bond module\n");
>       return 0;
>
>
>       fail:
>         bond_exit();
>         return result;
>       return 0;
>  }
>
>
> static void bond_exit(void) {
>   printk("<1> Bye, bond world\n");
> /* Freeing the major number */
>   unregister_chrdev(bond_major, "bond");
>
>
>   /* Freeing buffer memory */
>   if (bond_buffer) {
>     kfree(bond_buffer);
>   }
>
>
>   printk("<1>Removing bond module\n");
>
>
>
>
> }
>
>
> module_init(bond_init);
> module_exit(bond_exit);
>
>
>
I am not having any clue to any of above so let me know what you or some one
reading this thread thinks about it.

Reply via email to