mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
cpumf/pai: Improve -m XXX argument verification
Speed up the check of the option -m argument and improve the error message. The argument number must be a power of 2 number and this check is improved. Furthermore split the error message and provide one message for invalid characters and one error message for the argument not being a power of 2 number. Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Suggested-by: Eduard Stefes <eddy@linux.ibm.com> Suggested-by: Juergen Christ <jchrist@linux.ibm.com> Tested-by: Jan Polensky <japo@linux.ibm.com> Reviewed-by: Jan Polensky <japo@linux.ibm.com> Reviewed-by: Juergen Christ <jchrist@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
b6a4d7a6c1
commit
8f2d77c9d3
18
cpumf/pai.c
18
cpumf/pai.c
@@ -962,19 +962,13 @@ static void record_cpus_nnpa(const char *cp)
|
||||
parse_cpulist(S390_EVT_PAI_NNPA, cp);
|
||||
}
|
||||
|
||||
/* Mapsize must be power of 2 and larger than 4. Count bits in n and
|
||||
* return 0 if input is invalid and has a bit count larger than one.
|
||||
/* Mapsize must be power of 2 and larger than 4. Return true in this case.
|
||||
*/
|
||||
static unsigned long check_mapsize(unsigned long n)
|
||||
static bool check_mapsize(unsigned long n)
|
||||
{
|
||||
int bit, cnt = 0;
|
||||
|
||||
if (n < 4)
|
||||
return 0;
|
||||
for (bit = 0; bit < __BITS_PER_LONG; ++bit)
|
||||
if (n & (1 << bit))
|
||||
++cnt;
|
||||
return cnt == 1 ? n : 0;
|
||||
return (n & (n - 1)) == 0;
|
||||
}
|
||||
|
||||
static void setprio(const char *prio)
|
||||
@@ -1040,11 +1034,11 @@ int main(int argc, char **argv)
|
||||
errx(EXIT_FAILURE, "Invalid argument for -%c", ch);
|
||||
break;
|
||||
case 'm':
|
||||
errno = 0;
|
||||
mapsize = strtoul(optarg, &slash, 0);
|
||||
mapsize = check_mapsize(mapsize);
|
||||
if (errno || !mapsize || *slash)
|
||||
if (!mapsize || *slash)
|
||||
errx(EXIT_FAILURE, "Invalid argument for -%c", ch);
|
||||
if (!check_mapsize(mapsize))
|
||||
errx(EXIT_FAILURE, "No power of 2 number for -%c", ch);
|
||||
break;
|
||||
case 'n':
|
||||
record_cpus_nnpa(optarg);
|
||||
|
||||
Reference in New Issue
Block a user