Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5504177pxb; Mon, 28 Mar 2022 13:25:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyvbB+y9/xvGVf8iV3yGVHkZg3jvhXvaGDGxGu5nvJVVC71GdkJYMfYiVKokvMEv8FHomu X-Received: by 2002:ac8:7d51:0:b0:2e1:c757:6d25 with SMTP id h17-20020ac87d51000000b002e1c7576d25mr24220413qtb.301.1648499108575; Mon, 28 Mar 2022 13:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648499108; cv=none; d=google.com; s=arc-20160816; b=SLde3Kh55p9Qu6DMJN1iH4vqhhY603gdCsKgUc5GKZfXOTpMTewcJ4//EcKdPnyrvL lln1zaCDQw0tqgFTYwjD3FIGT4VGTNH3mmo/WOBk9NnESK4sMBql0kaatpbhvPPvRqll 7i7P1DqH0CRdy65JWPmVJ4w7FDqgOSV4T8nY1/bku68KAHzUOLIXsxhDWoU4la5JqjxE TdMrPmAWVQLZOThnbOV9uEtl3ihPidFNy4buTCeLShaeXoz6qUDA7O1hSfCMRGRgagml wX023PFuJlNC30MuciE5Q3+KNIHCIbIXDmuaqdQeZpAG8+JzXpYXA8vtyneD7X5U8GhA ePHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=59JhUNktdVz2W5QJS5bzmJcf9POr7QzcmSfTOiXjcAE=; b=dQr/+W4bDkIkYKi/Wd6CSNXCggJp6R+RvTL+D1IIETNLIbvukhYybBIqPPXb0aRKca U+XEzQfXp5uIF6LzZ2OZ020Z8Xgoig+LpPcRr/dvyguETRf45Jr+gMeTVOQK996ZpP+3 XaTF/Y8Dhn1tV/A1uJL8+3aFVBLR6LrKjALdBYR2wKL4zUdYkvtJZT6nrn/fCmlGltl1 2FcfsSSuEsDZprDIk/YnzRwySLW+PAo7QmKlqpgTRlTs82iMYyXstJcCEPHJpM0KkViw tVPNWFqM8dOQQ8rmhOkJp0Zij+49hGuIbjFrZErwnGUFQryHaKldxWeYrhveVVx8LGqq xmqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OZsDNWW6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s23-20020ac85ed7000000b002e20379764csi6605461qtx.468.2022.03.28.13.24.37; Mon, 28 Mar 2022 13:25:08 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OZsDNWW6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbiC0IPB (ORCPT + 99 others); Sun, 27 Mar 2022 04:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbiC0IPA (ORCPT ); Sun, 27 Mar 2022 04:15:00 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B3E54FC62; Sun, 27 Mar 2022 01:13:20 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id c23so12277053plo.0; Sun, 27 Mar 2022 01:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=59JhUNktdVz2W5QJS5bzmJcf9POr7QzcmSfTOiXjcAE=; b=OZsDNWW6DNUFlcVYdlNaJI92YyM8e/1vdhm693Motn3WyZ7ewgAsXDxbdBNDuI8hff ajoCrHaYyEZxqHcVTVdfqmCiAlgd0sXnfwfy3HsjWeyb24TnljM/iNf1SvULyd3sonld udFONOi7HhP3xVedtAuHx8XnHifA5u4dM9VEFCjcFn/kOUfkAOqXQkJIAGRriZLaV8DV C8xCK72j0QcEf1Ns1y5NnE0u3qGfo2oNQvxJqmdJFiRrUyn+xamdElZdMcv9PZEVqfqB VYcWoqB6UFyBQXda/CLno4HvjFHNnAuiS6oH8SytVgsKNkS/xJtzOIQttmqvlM7Kz/jR Z2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=59JhUNktdVz2W5QJS5bzmJcf9POr7QzcmSfTOiXjcAE=; b=Y+JJ5y2rVELqBr5kwgPE/XGi3gKLieTDS7LD2gHQpMEc71TN+aORjKd67iLbVmq4QY 14pJrT7PeHqItJv1a0zTqWq6oS9bOSk0LsQxHLPER9rFPeavidNHErLOLSuzGTSSSDQO o3VB/PMT+lthcfBQCeokuycLcrQHXe7vC+xsHdrvV5RA5XqtqEiLL5S/QNqJ3ugZSDOn tL10VRQjbLVHm0Cve8rz8wdHxD+lT8hF2EAZdLOqHeReOHBgGJbmiCFDmWa+JseWdOCz zVWNUeCiPPH4j+AMSfdcDUqmL5xOsp8t0raCqGL+LXpa8PMoDNsT6zc9OvmMg6gbPtUP 22/w== X-Gm-Message-State: AOAM533tPR/sYFeSR3QPAmztnarXPvUlcgcpE2tuh8KXHkDpXFrf5uu3 xvr/51vDXu9ertrwdvwJd+M= X-Received: by 2002:a17:903:124a:b0:154:c860:6d52 with SMTP id u10-20020a170903124a00b00154c8606d52mr18220698plh.159.1648368799693; Sun, 27 Mar 2022 01:13:19 -0700 (PDT) Received: from localhost ([115.220.243.108]) by smtp.gmail.com with ESMTPSA id h10-20020a056a00230a00b004faa0f67c3esm12594343pfh.23.2022.03.27.01.13.18 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 Mar 2022 01:13:19 -0700 (PDT) From: Xiaomeng Tong To: oder_chiou@realtek.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: derek.fang@realtek.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Xiaomeng Tong , stable@vger.kernel.org Subject: [PATCH] codecs: rt5682s: fix an incorrect NULL check on list iterator Date: Sun, 27 Mar 2022 16:13:00 +0800 Message-Id: <20220327081300.12962-1-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 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 The bug is here: if (!dai) { The list iterator value 'dai' will *always* be set and non-NULL by for_each_component_dais(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found (In fact, it will be a bogus pointer to an invalid struct object containing the HEAD). Otherwise it will bypass the check 'if (!dai) {' (never call dev_err() and never return -ENODEV;) and lead to invalid memory access lately when calling 'rt5682s_set_bclk1_ratio(dai, factor);'. To fix the bug, just return rt5682s_set_bclk1_ratio(dai, factor); when found the 'dai', otherwise dev_err() and return -ENODEV; Cc: stable@vger.kernel.org Fixes: bdd229ab26be9 ("ASoC: rt5682s: Add driver for ALC5682I-VS codec") Signed-off-by: Xiaomeng Tong --- sound/soc/codecs/rt5682s.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c index 1e662d1be2b3..c890e51ff953 100644 --- a/sound/soc/codecs/rt5682s.c +++ b/sound/soc/codecs/rt5682s.c @@ -2686,14 +2686,11 @@ static int rt5682s_bclk_set_rate(struct clk_hw *hw, unsigned long rate, for_each_component_dais(component, dai) if (dai->id == RT5682S_AIF1) - break; - if (!dai) { - dev_err(component->dev, "dai %d not found in component\n", - RT5682S_AIF1); - return -ENODEV; - } + return rt5682s_set_bclk1_ratio(dai, factor); - return rt5682s_set_bclk1_ratio(dai, factor); + dev_err(component->dev, "dai %d not found in component\n", + RT5682S_AIF1); + return -ENODEV; } static const struct clk_ops rt5682s_dai_clk_ops[RT5682S_DAI_NUM_CLKS] = { -- 2.17.1