]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Fix kmod_list_remove_n_latest()
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 27 Dec 2011 04:46:12 +0000 (02:46 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 27 Dec 2011 04:48:36 +0000 (02:48 -0200)
It only worked because n was always 1. kmod_list_remove returns a
pointer to the next element, relative to the removed one. Therefore we
need to always get a pointer to the last.

libkmod/libkmod-list.c

index 4b68b77e28372552bb4f8f0e07722fb39533a937..cf6df37e5c209e02ba0d961e4a28501da23429e5 100644 (file)
@@ -241,26 +241,17 @@ struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
 struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
                                                        unsigned int n)
 {
-       struct kmod_list *l;
+       struct kmod_list *l = list;
        unsigned int i;
 
-       /*
-        * Get last element, remove all appended elments and if list became
-        * empty, set return pointer to NULL
-        */
-       l = kmod_list_prev(list, list);
-       if (l == NULL)
-               l = list;
-
-       for (i = 0; i < n; i++)
+       for (i = 0; i < n; i++) {
+               l = kmod_list_last(l);
                l = kmod_list_remove(l);
+       }
 
-       /* If list became empty, save it*/
-       if (l == NULL)
-               list = NULL;
-
-       return list;
+       return l;
 }
+
 /**
  * kmod_list_prev:
  * @list: the head of the list