Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp455718pxb; Thu, 9 Sep 2021 05:01:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWz1K4dUp8OB4XHo8ryV69sGfJiftAdfp6OEt04G9bVwCSMVaURHJvvWJJbaX5IXzTNdIM X-Received: by 2002:a17:907:8309:: with SMTP id mq9mr2973347ejc.561.1631188889576; Thu, 09 Sep 2021 05:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188889; cv=none; d=google.com; s=arc-20160816; b=zaRC0BWtXRVU9Rfp8D01eDdL50+PjBWDDLb6qjUGOBRl27G4b50PcUZ7vgBKlAVah+ 00soSkgg+Q4dfv8mBIZ1JE8ncJkGELTGHKeRFxMb9qx6wsGDdh3MA6XHfVkxRt53NNif neLXIjtYldIqvZsDi8AA/JQr+JSY9kLhRiSo62U7RD4vVjM4/rboQJdoLCqdseQXuyOh 1ZieH7tRJ10s83HYRaz2DXF5ECCvBEjt1LS+sZe7e2LVoTwJ4zACtVG1fdQe8z4EzybO a7IsoDCGof875RspO0HUIdqT9faxSWM2LX9xvHJC9oU3O9GFdVc6+EaK0CarouxB1qGY BE4w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0ozy6S5XAkqaNOXMWxeoKgTM3FP4ZryTOmUyuPncQa4=; b=idteeZZ80Cr1f2MWnz5Ra1WfOGYp5UcMtWyHRviHCrdv5xbJnbmclNwWVX+ilcVZ2s k7E2tTCSYcsMqAAPsv9q7pZano/YrXIgsNrPJaRspoQ5oQsycmzkceTghhRUUTxvJMP5 w3bEB87iXSRXv6xBprjgcME8EtgG0uCd8fNuxTYtrTOvKbnCZz6qXwzzFgCkWiy2RjxV ApeGk3WC1uQQO4pdtFNmkNxxLZvhb1TLx0F2Sj38RVjJ6/0Unet1fqAKMOTxmDF8TCse WBkoblFLACLAXG++McLKsxGO2//6KmWvCdcRPWkvYCmV2B5UEyZjhnppQQvSTMbMHJyX wJDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nBNnfYx7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j10si1673844ejo.344.2021.09.09.05.01.03; Thu, 09 Sep 2021 05:01:29 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nBNnfYx7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238513AbhIIL6J (ORCPT + 99 others); Thu, 9 Sep 2021 07:58:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:34892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245240AbhIILy6 (ORCPT ); Thu, 9 Sep 2021 07:54:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B9F7613A7; Thu, 9 Sep 2021 11:44:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187900; bh=AV9wRD9lEMp2Qb/zjeTJnb2M22/TDCzs8tAi3oi+/+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBNnfYx74BMsC9aStgnCqbnoRWlxitjegf1CLbwOp0mwn+PxFVsSRJ0nVqOXo/Y7Y RPSS8FaR2RznpAnEXrlp+0ak4376f4sws36iHYq07SU/53imA9EK5/8HDn7ooyUZFK av4feSlSTMXNlTG/5RlBFwQNJMm7nVcRv/zhqS/1LWAb4Mro06rSDqAuTuDXx/v5VD 6V4v4GMsThw/hrLKW6mfOw6Paicr2Tb7CCU1ypIzfluBPsdhj2womyiQa0AbQnjJw2 /TqHFCp5CUQ5AsPSUJiwL9GuKsnQzVDXDr7Zpbcpsb6AAGf9En9g4casx+zXDzAlEc dUfLCmoSPFZSw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kuninori Morimoto , Dan Carpenter , Mark Brown , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.14 179/252] ASoC: rsnd: adg: clearly handle clock error / NULL case Date: Thu, 9 Sep 2021 07:39:53 -0400 Message-Id: <20210909114106.141462-179-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuninori Morimoto [ Upstream commit cc64c390b215b404524725a94857d6fb58d9a62a ] This driver is assuming that all adg->clk[i] is not NULL. Because of this prerequisites, for_each_rsnd_clk() is possible to work for all clk without checking NULL. In other words, all adg->clk[i] should not NULL. Some SoC might doesn't have clk_a/b/c/i. devm_clk_get() returns error in such case. This driver calls rsnd_adg_null_clk_get() and use null_clk instead of NULL in such cases. But devm_clk_get() might returns NULL even though such clocks exist, but it doesn't mean error (user deliberately chose to disable the feature). NULL clk itself is not error from clk point of view, but is error from this driver point of view because it is not assuming such case. But current code is using IS_ERR() which doesn't care NULL. This driver uses IS_ERR_OR_NULL() instead of IS_ERR() for clk check. And it uses ERR_CAST() to clarify null_clk error. One concern here is that it unconditionally uses null_clk if clk_a/b/c/i was error. It is correct if it doesn't exist, but is not correct if it returns error even though it exist. It needs to check "clock-names" from DT before calling devm_clk_get() to handling such case. But let's assume it is overkill so far. Link: https://lore.kernel.org/r/YMCmhfQUimHCSH/n@mwanda Reported-by: Dan Carpenter Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87v940wyf9.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sh/rcar/adg.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 0ebee1ed06a9..5f1e72edfee0 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -391,9 +391,9 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv, struct clk *clk; clk = clk_register_fixed_rate(dev, name, parent, 0, 0); - if (IS_ERR(clk)) { + if (IS_ERR_OR_NULL(clk)) { dev_err(dev, "create null clk error\n"); - return NULL; + return ERR_CAST(clk); } return clk; @@ -430,9 +430,9 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv) for (i = 0; i < CLKMAX; i++) { clk = devm_clk_get(dev, clk_name[i]); - if (IS_ERR(clk)) + if (IS_ERR_OR_NULL(clk)) clk = rsnd_adg_null_clk_get(priv); - if (IS_ERR(clk)) + if (IS_ERR_OR_NULL(clk)) goto err; adg->clk[i] = clk; @@ -582,7 +582,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) if (!count) { clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], parent_clk_name, 0, req_rate[0]); - if (IS_ERR(clk)) + if (IS_ERR_OR_NULL(clk)) goto err; adg->clkout[CLKOUT] = clk; @@ -596,7 +596,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) clk = clk_register_fixed_rate(dev, clkout_name[i], parent_clk_name, 0, req_rate[0]); - if (IS_ERR(clk)) + if (IS_ERR_OR_NULL(clk)) goto err; adg->clkout[i] = clk; -- 2.30.2