Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9046293pxu; Mon, 28 Dec 2020 05:19:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVfol2TcgTdihN65Wf9FqW6eS3ONHxGiNVBNNzHtb3jNUKXJNYJVfkGL3hW4PrrmoJDrV0 X-Received: by 2002:aa7:df91:: with SMTP id b17mr43017518edy.272.1609161574883; Mon, 28 Dec 2020 05:19:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161574; cv=none; d=google.com; s=arc-20160816; b=kuvNBggFVAXq7tChQZBBAFYaCBPdqJdMWZcfEj5ncoudS14Ut6PMOJtaR1Rp7zaoUL 2O7KA+bIZHvzxylnXIf9ZUWca99PZxjvw3xutvEMw7NwWPdDz1Q8MioUiCQekjIy15hb 5AwF3ut9lk1Lfn5b5zXH1oClGYEQ+D9OE8+UHLYCwQlxDXC1/gTEbedFxzEdUfIwJZXs jzAP+qRVs5rU9kNnl5L9MOob0NiB6xcp249TkKgQRmvK3Y3gDArKkHzYuULIbZGv5dHO yMfkm+TyeLcGTzKdWhOIKMfZlhbdLAHzxsQ+zjJOey/QpnFozauwu1aqHFHibtqHGe4A Jb7A== 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=gJq4+aQO6/WPrgngnnKhAZVjqxrV5KpToos/mSzCALQjNH04OZS4KjrExmcAvVaJt1 /vdBBHbnIYQP2HpA0wOJZeJX8/Y0K1VX7Ptuv8nYBz9Tf9gFELz7C4H7D0/sj2uuB6f/ pRYptyQcoGw61QRzO03J1BfDxnZbVepTF4psmvd/B3hF+r6vgLFrSm2keT2RAWDv/0W8 KwMCtHseUDE6QjyiyWx10i4d5DsJz7XtDujFV3ajHvd004wV4EPc2s/AfgTZ6LogBPbg yvo3BOngZBGrgdvZxIHz/Z0+PwdDHlk4SAWlcknC8/eYxDtDm+2m+NsCkwx4MdW+Q+nv Hv/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="FrEj0kz/"; 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 b24si17852832eju.531.2020.12.28.05.19.11; Mon, 28 Dec 2020 05:19:34 -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="FrEj0kz/"; 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 S1733232AbgL1NQ1 (ORCPT + 99 others); Mon, 28 Dec 2020 08:16:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:44714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733190AbgL1NQX (ORCPT ); Mon, 28 Dec 2020 08:16:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 50262207C9; Mon, 28 Dec 2020 13:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161342; bh=rN1UhIVGmv1kbOBSZbu95fHxVkQe5md3+jf0hDU4j3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FrEj0kz/gq0IXLsENKM1Fwbxom1vHWxyTLRwIWIz9GZ2QNAv008CelMWnMee3LY49 Ifp7akbAaKBZ0r9S4lzdHuhGdoEYnu2/tY3qmhqsaEY4ryALncokdKLtFSi+iuAfM4 zMgxlunNunmQwvKNYgzAZba52qhUVn2fcVnhrEWc= 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.14 183/242] media: netup_unidvb: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:49:48 +0100 Message-Id: <20201228124913.693729843@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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; }