public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched_ext: fix application of sizeof to pointer
@ 2024-11-16 23:02 guanjing
  2024-11-18 17:30 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: guanjing @ 2024-11-16 23:02 UTC (permalink / raw)
  To: tj, void, joshdon, haoluo, brho; +Cc: linux-kernel, guanjing

sizeof when applied to a pointer typed expression gives the size of
the pointer.

The proper fix in this particular case is to code sizeof(cpu_set_t)
instead of sizeof(cpuset).

This issue was detected with the help of Coccinelle.

Fixes: 22a920209ab6 ("sched_ext: Implement tickless support")
Signed-off-by: guanjing <guanjing@cmss.chinamobile.com>
---
 tools/sched_ext/scx_central.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/sched_ext/scx_central.c b/tools/sched_ext/scx_central.c
index 21deea320bd7..74f26423dd58 100644
--- a/tools/sched_ext/scx_central.c
+++ b/tools/sched_ext/scx_central.c
@@ -97,7 +97,7 @@ int main(int argc, char **argv)
 	SCX_BUG_ON(!cpuset, "Failed to allocate cpuset");
 	CPU_ZERO(cpuset);
 	CPU_SET(skel->rodata->central_cpu, cpuset);
-	SCX_BUG_ON(sched_setaffinity(0, sizeof(cpuset), cpuset),
+	SCX_BUG_ON(sched_setaffinity(0, sizeof(cpu_set_t), cpuset),
 		   "Failed to affinitize to central CPU %d (max %d)",
 		   skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);
 	CPU_FREE(cpuset);
-- 
2.33.0




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

* Re: [PATCH] sched_ext: fix application of sizeof to pointer
  2024-11-16 23:02 [PATCH] sched_ext: fix application of sizeof to pointer guanjing
@ 2024-11-18 17:30 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2024-11-18 17:30 UTC (permalink / raw)
  To: guanjing, Barret Rhoden, David Vernet, Hao Luo, Josh Don,
	Tejun Heo
  Cc: LKML, kernel-janitors

> sizeof when applied to a pointer typed expression gives the size of
> the pointer.
>
> The proper fix in this particular case is to code sizeof(cpu_set_t)
> instead of sizeof(cpuset).
…

I suggest to reconsider this view once more.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.12#n941

Would the specification “sizeof(*cpuset)” be more appropriate here?

Regards,
Markus

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

end of thread, other threads:[~2024-11-18 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-16 23:02 [PATCH] sched_ext: fix application of sizeof to pointer guanjing
2024-11-18 17:30 ` Markus Elfring

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