backports: add devm_kmalloc_array()
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 9 Aug 2014 12:00:29 +0000 (14:00 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 9 Aug 2014 14:40:38 +0000 (16:40 +0200)
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
backport/backport-include/linux/device.h

index 9ed73988e1af2de7bac89e2bf95f420d37a2ed65..830105df33fdb44a01fd0bb0df7865cf99b6d90e 100644 (file)
@@ -160,4 +160,15 @@ __ATTRIBUTE_GROUPS(_name)
 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
+#define devm_kmalloc_array LINUX_BACKPORT(devm_kmalloc_array)
+static inline void *devm_kmalloc_array(struct device *dev,
+                                      size_t n, size_t size, gfp_t flags)
+{
+       if (size != 0 && n > SIZE_MAX / size)
+               return NULL;
+       return devm_kmalloc(dev, n * size, flags);
+}
+#endif
+
 #endif /* __BACKPORT_DEVICE_H */