Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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"

+46 -29
+4 -4
arch/nios2/include/asm/uaccess.h
··· 172 172 173 173 #define __put_user(x, ptr) \ 174 174 ({ \ 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); \ 177 177 __put_user_common(__pu_val, __pu_ptr); \ 178 178 }) 179 179 180 180 #define put_user(x, ptr) \ 181 181 ({ \ 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); \ 184 184 access_ok(__pu_ptr, sizeof(*__pu_ptr)) ? \ 185 185 __put_user_common(__pu_val, __pu_ptr) : \ 186 186 -EFAULT; \
+1 -1
arch/x86/include/asm/bug.h
··· 129 129 130 130 #define __WARN_FLAGS(cond_str, flags) \ 131 131 do { \ 132 - __auto_type __flags = BUGFLAG_WARNING|(flags); \ 132 + auto __flags = BUGFLAG_WARNING|(flags); \ 133 133 instrumentation_begin(); \ 134 134 _BUG_FLAGS(cond_str, ASM_UD2, __flags, ARCH_WARN_REACHABLE); \ 135 135 instrumentation_end(); \
+3 -3
arch/x86/include/asm/string_64.h
··· 31 31 #define __HAVE_ARCH_MEMSET16 32 32 static inline void *memset16(uint16_t *s, uint16_t v, size_t n) 33 33 { 34 - const __auto_type s0 = s; 34 + const auto s0 = s; 35 35 asm volatile ( 36 36 "rep stosw" 37 37 : "+D" (s), "+c" (n) ··· 44 44 #define __HAVE_ARCH_MEMSET32 45 45 static inline void *memset32(uint32_t *s, uint32_t v, size_t n) 46 46 { 47 - const __auto_type s0 = s; 47 + const auto s0 = s; 48 48 asm volatile ( 49 49 "rep stosl" 50 50 : "+D" (s), "+c" (n) ··· 57 57 #define __HAVE_ARCH_MEMSET64 58 58 static inline void *memset64(uint64_t *s, uint64_t v, size_t n) 59 59 { 60 - const __auto_type s0 = s; 60 + const auto s0 = s; 61 61 asm volatile ( 62 62 "rep stosq" 63 63 : "+D" (s), "+c" (n)
+1 -1
arch/x86/include/asm/uaccess_64.h
··· 72 72 return ret; 73 73 } 74 74 #define masked_user_access_begin(x) ({ \ 75 - __auto_type __masked_ptr = (x); \ 75 + auto __masked_ptr = (x); \ 76 76 __masked_ptr = mask_user_address(__masked_ptr); \ 77 77 __uaccess_begin(); __masked_ptr; }) 78 78
+9 -10
fs/proc/inode.c
··· 303 303 304 304 static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos) 305 305 { 306 - __auto_type read = pde->proc_ops->proc_read; 306 + const auto read = pde->proc_ops->proc_read; 307 307 if (read) 308 308 return read(file, buf, count, ppos); 309 309 return -EIO; ··· 325 325 326 326 static ssize_t pde_write(struct proc_dir_entry *pde, struct file *file, const char __user *buf, size_t count, loff_t *ppos) 327 327 { 328 - __auto_type write = pde->proc_ops->proc_write; 328 + const auto write = pde->proc_ops->proc_write; 329 329 if (write) 330 330 return write(file, buf, count, ppos); 331 331 return -EIO; ··· 347 347 348 348 static __poll_t pde_poll(struct proc_dir_entry *pde, struct file *file, struct poll_table_struct *pts) 349 349 { 350 - __auto_type poll = pde->proc_ops->proc_poll; 350 + const auto poll = pde->proc_ops->proc_poll; 351 351 if (poll) 352 352 return poll(file, pts); 353 353 return DEFAULT_POLLMASK; ··· 369 369 370 370 static long pde_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg) 371 371 { 372 - __auto_type ioctl = pde->proc_ops->proc_ioctl; 372 + const auto ioctl = pde->proc_ops->proc_ioctl; 373 373 if (ioctl) 374 374 return ioctl(file, cmd, arg); 375 375 return -ENOTTY; ··· 392 392 #ifdef CONFIG_COMPAT 393 393 static long pde_compat_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg) 394 394 { 395 - __auto_type compat_ioctl = pde->proc_ops->proc_compat_ioctl; 395 + const auto compat_ioctl = pde->proc_ops->proc_compat_ioctl; 396 396 if (compat_ioctl) 397 397 return compat_ioctl(file, cmd, arg); 398 398 return -ENOTTY; ··· 414 414 415 415 static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct vm_area_struct *vma) 416 416 { 417 - __auto_type mmap = pde->proc_ops->proc_mmap; 417 + const auto mmap = pde->proc_ops->proc_mmap; 418 418 if (mmap) 419 419 return mmap(file, vma); 420 420 return -EIO; ··· 497 497 if (!use_pde(pde)) 498 498 return -ENOENT; 499 499 500 - __auto_type release = pde->proc_ops->proc_release; 500 + const auto release = pde->proc_ops->proc_release; 501 501 if (release) { 502 502 pdeo = kmem_cache_alloc(pde_opener_cache, GFP_KERNEL); 503 503 if (!pdeo) { ··· 534 534 struct pde_opener *pdeo; 535 535 536 536 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) 539 539 return release(inode, file); 540 - } 541 540 return 0; 542 541 } 543 542
+3 -3
include/linux/cleanup.h
··· 212 212 213 213 #define __free(_name) __cleanup(__free_##_name) 214 214 215 - #define __get_and_null(p, nullvalue) \ 215 + #define __get_and_null(p, nullvalue) \ 216 216 ({ \ 217 - __auto_type __ptr = &(p); \ 218 - __auto_type __val = *__ptr; \ 217 + auto __ptr = &(p); \ 218 + auto __val = *__ptr; \ 219 219 *__ptr = nullvalue; \ 220 220 __val; \ 221 221 })
+1 -1
include/linux/compiler.h
··· 190 190 #define data_race(expr) \ 191 191 ({ \ 192 192 __kcsan_disable_current(); \ 193 - __auto_type __v = (expr); \ 193 + auto __v = (expr); \ 194 194 __kcsan_enable_current(); \ 195 195 __v; \ 196 196 })
+13
include/linux/compiler_types.h
··· 18 18 #ifndef __ASSEMBLY__ 19 19 20 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 + 33 + /* 21 34 * Skipped when running bindgen due to a libclang issue; 22 35 * see https://github.com/rust-lang/rust-bindgen/issues/2244. 23 36 */
+3 -3
include/linux/minmax.h
··· 89 89 __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) 90 90 91 91 #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); \ 93 93 BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \ 94 94 #op"("#x", "#y") signedness error"); \ 95 95 __cmp(op, ux, uy); }) ··· 129 129 __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) 130 130 131 131 #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); \ 133 133 BUILD_BUG_ON_MSG(!__types_ok3(ux, uy, uz), \ 134 134 #op"3("#x", "#y", "#z") signedness error"); \ 135 135 __cmp(op, ux, __cmp(op, uy, uz)); }) ··· 203 203 * This macro checks @val/@lo/@hi to make sure they have compatible 204 204 * signedness. 205 205 */ 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) 207 207 208 208 /** 209 209 * clamp_t - return a value clamped to a given range using a given type
+7 -2
tools/testing/selftests/bpf/prog_tests/socket_helpers.h
··· 17 17 #define VMADDR_CID_LOCAL 1 18 18 #endif 19 19 20 + /* include/linux/compiler_types.h */ 21 + #if __STDC_VERSION__ < 202311L && !defined(auto) 22 + # define auto __auto_type 23 + #endif 24 + 20 25 /* include/linux/cleanup.h */ 21 26 #define __get_and_null(p, nullvalue) \ 22 27 ({ \ 23 - __auto_type __ptr = &(p); \ 24 - __auto_type __val = *__ptr; \ 28 + auto __ptr = &(p); \ 29 + auto __val = *__ptr; \ 25 30 *__ptr = nullvalue; \ 26 31 __val; \ 27 32 })
+1 -1
tools/virtio/linux/compiler.h
··· 31 31 */ 32 32 #define data_race(expr) \ 33 33 ({ \ 34 - __auto_type __v = (expr); \ 34 + auto __v = (expr); \ 35 35 __v; \ 36 36 }) 37 37