Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp801856rdh; Wed, 23 Aug 2023 15:56:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErKcP8QeWkqkSL1adyBV1V1uhZYo8TBCWk9gPopmV2k+QpRrchw+bjrzgI3joNWMtZh7ES X-Received: by 2002:a17:906:8456:b0:9a1:f3a6:b906 with SMTP id e22-20020a170906845600b009a1f3a6b906mr1512167ejy.36.1692831361565; Wed, 23 Aug 2023 15:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692831361; cv=none; d=google.com; s=arc-20160816; b=B1uhhr+bFjM+8Zi0TAAfuNP2VizrCaoy39ojtslVA2CdJe3WvL3btH1AgMfMgkuaZG bLMfHoSYUf+jXdI9cKRAGau2WuNYlv0tILqiOOTFZAYC746/DwCO651fDTswCoAyzwDn sErM3JWiAVTZgZxcgdoDBDhbPFGi/CJzEwNEQrevaRdEbOkdSrycYJyy5OFQsWpnAV7i bOtfP9TWv3tHkomzmfxi24paHmqPgmmRYshiLLaUSJ0lH+xQLFHhLVBvWPzJ6NhYIpAO U+TTcggeuf0epazRGYYB0AeRAeNrQ0Nyt3c8iJb0RQSC9J8MdlV93EuCNWUyhQKKnomc IDwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=RjKC8N3rhbvmz7M5EZ7zr3y/qVeZln2JOAmxwNn5okU=; fh=AZWJGvyp785PZ/eavYB3y94ucEJPnplnagmjSK3UKPs=; b=I6+ZfzOgva5FAS8RrcOs2U56+1EyMELR1PP2MPwZy+YzMTchRO2K2Q1ptcf0vKFoAb oGoBrpvDhEbTpyD07quGBvjM2yQ0dmbjwfKm7cPDGqK7E21Axgp0ScuGXvuta2Yimg9n mmbJ9TcmtCW8p3G+oaAi0hMEDaG+SbRBDXT7YxqPq8f8akA7cnwyhRFpk2/VOwAMZ9ZB yux08SLb7qnvtNfcfFejcVNXd/6ply1xb9cfPzwgjiGM9DyaTLySskdkbhbaWVAQ0//n aDUwm/KIF5XJP8ccR2b65nimPE7BiDhv1Fz4kfS3/7FLdgQf+s21PzTjL6HBF39e55Ws yp+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020a170906051600b0099cd068a168si9208769eja.173.2023.08.23.15.55.38; Wed, 23 Aug 2023 15:56:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232336AbjHWCwq (ORCPT + 99 others); Tue, 22 Aug 2023 22:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232327AbjHWCwo (ORCPT ); Tue, 22 Aug 2023 22:52:44 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id DF7EA1A5; Tue, 22 Aug 2023 19:52:40 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 5DA5F601ACF8E; Wed, 23 Aug 2023 10:52:36 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: perex@perex.cz, tiwai@suse.com, Christophe JAILLET Cc: suhui@nfschina.com, arnd@arndb.de, robert.jarzmik@free.fr, yangyingliang@huawei.com, maciej.szmigiero@oracle.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] ALSA: ac97: Fix possible error value of *rac97 Date: Wed, 23 Aug 2023 10:52:13 +0800 Message-Id: <20230823025212.1000961-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.2 required=5.0 tests=BAYES_00,RCVD_IN_SBL_CSS, RDNS_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before committing 79597c8bf64c, *rac97 always be NULL if there is an error. When error happens, make sure *rac97 is NULL is safer. For examble, in snd_vortex_mixer(): err = snd_ac97_mixer(pbus, &ac97, &vortex->codec); vortex->isquad = ((vortex->codec == NULL) ? 0 : (vortex->codec->ext_id&0x80)); If error happened but vortex->codec isn't NULL, this may cause some problems. Move the judgement order to be clearer and better. Fixes: 79597c8bf64c ("ALSA: ac97: Fix possible NULL dereference in snd_ac97_mixer") Suggested-by: Christophe JAILLET Signed-off-by: Su Hui --- sound/pci/ac97/ac97_codec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 80a65b8ad7b9..25f93e56cfc7 100644 --- a/sound/pci/ac97/ac97_codec.c +++ b/sound/pci/ac97/ac97_codec.c @@ -2069,10 +2069,9 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template, .dev_disconnect = snd_ac97_dev_disconnect, }; - if (!rac97) - return -EINVAL; - if (snd_BUG_ON(!bus || !template)) + if (snd_BUG_ON(!bus || !template || !rac97)) return -EINVAL; + *rac97 = NULL; if (snd_BUG_ON(template->num >= 4)) return -EINVAL; if (bus->codec[template->num]) -- 2.30.2