]> nv-tegra.nvidia Code Review - linux-2.6.git/commitdiff
Add CONFIG_DEBUG_SG sg validation
authorJens Axboe <jens.axboe@oracle.com>
Mon, 22 Oct 2007 18:01:06 +0000 (20:01 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 22 Oct 2007 19:20:03 +0000 (21:20 +0200)
Add a Kconfig entry which will toggle some sanity checks on the sg
entry and tables.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
25 files changed:
include/asm-alpha/scatterlist.h
include/asm-arm/scatterlist.h
include/asm-avr32/scatterlist.h
include/asm-blackfin/scatterlist.h
include/asm-cris/scatterlist.h
include/asm-frv/scatterlist.h
include/asm-h8300/scatterlist.h
include/asm-ia64/scatterlist.h
include/asm-m32r/scatterlist.h
include/asm-m68k/scatterlist.h
include/asm-m68knommu/scatterlist.h
include/asm-mips/scatterlist.h
include/asm-parisc/scatterlist.h
include/asm-powerpc/scatterlist.h
include/asm-s390/scatterlist.h
include/asm-sh/scatterlist.h
include/asm-sh64/scatterlist.h
include/asm-sparc/scatterlist.h
include/asm-sparc64/scatterlist.h
include/asm-v850/scatterlist.h
include/asm-x86/scatterlist_32.h
include/asm-x86/scatterlist_64.h
include/asm-xtensa/scatterlist.h
include/linux/scatterlist.h
lib/Kconfig.debug

index b7647063bd55e4bfc358cff736b34303293853d9..440747ca6349058d31f04b6191ed2de0870ce557 100644 (file)
@@ -5,6 +5,9 @@
 #include <asm/types.h>
   
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
 
index ab1d85dd0232b6d96bf6231ec4df36549eb27f2a..ca0a37d0340093b06b1a7d28f09b1c9e89015f48 100644 (file)
@@ -5,6 +5,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;         /* buffer offset                 */
        dma_addr_t      dma_address;    /* dma address                   */
index 1356f29d89f5b01c006f6496113c4821205372b4..377320e3bd1741b19d7c5acdc2ad2de78502ae6a 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+   unsigned long       sg_magic;
+#endif
     unsigned long      page_link;
     unsigned int       offset;
     dma_addr_t         dma_address;
index 384af549e5b8836fedfad06d0a1c6ff5d95a6895..32128d53469b0ba73c519cdba16098c55a0d9cf2 100644 (file)
@@ -4,6 +4,9 @@
 #include <linux/mm.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
        dma_addr_t dma_address;
index 5a8a83440d3b80a8d9c8033032e00c14dda566a3..faff53ad1f96cd56327caf8c182ad70c81fc161f 100644 (file)
@@ -2,6 +2,9 @@
 #define __ASM_CRIS_SCATTERLIST_H
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        char *  address;    /* Location data is to be transferred to */
        unsigned int length;
 
index 53dade7b2e167b3c6a54973f7ef7aa06d0c84a34..f7da007b763ccb0aa08e5b02738216924f242468 100644 (file)
@@ -22,6 +22,9 @@
  * and that's it. There's no excuse for not highmem enabling YOUR driver. /jens
  */
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;         /* for highmem, page offset */
 
index 7e41983d6b261ff182e7e77b0b45fa9287d33345..d3ecdd87ac90b0ca8642d6d38886f6afc14a56fe 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;
        dma_addr_t      dma_address;
index 2f76ce3049647e3972ef78651fd9bc1a92f565f3..d6f57874041d0f80e351dcfeafb27aed21d755a8 100644 (file)
@@ -9,6 +9,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
        unsigned int length;    /* buffer length */
index 33b4b4d2c89e17ae590b1f597887357aa4a7b76a..1ed372c73d0bd9ef05f143289ccecc77cbc3ada5 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long sg_magic;
+#endif
     char *  address;    /* Location data is to be transferred to, NULL for
                          * highmem page */
     unsigned long page_link;
index e06bb891048ec68c1e228de3afe084fcccfc2c3b..d3a7a0edfecab3d9ad3a04cc3e936cf1ca9faf50 100644 (file)
@@ -4,6 +4,9 @@
 #include <linux/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
        unsigned int length;
index 28bed41dc80b3d354802cae1f2c7c48514f1600d..10942840e88fcb030a3f3216930b6aa5c8b3d6c9 100644 (file)
@@ -5,6 +5,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;
        dma_addr_t      dma_address;
index 787797cdb0a973ded7c5ca6c75bd94a2a24d9318..83d69fe17c9f1404e481e2d2cbb22985f0be2cf5 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;
        dma_addr_t      dma_address;
index 26da9146fffbd814c6a98c12fb2ec78c7c23f79d..cd3cfdf822897141e1561655815977b540731b47 100644 (file)
@@ -5,6 +5,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
 
index b9f1dbc24843088f33eddc411a54794f26dae205..fcf7d55afe4599e3049713156145997fa066e1e3 100644 (file)
@@ -14,6 +14,9 @@
 #include <asm/dma.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
        unsigned int length;
index eb3948690d6e4c4895451303ba32e16d7c739323..29ec8e28c8df375f1aa13e12b9edf2fa89752831 100644 (file)
@@ -2,6 +2,9 @@
 #define _ASMS390_SCATTERLIST_H
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long sg_magic;
+#endif
     unsigned long page_link;
     unsigned int offset;
     unsigned int length;
index bc7c809e16fbe7f6ede7717c2edfd2c01eb536ff..a7d0d1856a993bae7cde541f6c4df72a6a464bf3 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long sg_magic;
+#endif
     unsigned long page_link;
     unsigned int offset;/* for highmem, page offset */
     dma_addr_t dma_address;
index 0afd856e218a46ba82460da48f52331901d68d98..5109251970e7ca96fde9b68e6cc66d74662e1f72 100644 (file)
@@ -14,6 +14,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long sg_magic;
+#endif
     unsigned long page_link;
     unsigned int offset;/* for highmem, page offset */
     dma_addr_t dma_address;
index 45b16f1072be2ac530087d4ce30336378239833c..e08d3d775b08aff2fa7029aa592744cc78ed5ad4 100644 (file)
@@ -5,6 +5,9 @@
 #include <linux/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long sg_magic;
+#endif
        unsigned long page_link;
        unsigned int offset;
 
index 4cbaf7c6b0bb95f34d861f1113b09170ce0b5b8f..6df23f070b1a31b6c916528ca870b52b538dc6f4 100644 (file)
@@ -6,6 +6,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;
 
index db91febc21001326fc207d9770f95786e44ae2dd..02d27b3fb061b1b47b84bf310c536ce3006d126a 100644 (file)
@@ -17,6 +17,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned        offset;
        dma_addr_t      dma_address;
index 140a5b37fa779df699e6bd6ee7202e9ebdb099b6..0e7d997a34be7c4aaf16da9201c7b2700de4157e 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long      sg_magic;
+#endif
     unsigned long      page_link;
     unsigned int       offset;
     dma_addr_t         dma_address;
index e3447846e03dacd05f6af9171aace3f9d5434cf6..1847c72befeb9aca69a3402c6a243c001b728c20 100644 (file)
@@ -4,6 +4,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+    unsigned long      sg_magic;
+#endif
     unsigned long      page_link;
     unsigned int       offset;
     unsigned int       length;
index 3b8aba5d2c68254b2d81717f6ae6169c7d9be9a2..810080bb0a2b2cfa498c39fed32c11d2897763bd 100644 (file)
@@ -14,6 +14,9 @@
 #include <asm/types.h>
 
 struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
        unsigned long   page_link;
        unsigned int    offset;
        dma_addr_t      dma_address;
index c6136e8a7f58fcb561ffc042b501e7a9f554c1a1..42daf5e1526592e351fdcafe464565a5d272682a 100644 (file)
@@ -23,6 +23,8 @@
  *
  */
 
+#define SG_MAGIC       0x87654321
+
 /**
  * sg_set_page - Set sg entry to point at given page
  * @sg:                 SG entry
@@ -39,6 +41,9 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page)
 {
        unsigned long page_link = sg->page_link & 0x3;
 
+#ifdef CONFIG_DEBUG_SG
+       BUG_ON(sg->sg_magic != SG_MAGIC);
+#endif
        sg->page_link = page_link | (unsigned long) page;
 }
 
@@ -81,6 +86,9 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
  **/
 static inline struct scatterlist *sg_next(struct scatterlist *sg)
 {
+#ifdef CONFIG_DEBUG_SG
+       BUG_ON(sg->sg_magic != SG_MAGIC);
+#endif
        if (sg_is_last(sg))
                return NULL;
 
@@ -123,6 +131,10 @@ static inline struct scatterlist *sg_last(struct scatterlist *sgl,
        for_each_sg(sgl, sg, nents, i)
                ret = sg;
 
+#endif
+#ifdef CONFIG_DEBUG_SG
+       BUG_ON(sgl[0].sg_magic != SG_MAGIC);
+       BUG_ON(!sg_is_last(ret));
 #endif
        return ret;
 }
@@ -180,6 +192,9 @@ static inline void sg_init_one(struct scatterlist *sg, const void *buf,
                               unsigned int buflen)
 {
        memset(sg, 0, sizeof(*sg));
+#ifdef CONFIG_DEBUG_SG
+       sg->sg_magic = SG_MAGIC;
+#endif
        sg_mark_end(sg, 1);
        sg_set_buf(sg, buf, buflen);
 }
@@ -198,6 +213,13 @@ static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
 {
        memset(sgl, 0, sizeof(*sgl) * nents);
        sg_mark_end(sgl, nents);
+#ifdef CONFIG_DEBUG_SG
+       {
+               int i;
+               for (i = 0; i < nents; i++)
+                       sgl[i].sg_magic = SG_MAGIC;
+       }
+#endif
 }
 
 /**
index c567f219191d590116bcdd4498349d72e62ce612..1faa5087dc86d65685f97a0714bf70e7f586fd35 100644 (file)
@@ -389,6 +389,16 @@ config DEBUG_LIST
 
          If unsure, say N.
 
+config DEBUG_SG
+       bool "Debug SG table operations"
+       depends on DEBUG_KERNEL
+       help
+         Enable this to turn on checks on scatter-gather tables. This can
+         help find problems with drivers that do not properly initialize
+         their sg tables.
+
+         If unsure, say N.
+
 config FRAME_POINTER
        bool "Compile the kernel with frame pointers"
        depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || AVR32 || SUPERH || BFIN)