v4l: video-buf magic numbers
PATCH 1/1 v4l: video-buf magic numbers
Hi,
This patch adds some magic IDs and checks for them to the data structs of the video-buf module.
Gerd
drivers/media/video/video-buf.c +26 -6
@@ -28,6 +28,11 @@#include <media/video-buf.h> +#define MAGIC_DMABUF 0x19721112 +#define MAGIC_BUFFER 0x20040302 +#define MAGIC_CHECK (is,should) if (unlikely((is) != (should))) \ + { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } +static int debug =0 ;MODULE_DESCRIPTION ("helper module to manage video4linux pci dma buffers" );
@@ -109,6 +114,12 @@ videobuf_pages_to_sg(struct page **pages/* --------------------------------------------------------------------- */ +void videobuf_dma_init (struct videobuf_dmabuf *dma) +{ +memset (dma,0 ,sizeof (*dma)); + dma->magic =MAGIC_DMABUF ; +} +int videobuf_dma_init_user (struct videobuf_dmabuf *dma,int direction,unsigned long data,unsigned long size) {
@@ -178,8 +189,8 @@ int videobuf_dma_init_overlay(struct vidint videobuf_dma_pci_map (struct pci_dev *dev,struct videobuf_dmabuf *dma) { -if (0 == dma->nr_pages) -BUG (); +MAGIC_CHECK (dma->magic,MAGIC_DMABUF ); +BUG_ON (0 == dma->nr_pages);if (dma->pages) { dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
@@ -211,8 +222,8 @@ int videobuf_dma_pci_map(struct pci_devint videobuf_dma_pci_sync (struct pci_dev *dev,struct videobuf_dmabuf *dma) { -if (!dma->sglen) -BUG (); +MAGIC_CHECK (dma->magic,MAGIC_DMABUF ); +BUG_ON (!dma->sglen);if (!dma->bus_addr)pci_dma_sync_sg_for_cpu (dev,dma->sglist,dma->nr_pages,dma->direction);
@@ -221,6 +232,7 @@ int videobuf_dma_pci_sync(struct pci_devint videobuf_dma_pci_unmap (struct pci_dev *dev,struct videobuf_dmabuf *dma) { +MAGIC_CHECK (dma->magic,MAGIC_DMABUF );if (!dma->sglen)return 0 ;
@@ -234,8 +246,8 @@ int videobuf_dma_pci_unmap(struct pci_deint videobuf_dma_free (struct videobuf_dmabuf *dma) { -if (dma->sglen) -BUG (); +MAGIC_CHECK (dma->magic,MAGIC_DMABUF ); +BUG_ON (dma->sglen);if (dma->pages) {int i;
@@ -264,7 +276,9 @@ void* videobuf_alloc(unsigned int size) vb =kmalloc (size,GFP_KERNEL );if (NULL != vb) {memset (vb,0 ,size); +videobuf_dma_init (&vb->dma);init_waitqueue_head (&vb->done); + vb->magic =MAGIC_BUFFER ; }return vb; }
@@ -274,6 +288,7 @@ int videobuf_waiton(struct videobuf_buffint retval =0 ;DECLARE_WAITQUEUE (wait, current); +MAGIC_CHECK (vb->magic,MAGIC_BUFFER );add_wait_queue (&vb->done, &wait);while (vb->state ==STATE_ACTIVE || vb->state ==STATE_QUEUED ) {if (non_blocking) {
@@ -302,6 +317,7 @@ videobuf_iolock(struct pci_dev *pci, strint err,pages;dma_addr_t bus; +MAGIC_CHECK (vb->magic,MAGIC_BUFFER );switch (vb->memory) {case V4L2_MEMORY_MMAP :case V4L2_MEMORY_USERPTR :
@@ -453,6 +469,8 @@ void videobuf_status(struct v4l2_buffer *b, struct videobuf_buffer *vb, enum v4l2_buf_type type) { + MAGIC_CHECK(vb->magic,MAGIC_BUFFER); + b->index = vb->i; b->type = type;
@@ -573,6 +591,7 @@ videobuf_qbuf(struct file *file, struct buf = q->bufs[b->index];if (NULL == buf) goto done; +MAGIC_CHECK (buf->magic,MAGIC_BUFFER );if (buf->memory != b->memory) goto done; if (buf->state == STATE_QUEUED ||
@@ -1206,6 +1225,7 @@ int videobuf_mmap_mapper(struct vm_area_EXPORT_SYMBOL_GPL (videobuf_vmalloc_to_sg); +EXPORT_SYMBOL_GPL (videobuf_dma_init);EXPORT_SYMBOL_GPL (videobuf_dma_init_user);EXPORT_SYMBOL_GPL (videobuf_dma_init_kernel);EXPORT_SYMBOL_GPL (videobuf_dma_init_overlay);
include/media/video-buf.h +4 -0
@@ -61,6 +61,8 @@ int videobuf_unlock(struct page **pages,*/ struct videobuf_dmabuf { +u32 magic; +/* for userland buffer */ int offset;struct page **pages;
@@ -78,6 +80,7 @@ struct videobuf_dmabuf {int direction; }; +void videobuf_dma_init (struct videobuf_dmabuf *dma);int videobuf_dma_init_user (struct videobuf_dmabuf *dma,int direction,unsigned long data,unsigned long size); int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
@@ -136,6 +139,7 @@ enum videobuf_state {struct videobuf_buffer {unsigned int i; +u32 magic;/* info about the buffer */ unsigned int width;
Signature · 1 line
Smoking Crack Organization