COPY_TO_USER PROBLEMS!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

 

I have a basic "char" driver that controls a PCI device with DMA capability.  I have a read routine that utilizes a "copy_to_user()" call to move data from a kernel-space buffer to a user-space buffer.   The kernel space buffer was created by calling by "dma_alloc_coherent" as follows:

 

            kernel_space_buffer_address = dma_alloc_coherent(&(pci_dev->dev), 1024*128, dma_handle_address, GFP_KERNEL);

 

I check that the "kernel_space_buffer_address" is not NULL and I print the address, which looks reasonable.  Then later in my driver's read routine I have the following code:

 

 

            static  ssize_t pci_read(struct file *file, char __user *ubuffer, size_t length, loff_t *offset)  {

                       

                        bytes_read = copy_to_user((void __user *)ubuffer,  (const void *)kernel_space_buffer_address), 10);

 

                        }

 

I have a simple user-space program that opens the device and calls the above read routine with:

 

 

            main()

            {

                        buffer = (char *)malloc(1024*8);

                        fd = open("/dev/pci_drv", O_RDONLY);

                        bytes_read = read(fd, buffer 10);

                        close(fd);

                        free(buffer);

            }

 

As soon as I hit the "read" I instantly get a kernel panic!!!   Am I missing something with my use of "copy_to_user"??

 

Thank you for your time.


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux