Skip to content

Commit 1256961

Browse files
nathanchancetiwai
authored andcommitted
ALSA: hda: tas2781-spi: Fix -Wsometimes-uninitialized in tasdevice_spi_switch_book()
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: bb5f86e ("ALSA: hda/tas2781: Add tas2781 hda SPI driver") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Nathan Chancellor <[email protected]> Link: https://patch.msgid.link/20250120-tas2781_hda_spi-fix-wsometimes-uninitialized-v1-1-d7fd104aa63e@kernel.org Signed-off-by: Takashi Iwai <[email protected]>
1 parent e576e78 commit 1256961

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

sound/pci/hda/tas2781_hda_spi.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,17 @@ static const struct regmap_config tasdevice_regmap = {
105105
static int tasdevice_spi_switch_book(struct tasdevice_priv *tas_priv, int reg)
106106
{
107107
struct regmap *map = tas_priv->regmap;
108-
int ret;
109108

110109
if (tas_priv->cur_book != TASDEVICE_BOOK_ID(reg)) {
111-
ret = regmap_write(map, TASDEVICE_BOOKCTL_REG,
112-
TASDEVICE_BOOK_ID(reg));
110+
int ret = regmap_write(map, TASDEVICE_BOOKCTL_REG,
111+
TASDEVICE_BOOK_ID(reg));
113112
if (ret < 0) {
114113
dev_err(tas_priv->dev, "Switch Book E=%d\n", ret);
115114
return ret;
116115
}
117116
tas_priv->cur_book = TASDEVICE_BOOK_ID(reg);
118117
}
119-
return ret;
118+
return 0;
120119
}
121120

122121
int tasdevice_spi_dev_read(struct tasdevice_priv *tas_priv,

0 commit comments

Comments
 (0)