diff options
author | Suraj Jitindar Singh <sjitindarsingh@gmail.com> | 2017-04-12 14:37:24 +1000 |
---|---|---|
committer | Suraj Jitindar Singh <sjitindarsingh@gmail.com> | 2017-04-19 16:57:43 +1000 |
commit | 0aff80c0fc286b9ba386365c79088ccf156a7ab8 (patch) | |
tree | aaf6025e6038dd437256b2f38e8091dd44997c8f | |
parent | c29172e1734012af7a9b97c5170b9da6a571e343 (diff) | |
download | phosphor-mboxd-0aff80c0fc286b9ba386365c79088ccf156a7ab8.tar.gz phosphor-mboxd-0aff80c0fc286b9ba386365c79088ccf156a7ab8.zip |
mboxd: Check that window size is indeed a power of 2
The window size can be specified on the command line however we restrict
this to being a power of 2 due to the internal working of the daemon.
Currently we specify that this is the case in the help message but don't
explicitly verify this when parsing the command line.
Check that if the window size parameter is provided that the value is
indeed a power of 2 and error out if this is not the case.
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Change-Id: I0cb36222d53830996380702802373d862010f503
-rw-r--r-- | common.h | 5 | ||||
-rw-r--r-- | mboxd.c | 4 |
2 files changed, 9 insertions, 0 deletions
@@ -83,6 +83,11 @@ static inline int log_2(int val) return ret; } +static inline bool is_power_of_2(unsigned val) +{ + return __builtin_popcount(val) == 1; +} + char *get_dev_mtd(void); #endif /* COMMON_H */ @@ -241,6 +241,10 @@ static bool parse_cmdline(int argc, char **argv, fprintf(stderr, "Unparseable window size\n"); return false; } + if (!is_power_of_2(context->windows.default_size)) { + fprintf(stderr, "Window size not power of 2\n"); + return false; + } break; case 'v': verbosity++; |