Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4970312imm; Tue, 9 Oct 2018 07:53:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Z2SJUJEmZyWDUvnyxs6iJ13agm5afLonjehpMq9/wQsDeSMBcSxkHwZ/t22c7yT2twqQ4 X-Received: by 2002:a17:902:8644:: with SMTP id y4-v6mr29173825plt.48.1539096785408; Tue, 09 Oct 2018 07:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539096785; cv=none; d=google.com; s=arc-20160816; b=0XF24NZtrct+TlLctIy0FKBnH1KSt/gBJPxrfwQp+VK9WVD4StdWlaCcWsAPLSwgzZ jvSnZmCizr7TQKFoOISHKflx1cp9X1Uw4uGFUZnDJPMU28B0asdNULMFmrFO94lj+S/L aqGd4ujx1MHilarUp47Cfg1mGuqZ9FwxihWj9xKIaGvDGKFAPgssN5g/g60Y5j6wm452 jQXKYcd4C+L5v0RpW5GqseAU/spMnYjIp0znzKCzKuTR6lmed+nOw1NMpQ2Yd7gn6SfL PixYAcqFM98WQwap+gOw+e149wYmuh9e7kUvp6E8UuXlqKuh5SqGkGtvYLNYEak3QrYg BMSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=Z3D2KenP45egrl0bEqe1OUiWM3Rw/qFUshg9EPy3Nb0=; b=linJgKKRQwz+aSxcCfbVMOzx3DqAweDdCnIv6/66P100JTveiS3+bgb01Tl4YhQo/w F12DMiT3mWuQ92D1kRTt1+2qB8ATP4y+E8YF9ImnQCtf27NLtvhCxZyaypDAvUhsSWgS QE8SmJo3XEYBgETlO1iwIZX3n0M29FSgqHgLFIPBGi4CFMuawsC+1cu/Q8Eta8Pzv1Eb Wn7kUZbYwF3uYXlaZKyDyieNctDGEKjMwmfK17jNALu+dRrQW31sOD/eXEDwlQ+U+gwG l2dJBPLFhCrSUhoLw12pwFIG8Jo0HGVs4BC3cgzIJxoE8d5+jg6J/NCNtnx9E5wgsVw1 tG7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62-v6si13025409plf.288.2018.10.09.07.52.50; Tue, 09 Oct 2018 07:53:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726616AbeJIWJD (ORCPT + 99 others); Tue, 9 Oct 2018 18:09:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:36756 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726415AbeJIWJC (ORCPT ); Tue, 9 Oct 2018 18:09:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8B38AAFFB; Tue, 9 Oct 2018 14:51:43 +0000 (UTC) Date: Tue, 09 Oct 2018 16:51:43 +0200 Message-ID: From: Takashi Iwai To: "Wenwen Wang" Cc: "moderated list:SOUND" , "Jaroslav Kysela" , "Kangjie Lu" , "open list" Subject: Re: [PATCH] ALSA: intel8x0: fix a redundant check bug In-Reply-To: <1539095754-5609-1-git-send-email-wang6495@umn.edu> References: <1539095754-5609-1-git-send-email-wang6495@umn.edu> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/26 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 09 Oct 2018 16:35:52 +0200, Wenwen Wang wrote: > > In snd_intel8x0_codec_semaphore(), the parameter 'codec' is firstly > checked to see whether it is greater than 2. If yes, an error code EIO is > returned. Otherwise, 'chip->in_sdin_init' is further checked. If > 'chip->in_sdin_init' is not zero, 'codec' is updated immediately with > 'chip->codec_isr_bits'. That means, the parameter 'codec' is not used in > this branch. Actually, it is only used in the else branch when > 'chip->in_sdin_init' is zero. Thus, the check on the parameter 'codec' is > redundant if 'chip->in_sdin_init' is not zero. This can cause potential > incorrect execution in this function. Suppose the parameter 'codec' is 3, > which is greater than 2, and 'chip->in_sdin_init' is not zero. The current > version of this function will return EIO after the first check because > 'codec' is greater than 2. However, since 'codec' will be updated in the > following execution when 'chip->in_sdin_init' is not zero, this check will > be meaningless and the execution should continue, instead of returning the > error code EIO. > > This patch avoids the above issue by moving the check on the parameter > 'codec' to the else branch of the if statement that checks > 'chip->in_sdin_init'. > > Signed-off-by: Wenwen Wang Passing codec > 2 is just incorrect, no matter whether it's in in_sdin_init state of not. In the in_sdin_init state, it's supposed to be ignored, but still passing such a value is already wrong. That said, there is no need to skip the check. Of course, if your patch fixes any real issue (i.e. a bug), I'll happily apply the patch. In that case, please show the exact use case that hits the bug. thanks, Takashi > --- > sound/pci/intel8x0.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c > index 5ee468d..f619e58 100644 > --- a/sound/pci/intel8x0.c > +++ b/sound/pci/intel8x0.c > @@ -515,13 +515,13 @@ static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int code > { > int time; > > - if (codec > 2) > - return -EIO; > if (chip->in_sdin_init) { > /* we don't know the ready bit assignment at the moment */ > /* so we check any */ > codec = chip->codec_isr_bits; > } else { > + if (codec > 2) > + return -EIO; > codec = chip->codec_bit[chip->ac97_sdin[codec]]; > } > > -- > 2.7.4 > >