[5/5] spi: spi-sun4i: sun4i_spi_transfer_one(): report effectively used speed_hz of transfer
| Message ID | 20260902-spi-sun4i-fixes-v1-5-19985ef75673@pengutronix.de (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-25492-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 6758E1C14B3 for <noreply@patchwork.local>; Wed, 2 Sep 2026 17:57:20 +0200 (CEST) Authentication-Results: mxe881; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-25492-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-25492-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 93908C0CE7 for <noreply@patchwork.local>; Wed, 2 Sep 2026 15:37:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8A3F4A99D0; Wed, 2 Sep 2026 15:36:27 +0000 (UTC) X-Original-To: linux-sunxi@lists.linux.dev Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 294C14A92C1 for <linux-sunxi@lists.linux.dev>; Wed, 2 Sep 2026 15:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788363384; cv=none; b=DZsVDilpGHjVhB4dCG0xlLUWb3AiTEXhwZkIp5IvwiEPilMHBSdmhwV5L7B4DUrdIWJGy8hclVjlguslj0pxDB7Mr2Z2MvENmvXqPYB4EMYZ3WEl1dvPSiYyfrlVNVbHpaw5eKHNLcf3uzGLxxBgDm3xObNQWKFF+EM4DBTEE2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788363384; c=relaxed/simple; bh=R3ZU8/kS8Pob+4N3MgpaA3ZAKG703jFLtNJQzuFDIEk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VdFtBlwz8NUyQohK421ixct4rF9fFsg9PCbwVGdeCyvJgl9yRECNPf5Kg79MHFIonivYgLNTCmk8fk9ZcSvLXXvm4S4A2xeO7DUX4ozgAzVHsj9/DgiLE3aJItkmqLgWi9Rn/6I2K3y2W85WWZSUkzt6ify2g97CV5cunmJ7Hxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 48E442058E6; Wed, 02 Sep 2026 17:35:54 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from <jre@pengutronix.de>) id 1x1n0E-004bxm-0Y; Wed, 02 Sep 2026 17:35:54 +0200 From: Jonas Rebmann <jre@pengutronix.de> Date: Wed, 02 Sep 2026 17:35:47 +0200 Subject: [PATCH 5/5] spi: spi-sun4i: sun4i_spi_transfer_one(): report effectively used speed_hz of transfer Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260902-spi-sun4i-fixes-v1-5-19985ef75673@pengutronix.de> References: <20260902-spi-sun4i-fixes-v1-0-19985ef75673@pengutronix.de> In-Reply-To: <20260902-spi-sun4i-fixes-v1-0-19985ef75673@pengutronix.de> To: Mark Brown <broonie@kernel.org>, Chen-Yu Tsai <wens@kernel.org>, Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, Maxime Ripard <mripard@kernel.org>, Alexandru Gagniuc <mr.nuke.me@gmail.com>, Olliver Schinagl <o.schinagl@ultimaker.com> Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Mark Brown <broonie@linaro.org>, kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>, Jonas Rebmann <jre@pengutronix.de> X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1162; i=jre@pengutronix.de; h=from:subject:message-id; bh=N+Ets8Mcr9PVPdeJK43FhH+k+VNCJ0EXzg70tuLR/+g=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYsia4RT5J/Roz9vH3723sjVKP+hi52X4tmJxT9yaVZ+5l 5lNMN2+vKOUhUGMi0FWTJElVk1OQcjY/7pZpV0szBxWJpAhDFycAjCRvdEM/8xnxBe9m9x41/Cw Yf2fkD+m2w3Ylou7exXcu1XM1nuzK4ORYfLE8s2TWJTN968unPXiidzEdGVlVqVN89xDDB2nnJx 4hBUA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
spi: spi-sun4i: assorted fixes
|
|
Commit Message
Jonas Rebmann
Sept. 2, 2026, 3:35 p.m. UTC
From: Marc Kleine-Budde <mkl@pengutronix.de> Report the effectively used speed_hz for the transfer by setting tfr->effective_speed_hz. For more information see commit 5d7e2b5ed585 ("spi: core: allow reporting the effectivly used speed_hz for a transfer"), which adds this feature to the SPI core. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Jonas Rebmann <jre@pengutronix.de> --- drivers/spi/spi-sun4i.c | 2 ++ 1 file changed, 2 insertions(+)
Comments
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Kernel panic due to division by zero when calculating `effective_speed_hz` if `mclk_rate` evaluates to 0. -- commit 035881eeeccd1fd72487c3c0c263d972c7662e72 Author: Marc Kleine-Budde <mkl@pengutronix.de> spi: spi-sun4i: sun4i_spi_transfer_one(): report effectively used speed_hz of transfer This commit updates the sun4i SPI driver to report the effectively used transfer speed by setting tfr->effective_speed_hz. It calculates this based on the chosen clock divider (CDR1 or CDR2). > diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c > index 18951c1972da6..fff0065ce9af9 100644 > --- a/drivers/spi/spi-sun4i.c > +++ b/drivers/spi/spi-sun4i.c [ ... ] > @@ -300,9 +300,11 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, > div_cdr2 = DIV_ROUND_UP(div_cdr1, 2); > if (div_cdr2 <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) { > reg = SUN4I_CLK_CTL_CDR2(div_cdr2 - 1) | SUN4I_CLK_CTL_DRS; > + tfr->effective_speed_hz = mclk_rate / (2 * div_cdr2); [Severity: High] Could this result in a division by zero kernel panic if the clock rate fails to initialize or is stubbed? If clk_get_rate(sspi->mclk) returns 0 (which can happen if the clock is missing or fails to set a rate), the calculation for div_cdr1 becomes: div_cdr1 = DIV_ROUND_UP(0, tfr->speed_hz); This evaluates to 0, which then makes div_cdr2 evaluate to 0: div_cdr2 = DIV_ROUND_UP(0, 2); Since 0 is less than or equal to SUN4I_CLK_CTL_CDR2_MASK + 1, this branch is taken. The new code then evaluates to: tfr->effective_speed_hz = 0 / (2 * 0); Would it be safer to check if div_cdr2 is non-zero before performing this division, or perhaps handle a 0 mclk_rate earlier in the function? > } else { > div = min(SUN4I_CLK_CTL_CDR1_MASK, order_base_2(div_cdr1)); > reg = SUN4I_CLK_CTL_CDR1(div); > + tfr->effective_speed_hz = mclk_rate / (1 << div); > } > > sun4i_spi_write(sspi, SUN4I_CLK_CTL_REG, reg);
diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c index 18951c1972da..fff0065ce9af 100644 --- a/drivers/spi/spi-sun4i.c +++ b/drivers/spi/spi-sun4i.c @@ -300,9 +300,11 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, div_cdr2 = DIV_ROUND_UP(div_cdr1, 2); if (div_cdr2 <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) { reg = SUN4I_CLK_CTL_CDR2(div_cdr2 - 1) | SUN4I_CLK_CTL_DRS; + tfr->effective_speed_hz = mclk_rate / (2 * div_cdr2); } else { div = min(SUN4I_CLK_CTL_CDR1_MASK, order_base_2(div_cdr1)); reg = SUN4I_CLK_CTL_CDR1(div); + tfr->effective_speed_hz = mclk_rate / (1 << div); } sun4i_spi_write(sspi, SUN4I_CLK_CTL_REG, reg);