From patchwork Sun Apr 23 13:19:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pan Bian X-Patchwork-Id: 9694827 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEA94601AE for ; Sun, 23 Apr 2017 13:21:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D09C9282E2 for ; Sun, 23 Apr 2017 13:21:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFBAB28338; Sun, 23 Apr 2017 13:21:00 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47748282E2 for ; Sun, 23 Apr 2017 13:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1045466AbdDWNUn (ORCPT ); Sun, 23 Apr 2017 09:20:43 -0400 Received: from m50-133.163.com ([123.125.50.133]:57186 "EHLO m50-133.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1045279AbdDWNUl (ORCPT ); Sun, 23 Apr 2017 09:20:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=S6PRvl4btaYSGsVBuZ cY/okTeUJH5h/f3gsOV9SiTzg=; b=iHsbN2xFtQNQNSAMSQFHm3xO0fQW4TaHOe LDMClUDpQozjXk7BsQuRMa2Kdb5j8G4PdOkJIkmc9QYZOXtl1rWV3SStjOsSEUKV rOf8E0FBILukZlkzdFDpw/8H4jKkg4M6BURiPIpyQOHxgkkt45bVfEmQHEELHBWM 0hjrHhyuI= Received: from localhost.localdomain (unknown [123.118.194.153]) by smtp3 (Coremail) with SMTP id DdGowAC3vtHqqfxY7vYqAA--.832S3; Sun, 23 Apr 2017 21:19:41 +0800 (CST) From: Pan Bian To: Kalle Valo , Bhaktipriya Shridhar , Tejun Heo Cc: libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] libertas: check return value of alloc_workqueue Date: Sun, 23 Apr 2017 21:19:38 +0800 Message-Id: <1492953578-387-1-git-send-email-bianpan201603@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DdGowAC3vtHqqfxY7vYqAA--.832S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7CryDtF1xAryrAr1DKr18Grg_yoW8Gw1kp3 yfury7Kr48ur4UCw4DXan5Zrn8ua1xt347Kw4I934rXw15ArySv3WSgFyYgryFvFWkAasr AFW2qasrJF90yw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jJYFAUUUUU= X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqwqtqiywtou0bp/1tbiSA3C91XlieysUgAAsb Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pan Bian Function alloc_workqueue() will return a NULL pointer if there is no enough memory, and its return value should be validated before using. However, in function if_spi_probe(), its return value is not checked. This may result in a NULL dereference bug. This patch fixes the bug. Signed-off-by: Pan Bian --- drivers/net/wireless/marvell/libertas/if_spi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/marvell/libertas/if_spi.c b/drivers/net/wireless/marvell/libertas/if_spi.c index c3a53cd..7b4955c 100644 --- a/drivers/net/wireless/marvell/libertas/if_spi.c +++ b/drivers/net/wireless/marvell/libertas/if_spi.c @@ -1181,6 +1181,10 @@ static int if_spi_probe(struct spi_device *spi) /* Initialize interrupt handling stuff. */ card->workqueue = alloc_workqueue("libertas_spi", WQ_MEM_RECLAIM, 0); + if (!card->workqueue) { + err = -ENOMEM; + goto remove_card; + } INIT_WORK(&card->packet_work, if_spi_host_to_card_worker); INIT_WORK(&card->resume_work, if_spi_resume_worker); @@ -1209,6 +1213,7 @@ static int if_spi_probe(struct spi_device *spi) free_irq(spi->irq, card); terminate_workqueue: destroy_workqueue(card->workqueue); +remove_card: lbs_remove_card(priv); /* will call free_netdev */ free_card: free_if_spi_card(card);