linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: use ARRAY_SIZE
@ 2021-11-24  9:22 cgel.zte
  2021-11-24  9:46 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2021-11-24  9:22 UTC (permalink / raw)
  To: pbonzini
  Cc: shuah, deng.changcheng, mlevitsk, kvm, linux-kselftest,
	linux-kernel, Zeal Robot

From: Changcheng Deng <deng.changcheng@zte.com.cn>

Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
---
 tools/testing/selftests/kvm/x86_64/debug_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/x86_64/debug_regs.c b/tools/testing/selftests/kvm/x86_64/debug_regs.c
index 5f078db1bcba..ef24ad62d36a 100644
--- a/tools/testing/selftests/kvm/x86_64/debug_regs.c
+++ b/tools/testing/selftests/kvm/x86_64/debug_regs.c
@@ -168,7 +168,7 @@ int main(void)
 	target_rip = CAST_TO_RIP(ss_start);
 	target_dr6 = 0xffff4ff0ULL;
 	vcpu_regs_get(vm, VCPU_ID, &regs);
-	for (i = 0; i < (sizeof(ss_size) / sizeof(ss_size[0])); i++) {
+	for (i = 0; i < ARRAY_SIZE(ss_size); i++) {
 		target_rip += ss_size[i];
 		CLEAR_DEBUG();
 		debug.control = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |
-- 
2.25.1


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

* Re: [PATCH] KVM: selftests: use ARRAY_SIZE
  2021-11-24  9:22 [PATCH] KVM: selftests: use ARRAY_SIZE cgel.zte
@ 2021-11-24  9:46 ` Greg KH
  2021-11-26 10:31   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2021-11-24  9:46 UTC (permalink / raw)
  To: cgel.zte
  Cc: pbonzini, shuah, deng.changcheng, mlevitsk, kvm, linux-kselftest,
	linux-kernel, Zeal Robot

On Wed, Nov 24, 2021 at 09:22:56AM +0000, cgel.zte@gmail.com wrote:
> From: Changcheng Deng <deng.changcheng@zte.com.cn>
> 
> Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>

Your email address does not match these here, you need to provide a
signed-off-by as well.

And are you _SURE_ that you can use kernel #defines in userspace testing
code?

thanks,

greg k-h

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

* Re: [PATCH] KVM: selftests: use ARRAY_SIZE
  2021-11-24  9:46 ` Greg KH
@ 2021-11-26 10:31   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-11-26 10:31 UTC (permalink / raw)
  To: Greg KH, cgel.zte
  Cc: shuah, deng.changcheng, mlevitsk, kvm, linux-kselftest,
	linux-kernel, Zeal Robot

On 11/24/21 10:46, Greg KH wrote:
>> From: Changcheng Deng<deng.changcheng@zte.com.cn>
>>
>> Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.
>>
>> Reported-by: Zeal Robot<zealci@zte.com.cn>
>> Signed-off-by: Changcheng Deng<deng.changcheng@zte.com.cn>
> Your email address does not match these here, you need to provide a
> signed-off-by as well.
> 
> And are you_SURE_  that you can use kernel #defines in userspace testing
> code?

Dpeends on which, but ARRAY_SIZE is among those that can be used:

$ git grep '#define ARRAY_SIZE' 'tools/*.h'
tools/gpio/gpio-utils.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
tools/iio/iio_utils.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
tools/include/linux/kernel.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
tools/testing/selftests/bpf/progs/profiler.inc.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
tools/testing/selftests/cgroup/cgroup_util.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/kselftest_harness.h:#define ARRAY_SIZE(a)	(sizeof(a) / sizeof(a[0]))
tools/testing/selftests/landlock/common.h:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
tools/testing/selftests/vm/pkey-helpers.h:#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
tools/virtio/linux/kernel.h:#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

In particular, most KVM tests already include linux/kernel.h
indirectly via linux/list.h.

Paolo


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

end of thread, other threads:[~2021-11-26 10:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24  9:22 [PATCH] KVM: selftests: use ARRAY_SIZE cgel.zte
2021-11-24  9:46 ` Greg KH
2021-11-26 10:31   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).