[3/3] backports: Add kvcalloc()
diff mbox series

Message ID 20191116183623.8858-3-hauke@hauke-m.de
State New
Headers show
Series
  • [1/3] backports: Add return value to backport_pci_disable_link_state()
Related show

Commit Message

Hauke Mehrtens Nov. 16, 2019, 6:36 p.m. UTC
kvcalloc() was added in kernel commit 1c542f38ab8d ("mm: Introduce
kvcalloc()") and is now used by the fq header filers.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/mm.h | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Johannes Berg Nov. 19, 2019, 8:59 a.m. UTC | #1
On Sat, 2019-11-16 at 19:36 +0100, Hauke Mehrtens wrote:
> kvcalloc() was added in kernel commit 1c542f38ab8d ("mm: Introduce
> kvcalloc()") and is now used by the fq header filers.

Oops, I did the same some time ago but forgot to send it out.

> +{
> +	return kvmalloc_array(n, size, flags | __GFP_ZERO);

I did end up wondering though if __GFP_ZERO actually worked on all old
kernels?

johannes

--
To unsubscribe from this list: send the line "unsubscribe backports" in
Hauke Mehrtens Nov. 19, 2019, 7:12 p.m. UTC | #2
On 11/19/19 9:59 AM, Johannes Berg wrote:
> On Sat, 2019-11-16 at 19:36 +0100, Hauke Mehrtens wrote:
>> kvcalloc() was added in kernel commit 1c542f38ab8d ("mm: Introduce
>> kvcalloc()") and is now used by the fq header filers.
> 
> Oops, I did the same some time ago but forgot to send it out.
> 
>> +{
>> +	return kvmalloc_array(n, size, flags | __GFP_ZERO);
> 
> I did end up wondering though if __GFP_ZERO actually worked on all old
> kernels?

__GFP_ZERO is at least defined on old kernel versions. I haven't seen an
error when building against 3.14 for example and it is already used
somewhere else in this file.

Hauke
--
To unsubscribe from this list: send the line "unsubscribe backports" in
Johannes Berg Nov. 19, 2019, 7:38 p.m. UTC | #3
On Tue, 2019-11-19 at 20:12 +0100, Hauke Mehrtens wrote:
> On 11/19/19 9:59 AM, Johannes Berg wrote:
> > On Sat, 2019-11-16 at 19:36 +0100, Hauke Mehrtens wrote:
> > > kvcalloc() was added in kernel commit 1c542f38ab8d ("mm: Introduce
> > > kvcalloc()") and is now used by the fq header filers.
> > 
> > Oops, I did the same some time ago but forgot to send it out.
> > 
> > > +{
> > > +	return kvmalloc_array(n, size, flags | __GFP_ZERO);
> > 
> > I did end up wondering though if __GFP_ZERO actually worked on all old
> > kernels?
> 
> __GFP_ZERO is at least defined on old kernel versions. I haven't seen an
> error when building against 3.14 for example and it is already used
> somewhere else in this file.

I know. I just have a vague recollection it didn't always work for any
kind of allocation. I guess I should go search tomorrow...

johannes

--
To unsubscribe from this list: send the line "unsubscribe backports" in

Patch
diff mbox series

diff --git a/backport/backport-include/linux/mm.h b/backport/backport-include/linux/mm.h
index b28156d3..8ff7d6a6 100644
--- a/backport/backport-include/linux/mm.h
+++ b/backport/backport-include/linux/mm.h
@@ -50,4 +50,12 @@  static inline void *kvzalloc(size_t size, gfp_t flags)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(4,18,0)
+#define kvcalloc LINUX_BACKPORT(kvcalloc)
+static inline void *kvcalloc(size_t n, size_t size, gfp_t flags)
+{
+	return kvmalloc_array(n, size, flags | __GFP_ZERO);
+}
+#endif /* < 4.18 */
+
 #endif /* __BACKPORT_MM_H */