Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2622345pxj; Mon, 31 May 2021 06:47:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyHO0GkHCScJDBWU2DB66BLDcBUFwCsEqtu8H1ITQqvmyzfsYbv4WfN1/xgmS+Y2qfVC1H X-Received: by 2002:a05:6e02:490:: with SMTP id b16mr17915532ils.213.1622468839238; Mon, 31 May 2021 06:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622468839; cv=none; d=google.com; s=arc-20160816; b=weOGMrWXHYmQJ2LNYm8s64WpVSyZhXOLlAnU7DD2YNFOtLR65NVpOjzVhkfJ2nIVdb LSmRMbxT8+PPqftjDNjBVehIAmSFSpUIxrLcelxmXL4n+M4XZbKo3C36Dv8/GIB489vN zauOeMYnA4fodbROkkWkdwer8eZmazodG6wbAtuzGcNw5EuKocJDynROS4LcnT80gPXq 5MrveEu2jaVW6+9LWM3VSZ0zg0pIP9ciFA6WH3mlDBeW60qx5viGUmF2O+DUjcj9er9r 5L4uvCClBcx2kADFNQhGriPu8/zLmGh/btKPna9tSle3dWEEUgfUyWwJWCoDidJyY68O zc9Q== 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=r9SRXN0ILPOqfGxv34O7lf/MCb4pDp9Vp6uwmw3txnI=; b=dW4LXtn3KOBvjlESu2FpOgwZzKdaK1Ju9Uu7y2e7kS0dWfHQywO+zLQ8TdewzqwZQm yazGwd3HjStd07sNnyeg7w0yTSNWRgKOsffpY0mghgRdx6y01NTN6/NzILT4qfHrHDIT J6LS3xfXxtCkRskunue6d3X74MKjWp2ixv82JgaZ2UoQNb027WxkEuFUO1kiV6SPTc5R QJ19DOKO1nfWg3RAmbq8a86jqzAL5J62bLprnBhi/9xbJFtADqK/qlohbjFoiUplBpxf 4dVf5opvflgtSNddaYZVAmo+4hnfgTVWtZL2H8hBOwwDc3/gD7ni1oDxCb7zs2GWgKZt ewFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l3E3Xegd; 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 h5si12323736iol.44.2021.05.31.06.47.05; Mon, 31 May 2021 06:47:19 -0700 (PDT) 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=l3E3Xegd; 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 S232484AbhEaNqj (ORCPT + 99 others); Mon, 31 May 2021 09:46:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:37634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbhEaNbz (ORCPT ); Mon, 31 May 2021 09:31:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A093C613EA; Mon, 31 May 2021 13:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467430; bh=wxtoUfqWMXTdNfadc7sU/GNV6l0LpwXlGpF4M7rLEoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3E3XegdoXa0h7+f73mSbUo8HBzmEajXq1c0vLFQdDnBu6Uu7lSnZCzC5zlzrw4H3 uXLgGq/CXtZj+Zp4IcONoqm1Tu/P677YxyhQfny46RVjJ7Yzq8r5auPrk03Be5hL4W 41GioA7hfeXFR+Knbs1M0TNh9xXH86es6JVAaCJ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Stefan Roese , Mark Brown Subject: [PATCH 4.19 061/116] spi: mt7621: Dont leak SPI master in probe error path Date: Mon, 31 May 2021 15:13:57 +0200 Message-Id: <20210531130642.238746730@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 46b5c4fb87ce8211e0f9b0383dbde72c3652d2ba upstream. If the calls to device_reset() or devm_spi_register_controller() fail on probe of the MediaTek MT7621 SPI driver, the spi_controller struct is erroneously not freed. Fix by switching over to the new devm_spi_alloc_master() helper. Additionally, there's an ordering issue in mt7621_spi_remove() wherein the spi_controller is unregistered after disabling the SYS clock. The correct order is to call spi_unregister_controller() *before* this teardown step because bus accesses may still be ongoing until that function returns. All of these bugs have existed since the driver was first introduced, so it seems fair to fix them together in a single commit. Fixes: 1ab7f2a43558 ("staging: mt7621-spi: add mt7621 support") Signed-off-by: Lukas Wunner Reviewed-by: Stefan Roese Cc: # v4.17+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.17+ Link: https://lore.kernel.org/r/72b680796149f5fcda0b3f530ffb7ee73b04f224.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown [lukas: backport to v4.19.192] Signed-off-by: Lukas Wunner Signed-off-by: Greg Kroah-Hartman --- drivers/staging/mt7621-spi/spi-mt7621.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/staging/mt7621-spi/spi-mt7621.c +++ b/drivers/staging/mt7621-spi/spi-mt7621.c @@ -452,7 +452,7 @@ static int mt7621_spi_probe(struct platf if (status) return status; - master = spi_alloc_master(&pdev->dev, sizeof(*rs)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(*rs)); if (master == NULL) { dev_info(&pdev->dev, "master allocation failed\n"); clk_disable_unprepare(clk); @@ -502,8 +502,8 @@ static int mt7621_spi_remove(struct plat master = dev_get_drvdata(&pdev->dev); rs = spi_master_get_devdata(master); - clk_disable(rs->clk); spi_unregister_master(master); + clk_disable_unprepare(rs->clk); return 0; }