From patchwork Thu Aug 17 03:59:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13355942 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DACDC2FC04 for ; Thu, 17 Aug 2023 04:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=mLQTzsuERiydMbcJMGmzB1lQyk25jv/z558rA4qsAtQ=; b=myd4hNvaeGNraX bFVzyGn0WgOvc+QCgtcfz45hva/IwilACLYe5LVrNvSZs1+69EoxCanAuNjGWLdWnuj/RgltiBSee El9bTXDuq2ioWZoZdrzNzfVdR8xGf1bHnAWJX5vGBxZfkWjhgyUqdjItjdmnMDNHyniyyimeMV329 6fuGloB3llaj6AVjX+XJcziUWVqnnQrDBA69i0G6UoBZhpK6arMWbGN2StuaqCCgtSgIu08nQk7LT fo+JNgRMa/PLlq3gfdi2jX4vmrkUu9KEnPyZqj7WxQlICwhYeEObN12mhEaaxdrpsXLnWKR66t4gO smhUN7asl1NquoWKEcqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWUAh-005V4c-1R; Thu, 17 Aug 2023 03:59:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWUAe-005V46-0o for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2023 03:59:42 +0000 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 74EB4D75; Wed, 16 Aug 2023 21:00:16 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.56.113]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 579A93F762; Wed, 16 Aug 2023 20:59:32 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com Cc: Anshuman Khandual , Mike Leach , James Clark , coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Dan Carpenter , Mike Leach Subject: [PATCH V2] coresight: etm4x: Ensure valid drvdata and clock before clk_put() Date: Thu, 17 Aug 2023 09:29:26 +0530 Message-Id: <20230817035926.157370-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230816_205940_343406_17E79E88 X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/ Reviewed-by: James Clark Reviewed-by: Mike Leach Signed-off-by: Anshuman Khandual --- This applies on coresight-next Changes in V2: - Dropped drvdata->pclk check for non-NULL - Replaced IS_ERR() with IS_ERR_OR_NULL() for drvdata->pclk Changes in V1: https://lore.kernel.org/all/20230811062738.1066787-1-anshuman.khandual@arm.com/ 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..77b0271ce6eb 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 && !IS_ERR_OR_NULL(drvdata->pclk)) clk_put(drvdata->pclk); return 0;