From patchwork Wed Jul 5 14:54:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13302286 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6618FEB64DA for ; Wed, 5 Jul 2023 14:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjGEOyl (ORCPT ); Wed, 5 Jul 2023 10:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbjGEOyj (ORCPT ); Wed, 5 Jul 2023 10:54:39 -0400 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE2B19AF for ; Wed, 5 Jul 2023 07:54:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:5979:7b6f:39a:b9cb]) by baptiste.telenet-ops.be with bizsmtp id HSuC2A00Z45Xpxs01SuCGm; Wed, 05 Jul 2023 16:54:13 +0200 Received: from rox.of.borg ([192.168.97.57] helo=rox) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qH3tR-000ccO-2b; Wed, 05 Jul 2023 16:54:12 +0200 Received: from geert by rox with local (Exim 4.95) (envelope-from ) id 1qH3tU-00Aw3y-K5; Wed, 05 Jul 2023 16:54:12 +0200 From: Geert Uytterhoeven To: Andrew Morton , Dan Carpenter Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] lib: dhry: Fix sleeping allocations inside non-preemptable section Date: Wed, 5 Jul 2023 16:54:04 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org 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. Fixes: 13684e966d46283e ("lib: dhry: fix unstable smp_processor_id(_) usage") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/0469eb3a-02eb-4b41-b189-de20b931fa56@moroto.mountain Signed-off-by: Geert Uytterhoeven --- Alternatively, memory (de)allocation could be spin off into their own functions, and called outside the non-preemptable section. But that would be more intrusive. --- lib/dhry_1.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/dhry_1.c b/lib/dhry_1.c index 83247106824cc7f4..08edbbb19f573ff7 100644 --- a/lib/dhry_1.c +++ b/lib/dhry_1.c @@ -139,8 +139,15 @@ int dhry(int n) /* Initializations */ - Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL); - Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL); + Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC); + if (!Next_Ptr_Glob) + return -ENOMEM; + + Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC); + if (!Ptr_Glob) { + kfree(Next_Ptr_Glob); + return -ENOMEM; + } Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; Ptr_Glob->Discr = Ident_1;