Skip to content

Commit c752c21

Browse files
committed
Merge tag 'auto-type-conversion-for-v6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto
Pull __auto_type to auto conversion from Peter Anvin: "Convert '__auto_type' to 'auto', defining a macro for 'auto' unless C23+ is in use" * tag 'auto-type-conversion-for-v6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto: tools/virtio: replace "__auto_type" with "auto" selftests/bpf: replace "__auto_type" with "auto" arch/x86: replace "__auto_type" with "auto" arch/nios2: replace "__auto_type" and adjacent equivalent with "auto" fs/proc: replace "__auto_type" with "const auto" include/linux: change "__auto_type" to "auto" compiler_types.h: add "auto" as a macro for "__auto_type"
2 parents 3d99347 + 4ecc26f commit c752c21

11 files changed

Lines changed: 46 additions & 29 deletions

File tree

arch/nios2/include/asm/uaccess.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ do { \
172172

173173
#define __put_user(x, ptr) \
174174
({ \
175-
__auto_type __pu_ptr = (ptr); \
176-
typeof(*__pu_ptr) __pu_val = (typeof(*__pu_ptr))(x); \
175+
auto __pu_ptr = (ptr); \
176+
auto __pu_val = (typeof(*__pu_ptr))(x); \
177177
__put_user_common(__pu_val, __pu_ptr); \
178178
})
179179

180180
#define put_user(x, ptr) \
181181
({ \
182-
__auto_type __pu_ptr = (ptr); \
183-
typeof(*__pu_ptr) __pu_val = (typeof(*__pu_ptr))(x); \
182+
auto __pu_ptr = (ptr); \
183+
auto __pu_val = (typeof(*__pu_ptr))(x); \
184184
access_ok(__pu_ptr, sizeof(*__pu_ptr)) ? \
185185
__put_user_common(__pu_val, __pu_ptr) : \
186186
-EFAULT; \

arch/x86/include/asm/bug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ do { \
129129

130130
#define __WARN_FLAGS(cond_str, flags) \
131131
do { \
132-
__auto_type __flags = BUGFLAG_WARNING|(flags); \
132+
auto __flags = BUGFLAG_WARNING|(flags); \
133133
instrumentation_begin(); \
134134
_BUG_FLAGS(cond_str, ASM_UD2, __flags, ARCH_WARN_REACHABLE); \
135135
instrumentation_end(); \

arch/x86/include/asm/string_64.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ KCFI_REFERENCE(__memset);
3131
#define __HAVE_ARCH_MEMSET16
3232
static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
3333
{
34-
const __auto_type s0 = s;
34+
const auto s0 = s;
3535
asm volatile (
3636
"rep stosw"
3737
: "+D" (s), "+c" (n)
@@ -44,7 +44,7 @@ static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
4444
#define __HAVE_ARCH_MEMSET32
4545
static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
4646
{
47-
const __auto_type s0 = s;
47+
const auto s0 = s;
4848
asm volatile (
4949
"rep stosl"
5050
: "+D" (s), "+c" (n)
@@ -57,7 +57,7 @@ static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
5757
#define __HAVE_ARCH_MEMSET64
5858
static inline void *memset64(uint64_t *s, uint64_t v, size_t n)
5959
{
60-
const __auto_type s0 = s;
60+
const auto s0 = s;
6161
asm volatile (
6262
"rep stosq"
6363
: "+D" (s), "+c" (n)

arch/x86/include/asm/uaccess_64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static inline void __user *mask_user_address(const void __user *ptr)
7272
return ret;
7373
}
7474
#define masked_user_access_begin(x) ({ \
75-
__auto_type __masked_ptr = (x); \
75+
auto __masked_ptr = (x); \
7676
__masked_ptr = mask_user_address(__masked_ptr); \
7777
__uaccess_begin(); __masked_ptr; })
7878

fs/proc/inode.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter)
303303

304304
static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos)
305305
{
306-
__auto_type read = pde->proc_ops->proc_read;
306+
const auto read = pde->proc_ops->proc_read;
307307
if (read)
308308
return read(file, buf, count, ppos);
309309
return -EIO;
@@ -325,7 +325,7 @@ static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count,
325325

326326
static ssize_t pde_write(struct proc_dir_entry *pde, struct file *file, const char __user *buf, size_t count, loff_t *ppos)
327327
{
328-
__auto_type write = pde->proc_ops->proc_write;
328+
const auto write = pde->proc_ops->proc_write;
329329
if (write)
330330
return write(file, buf, count, ppos);
331331
return -EIO;
@@ -347,7 +347,7 @@ static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t
347347

348348
static __poll_t pde_poll(struct proc_dir_entry *pde, struct file *file, struct poll_table_struct *pts)
349349
{
350-
__auto_type poll = pde->proc_ops->proc_poll;
350+
const auto poll = pde->proc_ops->proc_poll;
351351
if (poll)
352352
return poll(file, pts);
353353
return DEFAULT_POLLMASK;
@@ -369,7 +369,7 @@ static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts)
369369

370370
static long pde_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg)
371371
{
372-
__auto_type ioctl = pde->proc_ops->proc_ioctl;
372+
const auto ioctl = pde->proc_ops->proc_ioctl;
373373
if (ioctl)
374374
return ioctl(file, cmd, arg);
375375
return -ENOTTY;
@@ -392,7 +392,7 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne
392392
#ifdef CONFIG_COMPAT
393393
static long pde_compat_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg)
394394
{
395-
__auto_type compat_ioctl = pde->proc_ops->proc_compat_ioctl;
395+
const auto compat_ioctl = pde->proc_ops->proc_compat_ioctl;
396396
if (compat_ioctl)
397397
return compat_ioctl(file, cmd, arg);
398398
return -ENOTTY;
@@ -414,7 +414,7 @@ static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned
414414

415415
static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct vm_area_struct *vma)
416416
{
417-
__auto_type mmap = pde->proc_ops->proc_mmap;
417+
const auto mmap = pde->proc_ops->proc_mmap;
418418
if (mmap)
419419
return mmap(file, vma);
420420
return -EIO;
@@ -497,7 +497,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
497497
if (!use_pde(pde))
498498
return -ENOENT;
499499

500-
__auto_type release = pde->proc_ops->proc_release;
500+
const auto release = pde->proc_ops->proc_release;
501501
if (release) {
502502
pdeo = kmem_cache_alloc(pde_opener_cache, GFP_KERNEL);
503503
if (!pdeo) {
@@ -534,10 +534,9 @@ static int proc_reg_release(struct inode *inode, struct file *file)
534534
struct pde_opener *pdeo;
535535

536536
if (pde_is_permanent(pde)) {
537-
__auto_type release = pde->proc_ops->proc_release;
538-
if (release) {
537+
const auto release = pde->proc_ops->proc_release;
538+
if (release)
539539
return release(inode, file);
540-
}
541540
return 0;
542541
}
543542

include/linux/cleanup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@
212212

213213
#define __free(_name) __cleanup(__free_##_name)
214214

215-
#define __get_and_null(p, nullvalue) \
215+
#define __get_and_null(p, nullvalue) \
216216
({ \
217-
__auto_type __ptr = &(p); \
218-
__auto_type __val = *__ptr; \
217+
auto __ptr = &(p); \
218+
auto __val = *__ptr; \
219219
*__ptr = nullvalue; \
220220
__val; \
221221
})

include/linux/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
190190
#define data_race(expr) \
191191
({ \
192192
__kcsan_disable_current(); \
193-
__auto_type __v = (expr); \
193+
auto __v = (expr); \
194194
__kcsan_enable_current(); \
195195
__v; \
196196
})

include/linux/compiler_types.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717

1818
#ifndef __ASSEMBLY__
1919

20+
/*
21+
* C23 introduces "auto" as a standard way to define type-inferred
22+
* variables, but "auto" has been a (useless) keyword even since K&R C,
23+
* so it has always been "namespace reserved."
24+
*
25+
* Until at some future time we require C23 support, we need the gcc
26+
* extension __auto_type, but there is no reason to put that elsewhere
27+
* in the source code.
28+
*/
29+
#if __STDC_VERSION__ < 202311L
30+
# define auto __auto_type
31+
#endif
32+
2033
/*
2134
* Skipped when running bindgen due to a libclang issue;
2235
* see https://github.com/rust-lang/rust-bindgen/issues/2244.

include/linux/minmax.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
__cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))
9090

9191
#define __careful_cmp_once(op, x, y, ux, uy) ({ \
92-
__auto_type ux = (x); __auto_type uy = (y); \
92+
auto ux = (x); auto uy = (y); \
9393
BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \
9494
#op"("#x", "#y") signedness error"); \
9595
__cmp(op, ux, uy); })
@@ -129,7 +129,7 @@
129129
__careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
130130

131131
#define __careful_op3(op, x, y, z, ux, uy, uz) ({ \
132-
__auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\
132+
auto ux = (x); auto uy = (y); auto uz = (z); \
133133
BUILD_BUG_ON_MSG(!__types_ok3(ux, uy, uz), \
134134
#op"3("#x", "#y", "#z") signedness error"); \
135135
__cmp(op, ux, __cmp(op, uy, uz)); })
@@ -203,7 +203,7 @@
203203
* This macro checks @val/@lo/@hi to make sure they have compatible
204204
* signedness.
205205
*/
206-
#define clamp(val, lo, hi) __careful_clamp(__auto_type, val, lo, hi)
206+
#define clamp(val, lo, hi) __careful_clamp(auto, val, lo, hi)
207207

208208
/**
209209
* clamp_t - return a value clamped to a given range using a given type

tools/testing/selftests/bpf/prog_tests/socket_helpers.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
#define VMADDR_CID_LOCAL 1
1818
#endif
1919

20+
/* include/linux/compiler_types.h */
21+
#if __STDC_VERSION__ < 202311L && !defined(auto)
22+
# define auto __auto_type
23+
#endif
24+
2025
/* include/linux/cleanup.h */
2126
#define __get_and_null(p, nullvalue) \
2227
({ \
23-
__auto_type __ptr = &(p); \
24-
__auto_type __val = *__ptr; \
28+
auto __ptr = &(p); \
29+
auto __val = *__ptr; \
2530
*__ptr = nullvalue; \
2631
__val; \
2732
})

0 commit comments

Comments
 (0)