From patchwork Fri Jan 24 09:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A713EC2D0DB for ; Fri, 24 Jan 2020 11:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7953320708 for ; Fri, 24 Jan 2020 11:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864056; bh=HAw4S1gBe/g/LNIX93+Cp4icEvnyUdS6ePsP+BY3Y1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=i0bTEuceIY7SFL9vyt7ZUbrZm8ScwdCfGxr8oQ2UDaP99qGfGf5uCnaY9VD6MGKs0 KGNIKloH/cx02E/A885LWxnEU9rl+FdZdDBujyOP5Y8K/C+UI7YUtpl+GB3Q3sjhJL BxvmJ1HH/mFdVVm+im79HzIrt8zGhfWhm/WDSdmQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387657AbgAXLHb (ORCPT ); Fri, 24 Jan 2020 06:07:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:42740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389517AbgAXLHb (ORCPT ); Fri, 24 Jan 2020 06:07:31 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6B4B2071A; Fri, 24 Jan 2020 11:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864050; bh=HAw4S1gBe/g/LNIX93+Cp4icEvnyUdS6ePsP+BY3Y1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BMOkvHSsRvGyn+durmQST77xb8ctRNPwn0NCJ+fLBao4CXqaSjg+4NmdvFRRujL6t uV3xs11fgtU9z5Ix9bbzClHAR08tHIEg3q5U0vEs3X2gFr9o6Ns8pPFUWDINnB0X4F ECuV+VLXpcUmpZ8tCwlgH3TN9sPIySEmHnu9svHM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YueHaibing , Mark Brown , Sasha Levin Subject: [PATCH 4.19 144/639] spi/topcliff_pch: Fix potential NULL dereference on allocation error Date: Fri, 24 Jan 2020 10:25:14 +0100 Message-Id: <20200124093105.287334487@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: YueHaibing [ Upstream commit e902cdcb5112b89ee445588147964723fd69ffb4 ] In pch_spi_handle_dma, it doesn't check for NULL returns of kcalloc so it would result in an Oops. Fixes: c37f3c2749b5 ("spi/topcliff_pch: DMA support") Signed-off-by: YueHaibing Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-topcliff-pch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c index 4389ab80c23e6..fa730a871d252 100644 --- a/drivers/spi/spi-topcliff-pch.c +++ b/drivers/spi/spi-topcliff-pch.c @@ -1008,6 +1008,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) /* RX */ dma->sg_rx_p = kcalloc(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC); + if (!dma->sg_rx_p) + return; + sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */ /* offset, length setting */ sg = dma->sg_rx_p; @@ -1068,6 +1071,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) } dma->sg_tx_p = kcalloc(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC); + if (!dma->sg_tx_p) + return; + sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */ /* offset, length setting */ sg = dma->sg_tx_p;