From patchwork Tue Apr 16 04:03:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10901893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 471801390 for ; Tue, 16 Apr 2019 04:15:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20087287BB for ; Tue, 16 Apr 2019 04:15:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7D628880; Tue, 16 Apr 2019 04:15:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A38DE287BB for ; Tue, 16 Apr 2019 04:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=kPXo3DxdbqsLPtF3ohRIUuK9HKvP3RNmHCTfvJZ/c6M=; b=ITC wL68BZIJX4frHtK19VmVnlcEG4rBx4+zQW1C4mImkSJwL01dXwPNe1BifUFHxCTv+cvBQsPba4Glx 2/7wAt8cadBF0sDXIAXoySeJRhcBJjtkSS166u+Yy5eT56ftmhepO9AbszPTSofUAh63zi/guwPhi WoVcGk1EncKrSG5m8AHBB6u6akhyKWGSV1ggyDfskNKJXnTV3ph0S2Z7jPGBxap4o/4oz5oulHtvG iyc8JUmJH0Sbg+1p/uCf+F94D4/+Mfp50HdiFkST4wYzXyFsyiEPkO4cwMxiJz6GRuqZXrwsW7OQU m/qFlpKpSY6D8h02Hehu6brNasY3Y3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGFV2-00018e-Mw; Tue, 16 Apr 2019 04:15:12 +0000 Received: from www.osadl.org ([2001:a60:9266:ffff:62:245:132:105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGFUz-00016W-0R for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2019 04:15:10 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id x3G48kX0003254; Tue, 16 Apr 2019 06:08:46 +0200 From: Nicholas Mc Guire To: Russell King Subject: [PATCH V2] ARM: imx legacy: warn on failed allocation Date: Tue, 16 Apr 2019 06:03:29 +0200 Message-Id: <1555387409-9018-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190415_211509_350978_138078F8 X-CRM114-Status: GOOD ( 10.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Rapoport , Tony Lindgren , Shawn Guo , Sascha Hauer , Janusz Krzysztofik , linux-kernel@vger.kernel.org, Mark Brown , NXP Linux Team , Pengutronix Kernel Team , Nicholas Mc Guire , Fabio Estevam , Linus Walleij , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Even in init the allocation can fail and thus should report by pr_err() so that the cause can be easily identified. Signed-off-by: Nicholas Mc Guire Link: https://lkml.org/lkml/2019/4/14/152 --- Problem located with an experimental coccinelle script V2: Russell King pointed out that the use of WARN_ON() would result in a stack trace followed by the oops due to dereferencing of the NULL pointer and so make it even less likely that users would uncover the actual cause - so drop the WARN_ON() and use a short pr_err() message that points to the oops cause directly. Note that this will trigger a checkpatch WARNING: "WARNING: Possible unnecessary 'out of memory' message" but comparing the oops with an without the one-line pr_err I would argue that it makes sense to include it (first line here is from pr_err()): [ 8061.514840] shared page allocation failure in hello_init() [ 8113.563239] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 [ 8113.563250] #PF error: [WRITE] [ 8113.563255] PGD 8000000129993067 P4D 8000000129993067 PUD 129992067 PMD 0 [ 8113.563267] Oops: 0002 [#1] SMP PTI [ 8113.563276] CPU: 2 PID: 2656 Comm: bash Tainted: G W O 5.0.0-rc3livepatchtest-next-20190123+ #4 [ 8113.563280] Hardware name: Quanta TWH/TWH, BIOS QU221 10/14/2011 [ 8113.563292] RIP: 0010:foo_store+0x3a/0x90 [hello_chardev] ... Patch was compile-tested with: imx_v4_v5_defconfig (implies CONFIG_MACH_MX27ADS=y) (with some unrelated sparse warnings about unimplemented syscalls) Patch is against 5.1-rc4 (localversion-next is 20190415) arch/arm/mach-imx/mach-mx27ads.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/mach-imx/mach-mx27ads.c b/arch/arm/mach-imx/mach-mx27ads.c index 6dd7f57..cba6876 100644 --- a/arch/arm/mach-imx/mach-mx27ads.c +++ b/arch/arm/mach-imx/mach-mx27ads.c @@ -247,6 +247,10 @@ static void __init mx27ads_regulator_init(void) struct gpio_chip *vchip; vchip = kzalloc(sizeof(*vchip), GFP_KERNEL); + if (!vchip) + pr_err("vchip allocation failure in %s()\n", + __func__); + vchip->owner = THIS_MODULE; vchip->label = "LCD"; vchip->base = MX27ADS_LCD_GPIO;