LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-30-2013, 01:05 AM   #1
georgewhr
Member
 
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;

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

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_init(&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)
{
DECLARE_COMPLETION_ONSTACK(done);
int status;

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

spin_lock_irq(&spidev->spi_lock);
if (spidev->spi == NULL)
status = -ESHUTDOWN;
else
status = spi_async(spidev->spi, message);
spin_unlock_irq(&spidev->spi_lock);

if (status == 0) {
wait_for_completion(&done);
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)"
 
  


Reply


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 09:06 AM
C copy_from_user question conlonloi Programming 1 10-22-2011 11:49 PM
Using copy_from_user with 2 process wk30l Programming 1 10-25-2010 02:09 PM
copy_from_user and copy_to_user example krisonearth Programming 5 09-29-2009 05:08 PM
copy_from_user does not copy from process-heap najoshi Linux - Kernel 0 08-16-2009 12:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:04 PM.

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