Re: [PATCH bpf-next] bpf: fix 'dubious one-bit signed bitfield' warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 7/10/22 1:19 PM, Matthieu Baerts wrote:
Hi Yonghong,

Thank you for the review!

On 10/07/2022 18:59, Yonghong Song wrote:> On 7/10/22 1:35 AM, Matthieu
Baerts wrote:
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 81b19669efba..2ac424641cc3 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -345,10 +345,10 @@ struct bpf_verifier_state_list {
   };
     struct bpf_loop_inline_state {
-    int initialized:1; /* set to true upon first entry */
-    int fit_for_inline:1; /* true if callback function is the same
-                   * at each call and flags are always zero
-                   */
+    bool initialized; /* set to true upon first entry */
+    bool fit_for_inline; /* true if callback function is the same
+                  * at each call and flags are always zero
+                  */

I think changing 'int' to 'unsigned' is a better alternative for
potentially adding more bitfields in the future. This is also a pattern
for many other kernel data structures.

There was room, I was not sure if it would be OK but I saw 'bool' were
often used in structures from this bpf_verifier.h file.

I can of course switch to an unsigned one. I would have picked 'u8' when
looking at the structures around but any preferences from you?
'unsigned', 'unsigned int', 'u8', 'u32'?

The original data structure is
  struct bpf_loop_inline_state {
        int initialized:1; /* set to true upon first entry */
        int fit_for_inline:1; /* true if callback function is the same
                               * at each call and flags are always zero
                               */
        u32 callback_subprogno; /* valid when fit_for_inline is true */
  };

So 'initialized' and 'fit_for_inline' and additional padding will take
4 bytes, so 'unsigned', 'unsigned int', 'u32' should be appropriate here. Later, if people want to add a u8 or u16 to utilize the padding,
the type of 'initialized' and 'fit_for_inlined' might be changed to
u8 or u16.

For which of 'unsigned', 'unsigned int', 'u32', checking with
  $ [~/work/bpf-next/include/linux] grep ":1" *.h
both 'unsigned' and 'unsigned int' are used in many places. I don't have
a preference. I saw one instance 'unsigned int' is used in this file,
so 'unsigned int' should be okay here.



Cheers,
Matt



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux