Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1287431pxb; Fri, 10 Sep 2021 02:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbI9+JLt1ztwwXk/H8y0tiDytR3Ryge4h/lYmG6et1ZqXAQbjvG7u05JAh4EazDIQtz3Uc X-Received: by 2002:a17:906:4c89:: with SMTP id q9mr8592198eju.118.1631266079981; Fri, 10 Sep 2021 02:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631266079; cv=none; d=google.com; s=arc-20160816; b=Lde5Dnp1BFen/MQJ9H0bBS+exeqgm43AFcfKwU9IKOcc3ykoNvpkSLHYNia9EDtr7A /OiSZ5tue1rMhpwe1vKJquIJpWLMiwdOvrOU1wv2OjkmsTYEgFKeK+QpI4NipslCUlg6 ZHS43OvFAsKvyWpQ1ba3KCYg4gj1mcOWX32eZI2pWOk124r/HGVZl6JrxRrNpFYv6Qp6 xUHlUPN/Sax6RsRWMkZjiMOWTN/VM2eZrb0/gVm4wts78ccI/bppzIYiiziPfbrAKqga F3jsLpHrmT2bJ4EJQYMEkt+GOQLt2XDqIp5c/nP3AO7HLIBb0vFAfXJIUgAwVs9vyBQX QOpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=8JqBeOtKULbnQxzDgvoKvIMExY0ho10jyfWUcuY6nx4=; b=JySaPcy6huhFwmS9XuX9uFsVZRlBy9k08Et9/bQG5LUiR6yEkX0tZnmMLusP0We5sy RY2T3scZofDQQBx/aPVVXp9at0B1l77nY8BYIu7YvHXmWB8ruT3IhZ2Zd0piRoOjXGKE ZlphGSZuA6JZlXveoLpD4y0uYFyzV8t+t2PDeICtVMlm/OYqxmMSjbUK4yb3Lrdy6DCE EyRIWo5OZBUWEcjDgn3IW+tkyQtFiE+9qsHKHUmJNo0v9nc+FCwE0fsh52ccB/V3aaq5 lkjAvMh0zs0GE/WKADCjTXCvelmdRQvqami9xh1m+ym2M+xAd3VFf5OcDbCVdhSSRNNs QUuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si4630250edx.499.2021.09.10.02.27.36; Fri, 10 Sep 2021 02:27:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231991AbhIJJ1c (ORCPT + 99 others); Fri, 10 Sep 2021 05:27:32 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:37510 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231818AbhIJJ1b (ORCPT ); Fri, 10 Sep 2021 05:27:31 -0400 X-UUID: 30a0599609814a07a9fbc573b5fead1d-20210910 X-UUID: 30a0599609814a07a9fbc573b5fead1d-20210910 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 909894693; Fri, 10 Sep 2021 17:26:16 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 10 Sep 2021 17:26:15 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 10 Sep 2021 17:26:14 +0800 From: Trevor Wu To: , , CC: , , , , , Subject: [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function Date: Fri, 10 Sep 2021 17:26:13 +0800 Message-ID: <20210910092613.30188-1-trevor.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When memory allocation for afe->reg_back_up fails, reg_back_up can't be used. Keep the suspend/resume flow but skip register backup when afe->reg_back_up is NULL, in case illegal memory access happens. Fixes: 283b612429a2 ("ASoC: mediatek: implement mediatek common structure") Signed-off-by: Trevor Wu Reported-by: Dan Carpenter --- Change since v1: add Reported-by tag --- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c index baaa5881b1d4..e95c7c018e7d 100644 --- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c +++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c @@ -334,9 +334,11 @@ int mtk_afe_suspend(struct snd_soc_component *component) devm_kcalloc(dev, afe->reg_back_up_list_num, sizeof(unsigned int), GFP_KERNEL); - for (i = 0; i < afe->reg_back_up_list_num; i++) - regmap_read(regmap, afe->reg_back_up_list[i], - &afe->reg_back_up[i]); + if (afe->reg_back_up) { + for (i = 0; i < afe->reg_back_up_list_num; i++) + regmap_read(regmap, afe->reg_back_up_list[i], + &afe->reg_back_up[i]); + } afe->suspended = true; afe->runtime_suspend(dev); @@ -356,12 +358,13 @@ int mtk_afe_resume(struct snd_soc_component *component) afe->runtime_resume(dev); - if (!afe->reg_back_up) + if (!afe->reg_back_up) { dev_dbg(dev, "%s no reg_backup\n", __func__); - - for (i = 0; i < afe->reg_back_up_list_num; i++) - mtk_regmap_write(regmap, afe->reg_back_up_list[i], - afe->reg_back_up[i]); + } else { + for (i = 0; i < afe->reg_back_up_list_num; i++) + mtk_regmap_write(regmap, afe->reg_back_up_list[i], + afe->reg_back_up[i]); + } afe->suspended = false; return 0; -- 2.18.0