mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Add 'malloc' failure check in config_name
@ 2024-04-23  7:37 Kunwu Chan
  2024-04-23  8:50 ` Muhammad Usama Anjum
  2024-04-23 11:10 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Kunwu Chan @ 2024-04-23  7:37 UTC (permalink / raw)
  To: kunwu.chan, pbonzini, shuah
  Cc: kvm, linux-kselftest, linux-kernel, Kunwu Chan

There is a 'malloc' call in config_name function, which can
be unsuccessful. This patch will add the malloc failure checking
to avoid possible null dereference and give more information
about test fail reasons.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 tools/testing/selftests/kvm/get-reg-list.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
index 91f05f78e824..22398696ffd6 100644
--- a/tools/testing/selftests/kvm/get-reg-list.c
+++ b/tools/testing/selftests/kvm/get-reg-list.c
@@ -66,6 +66,7 @@ static const char *config_name(struct vcpu_reg_list *c)
 		len += strlen(s->name) + 1;
 
 	c->name = malloc(len);
+	TEST_ASSERT(c->name, "-ENOMEM when allocating config name");
 
 	len = 0;
 	for_each_sublist(c, s) {
-- 
2.40.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: selftests: Add 'malloc' failure check in config_name
  2024-04-23  7:37 [PATCH] KVM: selftests: Add 'malloc' failure check in config_name Kunwu Chan
@ 2024-04-23  8:50 ` Muhammad Usama Anjum
  2024-04-23 11:10 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-23  8:50 UTC (permalink / raw)
  To: Kunwu Chan, kunwu.chan, pbonzini, shuah
  Cc: Muhammad Usama Anjum, kvm, linux-kselftest, linux-kernel

On 4/23/24 12:37 PM, Kunwu Chan wrote:
> There is a 'malloc' call in config_name function, which can
> be unsuccessful. This patch will add the malloc failure checking
> to avoid possible null dereference and give more information
> about test fail reasons.
> 
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
LGTM

Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  tools/testing/selftests/kvm/get-reg-list.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
> index 91f05f78e824..22398696ffd6 100644
> --- a/tools/testing/selftests/kvm/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/get-reg-list.c
> @@ -66,6 +66,7 @@ static const char *config_name(struct vcpu_reg_list *c)
>  		len += strlen(s->name) + 1;
>  
>  	c->name = malloc(len);
> +	TEST_ASSERT(c->name, "-ENOMEM when allocating config name");
>  
>  	len = 0;
>  	for_each_sublist(c, s) {

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: selftests: Add 'malloc' failure check in config_name
  2024-04-23  7:37 [PATCH] KVM: selftests: Add 'malloc' failure check in config_name Kunwu Chan
  2024-04-23  8:50 ` Muhammad Usama Anjum
@ 2024-04-23 11:10 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-04-23 11:10 UTC (permalink / raw)
  To: Kunwu Chan, linux-kselftest, kvm, kernel-janitors,
	Muhammad Usama Anjum, Paolo Bonzini, Shuah Khan
  Cc: LKML, Kunwu Chan

…
> This patch will add the malloc failure checking
…

* Please use a corresponding imperative wording for the change description.

* Would you like to add the tag “Fixes” accordingly?


…
> +++ b/tools/testing/selftests/kvm/get-reg-list.c
> @@ -66,6 +66,7 @@ static const char *config_name(struct vcpu_reg_list *c)
>  		len += strlen(s->name) + 1;
>
>  	c->name = malloc(len);
> +	TEST_ASSERT(c->name, "-ENOMEM when allocating config name");
…

Can “errno” be relevant for the error message construction?

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-23 11:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23  7:37 [PATCH] KVM: selftests: Add 'malloc' failure check in config_name Kunwu Chan
2024-04-23  8:50 ` Muhammad Usama Anjum
2024-04-23 11:10 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®