From mboxrd@z Thu Jan 1 00:00:00 1970 From: SeeChen Ng Subject: Re: [PATCH net-next v4] xen-netback: Adding debugfs "io_ring_qX" files Date: Sun, 10 Aug 2014 22:57:51 +0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Hi, I'm a noob to linux kernel, I tried to figure out the usage of the function "simple_write_to_buffer", and I got confused about the code here. > +static ssize_t > +xenvif_write_io_ring(struct file *filp, const char __user *buf, size_t count, > + loff_t *ppos) > +{ > + struct xenvif_queue *queue = > + ((struct seq_file *)filp->private_data)->private; > + int len; > + char write[sizeof(XENVIF_KICK_STR)]; > + > + /* don't allow partial writes and check the length */ > + if (*ppos != 0) > + return 0; > + if (count < sizeof(XENVIF_KICK_STR) - 1) > + return -ENOSPC; The statement here is trying to verify the value of "count" is smaller than the size of array "write", make sure that the array got enough space for the write operation, right? So, I think the statement should be: if (count >= sizeof(XENVIF_KICK_STR)) return -ENOSPC; Sorry for bothering if I am mistaken. > + > + len = simple_write_to_buffer(write, > + sizeof(write), > + ppos, > + buf, > + count); > + if (len < 0) > + return len; > + > + if (!strncmp(write, XENVIF_KICK_STR, sizeof(XENVIF_KICK_STR) - 1)) > + xenvif_interrupt(0, (void *)queue); > + else { > + pr_warn("Unknown command to io_ring_q%d. Available: kick\n", > + queue->id); > + count = -EINVAL; > + } > + return count; > +}