Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428092AbdDWIm2 (ORCPT ); Sun, 23 Apr 2017 04:42:28 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:42657 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1428006AbdDWIlk (ORCPT ); Sun, 23 Apr 2017 04:41:40 -0400 Date: Sun, 23 Apr 2017 01:41:33 -0700 From: Christoph Hellwig To: Alexey Khoroshilov Cc: "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: Re: [PATCH] scsi: mvumi: add check for dma mapping errors Message-ID: <20170423084133.GE30869@infradead.org> References: <1492816670-25795-1-git-send-email-khoroshilov@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1492816670-25795-1-git-send-email-khoroshilov@ispras.ru> User-Agent: Mutt/1.8.0 (2017-02-23) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 872 Lines: 24 On Sat, Apr 22, 2017 at 02:17:50AM +0300, Alexey Khoroshilov wrote: > } 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; This looks completely broken. Why would you DMA map the in-memory struct scatterlist? It has no meaning for the hardware. In fact this whole branch (and the equivalent in the unmap path) are dead - SCSI commands that transfer data always have a SG entry. So the right fix is to remove the !scsi_sg_count(scmd) map/unmap path.