Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    copy_to_user hangs system on buffers >= 4K bytes

    Hello, I'm having trouble with returning data from my char driver's read method. During "probe" driver intialization I request a DMA buffer for my pci-express device like this:
    my_device.dma_cpu_addr = pci_alloc_consistent(dev, DMA_MEM_SIZE, &my_device.dma_phy_handle);
    in my read method I basically do this (watered down code)
    byte [] buffer[nbytes];
    memcpy_fromio( &buffer, my_device.dma_cpu_addr + my_device.offset, nbytes);
    copy_to_user(buf, &buffer, nbytes);
    *ppos += nbytes;
    return nbytes;
    This works well as long as nbytes is less than 4K. At 4K the system absolutely freezes. At first I assumed this maybe had to do with PAGE_SIZE limits, so I decided to loop the 'memcpy' and 'copy_to_user' calls multiple times in incrments less than 4K (I started with 1K). This also would result in system hangs. Perhaps is there something with my intermediate "buffer" array? Could I just directly copy from I/O memory to user space without using an intermediate buffer? Thank for taking the time to read this.

  2. #2
    byte [] buffer[nbytes]; what is this?? an array?? if yes, then this are wrong:
    memcpy_fromio( &buffer, my_device.dma_cpu_addr + my_device.offset, nbytes);
    copy_to_user(buf, &buffer, nbytes);

    These should be

    memcpy_fromio(buffer, my_device.dma_cpu_addr + my_device.offset, nbytes);
    copy_to_user(buf, buffer, nbytes);
    Note & deletion.

    Let me know, if this helps.
    Last edited by oz; 11-26-2011 at 12:43 PM. Reason: redirect spammer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts