Skip to content

Commit 911affa

Browse files
authored
Merge pull request #596 from ojeda/no-ifdef-in-c-file
`vsprintf`: avoid `#ifdef` in `.c` file
2 parents a0f5988 + 3e7c98c commit 911affa

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16574,6 +16574,7 @@ T: git https://github.com/Rust-for-Linux/linux.git rust-next
1657416574
F: rust/
1657516575
F: samples/rust/
1657616576
F: Documentation/rust/
16577+
F: include/linux/rust.h
1657716578
K: \b(?i:rust)\b
1657816579

1657916580
RXRPC SOCKETS (AF_RXRPC)

include/linux/rust.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __LINUX_RUST_H
3+
#define __LINUX_RUST_H
4+
5+
#ifdef CONFIG_RUST
6+
char *rust_fmt_argument(char* buf, char* end, void *ptr);
7+
#else
8+
static inline char *rust_fmt_argument(char* buf, char* end, void *ptr)
9+
{
10+
return NULL;
11+
}
12+
#endif
13+
14+
#endif /* __LINUX_RUST_H */

lib/vsprintf.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/siphash.h>
4242
#include <linux/compiler.h>
4343
#include <linux/property.h>
44+
#include <linux/rust.h>
4445
#ifdef CONFIG_BLOCK
4546
#include <linux/blkdev.h>
4647
#endif
@@ -2233,10 +2234,6 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
22332234
return widen_string(buf, buf - buf_start, end, spec);
22342235
}
22352236

2236-
#ifdef CONFIG_RUST
2237-
char *rust_fmt_argument(char* buf, char* end, void *ptr);
2238-
#endif
2239-
22402237
/* Disable pointer hashing if requested */
22412238
bool no_hash_pointers __ro_after_init;
22422239
EXPORT_SYMBOL_GPL(no_hash_pointers);
@@ -2468,10 +2465,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
24682465
return device_node_string(buf, end, ptr, spec, fmt + 1);
24692466
case 'f':
24702467
return fwnode_string(buf, end, ptr, spec, fmt + 1);
2471-
#ifdef CONFIG_RUST
24722468
case 'A':
24732469
return rust_fmt_argument(buf, end, ptr);
2474-
#endif
24752470
case 'x':
24762471
return pointer_string(buf, end, ptr, spec);
24772472
case 'e':

0 commit comments

Comments
 (0)