Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9096995pxu; Mon, 28 Dec 2020 06:33:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtn31x4qykzTbxUijoy+CBFSKCpp6a7Fyz2PZ9uBuSaXEeJHqbDioUodgALFDS/fc7bEg8 X-Received: by 2002:a17:906:1498:: with SMTP id x24mr40587585ejc.170.1609166036358; Mon, 28 Dec 2020 06:33:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166036; cv=none; d=google.com; s=arc-20160816; b=hYF0yGblJl2RMEraMa0WpbY9BYEHSvi5cYPSfoOpPImpJV9LtIojmGfKQ/g0klLsZ7 YdnK9DAXQi0B4apjxYKMLYzS9tXFJ3kHrjhu66FN9+RYUJOAaA/SVsBYY2RkQJjipZsL 2sWhDpQ1kS+Qjd2XJPZ68Jlq0ZE+5LODyHXFuzRPFlcb9rGw2nR6KEPL00uFwVgpJ98W e3Nap/2RWOs+GTc+UiEwAr3ielxYRfCM+tjbaTAJufZzQHXvm7uT1njUFsbo80hhCkOG SCXOz12AWOL72azImlcPUeCINIfXM58tzIOApAZkEqYiH86lYyNKSHn/uav5EClpmthY qezQ== 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=kp4bT0w6SnEb+RF5DsjNfvXymwgc7/6AYtzvVkEFmmE=; b=z1hHT9enYaOT85kuykh4KZnzdamO9usp81r2JQjAeqswb3bU2JC8AKFE7wUNm8aHRe XG7tkfhIj0+3lJJC/BkK+9ka3VB1zY+4N4PNjaOQL5DqAGvK/OU+X/WhN7+iNZvClr72 21nA0zQ+1I3XBuCeFyCFSK9T+5N0CwjarJyB6wzBoXUzy7aDRbW1IR7gqgs3Nf7CO8rD HR37c6ojAglzTnnP1EfOMo+uObSxry0G5bZh07RwcekeOJvyVRC3ZPqpnFSnZSVU0x21 JJGPk5jqBesF2onpbDcstYBSKRIM/kvPR1AnbCwI655oxnctbzItrEaQRMZtCsTQoLIA laqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cy65uM1C; 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 s11si19955123edw.280.2020.12.28.06.33.34; Mon, 28 Dec 2020 06:33:56 -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=cy65uM1C; 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 S2503841AbgL1OaV (ORCPT + 99 others); Mon, 28 Dec 2020 09:30:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:38076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503617AbgL1OaQ (ORCPT ); Mon, 28 Dec 2020 09:30:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B54FB20715; Mon, 28 Dec 2020 14:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165801; bh=1BSslsqxMy717FWz4yCJakZK4RQeXyjOWZHJDGse5vE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cy65uM1CVcqNzXgFlRe8RkdWzM4RUi9dav6MfughIlMWucNp+KRq9iRRuLP8XMEtC yY2e0i/sXYLqfFECPuUm+zVB5aTcG8EichjWAL0shf8mKDnBmrRWYAkYH8pHIO4Csg M3nT7kEuUolxay1EvuYTlbtIEWVGsPHDu1S90zAk= 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 5.10 660/717] spi: mt7621: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:50:58 +0100 Message-Id: <20201228125052.585986478@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 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 Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-mt7621.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/spi/spi-mt7621.c +++ b/drivers/spi/spi-mt7621.c @@ -350,7 +350,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) { dev_info(&pdev->dev, "master allocation failed\n"); clk_disable_unprepare(clk); @@ -382,7 +382,7 @@ static int mt7621_spi_probe(struct platf return ret; } - ret = devm_spi_register_controller(&pdev->dev, master); + ret = spi_register_controller(master); if (ret) clk_disable_unprepare(clk); @@ -397,6 +397,7 @@ static int mt7621_spi_remove(struct plat master = dev_get_drvdata(&pdev->dev); rs = spi_controller_get_devdata(master); + spi_unregister_controller(master); clk_disable_unprepare(rs->clk); return 0;