* [PATCH] ALSA: hda: tas2781-spi: Fix -Wsometimes-uninitialized in tasdevice_spi_switch_book()
@ 2025-01-20 13:32 Nathan Chancellor
2025-01-20 13:41 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2025-01-20 13:32 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Baojun Xu
Cc: linux-sound, llvm, patches, kernel test robot, Nathan Chancellor
Clang warns (or errors with CONFIG_WERROR=y):
sound/pci/hda/tas2781_hda_spi.c:110:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
110 | if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/pci/hda/tas2781_hda_spi.c:119:9: note: uninitialized use occurs here
119 | return ret;
| ^~~
sound/pci/hda/tas2781_hda_spi.c:110:2: note: remove the 'if' if its condition is always true
110 | if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/pci/hda/tas2781_hda_spi.c:108:9: note: initialize the variable 'ret' to silence this warning
108 | int ret;
| ^
| = 0
Sink the declaration of ret into the if block and just return 0 at the
end of the function, as there is nothing to do if cur_book has already
been changed.
Fixes: bb5f86ea50ff ("ALSA: hda/tas2781: Add tas2781 hda SPI driver")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202501192006.Hm9GmKiV-lkp@intel.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
sound/pci/hda/tas2781_hda_spi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/sound/pci/hda/tas2781_hda_spi.c b/sound/pci/hda/tas2781_hda_spi.c
index 8068c70b7014..5be71b538ce0 100644
--- a/sound/pci/hda/tas2781_hda_spi.c
+++ b/sound/pci/hda/tas2781_hda_spi.c
@@ -105,18 +105,17 @@ static const struct regmap_config tasdevice_regmap = {
static int tasdevice_spi_switch_book(struct tasdevice_priv *tas_priv, int reg)
{
struct regmap *map = tas_priv->regmap;
- int ret;
if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
- ret = regmap_write(map, TASDEVICE_BOOKCTL_REG,
- TASDEVICE_BOOK_ID(reg));
+ int ret = regmap_write(map, TASDEVICE_BOOKCTL_REG,
+ TASDEVICE_BOOK_ID(reg));
if (ret < 0) {
dev_err(tas_priv->dev, "Switch Book E=%d\n", ret);
return ret;
}
tas_priv->cur_book = TASDEVICE_BOOK_ID(reg);
}
- return ret;
+ return 0;
}
int tasdevice_spi_dev_read(struct tasdevice_priv *tas_priv,
---
base-commit: e576e7843c0d65b82d4092e5b386d9fbf5bc10c3
change-id: 20250120-tas2781_hda_spi-fix-wsometimes-uninitialized-4aac99e287dd
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: hda: tas2781-spi: Fix -Wsometimes-uninitialized in tasdevice_spi_switch_book()
2025-01-20 13:32 [PATCH] ALSA: hda: tas2781-spi: Fix -Wsometimes-uninitialized in tasdevice_spi_switch_book() Nathan Chancellor
@ 2025-01-20 13:41 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-01-20 13:41 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jaroslav Kysela, Takashi Iwai, Baojun Xu, linux-sound, llvm,
patches, kernel test robot
On Mon, 20 Jan 2025 14:32:48 +0100,
Nathan Chancellor wrote:
>
> Clang warns (or errors with CONFIG_WERROR=y):
>
> sound/pci/hda/tas2781_hda_spi.c:110:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
> 110 | if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> sound/pci/hda/tas2781_hda_spi.c:119:9: note: uninitialized use occurs here
> 119 | return ret;
> | ^~~
> sound/pci/hda/tas2781_hda_spi.c:110:2: note: remove the 'if' if its condition is always true
> 110 | if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> sound/pci/hda/tas2781_hda_spi.c:108:9: note: initialize the variable 'ret' to silence this warning
> 108 | int ret;
> | ^
> | = 0
>
> Sink the declaration of ret into the if block and just return 0 at the
> end of the function, as there is nothing to do if cur_book has already
> been changed.
>
> Fixes: bb5f86ea50ff ("ALSA: hda/tas2781: Add tas2781 hda SPI driver")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202501192006.Hm9GmKiV-lkp@intel.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Thanks, applied now.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-20 13:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 13:32 [PATCH] ALSA: hda: tas2781-spi: Fix -Wsometimes-uninitialized in tasdevice_spi_switch_book() Nathan Chancellor
2025-01-20 13:41 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox