Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-30-2013, 02:05 AM   #1
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Rep: Reputation: Disabled
difference between copy_from_user and spi_async

Happy Holiday Guys!

I m learning SPI interface.

static ssize_t
spidev_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos)
struct spidev_data *spidev;
ssize_t status = 0;
unsigned long missing;

/* chipselect only toggles at start or end of operation */
if (count > bufsiz)
return -EMSGSIZE;

spidev = filp->private_data;

missing = copy_from_user(spidev->buffer, buf, count);
if (missing == 0) {
status = spidev_sync_write(spidev, count);
} else
status = -EFAULT;

return status;

static inline ssize_t
spidev_sync_write(struct spidev_data *spidev, size_t len)
struct spi_transfer t = {
.tx_buf = spidev->buffer,
.len = len,
struct spi_message m;

spi_message_add_tail(&t, &m); //To add transfers to a spi_message, use the spi_message_add_tail() function
return spidev_sync(spidev, &m); // The core method for submitting any message to the SPI system is spi_async()

static ssize_t
spidev_sync(struct spidev_data *spidev, struct spi_message *message)
int status;

message->complete = spidev_complete;
message->context = &done;

if (spidev->spi == NULL)
status = -ESHUTDOWN;
status = spi_async(spidev->spi, message);

if (status == 0) {
status = message->status;
if (status == 0)
status = message->actual_length;
return status;

In the write function of spidev.c, it has "copy_from_user" and "spidev_sync_write(spidev, count) ->spidev_sync(spidev, &m)-> spi_async(spidev->spi, message) ". Both of two functions are sending message from user to kernel(SPI device), why the write function implement both of them? What's the difference between "copy_from_user" and "spi_async(spidev->spi, message)"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
copy_from_user strangeness spong Linux - Kernel 6 02-10-2014 10:06 AM
C copy_from_user question conlonloi Programming 1 10-23-2011 12:49 AM
Using copy_from_user with 2 process wk30l Programming 1 10-25-2010 03:09 PM
copy_from_user and copy_to_user example krisonearth Programming 5 09-29-2009 06:08 PM
copy_from_user does not copy from process-heap najoshi Linux - Kernel 0 08-16-2009 01:09 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration