drm: Make the hlist API compatible with Linux 3.17
authorFrançois Tigeot <ftigeot@wolfpond.org>
Tue, 25 Aug 2015 11:45:44 +0000 (13:45 +0200)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Tue, 25 Aug 2015 11:51:05 +0000 (13:51 +0200)
* Replace hlist_add_after_rcu by hlist_add_behind_rcu

* hlist_for_each_entry() now only uses 3 arguments

sys/dev/drm/drm_hashtab.c
sys/dev/drm/include/drm/drmP.h
sys/dev/drm/include/linux/fs.h [copied from sys/dev/drm/include/linux/hashtable.h with 91% similarity]
sys/dev/drm/include/linux/hashtable.h
sys/dev/drm/include/linux/list.h
sys/dev/drm/include/linux/rculist.h [copied from sys/dev/drm/include/linux/hashtable.h with 80% similarity]

index 046de46..73fca67 100644 (file)
@@ -60,14 +60,13 @@ void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
 {
        struct drm_hash_item *entry;
        struct hlist_head *h_list;
-       struct hlist_node *list;
        unsigned int hashed_key;
        int count = 0;
 
        hashed_key = hash_long(key, ht->order);
        DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
        h_list = &ht->table[hashed_key];
-       hlist_for_each_entry(entry, list, h_list, head)
+       hlist_for_each_entry(entry, h_list, head)
                DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
 }
 
@@ -76,14 +75,13 @@ static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
 {
        struct drm_hash_item *entry;
        struct hlist_head *h_list;
-       struct hlist_node *list;
        unsigned int hashed_key;
 
        hashed_key = hash_long(key, ht->order);
        h_list = &ht->table[hashed_key];
-       hlist_for_each_entry(entry, list, h_list, head) {
+       hlist_for_each_entry(entry, h_list, head) {
                if (entry->key == key)
-                       return list;
+                       return &entry->head;
                if (entry->key > key)
                        break;
        }
@@ -95,14 +93,13 @@ static struct hlist_node *drm_ht_find_key_rcu(struct drm_open_hash *ht,
 {
        struct drm_hash_item *entry;
        struct hlist_head *h_list;
-       struct hlist_node *list;
        unsigned int hashed_key;
 
        hashed_key = hash_long(key, ht->order);
        h_list = &ht->table[hashed_key];
-       hlist_for_each_entry_rcu(entry, list, h_list, head) {
+       hlist_for_each_entry_rcu(entry, h_list, head) {
                if (entry->key == key)
-                       return list;
+                       return &entry->head;
                if (entry->key > key)
                        break;
        }
@@ -113,22 +110,22 @@ int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
 {
        struct drm_hash_item *entry;
        struct hlist_head *h_list;
-       struct hlist_node *list, *parent;
+       struct hlist_node *parent;
        unsigned int hashed_key;
        unsigned long key = item->key;
 
        hashed_key = hash_long(key, ht->order);
        h_list = &ht->table[hashed_key];
        parent = NULL;
-       hlist_for_each_entry(entry, list, h_list, head) {
+       hlist_for_each_entry(entry, h_list, head) {
                if (entry->key == key)
                        return -EINVAL;
                if (entry->key > key)
                        break;
-               parent = list;
+               parent = &entry->head;
        }
        if (parent) {
-               hlist_add_after_rcu(parent, &item->head);
+               hlist_add_behind_rcu(&item->head, parent);
        } else {
                hlist_add_head_rcu(&item->head, h_list);
        }
index e6011b1..0baee5f 100644 (file)
@@ -99,6 +99,7 @@ MALLOC_DECLARE(M_DRM);
 #include <linux/pci.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
+#include <linux/fs.h>
 #include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/mm.h>
similarity index 91%
copy from sys/dev/drm/include/linux/hashtable.h
copy to sys/dev/drm/include/linux/fs.h
index c84d2b6..373e0fd 100644 (file)
@@ -24,9 +24,9 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _LINUX_HASHTABLE_H_
-#define _LINUX_HASHTABLE_H_
+#ifndef _LINUX_FS_H_
+#define _LINUX_FS_H_
 
-#define DECLARE_HASHTABLE(name, bits)
+#include <linux/rculist.h>
 
-#endif /* _LINUX_HASHTABLE_H_ */
+#endif /* _LINUX_FS_H_ */
index c84d2b6..46462d4 100644 (file)
 #ifndef _LINUX_HASHTABLE_H_
 #define _LINUX_HASHTABLE_H_
 
+#include <linux/rculist.h>
+
 #define DECLARE_HASHTABLE(name, bits)
 
+#define hash_for_each_possible(name, obj, member, key) \
+       hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], member)
+
 #endif /* _LINUX_HASHTABLE_H_ */
index 3dbeedf..5f2393a 100644 (file)
@@ -398,10 +398,14 @@ static inline int list_is_last(const struct list_head *list,
 #define        hlist_for_each_safe(p, n, head)                                 \
        for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
 
-#define        hlist_for_each_entry(tp, p, head, field)                        \
-       for (p = (head)->first;                                         \
-           p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
+#define hlist_entry_safe(ptr, type, member) \
+       (ptr) ? hlist_entry(ptr, type, member) : NULL
+
+#define hlist_for_each_entry(pos, head, member)                                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
+            pos;                                                       \
+            pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
+
 #define hlist_for_each_entry_continue(tp, p, field)                    \
        for (p = (p)->next;                                             \
            p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
@@ -418,11 +422,6 @@ static inline int list_is_last(const struct list_head *list,
 void drm_list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
     struct list_head *a, struct list_head *b));
 
-#define hlist_for_each_entry_rcu(tp, p, head, field)   \
-               hlist_for_each_entry(tp, p, head, field)
-
-#define hlist_add_after_rcu(prev, n)   hlist_add_after(prev, n)
-
 #define hlist_add_head_rcu(n, h)       hlist_add_head(n, h)
 
 #define hlist_del_init_rcu(n)          hlist_del_init(n)
similarity index 80%
copy from sys/dev/drm/include/linux/hashtable.h
copy to sys/dev/drm/include/linux/rculist.h
index c84d2b6..eb85f75 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _LINUX_HASHTABLE_H_
-#define _LINUX_HASHTABLE_H_
+#ifndef _LINUX_RCULIST_H_
+#define _LINUX_RCULIST_H_
 
-#define DECLARE_HASHTABLE(name, bits)
+#include <linux/list.h>
 
-#endif /* _LINUX_HASHTABLE_H_ */
+static inline void hlist_add_behind_rcu(struct hlist_node *n,
+                                       struct hlist_node *prev)
+{
+       hlist_add_after(prev, n);
+}
+
+#define hlist_for_each_entry_rcu(pos, head, member)    \
+       hlist_for_each_entry(pos, head, member)
+
+#endif /* _LINUX_RCULIST_H_ */