Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: scarlett2: Zero initialize ret in scarlett2_ag_target_ctl_get()
@ 2024-04-20  0:25 Nathan Chancellor
  2024-04-21 17:32 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2024-04-20  0:25 UTC (permalink / raw)
  To: g, tiwai; +Cc: alsa-devel, linux-sound, llvm, patches, Nathan Chancellor

Clang warns (or errors with CONFIG_WERROR):

  sound/usb/mixer_scarlett2.c:3697:6: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
   3697 |         if (private->autogain_updated) {
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~
  sound/usb/mixer_scarlett2.c:3707:9: note: uninitialized use occurs here
   3707 |         return err;
        |                ^~~
  sound/usb/mixer_scarlett2.c:3697:2: note: remove the 'if' if its condition is always true
   3697 |         if (private->autogain_updated) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  sound/usb/mixer_scarlett2.c:3688:9: note: initialize the variable 'err' to silence this warning
   3688 |         int err;
        |                ^
        |                 = 0
  1 error generated.

Initialize ret to zero to ensure ret is initialized in all paths within
scarlett2_ag_target_ctl_get(), which matches the style of other
functions in this driver.

Fixes: e30ea5340c25 ("ALSA: scarlett2: Add autogain target controls")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
FWIW, a lot of the functions that end in just 'mutex_unlock()' before
returning could probably benefit from the cleanup.h infrastructure,
which would help with the scope of err in this particular function, but
I decided to go with the most minimal fix here.
---
 sound/usb/mixer_scarlett2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index a2de31a0371b..b251d25f2a85 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -3685,7 +3685,7 @@ static int scarlett2_ag_target_ctl_get(
 	struct usb_mixer_elem_info *elem = kctl->private_data;
 	struct usb_mixer_interface *mixer = elem->head.mixer;
 	struct scarlett2_data *private = mixer->private_data;
-	int err;
+	int err = 0;
 
 	mutex_lock(&private->data_mutex);
 

---
base-commit: 32cb23a0f911317cdb5030035e49a204aa86fef5
change-id: 20240419-alsa-scarlett2-fix-wsometimes-uninitialized-d44f7659b52a

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


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

* Re: [PATCH] ALSA: scarlett2: Zero initialize ret in scarlett2_ag_target_ctl_get()
  2024-04-20  0:25 [PATCH] ALSA: scarlett2: Zero initialize ret in scarlett2_ag_target_ctl_get() Nathan Chancellor
@ 2024-04-21 17:32 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-04-21 17:32 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: g, tiwai, alsa-devel, linux-sound, llvm, patches

On Sat, 20 Apr 2024 02:25:59 +0200,
Nathan Chancellor wrote:
> 
> Clang warns (or errors with CONFIG_WERROR):
> 
>   sound/usb/mixer_scarlett2.c:3697:6: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>    3697 |         if (private->autogain_updated) {
>         |             ^~~~~~~~~~~~~~~~~~~~~~~~~
>   sound/usb/mixer_scarlett2.c:3707:9: note: uninitialized use occurs here
>    3707 |         return err;
>         |                ^~~
>   sound/usb/mixer_scarlett2.c:3697:2: note: remove the 'if' if its condition is always true
>    3697 |         if (private->autogain_updated) {
>         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   sound/usb/mixer_scarlett2.c:3688:9: note: initialize the variable 'err' to silence this warning
>    3688 |         int err;
>         |                ^
>         |                 = 0
>   1 error generated.
> 
> Initialize ret to zero to ensure ret is initialized in all paths within
> scarlett2_ag_target_ctl_get(), which matches the style of other
> functions in this driver.
> 
> Fixes: e30ea5340c25 ("ALSA: scarlett2: Add autogain target controls")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks, applied now.

> ---
> FWIW, a lot of the functions that end in just 'mutex_unlock()' before
> returning could probably benefit from the cleanup.h infrastructure,
> which would help with the scope of err in this particular function, but
> I decided to go with the most minimal fix here.

Yeah, we can clean up lots of such code now.

If it were a new code file, I'd suggest it, but since it was an
extention of the existing code, I accepted as is.


thanks,

Takashi

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

end of thread, other threads:[~2024-04-21 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-20  0:25 [PATCH] ALSA: scarlett2: Zero initialize ret in scarlett2_ag_target_ctl_get() Nathan Chancellor
2024-04-21 17:32 ` Takashi Iwai

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