Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9179561pxu; Mon, 28 Dec 2020 08:33:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJytLBj1ZBayOXgi11VjNi6JRxBQeHGojlh39Pb5xzkul2tpS2ePxnYzqU/gRM/mL6Duh7ov X-Received: by 2002:a17:906:94d4:: with SMTP id d20mr41933714ejy.475.1609173205204; Mon, 28 Dec 2020 08:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173205; cv=none; d=google.com; s=arc-20160816; b=nP41NjmeoJy9BdvV2hgHlWIChU6Z8zoWqOXf0B7MdxDdXQ8h20l6cDsGK3J4DBCjk/ jqaf+OK7Vmus+G85OXkf/EXxfXMBUoL+tLBWL0XPxoq+y3XCXIF/DqRTr3vwvFD8c5qv UImRwj4f4tOEs32Zmes8/qHD1Z6ZX5oGTPBt+3Q2zgklPLQGIFM4JBHFRoCxABtC/wQw Y3XN04FLp2YUf6luuFOjBochXKpIKZh4pQcS1wpw4ksiZqqqai5UTA2r+69d8ZKHYXf7 urVqAfFmHvAnJxtObOqrfUnTpcq953a4aozmbVD/RL3jLhiuym1ztT2JvuxfK4kbxvbf OuIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mSCipIJ+Z/rkeLDW9LkUnmkN18661dPG0WkTod2U+c8=; b=LWPvt2kJyvIiLi93Fy/sQKJ3JHrCXG1ETZVPo7TmMoy/hSBv4vU+a67ezjqoRC12gD A3d+dbUm6fY62tN1X4YTpk2AyrYn+78GU4rKyIhu4TOmLZmBzvGSXKTD/XlNA4RAk6sI E5nvKj8UD1ceQU+iTwZiUnfoex11lWPO6eoiffa7q+kCZcrF7mQr3tQg0+N86KaNusvR BHNkoYXGmu2l5Ip9CKZ/5/v+yQ3YNbX0Rn+7YObRJPqYydjeDWRSnN6QiOcdNU/yY7sF yodfBTD6S7ZW9kIaxvbI066a0/H/yRqSGJqhIuIijOwYXFRpXO46pdU4hs2KwsbAb/Fe iDNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iyheYx+9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx4si19010558edb.137.2020.12.28.08.33.01; Mon, 28 Dec 2020 08:33:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iyheYx+9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2634030AbgL1QbX (ORCPT + 99 others); Mon, 28 Dec 2020 11:31:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:33172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbgL1NFR (ORCPT ); Mon, 28 Dec 2020 08:05:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C4D622245C; Mon, 28 Dec 2020 13:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160676; bh=rN1UhIVGmv1kbOBSZbu95fHxVkQe5md3+jf0hDU4j3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iyheYx+9LRpvtrXlfHeP7XlcK3PPZO+EyEHtB39PzM7kFyrQvSefGL1QHZLUqCVP9 8qBH/KOHU1WiKUg1vOPZxhK8VlNuhFnk/73bURDPY71n8YVAfGXSHw+XhMjbatYyyU Kfp+SkCLOqK2M3XzMVEnm4V07BRHqhgTk43H4vs8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mauro Carvalho Chehab , Kozlov Sergey , Mark Brown Subject: [PATCH 4.9 133/175] media: netup_unidvb: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:49:46 +0100 Message-Id: <20201228124859.696786162@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit e297ddf296de35037fa97f4302782def196d350a upstream. If the call to spi_register_master() fails on probe of the NetUP Universal DVB driver, the spi_master struct is erroneously not freed. Likewise, if spi_new_device() fails, the spi_controller struct is not unregistered. Plug the leaks. While at it, fix an ordering issue in netup_spi_release() wherein spi_unregister_master() is called after fiddling with the IRQ control register. The correct order is to call spi_unregister_master() *before* this teardown step because bus accesses may still be ongoing until that function returns. Fixes: 52b1eaf4c59a ("[media] netup_unidvb: NetUP Universal DVB-S/S2/T/T2/C PCI-E card driver") Signed-off-by: Lukas Wunner Reviewed-by: Mauro Carvalho Chehab Cc: # v4.3+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.3+ Cc: Kozlov Sergey Link: https://lore.kernel.org/r/c4c24f333fc7840f4a3db24789e6e10dd660bede.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/media/pci/netup_unidvb/netup_unidvb_spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/media/pci/netup_unidvb/netup_unidvb_spi.c +++ b/drivers/media/pci/netup_unidvb/netup_unidvb_spi.c @@ -184,7 +184,7 @@ int netup_spi_init(struct netup_unidvb_d struct spi_master *master; struct netup_spi *nspi; - master = spi_alloc_master(&ndev->pci_dev->dev, + master = devm_spi_alloc_master(&ndev->pci_dev->dev, sizeof(struct netup_spi)); if (!master) { dev_err(&ndev->pci_dev->dev, @@ -217,6 +217,7 @@ int netup_spi_init(struct netup_unidvb_d ndev->pci_slot, ndev->pci_func); if (!spi_new_device(master, &netup_spi_board)) { + spi_unregister_master(master); ndev->spi = NULL; dev_err(&ndev->pci_dev->dev, "%s(): unable to create SPI device\n", __func__); @@ -235,13 +236,13 @@ void netup_spi_release(struct netup_unid if (!spi) return; + spi_unregister_master(spi->master); spin_lock_irqsave(&spi->lock, flags); reg = readw(&spi->regs->control_stat); writew(reg | NETUP_SPI_CTRL_IRQ, &spi->regs->control_stat); reg = readw(&spi->regs->control_stat); writew(reg & ~NETUP_SPI_CTRL_IMASK, &spi->regs->control_stat); spin_unlock_irqrestore(&spi->lock, flags); - spi_unregister_master(spi->master); ndev->spi = NULL; }