Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11812429pjo; Thu, 2 Jan 2020 14:42:55 -0800 (PST) X-Google-Smtp-Source: APXvYqykRh2+BekCk9JPV4jHJQoFPE+AK5Nz8OMVuPh7cFZSWQhs8O0Vq1IddWSh+H83hLUQQ+xv X-Received: by 2002:a05:6830:2102:: with SMTP id i2mr92340206otc.123.1578004975039; Thu, 02 Jan 2020 14:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004975; cv=none; d=google.com; s=arc-20160816; b=Ain5YkECqFji1egHWXFYrrxlitrc5JEuicTi5anyowxAfCdJ+mY/OggQgBe/O+q2f+ 9Cy3vUVCJqETnDA/k6qWaG6mzm1Rt/dt3YU5J5usPCs6/TBMIQOxEgYgYu9NIc0Mrrel YDwlu/kdknAllzu9ECsJrO1kCHp4PQ6qwOITk/6Ir5oDs60K3kyj5znfkN2GdCnzJFkQ GlmJHKpUoTFFKn8eJzMSX+BKrmXadyfPPkcefSp7w1USLcg4C/kP+HkgJrdzBL3Zrk1H TwkjX+/EY4IYHZqT7Mg+JlQJIIFq3Ek8AVxbmwSYp2oLPIUXlm/qXPXCUuruLfwDGBoQ ia6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LPNxYwDpGKYr6SYWXcGdn/qLlRsS0WB0SviLO842Grc=; b=UqtBFQJfE5k97yyHisStou3YK53IjPNbnCGJJ4CkdvNHke8420yAtoa2mYlNZgLIDx sel0eELI6foHvYRgk/XU3wfHwYCrgJedoBeb/Jv3gMYog9Y7Qagkz/zjF/ZH6/oN+n1A EELzhmnT4ZccZZ+MP8+mIFWxGc6ELgrY8gdr4n+LkhiNhJr8/bd3Mn8w/cgUrWrQ3K/K KFUuUKKrsCaexd2yOnVDV541ykJ3dSf/shNuQubCTTWNq3NOzgzw6EHgIue/38IKIUxt 3iZotusq5czJ0sNvSQFjsVX0e9VcCDZxc0RI3zqKOJ/69NRiOkwX7VGf9tWEiRcKhQLl n5ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vqC7JMZD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si20154799oic.222.2020.01.02.14.42.43; Thu, 02 Jan 2020 14:42:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vqC7JMZD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731070AbgABWki (ORCPT + 99 others); Thu, 2 Jan 2020 17:40:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:51778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731273AbgABWiL (ORCPT ); Thu, 2 Jan 2020 17:38:11 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A5AE9217F4; Thu, 2 Jan 2020 22:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004691; bh=DrMkQubWzL8TRWQ6BdEhxtUI4bDasxnhwOZ4Cpj6aeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vqC7JMZD52O50zOqq0F5QKnZzv9WRZHsKMxc+VbzKyD+DnQMllsEV2Fz40e+BegwD dbP0i9HiAcdlVIw5SOAt1XQW8JSTabTqMUjiw8NojS/MNASzAb/cprAtjTA7bukQu0 Yzj9nfLrUzprfbWETc7toXH8MWdsC+qt9QRobZzo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 4.4 085/137] staging: comedi: gsc_hpdi: check dma_alloc_coherent() return value Date: Thu, 2 Jan 2020 23:07:38 +0100 Message-Id: <20200102220558.121434781@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Abbott commit ab42b48f32d4c766420c3499ee9c0289b7028182 upstream. The "auto-attach" handler function `gsc_hpdi_auto_attach()` calls `dma_alloc_coherent()` in a loop to allocate some DMA data buffers, and also calls it to allocate a buffer for a DMA descriptor chain. However, it does not check the return value of any of these calls. Change `gsc_hpdi_auto_attach()` to return `-ENOMEM` if any of these `dma_alloc_coherent()` calls fail. This will result in the comedi core calling the "detach" handler `gsc_hpdi_detach()` as part of the clean-up, which will call `gsc_hpdi_free_dma()` to free any allocated DMA coherent memory buffers. Cc: #4.6+ Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/20191216110823.216237-1-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/gsc_hpdi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/staging/comedi/drivers/gsc_hpdi.c +++ b/drivers/staging/comedi/drivers/gsc_hpdi.c @@ -632,12 +632,22 @@ static int gsc_hpdi_auto_attach(struct c devpriv->dio_buffer[i] = pci_alloc_consistent(pcidev, DMA_BUFFER_SIZE, &devpriv->dio_buffer_phys_addr[i]); + if (!devpriv->dio_buffer[i]) { + dev_warn(dev->class_dev, + "failed to allocate DMA buffer\n"); + return -ENOMEM; + } } /* allocate dma descriptors */ devpriv->dma_desc = pci_alloc_consistent(pcidev, sizeof(struct plx_dma_desc) * NUM_DMA_DESCRIPTORS, &devpriv->dma_desc_phys_addr); + if (!devpriv->dma_desc) { + dev_warn(dev->class_dev, + "failed to allocate DMA descriptors\n"); + return -ENOMEM; + } if (devpriv->dma_desc_phys_addr & 0xf) { dev_warn(dev->class_dev, " dma descriptors not quad-word aligned (bug)\n");