Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp1169018rdb; Wed, 16 Aug 2023 04:02:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQynwpabnbUhsW9UQATK476lETMMW/MlVx+ZVlQT52DWHF4Lkr49UFf4U1HvCFLbu7Wb1T X-Received: by 2002:a05:6a20:321b:b0:131:f3a:4020 with SMTP id hl27-20020a056a20321b00b001310f3a4020mr1436848pzc.33.1692183769468; Wed, 16 Aug 2023 04:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692183769; cv=none; d=google.com; s=arc-20160816; b=MHXFiD/bQJy5F9Cp+BEGP4751RIAJdWpnif1gngVL/Ifysvk6l8TZzURMZI/cIovoz 7xXb5cfWHP6hPpatnFxpzayupd7ueFBuqIzHQtuomR262s9YzHIS4d/Se+PM0u5guMz7 PvfJsRyOY3d/PcL+Pww87JpAc3OB0fwVZh556aXdhjzuzgb+9C8UpMQ5K8CLMyHtW1lh IKczZyi0RbVNdBBOcSePn/hoNAPofr91J0yCnGF3uHKWw62J8O7KE0gnPlSvIMvfLd+8 qec2qLkfgzgscKJ4GBawfCRxoyIwK/Ut2MOEOCV4WIEdcj6AJfXXDJJkkZ2Wqnz9rHVl m4cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=L8Xie+sBUMsHtYYkSezInEQY+qbuzP3FoZ0DWReMnmY=; fh=yhS3uiYjFGhTOFczF9ad5OJmXI/isz2/G0fjz2jGNKk=; b=IXkJpjyFFJWw59Xs2xk7J+/lOwMvbJOLzTYoEoazhnLJg0LWYCL9uhiC0mCw736+zw qF4ilxiU7aixonbBPizFpXgcJlOiQS14VtLNpWgYSOXFRj1jK5yfCy/e9yDy61zJ/zrj ReGk9oaAMHjbFPniTEbLBQ8JoDAE52d1aHprlTuh2hF1Kkzr+squMi6zx96ITKVkpLf7 XAb/7LLaTQ4EKOz2v/78ODItwo3iLzd9JR5+hAIO4UcHuBeyYy/4d24IXE4uE6gH8oJ7 r84iEYsZrFtV9fyjMvutdQq/GDhqZ+J8JjfVfNQY7LuiT7xZaotJA3fq5Fz7GC6GSxdv ufzw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x185-20020a6386c2000000b00565f5f197a0si1162057pgd.144.2023.08.16.04.02.36; Wed, 16 Aug 2023 04:02:49 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242706AbjHPIGs (ORCPT + 99 others); Wed, 16 Aug 2023 04:06:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242752AbjHPIGg (ORCPT ); Wed, 16 Aug 2023 04:06:36 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB7E9AB for ; Wed, 16 Aug 2023 01:06:34 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3280F1063; Wed, 16 Aug 2023 01:07:15 -0700 (PDT) Received: from [10.162.40.18] (a077893.blr.arm.com [10.162.40.18]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE5EA3F64C; Wed, 16 Aug 2023 01:06:31 -0700 (PDT) Message-ID: <435813e1-3e26-d125-d706-a2e3d8fd4e45@arm.com> Date: Wed, 16 Aug 2023 13:36:29 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] coresight: etm4x: Ensure valid drvdata and clock before clk_put() Content-Language: en-US To: James Clark , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org Cc: Mike Leach , coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Dan Carpenter References: <20230811062738.1066787-1-anshuman.khandual@arm.com> <07b0dabb-5409-9ba8-543f-aeecafe083e9@arm.com> <72960b11-9e35-a259-3ea6-bae91ff94838@arm.com> <32017de8-7b92-a88f-0bf6-da1dfe3a7f7d@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 On 8/11/23 15:44, James Clark wrote: > > > On 11/08/2023 10:22, Anshuman Khandual wrote: >> >> >> On 8/11/23 14:39, Suzuki K Poulose wrote: >>> On 11/08/2023 09:39, James Clark wrote: >>>> >>>> >>>> On 11/08/2023 07:27, Anshuman Khandual wrote: >>>>> This validates 'drvdata' and 'drvdata->pclk' clock before calling clk_put() >>>>> in etm4_remove_platform_dev(). The problem was detected using Smatch static >>>>> checker as reported. >>>>> >>>>> Cc: Suzuki K Poulose >>>>> Cc: Mike Leach >>>>> Cc: James Clark >>>>> Cc: coresight@lists.linaro.org >>>>> Cc: linux-arm-kernel@lists.infradead.org >>>>> Cc: linux-kernel@vger.kernel.org >>>>> Reported-by: Dan Carpenter >>>>> Closes: https://lists.linaro.org/archives/list/coresight@lists.linaro.org/thread/G4N6P4OXELPLLQSNU3GU2MR4LOLRXRMJ/ >>>>> Signed-off-by: Anshuman Khandual >>>>> --- >>>>> This applies on coresight-next >>>>> >>>>>   drivers/hwtracing/coresight/coresight-etm4x-core.c | 2 +- >>>>>   1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c >>>>> index 703b6fcbb6a5..eb412ce302cc 100644 >>>>> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c >>>>> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c >>>>> @@ -2269,7 +2269,7 @@ static int __exit etm4_remove_platform_dev(struct platform_device *pdev) >>>>>           etm4_remove_dev(drvdata); >>>>>       pm_runtime_disable(&pdev->dev); >>>>>   -    if (drvdata->pclk) >>>>> +    if (drvdata && drvdata->pclk && !IS_ERR(drvdata->pclk)) >>>>>           clk_put(drvdata->pclk); >>>>>         return 0; >>>> >>>> It could be !IS_ERR_OR_NULL(drvdata->pclk), but I wouldn't bother >>>> changing it at this point. >>> >>> +1, please could we have that. Someone else will run a code scanner and >>> send a patch later. Given this is straight and easy change, lets do it >>> in the first place. >> >> But we already have a drvdata->pclk validation check before IS_ERR(). >> Would not _OR_NULL be redundant ? > > I meant that it could be replaced with the single check: > > if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk)) > clk_put(drvdata->pclk); > > As Dan mentions it can't be an error pointer anyway, but leaving it like > this could just be considered defensive coding. Let's just go with the above change as you had suggested unless there is any particular objection. if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk)) clk_put(drvdata->pclk);