aboutsummaryrefslogtreecommitdiffstats
path: root/samples/kfifo/dma-example.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2013-11-15kfifo API type safetyStefani Seibold1-1/+1
This patch enhances the type safety for the kfifo API. It is now safe to put const data into a non const FIFO and the API will now generate a compiler warning when reading from the fifo where the destination address is pointing to a const variable. As a side effect the kfifo_put() does now expect the value of an element instead a pointer to the element. This was suggested Russell King. It make the handling of the kfifo_put easier since there is no need to create a helper variable for getting the address of a pointer or to pass integers of different sizes. IMHO the API break is okay, since there are currently only six users of kfifo_put(). The code is also cleaner by kicking out the "if (0)" expressions. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Stefani Seibold <stefani@seibold.net> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-10-01kfifo: fix scatterlist usageIra W. Snyder1-8/+9
The kfifo_dma family of functions use sg_mark_end() on the last element in their scatterlist. This forces use of a fresh scatterlist for each DMA operation, which makes recycling a single scatterlist impossible. Change the behavior of the kfifo_dma functions to match the usage of the dma_map_sg function. This means that users must respect the returned nents value. The sample code is updated to reflect the change. This bug is trivial to cause: call kfifo_dma_in_prepare() such that it prepares a scatterlist with a single entry comprising the whole fifo. This is the case when you map the entirety of a newly created empty fifo. This causes the setup_sgl() function to mark the first scatterlist entry as the end of the chain, no matter what comes after it. Afterwards, add and remove some data from the fifo such that another call to kfifo_dma_in_prepare() will create two scatterlist entries. It returns nents=2. However, due to the previous sg_mark_end() call, sg_is_last() will now return true for the first scatterlist element. This causes the sample code to print a single scatterlist element when it should print two. By removing the call to sg_mark_end(), we make the API as similar as possible to the DMA mapping API. All users are required to respect the returned nents. Signed-off-by: Ira W. Snyder <iws@ovro.caltech.edu> Cc: Stefani Seibold <stefani@seibold.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-20kfifo: add explicit error checking in all the examplesAndrea Righi1-39/+67
Provide a check in all the kfifo examples to validate the correct execution of each testcase. Signed-off-by: Andrea Righi <arighi@develer.com> Acked-by: Stefani Seibold <stefani@seibold.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-20kfifo: fix a memory leak in dma exampleAndrea Righi1-3/+1
We use a dynamically allocated kfifo in the dma example, so we need to free it when unloading the module. Signed-off-by: Andrea Righi <arighi@develer.com> Acked-by: Stefani Seibold <stefani@seibold.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-20kfifo: fix kernel BUG in dma exampleAndrea Righi1-0/+1
The scatterlist is used uninitialized in kfifo_dma_in_prepare(). This triggers the following bug if CONFIG_DEBUG_SG=y: ------------[ cut here ]------------ kernel BUG at include/linux/scatterlist.h:65! invalid opcode: 0000 [#1] PREEMPT SMP ... Call Trace: [<ffffffff810a1eab>] setup_sgl+0x6b/0xe0 [<ffffffffa03d7000>] ? example_init+0x0/0x265 [dma_example] [<ffffffff810a2021>] __kfifo_dma_in_prepare+0x21/0x30 [<ffffffffa03d7124>] example_init+0x124/0x265 [dma_example] [<ffffffff810f9c55>] ? trace_module_notify+0x25/0x370 [<ffffffff81110c6e>] ? free_pages_prepare+0x11e/0x1e0 [<ffffffff8106f2b1>] ? get_parent_ip+0x11/0x50 [<ffffffff810f9c55>] ? trace_module_notify+0x25/0x370 [<ffffffff810b65fd>] ? trace_hardirqs_on+0xd/0x10 [<ffffffff814beade>] ? mutex_unlock+0xe/0x10 [<ffffffff810f9c71>] ? trace_module_notify+0x41/0x370 [<ffffffff810a77d5>] ? __blocking_notifier_call_chain+0x45/0x80 [<ffffffff81137b7a>] ? vfree+0x2a/0x30 [<ffffffff810a6ac3>] ? up_read+0x23/0x40 [<ffffffff810a77f5>] ? __blocking_notifier_call_chain+0x65/0x80 [<ffffffff810001e3>] do_one_initcall+0x43/0x180 [<ffffffff810c577a>] sys_init_module+0xba/0x200 [<ffffffff8103819b>] system_call_fastpath+0x16/0x1b RIP [<ffffffff810a1e31>] setup_sgl_buf+0x1a1/0x1b0 RSP <ffff88006720dc98> ---[ end trace a72b979fd3c1d3a5 ]--- Add the proper initialization to avoid the bug. Signed-off-by: Andrea Righi <arighi@develer.com> Acked-by: Stefani Seibold <stefani@seibold.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-11kfifo: add example files to the kernel sample directoryStefani Seibold1-0/+115
Add four examples to the kernel sample directory. It shows how to handle: - a byte stream fifo - a integer type fifo - a dynamic record sized fifo - the fifo DMA functions [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Stefani Seibold <stefani@seibold.net> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>