]> www.infradead.org Git - users/dwmw2/linux.git/commit
add a string-to-qstr constructor
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 24 Jan 2025 03:51:04 +0000 (22:51 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 28 Jan 2025 00:25:45 +0000 (19:25 -0500)
commitc1feab95e0b2e9fce7e4f4b2739baf40d84543af
tree8ca3bca18afaac45263905c50491ae86e99ae636
parent5f4e6f7f8b77a3b1fb0005f6e1692475785ae05f
add a string-to-qstr constructor

Quite a few places want to build a struct qstr by given string;
it would be convenient to have a primitive doing that, rather
than open-coding it via QSTR_INIT().

The closest approximation was in bcachefs, but that expands to
initializer list - {.len = strlen(string), .name = string}.
It would be more useful to have it as compound literal -
(struct qstr){.len = strlen(string), .name = string}.

Unlike initializer list it's a valid expression.  What's more,
it's a valid lvalue - it's an equivalent of anonymous local
variable with such initializer, so the things like
path->dentry = d_alloc_pseudo(mnt->mnt_sb, &QSTR(name));
are valid.  It can also be used as initializer, with identical
effect -
struct qstr x = (struct qstr){.name = s, .len = strlen(s)};
is equivalent to
struct qstr anon_variable = {.name = s, .len = strlen(s)};
struct qstr x = anon_variable;
// anon_variable is never used after that point
and any even remotely sane compiler will manage to collapse that
into
struct qstr x = {.name = s, .len = strlen(s)};

What compound literals can't be used for is initialization of
global variables, but those are covered by QSTR_INIT().

This commit lifts definition(s) of QSTR() into linux/dcache.h,
converts it to compound literal (all bcachefs users are fine
with that) and converts assorted open-coded instances to using
that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/anon_inodes.c
fs/bcachefs/fsck.c
fs/bcachefs/recovery.c
fs/bcachefs/util.h
fs/erofs/xattr.c
fs/file_table.c
fs/kernfs/file.c
include/linux/dcache.h
mm/secretmem.c
net/sunrpc/rpc_pipe.c