From patchwork Mon Jan 25 18:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 8113781 X-Patchwork-Delegate: jejb@hansenpartnership.com Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C39239F859 for ; Mon, 25 Jan 2016 18:02:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0415B20260 for ; Mon, 25 Jan 2016 18:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1ACB72034B for ; Mon, 25 Jan 2016 18:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757703AbcAYSCj (ORCPT ); Mon, 25 Jan 2016 13:02:39 -0500 Received: from mail.ispras.ru ([83.149.199.45]:58353 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757586AbcAYSCh (ORCPT ); Mon, 25 Jan 2016 13:02:37 -0500 Received: from hednb2.access.network (unknown [185.26.91.14]) by mail.ispras.ru (Postfix) with ESMTPSA id 97BB554006A; Mon, 25 Jan 2016 21:02:33 +0300 (MSK) From: Alexey Khoroshilov To: Tomas Henzl , Sreekanth Reddy Cc: Alexey Khoroshilov , MPT-FusionLinux.pdl@avagotech.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH v3] mptlan: add checks for dma mapping errors Date: Mon, 25 Jan 2016 19:02:24 +0100 Message-Id: <1453744944-4065-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <56A6568B.9020707@ispras.ru> References: <56A6568B.9020707@ispras.ru> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check if mapping dma memory succeed. The patch adds the checks and failure handling. v3: Fix resource deallocation (reported by Tomas Henzl). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- drivers/message/fusion/mptlan.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c index cbe96072a6cc..e9b83fc7be35 100644 --- a/drivers/message/fusion/mptlan.c +++ b/drivers/message/fusion/mptlan.c @@ -734,6 +734,13 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev) dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len, PCI_DMA_TODEVICE); + if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) { + mpt_put_msg_frame(LanCtx, mpt_dev, mf); + netif_stop_queue(dev); + + printk (KERN_ERR "%s: dma mapping failed\n", __func__); + return NETDEV_TX_BUSY; + } priv->SendCtl[ctx].skb = skb; priv->SendCtl[ctx].dma = dma; @@ -1232,6 +1239,15 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv) dma = pci_map_single(mpt_dev->pcidev, skb->data, len, PCI_DMA_FROMDEVICE); + if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) { + printk (KERN_WARNING + MYNAM "/%s: dma mapping failed\n", + __func__); + dev_kfree_skb(skb); + priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx; + spin_unlock_irqrestore(&priv->rxfidx_lock, flags); + break; + } priv->RcvCtl[ctx].skb = skb; priv->RcvCtl[ctx].dma = dma;