Skip to content

Commit 8ba388c

Browse files
geertuakpm00
authored andcommitted
lib: dhry: fix sleeping allocations inside non-preemptable section
The Smatch static checker reports the following warnings: lib/dhry_run.c:38 dhry_benchmark() warn: sleeping in atomic context lib/dhry_run.c:43 dhry_benchmark() warn: sleeping in atomic context Indeed, dhry() does sleeping allocations inside the non-preemptable section delimited by get_cpu()/put_cpu(). Fix this by using atomic allocations instead. Add error handling, as atomic these allocations may fail. Link: https://lkml.kernel.org/r/bac6d517818a7cd8efe217c1ad649fffab9cc371.1688568764.git.geert+renesas@glider.be Fixes: 13684e9 ("lib: dhry: fix unstable smp_processor_id(_) usage") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/0469eb3a-02eb-4b41-b189-de20b931fa56@moroto.mountain Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent fdb54d9 commit 8ba388c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/dhry_1.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,15 @@ int dhry(int n)
139139

140140
/* Initializations */
141141

142-
Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL);
143-
Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL);
142+
Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC);
143+
if (!Next_Ptr_Glob)
144+
return -ENOMEM;
145+
146+
Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC);
147+
if (!Ptr_Glob) {
148+
kfree(Next_Ptr_Glob);
149+
return -ENOMEM;
150+
}
144151

145152
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
146153
Ptr_Glob->Discr = Ident_1;

0 commit comments

Comments
 (0)