Skip to content

Commit 3cd39bc

Browse files
alejandro-colomarandy-shev
authored andcommitted
kernel.h: Move ARRAY_SIZE() to a separate header
Touching files so used for the kernel, forces 'make' to recompile most of the kernel. Having those definitions in more granular files helps avoid recompiling so much of the kernel. Signed-off-by: Alejandro Colomar <alx@kernel.org> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20230817143352.132583-2-lucas.segarra.fernandez@intel.com [andy: reduced to cover only string.h for now] Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent cec422a commit 3cd39bc

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

include/linux/array_size.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_ARRAY_SIZE_H
3+
#define _LINUX_ARRAY_SIZE_H
4+
5+
#include <linux/compiler.h>
6+
7+
/**
8+
* ARRAY_SIZE - get the number of elements in array @arr
9+
* @arr: array to be sized
10+
*/
11+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
12+
13+
#endif /* _LINUX_ARRAY_SIZE_H */

include/linux/kernel.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <linux/stdarg.h>
1515
#include <linux/align.h>
16+
#include <linux/array_size.h>
1617
#include <linux/limits.h>
1718
#include <linux/linkage.h>
1819
#include <linux/stddef.h>
@@ -50,12 +51,6 @@
5051
#define READ 0
5152
#define WRITE 1
5253

53-
/**
54-
* ARRAY_SIZE - get the number of elements in array @arr
55-
* @arr: array to be sized
56-
*/
57-
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
58-
5954
#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
6055

6156
#define u64_to_user_ptr(x) ( \

include/linux/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _LINUX_STRING_H_
33
#define _LINUX_STRING_H_
44

5+
#include <linux/array_size.h>
56
#include <linux/compiler.h> /* for inline */
67
#include <linux/types.h> /* for size_t */
78
#include <linux/stddef.h> /* for NULL */

0 commit comments

Comments
 (0)