From nobody Wed Dec 17 07:30:13 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E684AEE49A3 for ; Wed, 23 Aug 2023 02:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbjHWCws (ORCPT ); Tue, 22 Aug 2023 22:52:48 -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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D snd_ac97_mixer(pbus, &ac97, &vortex->codec); vortex->isquad =3D ((vortex->codec =3D=3D 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 Acked-by: Christophe JAILLET --- 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 =3D snd_ac97_dev_disconnect, }; =20 - if (!rac97) - return -EINVAL; - if (snd_BUG_ON(!bus || !template)) + if (snd_BUG_ON(!bus || !template || !rac97)) return -EINVAL; + *rac97 =3D NULL; if (snd_BUG_ON(template->num >=3D 4)) return -EINVAL; if (bus->codec[template->num]) --=20 2.30.2