From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96A233F7A85 for ; Wed, 20 May 2026 15:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779290301; cv=none; b=b3zrPL/9rIIS8fJrMBTQpajuNQJgVj13nff4h3il7ILn0N//3jXL6GLp4MuHHpuMhPfq0+kyvHRhk7J3cqyTEmAajt/aOSmBrL6p8u9n3mg9Zn4ok21UL9xkzu+nyPM0fE2JWAx8xCKuXlhzFbcRmpcE5mL5dIMSRaG9MXuYRzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779290301; c=relaxed/simple; bh=UR0qn3BUMfjPxmzqVk5EJgRVtUYnYvuiO9yLlODWC34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YG3eeAOPGM4eH9IO+v+ADcnC2md5mZfHITe8CMIrI4R2YknXje2SHIba7h1SfR0T7iiX9ZDs6e3IlHbw8a8gme5oT/D8PYCfPMeMmPSSPcQ5MFFgHODNKsko7aVMXf7OiVJ5A+7gjBOaEn+9oVd2hyRT4UIwlalo8MwOqtrANkw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kK3uzTq7; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kK3uzTq7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6BF11F00893; Wed, 20 May 2026 15:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779290300; bh=bPcovmQKsQnKLiBPZmVcJ1Vj2HELlGWX5Ptbct8LFjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kK3uzTq7xkFbwcWXurfOCJQmU0mAgrMDmAe3sG9kQRLstt3GG5nO8NnQuhcPfrgeU lhmw4URYruK+qQtNnpITwmdkRELvqDyFGTgTLP0JJLHaoemv0wW9bnzmZKPPobvipE E+UOA1I5cddrFflJ/6lwM8MJCSa6NJFmKfhJugoivdgtvDXug0kUOk8SuNzvC1S0oo PNc2ClsN1+XccMYMh+DHpspiZifZ5AOpctKyqYnS/T6qhlT2UWpKGUQEgVpmUEZtXV xNv2wZuCeLKGK3AbV0w51uk2bseAIDcimNBkfH86IrFaAlpl1AF1XXErWagi5ej5c5 9rsn6W8Pp+e/w== From: Sasha Levin To: stable@vger.kernel.org Cc: Pei Xiao , Mark Brown , Sasha Levin Subject: [PATCH 6.6.y 1/2] spi: sifive: Simplify clock handling with devm_clk_get_enabled() Date: Wed, 20 May 2026 11:18:17 -0400 Message-ID: <20260520151818.3912903-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026051547-backside-sermon-2557@gregkh> References: <2026051547-backside-sermon-2557@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Pei Xiao [ Upstream commit 140039c23aca067b9ff0242e3c0ce96276bb95f3 ] Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for the bus clock. This reduces boilerplate code and error handling, as the managed API automatically disables the clock when the device is removed or if probe fails. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error path and the remove callback. Adjust the error handling to use the existing put_host label. Signed-off-by: Pei Xiao Link: https://patch.msgid.link/73d0d8ecb4e1af5a558d6a7866c0f886d94fe3d1.1773885292.git.xiaopei01@kylinos.cn Signed-off-by: Mark Brown Stable-dep-of: 0f25236694a2 ("spi: sifive: fix controller deregistration") Signed-off-by: Sasha Levin --- drivers/spi/spi-sifive.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-sifive.c b/drivers/spi/spi-sifive.c index cfd17bbb22023..6964d287ae141 100644 --- a/drivers/spi/spi-sifive.c +++ b/drivers/spi/spi-sifive.c @@ -312,7 +312,8 @@ static int sifive_spi_probe(struct platform_device *pdev) goto put_host; } - spi->clk = devm_clk_get(&pdev->dev, NULL); + /* Spin up the bus clock before hitting registers */ + spi->clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(spi->clk)) { dev_err(&pdev->dev, "Unable to find bus clock\n"); ret = PTR_ERR(spi->clk); @@ -342,13 +343,6 @@ static int sifive_spi_probe(struct platform_device *pdev) goto put_host; } - /* Spin up the bus clock before hitting registers */ - ret = clk_prepare_enable(spi->clk); - if (ret) { - dev_err(&pdev->dev, "Unable to enable bus clock\n"); - goto put_host; - } - /* probe the number of CS lines */ spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF); sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU); @@ -357,14 +351,14 @@ static int sifive_spi_probe(struct platform_device *pdev) if (!cs_bits) { dev_err(&pdev->dev, "Could not auto probe CS lines\n"); ret = -EINVAL; - goto disable_clk; + goto put_host; } num_cs = ilog2(cs_bits) + 1; if (num_cs > SIFIVE_SPI_MAX_CS) { dev_err(&pdev->dev, "Invalid number of spi targets\n"); ret = -EINVAL; - goto disable_clk; + goto put_host; } /* Define our host */ @@ -393,7 +387,7 @@ static int sifive_spi_probe(struct platform_device *pdev) dev_name(&pdev->dev), spi); if (ret) { dev_err(&pdev->dev, "Unable to bind to interrupt\n"); - goto disable_clk; + goto put_host; } dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n", @@ -402,13 +396,11 @@ static int sifive_spi_probe(struct platform_device *pdev) ret = devm_spi_register_controller(&pdev->dev, host); if (ret < 0) { dev_err(&pdev->dev, "spi_register_host failed\n"); - goto disable_clk; + goto put_host; } return 0; -disable_clk: - clk_disable_unprepare(spi->clk); put_host: spi_controller_put(host); @@ -422,7 +414,6 @@ static void sifive_spi_remove(struct platform_device *pdev) /* Disable all the interrupts just in case */ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0); - clk_disable_unprepare(spi->clk); } static int sifive_spi_suspend(struct device *dev) -- 2.53.0