From patchwork Tue Apr 16 03:56:31 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: 10901889 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 D495713B5 for ; Tue, 16 Apr 2019 04:02:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B23BE2881B for ; Tue, 16 Apr 2019 04:02:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A292C28942; Tue, 16 Apr 2019 04:02:43 +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 C46012881B for ; Tue, 16 Apr 2019 04:02:42 +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=0dOSczRKDkmLEDTbaxeUX7BxYv1U+/TqlbKGcvoumOw=; b=e7j CGGVuuzKTjVIgQr1m/x/XMfrhoi7Ls6+7WUDSgAh58sGEAhPoGTPM1TKDHb2/BDfDWI9K6HIDTIfg r9XI5TkCci3E8KiEFidHOU+ELLKF343BtqxD+Hzxgp0IWKXAY+tFc5OMonMw9ST8cprVocOgIjhzZ ECDYgjs0UA5lU8yl7rcicMbSs9uZZ6drm+u96JPqOtS8FExdg6byP+5D8DqKvTMuP2Of8Zlac+/EE 8wabiNtRe0Wq+U5HbPuwR2kzCmOWyu8oGSepyCxv+ES6b56ynm0stHt11XPswzRvIWVoHxDv9RUaN ogcT2NzXtCJemQviT93edacXXnvuKDQ==; 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 1hGFIt-0005CI-Ug; Tue, 16 Apr 2019 04:02:39 +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 1hGFIq-0005Bb-9f for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2019 04:02:38 +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 x3G427M9032015; Tue, 16 Apr 2019 06:02:07 +0200 From: Nicholas Mc Guire To: Jason Cooper Subject: [PATCH V2] ARM: mvebu: at least report the kzalloc failure Date: Tue, 16 Apr 2019 05:56:31 +0200 Message-Id: <1555386991-8855-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_210236_636501_B58DD17D X-CRM114-Status: GOOD ( 10.54 ) 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: Andrew Lunn , Gregory Clement , linux-kernel@vger.kernel.org, Russell King , Nicholas Mc Guire , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth 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 Although it is very unlikely that the allocation during init would fail any such failure should point to the original cause to allow easier understanding of the ensuing null-pointer dereference splat. Signed-off-by: Nicholas Mc Guire --- Problem located with 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: [ 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: mvebu_v7_defconfig (implies MACH_MVEBU_ANY=y) (with some unrelated sparse warnings about missing syscalls) Patch is against 5.1-rc4 (localversion-next is 20190415) arch/arm/mach-mvebu/board-v7.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c index 0b10acd..df84cb6 100644 --- a/arch/arm/mach-mvebu/board-v7.c +++ b/arch/arm/mach-mvebu/board-v7.c @@ -128,6 +128,9 @@ static void __init i2c_quirk(void) struct property *new_compat; new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); + if (!new_compat) + pr_err("new_compat allocation failure in %s()\n", + __func__); new_compat->name = kstrdup("compatible", GFP_KERNEL); new_compat->length = sizeof("marvell,mv78230-a0-i2c");