Skip to contentSkip to conversation

bpf: replace redundant |= operation with assignmen

PATCH In review Colin Ian King 3 participants 3 messages Oct 31, 2024 – Nov 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: replace redundant |= operation with assignmen

The operation msk |= ~0ULL contains a redundant bit-wise or operation since all the bits are going to be set to 1, so replace this with an assignment since this is more optimal and probably clearer too.

---
 kernel/bpf/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/inode.c +1 -1
index 9aaf5124648b..fea07e12601f 100644
@@ -914,7 +914,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		str = param->string;
 		while ((p = strsep(&str, ":"))) {
 			if (strcmp(p, "any") == 0) {
-				msk |= ~0ULL;
+				msk = ~0ULL;
 			} else if (find_btf_enum_const(info.btf, enum_t, enum_pfx, p, &val)) {
 				msk |= 1ULL << val;
 			} else {
Signature · 1 line
2.39.5
#1 lore raw
Quoted 15 lines · Colin Ian King

The operation msk |= ~0ULL contains a redundant bit-wise or operation since all the bits are going to be set to 1, so replace this with an assignment since this is more optimal and probably clearer too.

---
 kernel/bpf/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/inode.c +0 -0
index 9aaf5124648b..fea07e12601f 100644

kernel/bpf/inode.c static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 917

Quoted 5 lines
kernel/bpf/inode.c +1 -1
@@ -914,7 +914,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
                str = param->string;
                while ((p = strsep(&str, ":"))) {
                        if (strcmp(p, "any") == 0) {
-                               msk |= ~0ULL;
+                               msk = ~0ULL;

This was done for consistency with the other branch. Is there anything wrong with this code? Doesn't seem so, so I'd like to keep it as is.

pw-bot: cr

Quoted 6 lines
kernel/bpf/inode.c +0 -1
                        } else if (find_btf_enum_const(info.btf, enum_t, enum_pfx, p, &val)) {
                                msk |= 1ULL << val;
                        } else {
--

2.39.5

#2 lore raw
In reply to Colin Ian King
Quoted 24 lines · Colin Ian King

The operation msk |= ~0ULL contains a redundant bit-wise or operation since all the bits are going to be set to 1, so replace this with an assignment since this is more optimal and probably clearer too.

---
 kernel/bpf/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/inode.c +1 -1
index 9aaf5124648b..fea07e12601f 100644
@@ -914,7 +914,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		str = param->string;
 		while ((p = strsep(&str, ":"))) {
 			if (strcmp(p, "any") == 0) {
-				msk |= ~0ULL;
+				msk = ~0ULL;
 			} else if (find_btf_enum_const(info.btf, enum_t, enum_pfx, p, &val)) {
 				msk |= 1ULL << val;
 			} else {
Signature · 1 line
2.39.5

The patch subject contains a typo ("assignmen" should be "assignment"), but maybe this can just be fixed on apply ..

Cheers,
Chris