Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2809456yba; Mon, 15 Apr 2019 21:16:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqxgGlzIeLOyAfXkeevSXqXPF9csNi7+1hP23doHaO3MR6NNB3DPlYhvx/9AuoNrU7hab1 X-Received: by 2002:a17:902:9a4c:: with SMTP id x12mr32508249plv.90.1555388177047; Mon, 15 Apr 2019 21:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555388177; cv=none; d=google.com; s=arc-20160816; b=xpTeKG5PjrzWne+6s3yVnHAnaDsEEhdzjC6+HhXxip7OzfbtRhSe+qefhAHMR2BZ/u zcW5OrUV8e2k7v4XKw5FZu7Ll7Gkw2UCSkjxifTtT2w9pqcyjdwK747c6AYc7f4F/xH1 1c6qxE3ofyYuYtkAmYbjw+82aLHlPI+NPLmWS2jTho6akfr087VBFm/oxEGsBRTzZ9Td 806KyPX56oojde5P8X3mB1g9AMjZEBlrLgBT2PaG3/jXAPoz2tMb1USq6kPBvJkeV7Ud jZxonjhnoV9xuD/QQYd1X1uetOGynd4foKIYzz+5clOLhMuFTEUWfvrw76TC7+b1sXi/ qK1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=cZaTnJzaj1g2Y2ZnsXXsRF2Ws6T/OU9xvE2CI6kI6Ww=; b=hZqFMwLdJo82zaJc11P3pSqQJAxCqgavkcZsYgL9L4kDSRwmra3+4amNjKrnKW1sfD dWod6Gevu1ti3mSisPM0YGCiY6gPqTEYaLKn8jMO7trKH+bznJTluRChJy+BlxI2QIyn SXAjugdLl36OwMB4pE083Ba8iBkUD0Vd+bQxIUMD1YzNrv4I+pdCmDcuCh4FegYg62m3 wD/syxY7vImLMxh+DBKYsdxGdl0510rbUxBAMgBwQW4haV7qQaegMXxK+xZiZmJQjbJV zdrirIafTnuhqE2xPi3eY1odxe3KAZShPJMwjGWN+PBgj86RJZzceogukjOIr7uIDy8o /q6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h73si50327235pfj.220.2019.04.15.21.15.58; Mon, 15 Apr 2019 21:16:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726258AbfDPEPQ (ORCPT + 99 others); Tue, 16 Apr 2019 00:15:16 -0400 Received: from www.osadl.org ([62.245.132.105]:49326 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbfDPEPQ (ORCPT ); Tue, 16 Apr 2019 00:15:16 -0400 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 Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Mark Brown , Tony Lindgren , Linus Walleij , Janusz Krzysztofik , Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire 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-Spam-Status: No, score=-4.2 required=6.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.1.4