Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp883856pxb; Wed, 6 Apr 2022 03:10:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7pd28gh4v6ScBN84RICqTS5W05A6F6WRDSjAgixXMV+OubSdbM67n2O0H/CfJqmp1RiKE X-Received: by 2002:a17:902:d48b:b0:156:bddf:f06 with SMTP id c11-20020a170902d48b00b00156bddf0f06mr7867914plg.141.1649239803034; Wed, 06 Apr 2022 03:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649239803; cv=none; d=google.com; s=arc-20160816; b=EW6SyGa2XmNuxkhDYKajoBlyrhId3WlHTXzpiXEI1YY1cNCfaLuA7lqKunUi2MOQA1 /R8fUySU93E/UX/7FajVBkhrIqFXSGoX0w8Y/dl+OBID541Zg1IDLNBIbJ527vq694PC dug7jvYfynpCDQCKtEZsxdvwaSpQ7UoLGDUw3VgOKiljEA+bidwcWp/aXXvRR5WEY2OL +uKHpSJIFjVEAC/QMZQulRVIFJd6Kb361lI42ZgjmE3knsvSayd/9YlSM2C7vYzJcUcr EACRJToTxZiywNmuSA6NiyrNrKYMdATa2lpAMQRmXhSRZsbakPTW+fKKqkPWbyrEmW0R XP+Q== 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=W2Ngi+Cure9IyObEcoH6A1IpEV+DBbpJI47XaEg1bVU=; b=ZIhBYfaFkmF75s9WxbHhQQuAu4KF/BH5vTmxUA5q9pYS7s/rp0nuCFYGn/GEcGN4Ba rE+nw11dAjI7uIxsl7dAVHSzFO+gqchFKRc/t+QBuhG27/Jflp0fG4DNEMhhyowXkwHx JjqFMPetvUolOJU/jXlrRptbmei9RosFPV7kMbrJliFoRJsD6BP9ljFurtm/qzjWKZV3 m89lofdYKqELPM3b3n9br3ZXWoT6EcClFpwAKRnzqmIqW5ArekMRJdd17MYmPBr8y3IX rajQhMhCxmpTsI1HoH8/SSEwxoP7viV5NQ4itMCQC1RtraCylMF0QFNjRdqYKZDZTbxb +4tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yUNCoTkj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j13-20020a63ec0d000000b003980ae22575si14676020pgh.438.2022.04.06.03.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:10:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yUNCoTkj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2653A58B3AD; Wed, 6 Apr 2022 01:33:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391990AbiDEWJA (ORCPT + 99 others); Tue, 5 Apr 2022 18:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349436AbiDEJtw (ORCPT ); Tue, 5 Apr 2022 05:49:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F0225EAE; Tue, 5 Apr 2022 02:45:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 46E0661673; Tue, 5 Apr 2022 09:45:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C4A1C385A2; Tue, 5 Apr 2022 09:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151953; bh=fbmWagNRxHPIiRN8Gss2tgOhhrkL1vPbW80ajYdC408=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yUNCoTkjHSJL8U0nZKO9q7rZTD05m0B6zo8KTSPMfoS6uhW3LG5ZCkWSO+nS4jFyC N00oBOueRPTjUvVlFSKT4XglPPeEjH+FJkxqoWYqN1KDOEs2tjkD7Awpr8drFzZUZW /3n3/4NZBVmVXZgZAxwiOjgloO0YqQ2p5ZZ+/j3I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qing Wang , Andy Shevchenko , Sasha Levin Subject: [PATCH 5.15 601/913] serial: 8250_lpss: Balance reference count for PCI DMA device Date: Tue, 5 Apr 2022 09:27:43 +0200 Message-Id: <20220405070357.856906218@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko [ Upstream commit 5318f70da7e82649d794fc27d8a127c22aa3566e ] The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put(). Fixes: 9a1870ce812e ("serial: 8250: don't use slave_id of dma_slave_config") Depends-on: a13e19cf3dc1 ("serial: 8250_lpss: split LPSS driver to separate module") Reported-by: Qing Wang Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220223151240.70248-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_lpss.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c index 848d81e3838c..49ae73f4d3a0 100644 --- a/drivers/tty/serial/8250/8250_lpss.c +++ b/drivers/tty/serial/8250/8250_lpss.c @@ -121,8 +121,7 @@ static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) { struct dw_dma_slave *param = &lpss->dma_param; struct pci_dev *pdev = to_pci_dev(port->dev); - unsigned int dma_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); - struct pci_dev *dma_dev = pci_get_slot(pdev->bus, dma_devfn); + struct pci_dev *dma_dev; switch (pdev->device) { case PCI_DEVICE_ID_INTEL_BYT_UART1: @@ -141,6 +140,8 @@ static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) return -EINVAL; } + dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); + param->dma_dev = &dma_dev->dev; param->m_master = 0; param->p_master = 1; @@ -156,6 +157,14 @@ static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) return 0; } +static void byt_serial_exit(struct lpss8250 *lpss) +{ + struct dw_dma_slave *param = &lpss->dma_param; + + /* Paired with pci_get_slot() in the byt_serial_setup() above */ + put_device(param->dma_dev); +} + static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port) { struct uart_8250_dma *dma = &lpss->data.dma; @@ -171,6 +180,13 @@ static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port) return 0; } +static void ehl_serial_exit(struct lpss8250 *lpss) +{ + struct uart_8250_port *up = serial8250_get_port(lpss->data.line); + + up->dma = NULL; +} + #ifdef CONFIG_SERIAL_8250_DMA static const struct dw_dma_platform_data qrk_serial_dma_pdata = { .nr_channels = 2, @@ -345,8 +361,7 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id) return 0; err_exit: - if (lpss->board->exit) - lpss->board->exit(lpss); + lpss->board->exit(lpss); pci_free_irq_vectors(pdev); return ret; } @@ -357,8 +372,7 @@ static void lpss8250_remove(struct pci_dev *pdev) serial8250_unregister_port(lpss->data.line); - if (lpss->board->exit) - lpss->board->exit(lpss); + lpss->board->exit(lpss); pci_free_irq_vectors(pdev); } @@ -366,12 +380,14 @@ static const struct lpss8250_board byt_board = { .freq = 100000000, .base_baud = 2764800, .setup = byt_serial_setup, + .exit = byt_serial_exit, }; static const struct lpss8250_board ehl_board = { .freq = 200000000, .base_baud = 12500000, .setup = ehl_serial_setup, + .exit = ehl_serial_exit, }; static const struct lpss8250_board qrk_board = { -- 2.34.1