Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9092094pxu; Mon, 28 Dec 2020 06:26:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5oJtPmRv9/8x/u35qreXV+uBvrDEERdUxPfivSLFLaytcsqi8ZJDg8+9vrsiwqpqPfz97 X-Received: by 2002:a17:906:5912:: with SMTP id h18mr41360324ejq.261.1609165607854; Mon, 28 Dec 2020 06:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165607; cv=none; d=google.com; s=arc-20160816; b=xdFgzpMHx5cw6UUdSr6tdCD///eFjEaxAbFuG3eAUw6Sy9klUxiKZdJKLirOUwlUME 4oARVfMBWvLFmRA3DO14VWkPlGcZjdgO7B9MnYrNwDCpczRPpdsNOtVj96Pa25OxYp5Y 3BSOX/uLNF+O7IRaj5H7+2yXEnhKAE3wHPWT4YCS1S7oV99JzxqvaFw2GXqw+V8Bx80p Bwuwndb6pQlp5X/dZ1SIRuT0W9zOi5mK1CS5AgsH6LXz4Cjv58oQf8rj1fkNbWSuKgsY pUp2UofnOKhgZr/qaWH7N0w7EShMX9Q0FfxXixjuQnEAeLKG1wBoeV/EkPzpMygdBDd1 S5rQ== 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=4LdECoIALOs+4SfX6G5tRZrE2V8McfB2lKDNgUdBABU=; b=Q9YsC1O7TeEwrpZ+kGwnDtFA8ZgWYY+VcEOa4VEDFoR7Eaz1Xrw4Ykskw888ys2vZ3 JB6PNbioRaA/Z+wm3C3YWODqKS3YxyxjAxczHv62dmMOOIvocIoWc9uo+S6SciTuLhc/ CaHCS05Uokx+utVb4E5y7Ok/21Q/vXXnwxbIXDy5fw1GKHVaH2oUiDu9et4QdD7QS6+c g3D82+rv22X51yXTRkHO8fKlYgV38biCc+qkoqaRyYasyyvDfoTtAYzak12KIDcwPAgQ 0P+XSKYDTKvOeXuOcOlb81Q739+RBBaunordv3num2kkOgnT5Z073FTg2EtFIjOdTE/I xCZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BKrCTOCu; 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 r16si18087091ejz.602.2020.12.28.06.26.24; Mon, 28 Dec 2020 06:26:47 -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=BKrCTOCu; 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 S2503019AbgL1OYP (ORCPT + 99 others); Mon, 28 Dec 2020 09:24:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:60270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502985AbgL1OYN (ORCPT ); Mon, 28 Dec 2020 09:24:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 212B922B2E; Mon, 28 Dec 2020 14:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165412; bh=yyNTEGvidqyY7u2UNfNu6Uh8DCiiaOGctmRuLJ5eDAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BKrCTOCu5UsPBiHpxwRicgSfNlyo5+/Y+UsqMOzX5a2GPBLbXZpcuKy8JCDBASRcQ 8QHiURwqbdk+WzbLS6czSXZXLa9hwHDDsMHgwS4uetc+HQui/OTqogatc74ga1MAmg BUrXoLBApvW9ew/MgGy/qYqOTzWw8nn5TPEgSyQ0= 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 5.10 523/717] media: netup_unidvb: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:48:41 +0100 Message-Id: <20201228125046.025171268@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 @@ -175,7 +175,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, @@ -208,6 +208,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__); @@ -226,13 +227,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; }