mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Long <long.wanglong@huawei.com>
To: <stefani@seibold.net>
Cc: <long.wanglong@huawei.com>, <peifeiyue@huawei.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] samples: Fix `echo 1 > /proc/int-fifo` never return error
Date: Tue, 3 Feb 2015 11:51:16 +0000	[thread overview]
Message-ID: <1422964277-140278-1-git-send-email-long.wanglong@huawei.com> (raw)

With the kernel module *samples/kfifo/inttype-example.ko*, the system will
create file /proc/int-fifo.

but the current code for this module may have some bug, as the following:

# echo 100 > /proc/int-fifo      ----------------> OK
# echo 1000000 > /proc/int-fifo  ----------------> OK
# echo 99 > /proc/int-fifo       ----------------> Never return
# echo 1000 > /proc/int-fifo     ----------------> Never return

so i found that, the length of the content putting into /proc/int-fifo must be 4, 8, 12 .....

another idea:
this kernel module is about a FIFO which type is int. we should put an interger into it, not the string.
when we reading from this file, we should get all elements in the FIFO. just as the following:

# echo 1 > /proc/int-fifo 
# echo 2 > /proc/int-fifo 
# echo 3 > /proc/int-fifo 
# cat /proc/int-fifo 
1
2
3
# echo 101 > /proc/int-fifo 
# echo 103 > /proc/int-fifo 
# echo 104 > /proc/int-fifo 
# echo 102 > /proc/int-fifo 
# cat /proc/int-fifo 
101
103
104
102

with my patch, we can echo an integer into the FIFO. so the following command is OK.
echo 1 > /proc/int-fifo 

without my patch, the command `echo 1 > /proc/int-fifo` will never return, beacuse the following code:

223 int __kfifo_from_user(struct __kfifo *fifo, const void __user *from,
224                 unsigned long len, unsigned int *copied)
225 {
226         unsigned int l;
227         unsigned long ret;
228         unsigned int esize = fifo->esize;
229         int err;
230 
231         if (esize != 1)
232                 len /= esize;
233 
234         l = kfifo_unused(fifo);
235         if (len > l)
236                 len = l;
237 
238         ret = kfifo_copy_from_user(fifo, from, len, fifo->in, copied);
239         if (unlikely(ret)) {
240                 len -= ret;
241                 err = -EFAULT;
242         } else
243                 err = 0;
244         fifo->in += len;
245         return err;
246 }
247 EXPORT_SYMBOL(__kfifo_from_user);

int the line 231: if len = 3, esize = 4, then at the line 232 len = 0.





Wang Long (1):
  samples: Fix `echo 1 > /proc/int-fifo` never return error

 samples/kfifo/inttype-example.c | 51 ++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 11 deletions(-)

-- 
1.8.3.1


             reply	other threads:[~2015-02-03 11:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03 11:51 Wang Long [this message]
2015-02-03 11:51 ` Wang Long
2015-02-04 10:18   ` Stefani Seibold
2015-02-04 10:35     ` long.wanglong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422964277-140278-1-git-send-email-long.wanglong@huawei.com \
    --to=long.wanglong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peifeiyue@huawei.com \
    --cc=stefani@seibold.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®