backports: add sg_nents()
authorJohannes Berg <johannes.berg@intel.com>
Tue, 7 Feb 2017 13:13:14 +0000 (14:13 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 7 Feb 2017 14:07:22 +0000 (15:07 +0100)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
backport/backport-include/linux/scatterlist.h
backport/compat/compat-3.7.c

index 62d7078c2bb5fb56564a000cb5f033907db0014e..6a264ed4e769591ba89b76e42dc25044821de983 100644 (file)
@@ -2,6 +2,10 @@
 #define __BACKPORT_SCATTERLIST_H
 #include_next <linux/scatterlist.h>
 
+#if LINUX_VERSION_IS_LESS(3,7,0)
+int sg_nents(struct scatterlist *sg);
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
 
 /*
index f7e7848b22baeba555a18dc0621880c2eb93e550..e3721676a423e1ac30f21131573516d88d525bd5 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/pci.h>
 #include <linux/pci_regs.h>
 #include <linux/of.h>
+#include <linux/scatterlist.h>
 
 bool mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
                      unsigned long delay)
@@ -278,3 +279,12 @@ struct device_node *of_get_child_by_name(const struct device_node *node,
 EXPORT_SYMBOL_GPL(of_get_child_by_name);
 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) */
 #endif /* CONFIG_OF */
+
+int sg_nents(struct scatterlist *sg)
+{
+       int nents;
+       for (nents = 0; sg; sg = sg_next(sg))
+               nents++;
+       return nents;
+}
+EXPORT_SYMBOL_GPL(sg_nents);