Re: [kvm-unit-tests PATCH v8 08/12] s390x: retrieve decimal and hexadecimal kernel parameters

Thomas Huth
2020-06-09T05:22:12Z

On 08/06/2020 10.12, Pierre Morel wrote:
> We often need to retrieve hexadecimal kernel parameters.
> Let's implement a shared utility to do it.
>
> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
> lib/s390x/kernel-args.c | 60 +++++++++++++++++++++++++++++++++++++++++
> lib/s390x/kernel-args.h | 18 +++++++++++++
> s390x/Makefile | 1 +
> 3 files changed, 79 insertions(+)
> create mode 100644 lib/s390x/kernel-args.c
> create mode 100644 lib/s390x/kernel-args.h
[...]
> +int kernel_arg(int argc, char *argv[], const char *str, unsigned long *val)
> +{
> + int i, ret;
> + char *p;
> +
> + for (i = 0; i < argc; i++) {
> + ret = strncmp(argv[i], str, strlen(str));
> + if (ret)
> + continue;
> + p = strchr(argv[i], '=');
> + if (!p)
> + return -1;
> + p = strchr(p, 'x');
> + if (!p)
> + *val = atol(p + 1);

If p is NULL, then you call atol(NULL + 1) ... I think you need another
temporary variable here instead to hold the new pointer / NULL value?

Thomas