All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
To: Mark Brown <broonie@kernel.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>
Cc: <linux-spi@vger.kernel.org>, <linux-renesas-soc@vger.kernel.org>
Subject: [PATCH 1/2] spi: sh-msiof: Fix bit field overflow writes to TSCR/RSCR
Date: Fri, 13 Apr 2018 15:44:16 +0300	[thread overview]
Message-ID: <1523623457-9682-2-git-send-email-vladimir_zapolskiy@mentor.com> (raw)
In-Reply-To: <1523623457-9682-1-git-send-email-vladimir_zapolskiy@mentor.com>

The change fixes a bit field overflow which allows to write to higher
bits while calculating SPI transfer clock and setting BRPS and BRDV
bit fields, the problem is reproduced if 'parent_rate' to 'spi_hz'
ratio is greater than 1024, for instance

  p->min_div      = 2,
  MSO rate        = 33333333,
  SPI device rate = 10000

results in

  k          = 5, i.e. BRDV = 0b100 or 1/32 prescaler output,
  BRPS       = 105,
  TSCR value = 0x6804, thus MSSEL and MSIMM bit fields are non-zero.

Fixes: 65d5665bb260 ("spi: sh-msiof: Update calculation of frequency dividing")
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
---
 drivers/spi/spi-sh-msiof.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index ae086aab57d5..8171eedbfc90 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -283,6 +283,7 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
 	}
 
 	k = min_t(int, k, ARRAY_SIZE(sh_msiof_spi_div_table) - 1);
+	brps = min_t(int, brps, 32);
 
 	scr = sh_msiof_spi_div_table[k].brdv | SCR_BRPS(brps);
 	sh_msiof_write(p, TSCR, scr);
-- 
2.8.1

  reply	other threads:[~2018-04-13 12:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 12:44 [PATCH 0/2] spi: sh-msiof: Fix bit field overflow writes to TSCR/RSCR Vladimir Zapolskiy
2018-04-13 12:44 ` Vladimir Zapolskiy [this message]
2018-04-16 17:16   ` Applied "spi: sh-msiof: Fix bit field overflow writes to TSCR/RSCR" to the spi tree Mark Brown
2018-04-13 12:44 ` [PATCH 2/2] spi: sh-msiof: Simplify calculation of divisors for transfer rate Vladimir Zapolskiy
2018-04-16 17:15   ` Applied "spi: sh-msiof: Simplify calculation of divisors for transfer rate" to the spi tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523623457-9682-2-git-send-email-vladimir_zapolskiy@mentor.com \
    --to=vladimir_zapolskiy@mentor.com \
    --cc=broonie@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.