From patchwork Thu Apr 18 23:31:08 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: 10908219 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 1CA1D14DB for ; Thu, 18 Apr 2019 23:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFA07283B1 for ; Thu, 18 Apr 2019 23:37:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD3E528CC8; Thu, 18 Apr 2019 23:37:06 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 29A0728BDE for ; Thu, 18 Apr 2019 23:37:06 +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=UkXdmMmRiVplaObflaSyLUwPQZKcG0r0Wh0qLDLQ/hY=; b=f8g kGCDn+hclkJfR2Nv3vZwKPQAo5XwUQ2drvAIDTiN4aQ6AdoeL8B4MvChZVEijyzRll6WIfT5efE7g 1BFQXfHW4APHafYeWUthi/YPM65odn7voWtK3RpO7avFPXKzMAQ83Knl5psoEFWpaUAY5u4ZCQJoT 9Yfq3IFvsm8vOxMr7GpmSkOHnmvAa2Blj9P9pdBPPX813tqjXkLFAOnbxlonire5U6a5eUU17MaHZ u8/QO+gCsiFnSGFCqradv/z1ngZy2/rFduexq8DoAVPAKn0Jz8TWu6nIByMpxDhFQ41IwAp9mCEsW URCmM9Ma9Kdm2vwFB+HZrhOAtkEsvXg==; 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 1hHGaW-0003bu-UF; Thu, 18 Apr 2019 23:37:04 +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 1hHGaT-0003bO-4g; Thu, 18 Apr 2019 23:37:03 +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 x3INaWCx006335; Fri, 19 Apr 2019 01:36:32 +0200 From: Nicholas Mc Guire To: Eric Anholt Subject: [PATCH V2] staging: vc04_services: handle kzalloc failure Date: Fri, 19 Apr 2019 01:31:08 +0200 Message-Id: <1555630268-17017-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-20190418_163701_482965_6D077F78 X-CRM114-Status: GOOD ( 10.98 ) 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: Stefan Wahren , devel@driverdev.osuosl.org, Greg Kroah-Hartman , Phil Elwell , linux-kernel@vger.kernel.org, Tobias Buettner , Luis Chamberlain , linux-rpi-kernel@lists.infradead.org, Nicholas Mc Guire , Dominic Braun , Nicolas Saenz Julienne , 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 The kzalloc here was being used without checking the return - if the kzalloc fails return VCHIQ_ERROR. The call-site of vchiq_platform_init_state() vchiq_init_state() was not responding to an allocation failure so checks for != VCHIQ_SUCCESS and pass VCHIQ_ERROR up to vchiq_platform_init() which then will fail with -EINVAL. Signed-off-by: Nicholas Mc Guire Reported-by: kbuild test robot Acked-By: Stefan Wahren --- Problem located with experimental coccinelle script V2: The != VCHIQ_SUCCES went unnoticed not clear how I did that as building drivers/staging/vc04_services/vchiq.o seemed to have succeeded anyway kbuild test found it. This is one of the disadvantages if one can not make path/file.o due to missing Makefiles and is required to build entire directories for compile-testing, I suspect that I did not clean the directory before compile-testing the patch. Patch was compile-tested with: bcm2835_defconfig (implies BCM2835_VCHIQ=m) (with sparse warning: CHECK drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29: warning: incorrect type in argument 1 (different address spaces) drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29: expected void const *x drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29: got char [noderef] *buf drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63: warning: incorrect type in argument 1 (different address spaces) drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63: expected void const *addr drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63: got char [noderef] * CC [M] drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.o Q: should this buf have been remapped to user space e.g. remap_vmalloc_range ? Patch is against 5.1-rc5 (localversion next is 20190417) drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c | 3 +++ drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c index 31eb7d5..a9a2291 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c @@ -179,6 +179,9 @@ vchiq_platform_init_state(struct vchiq_state *state) struct vchiq_2835_state *platform_state; state->platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL); + if (!state->platform_state) + return VCHIQ_ERROR; + platform_state = (struct vchiq_2835_state *)state->platform_state; platform_state->inited = 1; diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c index 6057a90..92e6221 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -2209,6 +2209,8 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero) local->debug[DEBUG_ENTRIES] = DEBUG_MAX; status = vchiq_platform_init_state(state); + if (status != VCHIQ_SUCCESS) + return VCHIQ_ERROR; /* bring up slot handler thread