From patchwork Thu Apr 20 05:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 85725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp103353vqo; Wed, 19 Apr 2023 23:03:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgO8qFiLTrzPvAlntsGc74NQSrklaLzOKco1o3WmdY1Eo2/Vqk8AE4FQPxu6lsQQR4YnGI X-Received: by 2002:aca:280a:0:b0:389:234:6107 with SMTP id 10-20020aca280a000000b0038902346107mr326941oix.25.1681970593282; Wed, 19 Apr 2023 23:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681970593; cv=none; d=google.com; s=arc-20160816; b=HLIxbesEyut8vO4w6a3xRvkzA2qIDj8IIfuIsHfAIx9qJLEsP3mYug76U/RuXt4iSz c5UoNuk0qtekzPs6a2IX0577QrPVRslMgixKOgQRsP3NZd1DXvr1G/PIR1HzeFcBZJSF UeQg0hs8C7YEcyeUpaCszDa0YkuhuhLdAslwbi96iMXHPlyv9p8z0IjlY8TYss0YkcSq iGq9njTQur8/ZYjpWn1iycd4iEWxumcOoumOeZRgMZhN9SQ4FCzWXlWFFzFlm+djoqCZ mG5SKx5BXyIxNbcFSW0PwcZMeclQXSc+XF2d9V7Onf6LSoTyCMZvzAx1zyXBwTlYg8vv wIgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=iO/fEp/BsQC41PC1QuH2cxT7T+9h9UhwnMxo1CRSG0GQIRSjgTUn23iNa2+v8RgrKH CRPnhhnkAVcluP/JnzCrpCYlAbbZW9t2owwi5g69QZfvg0OF6JE4iLilim7HJI5Rn4Xv gnXrRLpLplgMkJPtYpQf3XWqil1Gu4PaEhfm0PR05eNu6kCBZ1MZNilvL75rzNA4gYAU nktswA3iY2FhbtFx8yaB/MrswD/OxE3HGJ+3fkKlA68Lutni4e0KJ+CyOZzN4G/QL1W8 +qrARC7k/85lpUcQMQ/QHjFF7UqCw9K3s9rU0jANSVEvoV8J/14IqwofS1DIiTAVJvsn 33Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=wP4LdQuS; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020acaa808000000b0038cabdbe3a0si821463oie.7.2023.04.19.23.02.59; Wed, 19 Apr 2023 23:03:13 -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=@google.com header.s=20221208 header.b=wP4LdQuS; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233822AbjDTFx2 (ORCPT + 99 others); Thu, 20 Apr 2023 01:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233823AbjDTFxY (ORCPT ); Thu, 20 Apr 2023 01:53:24 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C8C40CA for ; Wed, 19 Apr 2023 22:53:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 188-20020a250ac5000000b00b9265c9a5e9so1359998ybk.11 for ; Wed, 19 Apr 2023 22:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969990; x=1684561990; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=wP4LdQuSoesNvn/B4nq+v65j9QBURAtfrTfJclyIGQZl/zwlfdNdJk9rDvE+kJen70 KrMp944AeYP1jG4zsWJL8KqCjL7ehlImk2NQGbHDJXbKlV6ksBUb5Szyn63HVFN15p9X ZdZTIiKtAlOSw04ORDBVFNr9N1YF6VreBh6brM47mSF8r2T7YO9s872kdz6IUsOraA4B XZgr783K4qPobQTNyib+UTF9lzfKpDUudWPLkzkgdi8XDkeEqfoRkm4OIRbSCRjYB5cN sG+wM4RZqUlfjFPfWoc2QLvy/yXVDJxN9SM2P3SkKfFV6DTfkbKBDuZe8XiaDjpKhDr0 4u5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969990; x=1684561990; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=QdehQp/+queeEZwM3FT0oPtYK3VnNOsCfXlIpSFbOjO902VPIn2lsydTe/RvrsdO1N gYk14MaDfvziK68vKBJbg0drDa09UQhKf46gOjS8wQZ1pYbvmoyl0UCl3YvpztycUpg0 0lft2TQhsENJhc8/xRzeYVOPRiAQRrCa6vvlPNTGJoZ5a2FMu9GdXUfl21bAIDFckZ1n b+FAhyH318Jt+HtrB6SdM1xmNpdSsu0YBysI14tiL3m2UEGGmxRi0Rvq58geqhcNhycS GN9rJdR+kW8UgRG+m8fRV3MmKGFSwdF4t8EfAt7zQpaFzgNiGnTRYLiIbpnBDxeQdrpW NXJg== X-Gm-Message-State: AAQBX9efWW39yooRBPPStHQ9IZuALf/WMjea6zbtnVgrhXw5QGefUdl7 amXetZxynsdOwlFQV0xnKHvUAJ4AfGQNmw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:3157:0:b0:b8f:3647:d757 with SMTP id x84-20020a253157000000b00b8f3647d757mr310587ybx.11.1681969990443; Wed, 19 Apr 2023 22:53:10 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:31 +0000 In-Reply-To: <20230420055131.2048959-1-joychakr@google.com> Mime-Version: 1.0 References: <20230420055131.2048959-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230420055131.2048959-6-joychakr@google.com> Subject: [PATCH v8 5/5] spi: dw: Round of n_bytes to power of 2 From: Joy Chakraborty To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763673996733485139?= X-GMAIL-MSGID: =?utf-8?q?1763673996733485139?= n_bytes variable in the driver represents the number of bytes per word that needs to be sent/copied to fifo. Bits/word can be between 8 and 32 bits from the client but in memory they are a power of 2, same is mentioned in spi.h header: " * @bits_per_word: Data transfers involve one or more words; word sizes * like eight or 12 bits are common. In-memory wordsizes are * powers of two bytes (e.g. 20 bit samples use 32 bits). * This may be changed by the device's driver, or left at the * default (0) indicating protocol words are eight bit bytes. * The spi_transfer.bits_per_word can override this for each transfer. " Hence, round of n_bytes to a power of 2 to avoid values like 3 which would generate unalligned/odd accesses to memory/fifo. Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size") Suggested-by: Andy Shevchenko Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c index c3bfb6c84cab..a6486db46c61 100644 --- a/drivers/spi/spi-dw-core.c +++ b/drivers/spi/spi-dw-core.c @@ -426,7 +426,7 @@ static int dw_spi_transfer_one(struct spi_controller *master, int ret; dws->dma_mapped = 0; - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); dws->tx = (void *)transfer->tx_buf; dws->tx_len = transfer->len / dws->n_bytes; dws->rx = transfer->rx_buf;