public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid()
@ 2024-02-27 10:00 Richard Fitzgerald
  2024-02-27 16:10 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Fitzgerald @ 2024-02-27 10:00 UTC (permalink / raw)
  To: broonie, tiwai
  Cc: alsa-devel, linux-sound, linux-kernel, patches,
	Richard Fitzgerald

Cast u8 values to u32 when using them to build a 32-bit unsigned value
that is then stored in a u64. This avoids the possibility of a bad sign
extension where the u8 is implicitly extended to an int, thus changing it
from an unsigned to a signed value.

Whether this is a real problem is debatable, but it does no harm to
ensure that the u8 are cast to a suitable type for shifting.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: e1830f66f6c6 ("ASoC: cs35l56: Add helper functions for amp calibration")
---
 sound/soc/codecs/cs35l56-shared.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/cs35l56-shared.c b/sound/soc/codecs/cs35l56-shared.c
index 20b6dbd3fbab..f3670bf85a95 100644
--- a/sound/soc/codecs/cs35l56-shared.c
+++ b/sound/soc/codecs/cs35l56-shared.c
@@ -659,9 +659,10 @@ static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
 		return ret;
 	}
 
-	unique_id = pte.lot[2] | (pte.lot[1] << 8) | (pte.lot[0] << 16);
+	unique_id = (u32)pte.lot[2] | ((u32)pte.lot[1] << 8) | ((u32)pte.lot[0] << 16);
 	unique_id <<= 32;
-	unique_id |= pte.x | (pte.y << 8) | (pte.wafer_id << 16) | (pte.dvs << 24);
+	unique_id |= (u32)pte.x | ((u32)pte.y << 8) | ((u32)pte.wafer_id << 16) |
+		     ((u32)pte.dvs << 24);
 
 	dev_dbg(cs35l56_base->dev, "UniqueID = %#llx\n", unique_id);
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid()
  2024-02-27 10:00 [PATCH] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid() Richard Fitzgerald
@ 2024-02-27 16:10 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2024-02-27 16:10 UTC (permalink / raw)
  To: tiwai, Richard Fitzgerald; +Cc: alsa-devel, linux-sound, linux-kernel, patches

On Tue, 27 Feb 2024 10:00:42 +0000, Richard Fitzgerald wrote:
> Cast u8 values to u32 when using them to build a 32-bit unsigned value
> that is then stored in a u64. This avoids the possibility of a bad sign
> extension where the u8 is implicitly extended to an int, thus changing it
> from an unsigned to a signed value.
> 
> Whether this is a real problem is debatable, but it does no harm to
> ensure that the u8 are cast to a suitable type for shifting.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid()
      commit: cb9d8a2c6cb7cbb0fc919defe4fae741bfcae9de

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-27 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27 10:00 [PATCH] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid() Richard Fitzgerald
2024-02-27 16:10 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox