Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1117164rdb; Fri, 16 Feb 2024 06:03:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUb6gYhSDEgofCOmZg7Q4WDipTKs2nuORO/Hy1rx7Jt3gPi9OqDH7SC964BYGvo0N7+jWeysh0D1Wbd87Qq/ae3zecyJtwkjktf4KZjgg== X-Google-Smtp-Source: AGHT+IGiovuOxd8n5CllbK6/eg397TFLkIFevJSF+Pk4SDyyfQ5c57FRjBKvUdq5SdSerCSlLg5h X-Received: by 2002:a0c:e2ca:0:b0:68f:3dbd:466c with SMTP id t10-20020a0ce2ca000000b0068f3dbd466cmr474296qvl.22.1708092187858; Fri, 16 Feb 2024 06:03:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708092187; cv=pass; d=google.com; s=arc-20160816; b=k9YD+pEpHWiM77qIIMe3mH/hZ2FuNbtHmFn61KiKn6emWOMPZRVInwt7qTCsRhe1uZ 5/EwlxSn/Ck5R348+8pPz8Sp/RZQTj8iUt4dHD7CUeIDOenKLpeN0aFEAHyJ3af5sF70 eWtxAOJloSuhDPqbi4Q2ea19sfdXwO1PvKqBMRKR7PzS8dSdLysX6u7MujM5zY5yInEC XbwInl+KlgHCI3bmSIliVdxT3nTECNq5Nwh+h8q7ZLzz2bgLv4mYEg29xmO1zGuDDk5b +pbDtgmkK0j9lWD2fzYndrWG+7plUKmtLraOxZhNhE5G+RkWodloFcxvOdW96FhjQkcC f6gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=DX6t6X+yIdGbLB39W9vftzQkoVtLDPdmu/GnvJ6LhTI=; fh=RqxIMMcaeRnN77Z9NTXByeZt27maI508uueYtXjeQS8=; b=RssCVjpOxOP853hRJJLkNpMvg2/WrB8NkEokslcHvi1mN1517u+DKXsf/1lTWUnN6Y lxyp9TRLN0piRvaSDcmhqNPtoCp+1Zy9AIrkug6iJKiAiSPizlnYXM5BuRc/hgqGS78M ZlVJ/OBcAoIFmyED6PWzPG2FeTkfN9n48vWxaKZvvuz4g3YfDc88QhUfdTZYXbMbHMta 8LZng+Fxhi/+1xmRThwG6yjdln4mih4u47/NeCCvrXRfvgiMU3jQP82vcG8gg9hGT7Nc Ed5E3FluCFAApn3XebjMGs9LmxBtlmixlutxT23TA7rSjFX8cAl9wF5wVlDUTc44Wqjq litg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=jyDqzY0N; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Lv0MGNUO; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LxvnyCHL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-68688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jz1-20020a0562140e6100b0068c65ca8e3esi3912949qvb.143.2024.02.16.06.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 06:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=jyDqzY0N; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Lv0MGNUO; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LxvnyCHL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-68688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 41E0D1C252F8 for ; Fri, 16 Feb 2024 14:02:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E485812C54E; Fri, 16 Feb 2024 14:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jyDqzY0N"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Lv0MGNUO"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="LxvnyCHL"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="t+ekt5pV" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A54D12C541 for ; Fri, 16 Feb 2024 14:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708092136; cv=none; b=AYnApWMO4mIBGEXj0dCRvgvG/pE4ncitc7g5zH1joERgKxVcviq00uxgRjvYhOyHpWZdToxhOkgNtsMak0UvDY0oD6S70WDdRKpUyRHaKGUc87hrOSscbC1T6TRwqKpvAZ1+ZMFKTt7XBRqBTh5kyetZGo1a8+C6mC9uddh/MZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708092136; c=relaxed/simple; bh=tv/orOiraGfFT/LCQPcSh2kGKvQA7D4GbtgfVaTK234=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=VOWXx+hvxUb9fZZ8m8JcMfS+f9RFF5T+RCs1WCkih3GL9StQ4DP0WeRdOq2uCWsXp5gL7a1hjkhqlux+Ro+fCHX4B6x2IDE1Q1hX5Nogjww3Y2e0zLzzz/aCZ5N865jUXBAqbqQnnnfYHZ9D8ZbSRTpe6XuoUNsbNFclorGddAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jyDqzY0N; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Lv0MGNUO; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=LxvnyCHL; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=t+ekt5pV; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 001B0220B0; Fri, 16 Feb 2024 14:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708092126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DX6t6X+yIdGbLB39W9vftzQkoVtLDPdmu/GnvJ6LhTI=; b=jyDqzY0NLFhPSBRgRykDHCm65D5PNw1PrSg60JuI6O4lXxFmBpMmA/ZJWQYlm72I0WGtAk SjiVzn9KCW1/6DfyRJj2cBFhoWQxIha/P7fd8t0LXiJRE6+d4E0OvdtQUnem5B4a8kE5ZD i9n1VnTMBOeJ+KZ1RDZItC7EfENuej0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708092126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DX6t6X+yIdGbLB39W9vftzQkoVtLDPdmu/GnvJ6LhTI=; b=Lv0MGNUOHOm4qYvaIOrCMSdTts66FhSCpmhBiJpFrPQeHUDGCBaabNhg2TWWHlSrAwb3Ia dSZ8yQyIY082kBAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708092124; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DX6t6X+yIdGbLB39W9vftzQkoVtLDPdmu/GnvJ6LhTI=; b=LxvnyCHLnF2BFGpigNMeVm3/+promMiSuC3Vbu/B12dQKN3T0g5Vz+GNKP1WUIjE9n1Vt7 OHxBgb4+DPsPG7dQIJa6Th7eD3YdtHpL8hI415UcvRVdEeS+ApkWF2H9TgM0ZucgZKApAw Dm/3lvYBdWo5v49J3EYSDdLx3kgTeZY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708092124; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DX6t6X+yIdGbLB39W9vftzQkoVtLDPdmu/GnvJ6LhTI=; b=t+ekt5pViC8fLjh59BuatpPUvUykK4qjQ+oVpsii7Ccrw3HxrO2k2JpGJW0Dqe16BIBx35 WfYno0nra2hbuaAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9972F13A39; Fri, 16 Feb 2024 14:02:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id k1L1I9tqz2VdLgAAD6G6ig (envelope-from ); Fri, 16 Feb 2024 14:02:03 +0000 Date: Fri, 16 Feb 2024 15:02:03 +0100 Message-ID: <87a5o0ik2s.wl-tiwai@suse.de> From: Takashi Iwai To: "Michael S. Tsirkin" Cc: Aiswarya Cyriac , jasowang@redhat.com, perex@perex.cz, tiwai@suse.com, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, virtualization@lists.linux-foundation.org, virtio-dev@lists.oasis-open.org, Anton Yakovlev , coverity-bot Subject: Re: [v4 PATCH] ALSA: virtio: Fix "Coverity: virtsnd_kctl_tlv_op(): Uninitialized variables" warning. In-Reply-To: <20240216084610-mutt-send-email-mst@kernel.org> References: <20240216100643.688590-1-aiswarya.cyriac@opensynergy.com> <20240216062630-mutt-send-email-mst@kernel.org> <87eddcikz6.wl-tiwai@suse.de> <20240216084610-mutt-send-email-mst@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=LxvnyCHL; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=t+ekt5pV X-Spamd-Result: default: False [-0.81 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; TAGGED_RCPT(0.00)[coverity-bot]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[11]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -0.81 X-Rspamd-Queue-Id: 001B0220B0 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Bar: / On Fri, 16 Feb 2024 14:48:10 +0100, Michael S. Tsirkin wrote: > > On Fri, Feb 16, 2024 at 02:42:37PM +0100, Takashi Iwai wrote: > > On Fri, 16 Feb 2024 12:27:48 +0100, > > Michael S. Tsirkin wrote: > > > > > > On Fri, Feb 16, 2024 at 11:06:43AM +0100, Aiswarya Cyriac wrote: > > > > This commit fixes the following warning when building virtio_snd driver. > > > > > > > > " > > > > *** CID 1583619: Uninitialized variables (UNINIT) > > > > sound/virtio/virtio_kctl.c:294 in virtsnd_kctl_tlv_op() > > > > 288 > > > > 289 break; > > > > 290 } > > > > 291 > > > > 292 kfree(tlv); > > > > 293 > > > > vvv CID 1583619: Uninitialized variables (UNINIT) > > > > vvv Using uninitialized value "rc". > > > > 294 return rc; > > > > 295 } > > > > 296 > > > > 297 /** > > > > 298 * virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type. > > > > 299 * @snd: VirtIO sound device. > > > > " > > > > > > > > This warning is caused by the absence of the "default" branch in the > > > > switch-block, and is a false positive because the kernel calls > > > > virtsnd_kctl_tlv_op() only with values for op_flag processed in > > > > this block. > > > > > > > > Also, this commit unifies the cleanup path for all possible control > > > > paths in the callback function. > > > > > > > > Signed-off-by: Anton Yakovlev > > > > Signed-off-by: Aiswarya Cyriac > > > > Reported-by: coverity-bot > > > > Addresses-Coverity-ID: 1583619 ("Uninitialized variables") > > > > Fixes: d6568e3de42d ("ALSA: virtio: add support for audio controls") > > > > > > > > > > > > > --- > > > > sound/virtio/virtio_kctl.c | 19 +++++++++++++++---- > > > > 1 file changed, 15 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/sound/virtio/virtio_kctl.c b/sound/virtio/virtio_kctl.c > > > > index 0c6ac74aca1e..7aa79c05b464 100644 > > > > --- a/sound/virtio/virtio_kctl.c > > > > +++ b/sound/virtio/virtio_kctl.c > > > > @@ -253,8 +253,8 @@ static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, > > > > > > > > tlv = kzalloc(size, GFP_KERNEL); > > > > if (!tlv) { > > > > - virtsnd_ctl_msg_unref(msg); > > > > - return -ENOMEM; > > > > + rc = -ENOMEM; > > > > + goto on_msg_unref; > > > > } > > > > > > > > sg_init_one(&sg, tlv, size); > > > > @@ -281,14 +281,25 @@ static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, > > > > hdr->hdr.code = > > > > cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND); > > > > > > > > - if (copy_from_user(tlv, utlv, size)) > > > > + if (copy_from_user(tlv, utlv, size)) { > > > > rc = -EFAULT; > > > > - else > > > > + goto on_msg_unref; > > > > + } else { > > > > rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false); > > > > + } > > > > > > > > break; > > > > + default: > > > > + rc = -EINVAL; > > > > + /* We never get here - we listed all values for op_flag */ > > > > + WARN_ON(1); > > > > + goto on_msg_unref; > > > > } > > > > + kfree(tlv); > > > > + return rc; > > > > > > > > +on_msg_unref: > > > > + virtsnd_ctl_msg_unref(msg); > > > > kfree(tlv); > > > > > > > > return rc; > > > > > > I don't really like adding code for a false-positive but ALSA > > > maintainers seem to like this. If yes, this seems like as good > > > a way as any to do it. > > > > Err, no, you misunderstood the situation. > > > > I took the v1 patch quickly because: > > - It was with Anton's SOB, who is another maintainer of the driver > > - I assumed you lost interest in this driver since you haven't reacted > > to the previous patches for long time > > - The change there was small and simple enough > > > > Now, it grows unnecessarily large, and yet you complained. Why should > > I take it, then? > > > > This is a subtle cosmetic issue that isn't worth for wasting too much > > time and energy. If we want to shut up the compile warning, and this > > is a case where it can't happen, just put the "default:" to the > > existing case. If you want to be user-friendly, put some comment. > > That's all. It'll be a one-liner. > > > > OTOH, if we do care and want to catch any potential logical mistake, > > you can put WARN(). But, this doesn't have to go out as an error. > > Simply putting WARN() for the default and going through would work, > > too. > > > > Or we can keep this lengthy changes if we want, too. > > > > So, I really don't mind which way to fix as long as it works correctly > > (and doesn't look too ugly). Please make agreement among you guys, > > and resubmit if needed. > > > > > > thanks, > > > > Takashi > > OK sorry about too verbose. I mean since Anton wants it, I ack this. > > Acked-by: Michael S. Tsirkin Alright, I applied this one. Thanks! Takashi