dma-debug: check for sg_call_ents in best-fit algorithm too
[pandora-kernel.git] / lib / dma-debug.c
index 27b369d..c71e2dd 100644 (file)
@@ -147,6 +147,10 @@ static inline void dump_entry_trace(struct dma_debug_entry *entry)
 
 static bool driver_filter(struct device *dev)
 {
+       struct device_driver *drv;
+       unsigned long flags;
+       bool ret;
+
        /* driver filter off */
        if (likely(!current_driver_name[0]))
                return true;
@@ -155,32 +159,28 @@ static bool driver_filter(struct device *dev)
        if (current_driver && dev->driver == current_driver)
                return true;
 
-       /* driver filter on but not yet initialized */
-       if (!current_driver && current_driver_name[0]) {
-               struct device_driver *drv = get_driver(dev->driver);
-               unsigned long flags;
-               bool ret = false;
+       if (current_driver || !current_driver_name[0])
+               return false;
 
-               if (!drv)
-                       return false;
-
-               /* lock to protect against change of current_driver_name */
-               read_lock_irqsave(&driver_name_lock, flags);
-
-               if (drv->name &&
-                   strncmp(current_driver_name, drv->name,
-                           NAME_MAX_LEN-1) == 0) {
-                       current_driver = drv;
-                       ret = true;
-               }
+       /* driver filter on but not yet initialized */
+       drv = get_driver(dev->driver);
+       if (!drv)
+               return false;
 
-               read_unlock_irqrestore(&driver_name_lock, flags);
-               put_driver(drv);
+       /* lock to protect against change of current_driver_name */
+       read_lock_irqsave(&driver_name_lock, flags);
 
-               return ret;
+       ret = false;
+       if (drv->name &&
+           strncmp(current_driver_name, drv->name, NAME_MAX_LEN - 1) == 0) {
+               current_driver = drv;
+               ret = true;
        }
 
-       return false;
+       read_unlock_irqrestore(&driver_name_lock, flags);
+       put_driver(drv);
+
+       return ret;
 }
 
 #define err_printk(dev, entry, format, arg...) do {            \
@@ -262,11 +262,12 @@ static struct dma_debug_entry *hash_bucket_find(struct hash_bucket *bucket,
                 */
                matches += 1;
                match_lvl = 0;
-               entry->size      == ref->size      ? ++match_lvl : match_lvl;
-               entry->type      == ref->type      ? ++match_lvl : match_lvl;
-               entry->direction == ref->direction ? ++match_lvl : match_lvl;
+               entry->size         == ref->size         ? ++match_lvl : 0;
+               entry->type         == ref->type         ? ++match_lvl : 0;
+               entry->direction    == ref->direction    ? ++match_lvl : 0;
+               entry->sg_call_ents == ref->sg_call_ents ? ++match_lvl : 0;
 
-               if (match_lvl == 3) {
+               if (match_lvl == 4) {
                        /* perfect-fit - return the result */
                        return entry;
                } else if (match_lvl > last_lvl) {
@@ -1076,16 +1077,14 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
                        .dev_addr       = sg_dma_address(s),
                        .size           = sg_dma_len(s),
                        .direction      = dir,
-                       .sg_call_ents   = 0,
+                       .sg_call_ents   = nelems,
                };
 
                if (mapped_ents && i >= mapped_ents)
                        break;
 
-               if (!i) {
-                       ref.sg_call_ents = nelems;
+               if (!i)
                        mapped_ents = get_nr_mapped_entries(dev, s);
-               }
 
                check_unmap(&ref);
        }