Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9098615pxu; Mon, 28 Dec 2020 06:36:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOv3l/pj6Lb0Jqc3sCnp8c4ErA21Et3/pgjntXI83EV9sQIlyspVs0aqy2kF4L1WQ2L9RQ X-Received: by 2002:a05:6402:22e1:: with SMTP id dn1mr43320661edb.347.1609166177208; Mon, 28 Dec 2020 06:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166177; cv=none; d=google.com; s=arc-20160816; b=fB6N4ExF3rvOoOaFH9sGfH+a+94Ykcfv5rf7LV+3p931dD0ZW85Zk4TsiWFsfM90xY v8WtAol8RpO50v1gPRfmk9GWpP8zYxWnzkJzCgjTlYaYjAYZ+C+tRimCQje9S5ylEC44 fB/trdX1UT3TBqI4uIXa29ckrwJRjZqy5ZnePN3CiB1dW0CGRcPNYW1CjgEfikqA+TwV MwSFI8JQBezk8mjqcfaT66FF8jSHMv34q/fqfh4mNz5LTkdGgh+UgbvoyGesujthgytf hBhTM/MA//2MEBF5O7YSJDqq3Pji5Z6tRauvbEBefijycT6rtTCIwS6rhy3EQ7X6S6n1 YFFQ== 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=hBh0tEB90NtOJR3R9TbNXEU0FwJeizHks0OLOLlg/Gg=; b=BIldgijx9HiEvpDXEW62xejkmG1jvAsNzwKqq1TvoiTz5+v9phVzfW/bAZs6HUxUxb DMMS4g5zh4ha4YtiraqTnlAkW1VJF6rgtnJpMGY3UxIu3jWbguWbOyNIqdB2j0r5Iesp pFfzCv26Fj9svwf6me0ew2s2dYGYoPjlaa8bQL8AZ5I1xnGhZ9r4O9YtirN341DE+GNs xbljinrPJxa+J5fLaG2IanDayGf6PtdPDO4JQ8+dizlJD1uj/quTRDkhW+6UvDDJXLvP Q9vCzrH0v0Xi8B0jROfcY10R33BznGzWqEeDOUhBd0T7nYn5H9gWXc+CATppFHMoGsfg yxpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fJ2nrFJe; 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 v1si20204350edf.22.2020.12.28.06.35.54; Mon, 28 Dec 2020 06:36:17 -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=fJ2nrFJe; 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 S2504694AbgL1Oc1 (ORCPT + 99 others); Mon, 28 Dec 2020 09:32:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:39680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504489AbgL1Oba (ORCPT ); Mon, 28 Dec 2020 09:31:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B27920791; Mon, 28 Dec 2020 14:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165849; bh=xvED9HZ6Hzg2Z33M0isYotNPsw5UsYBK1xpu7VlUT9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ2nrFJeDoxkHaL0ioenog07WCYh9h7xEIgFI9E44sJgDkKnlfQ3Rs2TjFbQvlx4w akAwSB1zMtIxF35XcYDjgyNiqueAFkUgdOGz120pnM0zuaVRieq1HvGrNAxPxLO8g4 zi3fCQWLDeaUJevnXNefwMNxLyfBfHahzUvoDlHM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Chuanhong Guo , Mark Brown Subject: [PATCH 5.10 645/717] spi: ar934x: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:50:43 +0100 Message-Id: <20201228125051.838378190@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 236924ee531d6251c8d10e9177b7742a60534ed5 upstream. If the call to devm_spi_register_controller() fails on probe of the Qualcomm Atheros AR934x/QCA95xx SPI driver, the spi_controller struct is erroneously not freed. Fix by switching over to the new devm_spi_alloc_master() helper. Moreover, the controller's clock is enabled on probe but not disabled if any of the subsequent probe steps fail. Finally, there's an ordering issue in ar934x_spi_remove() wherein the clock is disabled even though the controller is not yet unregistered. It is unregistered after ar934x_spi_remove() by the devres framework. As long as it is not unregistered, SPI transfers may still be ongoing and disabling the clock may break them. It is not possible to use devm_spi_register_controller() in this case, so move to the non-devm variant. 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: 047980c582af ("spi: add driver for ar934x spi controller") Signed-off-by: Lukas Wunner Cc: # v5.7+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v5.7+ Cc: Chuanhong Guo Link: https://lore.kernel.org/r/1d58367d74d55741e0c2730a51a2b65012c8ab33.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-ar934x.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/spi/spi-ar934x.c +++ b/drivers/spi/spi-ar934x.c @@ -176,10 +176,11 @@ static int ar934x_spi_probe(struct platf if (ret) return ret; - ctlr = spi_alloc_master(&pdev->dev, sizeof(*sp)); + ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*sp)); if (!ctlr) { dev_info(&pdev->dev, "failed to allocate spi controller\n"); - return -ENOMEM; + ret = -ENOMEM; + goto err_clk_disable; } /* disable flash mapping and expose spi controller registers */ @@ -202,7 +203,13 @@ static int ar934x_spi_probe(struct platf sp->clk_freq = clk_get_rate(clk); sp->ctlr = ctlr; - return devm_spi_register_controller(&pdev->dev, ctlr); + ret = spi_register_controller(ctlr); + if (!ret) + return 0; + +err_clk_disable: + clk_disable_unprepare(clk); + return ret; } static int ar934x_spi_remove(struct platform_device *pdev) @@ -213,6 +220,7 @@ static int ar934x_spi_remove(struct plat ctlr = dev_get_drvdata(&pdev->dev); sp = spi_controller_get_devdata(ctlr); + spi_unregister_controller(ctlr); clk_disable_unprepare(sp->clk); return 0;