Message ID | 20230710154932.68377-4-andriy.shevchenko@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5130510vqx; Mon, 10 Jul 2023 09:08:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlEh/FLmTHZLc8QN1cJpVKyj9VbLF/qUTAiloFTpuFJKT0g03b9FeudNcl/415wcDLiwHaho X-Received: by 2002:a19:2d46:0:b0:4f8:7754:62e1 with SMTP id t6-20020a192d46000000b004f8775462e1mr9567338lft.40.1689005336126; Mon, 10 Jul 2023 09:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689005336; cv=none; d=google.com; s=arc-20160816; b=Gr9AOn0Qcsa9WH30+qqRGzxbso5dbgP5ms6nRo6/ZN7aAx7i4PZ2W6pG+fKWCtqrXv 82aZl1EHQ2aBa7ZfLSn8tDe2PYCj22pebLxn3eJ4m24uJKTI8yiZMte4A8x7TVvulpMa +uLM4hM7MDRwgtZv/YxgCa5EidAJqGwhE3YhsyJlUpeH8zB4TdYWeot1/HF72owF3mq0 RM3XTcddJN+6v5agPtzN4fNDJfIyw/A2UdPU5rJ6ZOOxBvalKcSz6+QyZ5zwytfGYW+b WB7QEqSUaQzI4jnIlsf+PyAJnwmEbKQ5o9Rjzd8bjWkLy+G7Eiw3jvvE+2M3jTPIKe+b 2wlQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w39HcD/C+m8DBdOohl92QIDnMjeqtcf1GqHEJ0IQ5f4=; fh=CWfEt6/vd4IsHMc+T8W3bMkH4b5uOoX72TeJSijIGlU=; b=Cp/76UrVF5wLTUsghAwzs9qCK5uummVb6UwoRkWX/1hFUlmMsBlktVqvmwL9/xSNFc vZYER36xRzUy56QUdvJa1+IuLaIPxFgEFPpI7OqrJX8aD2T4ovTGiOyRe1zTYzj9dqJu e/w7Xnn6AB4j9h0AGfANf9iuz73T9Yz4ZVrb0QY89vPXdIAF8SNPRS230LxKA/44rOyP KRw5ByE+ElKdAjkGi9Csf1JuuUV4AjqDouhQYhP863/4Mf91o96srpM3pqbIj3KezWFD 8050ZhL+0h5Fs0AVBN+piRzULeE0B5gK6g72WDu1+YvalFPVWddr8Oh551Vd80rl97By EZUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="c9A/RJz0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020a170906241400b00992b521a3f6si9454691eja.24.2023.07.10.09.08.32; Mon, 10 Jul 2023 09:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="c9A/RJz0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233645AbjGJPt7 (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Mon, 10 Jul 2023 11:49:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233590AbjGJPtt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 10 Jul 2023 11:49:49 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2854187; Mon, 10 Jul 2023 08:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689004186; x=1720540186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vBn0rQkEvhyNS8x5dx+OCo1BBkRa+6Quzvw7Xp2sQ+U=; b=c9A/RJz0XWvj4cFFGeif9AVCOZqiLSpQ8sgFktP0B1GyWNDV5yWYliDS 05KHFZC0+Aflt2QmRPURtcDynjEaHW0HtKYmn7JgxRIdS69U8fQUvtIdQ xGDcodwh1/1ESHelVNJzE0XQf4QzaMkifWvrZv5dQnVM5KALB92pYSyHZ sJZNiGxVw2IWpqBpTRECRpr5+8TZd+Dg9aNkjFTt0ZaMWNhZKAqNlPJBi 0mW8MNdcg6jq5LVKgknka2ruzDX1thNg60GNqMSUQ9Z0ok40Ui05s1brE pYcayTM9fWpDrbi/5/jBIfdKzI2yLH+YHa5B1uGZhoCVni9drxZO/H2/W A==; X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="349185378" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="349185378" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2023 08:49:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="844921835" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="844921835" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 10 Jul 2023 08:49:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4B00D3E3; Mon, 10 Jul 2023 18:49:34 +0300 (EEST) From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> To: Mark Brown <broonie@kernel.org>, Cristian Ciocaltea <cristian.ciocaltea@collabora.com>, Yang Yingliang <yangyingliang@huawei.com>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Amit Kumar Mahapatra via Alsa-devel <alsa-devel@alsa-project.org>, Neil Armstrong <neil.armstrong@linaro.org>, Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>, Vijaya Krishna Nivarthi <quic_vnivarth@quicinc.com>, =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= <u.kleine-koenig@pengutronix.de>, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-riscv@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Sanjay R Mehta <sanju.mehta@amd.com>, Radu Pirea <radu_nicolae.pirea@upb.ro>, Nicolas Ferre <nicolas.ferre@microchip.com>, Alexandre Belloni <alexandre.belloni@bootlin.com>, Claudiu Beznea <claudiu.beznea@microchip.com>, Tudor Ambarus <tudor.ambarus@linaro.org>, Serge Semin <fancer.lancer@gmail.com>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix Kernel Team <kernel@pengutronix.de>, Fabio Estevam <festevam@gmail.com>, NXP Linux Team <linux-imx@nxp.com>, Kevin Hilman <khilman@baylibre.com>, Jerome Brunet <jbrunet@baylibre.com>, Martin Blumenstingl <martin.blumenstingl@googlemail.com>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Heiko Stuebner <heiko@sntech.de>, Palmer Dabbelt <palmer@dabbelt.com>, Paul Walmsley <paul.walmsley@sifive.com>, Orson Zhai <orsonzhai@gmail.com>, Baolin Wang <baolin.wang@linux.alibaba.com>, Chunyan Zhang <zhang.lyra@gmail.com>, Alain Volmat <alain.volmat@foss.st.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, Max Filippov <jcmvbkbc@gmail.com>, Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org>, Richard Cochran <richardcochran@gmail.com> Subject: [PATCH v2 03/15] spi: Replace if-else-if by bitops and multiplications Date: Mon, 10 Jul 2023 18:49:20 +0300 Message-Id: <20230710154932.68377-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com> References: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771050459361029212 X-GMAIL-MSGID: 1771050459361029212 |
Series |
spi: Header and core clean up and refactoring
|
|
Commit Message
Andy Shevchenko
July 10, 2023, 3:49 p.m. UTC
Instead of if-else-if, simply call roundup_pow_of_two(BITS_PER_BYTES()).
Note, there is no division assumed as compiler may optimize it away.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/spi/spi.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
Comments
On Mon, Jul 10, 2023 at 06:49:20PM +0300, Andy Shevchenko wrote: > - if (xfer->bits_per_word <= 8) > - maxsize = maxwords; > - else if (xfer->bits_per_word <= 16) > - maxsize = 2 * maxwords; > - else > - maxsize = 4 * maxwords; > - > + maxsize = maxwords * roundup_pow_of_two(BITS_TO_BYTES(xfer->bits_per_word)); This will change the behaviour if bits_per_word is more than 32. That is validated out elsewhere but I shouldn't have had to go around checking the code to confirm that this is the case. This is the sort of thing that should be highlighted when doing this sort of edge case stylistic change.
On Mon, Jul 10, 2023 at 05:56:59PM +0100, Mark Brown wrote: > On Mon, Jul 10, 2023 at 06:49:20PM +0300, Andy Shevchenko wrote: > > > - if (xfer->bits_per_word <= 8) > > - maxsize = maxwords; > > - else if (xfer->bits_per_word <= 16) > > - maxsize = 2 * maxwords; > > - else > > - maxsize = 4 * maxwords; > > - > > + maxsize = maxwords * roundup_pow_of_two(BITS_TO_BYTES(xfer->bits_per_word)); > > This will change the behaviour if bits_per_word is more than 32. That > is validated out elsewhere but I shouldn't have had to go around > checking the code to confirm that this is the case. This is the sort of > thing that should be highlighted when doing this sort of edge case > stylistic change. Right, I have to add this into commit message of v3.
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6d74218cf38e..125dea8fae00 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3643,13 +3643,7 @@ int spi_split_transfers_maxwords(struct spi_controller *ctlr, size_t maxsize; int ret; - if (xfer->bits_per_word <= 8) - maxsize = maxwords; - else if (xfer->bits_per_word <= 16) - maxsize = 2 * maxwords; - else - maxsize = 4 * maxwords; - + maxsize = maxwords * roundup_pow_of_two(BITS_TO_BYTES(xfer->bits_per_word)); if (xfer->len > maxsize) { ret = __spi_split_transfer_maxsize(ctlr, msg, &xfer, maxsize, gfp);