[lkml]   [2022]   [Oct]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask()
I looked at this a bit more closely.  The code is just bonkers now.  It
can't go in like this.

tdx_parse_tdinfo() stashes two global variables. Then, about three
lines later in the function, it calls get_cc_mask() which just returns
one of those variables, modulo a little masking.

Ditto for the td_attr. It's stashed in a global variable and then read
one time.

There is *ZERO* reason to store 'td_attr'. There's also zero reason to
have 'gpa_width' as a global variable. It's only used *ONE* *TIME* from
the scope of *ONE* *FUNCTION*.

Even the comment is bonkers:

* Initializes gpa_width and td_attr. Must be called before
* get_cc_mask() or attribute checks.

Comments are great. But comments that are only there because the code
is obtuse are not. I changed it to:


It doesn't even need a comment now. Why? Because it's obvious from the
naming and calling convention that it initializes cc_mask and what the
ordering dependency is. Plus, even *if* I missed the call, or screwed
up the order, the compiler would tell me that I'm a dolt.

The whole global variable thing actually makes the code objectively
worse in almost every possible way.

Can you please take a look through this and make sure I didn't botch


The end result is about 50 lines less than what was there before. Most
of it is comment removal but the code is simpler too.

Acks and Tested-by's would be appreciated.

 \ /
  Last update: 2022-10-29 01:28    [W:0.404 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site