From patchwork Thu Apr 18 10:29:44 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: 10906977 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 C12571515 for ; Thu, 18 Apr 2019 10:35:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3DC128BB6 for ; Thu, 18 Apr 2019 10:35:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96F3128C73; Thu, 18 Apr 2019 10:35:54 +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 E38B128BB6 for ; Thu, 18 Apr 2019 10:35:53 +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=mZl3uaYn9OfP3Nck5SvTMSd6lbY4hZ+Pgo3VGaGPEUs=; b=o/y dsXO8DOwiSyUMtxMxcLyjQ0alVs2uP3MMmM27JxNpo09gD3revOycgEGCmJvDQw+GM8i9lhXl0qxG 2jlXQuow7zUAuHFoZVaf9PRRyH2gMJcM/6imWUaVOefHHQ61jhMMTUa5963MBnv5DbH7Z1F6P3ycw sO/O96/lmjTAYCxZAOaXoGSGDrXE77kYTxceRyKBzLos/iL/SZ96hd/lCd3VnvlHIbEGEe8HdqEE/ pEdSYD7qBZuAWMAwH5XQpZWVNpIFuRsO9PZ057u3xGxf3ciCWw4N+8hbaNDOWUbF34/H9MEsqD2Kx WhnHBj1Pfd8U9amFPrJknP9wdDfY70Q==; 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 1hH4OV-0002vR-Nf; Thu, 18 Apr 2019 10:35:51 +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 1hH4OS-0002uk-KZ; Thu, 18 Apr 2019 10:35:50 +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 x3IAZ8Hf025627; Thu, 18 Apr 2019 12:35:08 +0200 From: Nicholas Mc Guire To: Eric Anholt Subject: [PATCH RFC] staging: vc04_services: handle kzalloc failure Date: Thu, 18 Apr 2019 12:29:44 +0200 Message-Id: <1555583384-15670-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_033549_193662_F7AD439C X-CRM114-Status: GOOD ( 10.17 ) 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 Acked-by: Stefan Wahren --- Problem located with experimental coccinelle script 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_SUCCES) + return VCHIQ_ERROR; /* bring up slot handler thread