From patchwork Fri Apr 21 23:17:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 9693943 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 710F0601D4 for ; Fri, 21 Apr 2017 23:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62E6F2867F for ; Fri, 21 Apr 2017 23:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56E2628684; Fri, 21 Apr 2017 23:19:28 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 E551D2867F for ; Fri, 21 Apr 2017 23:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425062AbdDUXTA (ORCPT ); Fri, 21 Apr 2017 19:19:00 -0400 Received: from mail.ispras.ru ([83.149.199.45]:40776 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424963AbdDUXS7 (ORCPT ); Fri, 21 Apr 2017 19:18:59 -0400 Received: from localhost.localdomain (unknown [85.140.191.168]) by mail.ispras.ru (Postfix) with ESMTPSA id 0F33854006A; Sat, 22 Apr 2017 02:18:57 +0300 (MSK) From: Alexey Khoroshilov To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Alexey Khoroshilov , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] scsi: mvumi: add check for dma mapping errors Date: Sat, 22 Apr 2017 02:17:50 +0300 Message-Id: <1492816670-25795-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mvumi_make_sgl() does not check if mapping dma memory succeed. The patch adds return error code if the mapping failed and if scsi_bufflen(scmd) is zero. The latter is just in case since the only call site of mvumi_make_sgl() check the scsi_bufflen(scmd) before the call. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- drivers/scsi/mvumi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c index 247df5e79b71..49f8b20f5d91 100644 --- a/drivers/scsi/mvumi.c +++ b/drivers/scsi/mvumi.c @@ -232,11 +232,14 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd, sgd_inc(mhba, m_sg); } } else { - scmd->SCp.dma_handle = scsi_bufflen(scmd) ? - pci_map_single(mhba->pdev, scsi_sglist(scmd), - scsi_bufflen(scmd), - (int) scmd->sc_data_direction) - : 0; + if (!scsi_bufflen(scmd)) + return -1; + scmd->SCp.dma_handle = pci_map_single(mhba->pdev, + scsi_sglist(scmd), + scsi_bufflen(scmd), + (int) scmd->sc_data_direction); + if (pci_dma_mapping_error(mhba->pdev, scmd->SCp.dma_handle)) + return -1; busaddr = scmd->SCp.dma_handle; m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr)); m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));