Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Dhruva Gole <d-gole@ti.com>
Cc: Nathan Barrett-Morrison <nathan.morrison@timesys.com>,
	greg.malysa@timesys.com,
	"open list:SPI SUBSYSTEM" <linux-spi@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] spi: cadence-quadspi: Add upper limit safety check to baudrate divisor
Date: Thu, 24 Nov 2022 12:41:54 +0000	[thread overview]
Message-ID: <Y39mkl+9W8S6ZzOk@sirena.org.uk> (raw)
In-Reply-To: <88b6dab2-87b1-34ef-b267-43933d79ab8e@ti.com>

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

On Thu, Nov 24, 2022 at 05:57:10PM +0530, Dhruva Gole wrote:
> On 24/11/22 17:05, Mark Brown wrote:

> > As far as I can tell the issue here is that the device is asking for a
> > rate which requires a larger divisor than the controller can support but
> > the driver doesn't do any bounds checking so it just writes the
> > calculated divisor out to the hardware, corrupting any adjacent fields.

> but, I am not sure it would anyway corrupt any adjacent bits,

> The code
> reg |= (div & CQSPI_REG_CONFIG_BAUD_MASK) << CQSPI_REG_CONFIG_BAUD_LSB

> does mask the div value to ensure bits ONLY in CQSPI_REG_CONFIG_BAUD_MASK
> region are set and nothing else right?

Yes, that'd avoid corrupting adjacent bits (though it'd still be making
things worse in that it makes the divider smaller).

> I believe a simple warning is enough, and better not touch the div variable
> because it seems unnecessary. We already have a mask to take care of masking
> the appropriate bits.

That'd still leave the clock driven too fast which could break things,
going for the maximum divider would mitigate this (though an error would
be even safer).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-11-24 12:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 21:17 [PATCH] spi: cadence-quadspi: Add upper limit safety check to baudrate divisor Nathan Barrett-Morrison
2022-11-24  6:46 ` Dhruva Gole
2022-11-24 11:35   ` Mark Brown
2022-11-24 12:27     ` Dhruva Gole
2022-11-24 12:41       ` Mark Brown [this message]
2022-11-24 11:40 ` Mark Brown
2022-11-24 11:53   ` Nathan Barrett-Morrison
2022-11-24 12:02     ` 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=Y39mkl+9W8S6ZzOk@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=d-gole@ti.com \
    --cc=greg.malysa@timesys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=nathan.morrison@timesys.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox