spi: sh-msiof: Fix bit field overflow writes to TSCR/RSCR
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Fri, 13 Apr 2018 12:44:16 +0000 (15:44 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Jun 2018 19:02:41 +0000 (04:02 +0900)
commit3ca7dddaa13f8e7f4e618bf54dad2d18e9efc251
tree5357859e49db9c6715b17ece20c47d6e0edc15d4
parentb3ccb8a77ed11c366fe8d3c3d64a71b5ddf44a75
spi: sh-msiof: Fix bit field overflow writes to TSCR/RSCR

[ Upstream commit 10b4640833e95eeacaef8060bc1b35e636df3218 ]

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>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/spi/spi-sh-msiof.c