On 01/20/2017 02:19 AM, Ingo Molnar wrote:

* Jason Baron <jba...@akamai.com> wrote:

 struct static_key {
        atomic_t enabled;
+/*
+ * bit 0 => 1 if key is initially true
+ *         0 if initially false
+ * bit 1 => 1 if points to struct static_key_mod
+ *         0 if points to struct jump_entry
+ */
+       union {
+               unsigned long type;
+               struct jump_entry *entries;
+               struct static_key_mod *next;
+       };


+                       key->type = (unsigned long)jlm2 | static_key_type(key);

+               key->type = (unsigned long)jlm | static_key_type(key);

+               *prev = (struct static_key_mod *)((unsigned long)jlm->next |
+                               ((unsigned long)*prev & JUMP_TYPE_MASK));

+                       key->type = (unsigned long)jlm->entries |
+                                       static_key_type(key);

I really hate these very ugly type conversions. Is there no cleaner way?

For example the last line could sure be written as:

                        key->entries = jlm->entries;
                        key->type |= static_key_type(key);

right?

Hi,

So that is going to over-write the static_key_type(key) in the first assignment. If the order is reversed we can't just |= in the pointer type.

How about:

static void jump_key_set_entries(struct static_key *key, struct jump_entry *entries)
{
       unsigned long type;

       type = static_key_type(key);
       key->entries = entries;
       key->type |= type;
}

and then we can also add:

void jump_key_set_mod(struct static_key *key, struct static_key_mod *mod)

doing basically the same thing. That will avoid the casts that you called out.

better?

Thanks,

-Jason

Reply via email to