diff options
| -rw-r--r-- | main.c | 20 | ||||
| -rw-r--r-- | main.h | 6 | 
2 files changed, 17 insertions, 9 deletions
| @@ -146,7 +146,7 @@ static int hello_trim(struct hello_dev *dev)  static struct hello_ll *hello_follow(struct hello_dev *dev, int n)  {  	struct hello_ll *nptr = dev->mylist, *tmp; -    PDEBUG("follow() called with n: %i\n", n); +    PRDEBUG("follow() called with n: %i\n", n);      /* allocate first node explicitly if it needs to be */      if (!nptr) { @@ -162,8 +162,12 @@ static struct hello_ll *hello_follow(struct hello_dev *dev, int n)      /* follow the list */      while (n--) {          /* almost like testing for NULL, remember this is circular list */ -        if (nptr->list.next == &nptr->list) { -            PDEBUG("allocating additional node"); +        PRDEBUG("while loop: n is: %i, nptr->list is at: %p, ntpr->list.next is at %p\n", +            n, /* &nptr->list */ &dev->mylist->list, nptr->list.next); + +        /* there was a bug below, took 2 hours to track down */ +        if (nptr->list.next == /* &nptr->list */ &dev->mylist->list) { +            PRDEBUG("allocating additional node");              tmp = kmalloc(sizeof(struct hello_ll), GFP_KERNEL);              if (!tmp)                  return NULL; @@ -187,7 +191,7 @@ static ssize_t hello_read(struct file *filp, char __user *buff, size_t count, lo      ssize_t ret = 0; /* end of file, also in case of out of bound */      struct hello_ll *cptr = NULL; /* node where right chunk is */      int chunk_pos = 0; -    PDEBUG("read() called\n"); +    PRDEBUG("read() called\n");      if (down_interruptible(&dev->sem))          return -ERESTARTSYS; @@ -220,7 +224,7 @@ static ssize_t hello_read(struct file *filp, char __user *buff, size_t count, lo          count = dev->chunk_sz - chunk_pos;      /* write to userspace memory by reading only up to the end of chunk */ -    if (copy_to_user(buff, cptr->chunk + (*f_pos % dev->chunk_sz), count)) +    if (copy_to_user(buff, cptr->chunk + chunk_pos, count))      {          ret = -EFAULT;          goto out; @@ -240,12 +244,12 @@ static ssize_t hello_write(struct file *filp, const char __user *buff, size_t co      ssize_t ret = -ENOMEM;      struct hello_ll *cptr = NULL; /* node where right chunk is */      int chunk_pos = 0; -    PDEBUG("write() called\n"); +    PRDEBUG("write() called, user buffer is at: %p, f_pos: %lli, c: %lu\n", buff, *f_pos, count);      if (down_interruptible(&dev->sem))          return -ERESTARTSYS; -    chunk_pos = *f_pos / dev->chunk_sz; +    chunk_pos = *f_pos % dev->chunk_sz;      cptr = hello_follow(dev, *f_pos / dev->chunk_sz);      if (!cptr) @@ -342,7 +346,7 @@ static int __init hello_init(void)          ret = alloc_chrdev_region(&devnum, 0 /* first minor */, 1, "helloc");          hello_major = MAJOR(devnum);          hello_minor = MINOR(devnum); -        printk(KERN_INFO "[hello] major: %d, minor: %d\n", hello_major, hello_minor); +        PDEBUG("[hello] major: %d, minor: %d\n", hello_major, hello_minor);      }      if (ret < 0) {          printk(KERN_WARNING "[hello] can't get the major %d number\n", hello_major); @@ -9,8 +9,12 @@   */  #ifdef HELLO_DEBUG    #define PDEBUG(fmt, args...) printk( KERN_DEBUG "[hello] " fmt, ##args) +  #define PRDEBUG(fmt, args...) if (printk_ratelimit()) \ +                                    printk( KERN_DEBUG "[hello] " fmt, ##args)  #else -  #define PDEBUG(fmt, args...) /* not debugging: nothing */ +  /* not debugging: nothing */ +  #define PDEBUG(fmt, args...) +  #define PRDEBUG(fmt, args...)  #endif  #ifndef HELLO_MAJOR | 
