From patchwork Sun Oct 13 11:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13834011 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 AF9D9CF2579 for ; Sun, 13 Oct 2024 11:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: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=lO4MDn91uaEGvfavIYEn+tk1h5d1HCRNmemjl9PlHpI=; b=vfkdv8F73ciJKbyFnE/wyTRIhx L5hr3efupjecPXOlYR4rQvxhu7bt89AMYq8sT3eD7M1hQBOSK1CoH24x34cwceF/SxugmNAoVzOJg HswYy4/3DkJrihD5Z3NC42B4M8hqo8WVR3oZlyUPZ24+UGMbDnFsOPg3j9qSvBwpeIF0pxlczmkV6 cGeXxTn0eMqnY1QayyMCYW5ZM9WihS/eez92lytLD9kM+NGSd9lOeFs0n2Ya0uwTVf/eu+zZyVl/E /cNQ832vdNagKFXrCjFYVwCk9k7FxL55EmaCrhFT04bt3Fw0IO3lQHhy4hmqPGsFJQZhSGE0y4lL8 X3V1E8mA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szwU5-00000002Zx2-0TRr; Sun, 13 Oct 2024 11:10:01 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szwSf-00000002ZTP-0xqq for linux-arm-kernel@lists.infradead.org; Sun, 13 Oct 2024 11:08:35 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-430ee5c9570so38624475e9.3 for ; Sun, 13 Oct 2024 04:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728817711; x=1729422511; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=lO4MDn91uaEGvfavIYEn+tk1h5d1HCRNmemjl9PlHpI=; b=Kqf4666IHFUVqvH9n3auCi+FSz3efjP9l+9MdYpu6BpZZ1SlIUzhpZsUlHqCLfe1KA 1mAD89sMSYKyR8UnIC55IEFZhch2ceAlWMYqtdLGJemoBFF7WP5J4cAAbY5R9LcmRxO3 Cpqs/gQco6S+UfTfNvSZqw/uRIPtxBOZRZD/kbAeKXxBfGkgiWCZjeGVtgtqAo3yw9SC 4rGIJ1d2X7H4pGdU7IeFcH6TLzC+LHOkvZy8RMLLGMmiAFGODUJaUELBfeKJr7zPL6qp Is/MmJ2xLYxTDANT4iNFe/lxAfqR+7b3bsmdpOJoJZiEW049aCPb+yRXmx/l/6uaXtN+ m4Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728817711; x=1729422511; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lO4MDn91uaEGvfavIYEn+tk1h5d1HCRNmemjl9PlHpI=; b=wl/l51W63TvaUFUkz6J4i43JLit6TNWWN9w+Tui9mU2eNpKeF1T1cJKtEeiVj2einV 6pBhVOEKoCFFNRHc2oXfBf0sxmjBvsqZLMPJKLP0EaH1wKypCzAGAdtZ7wUxnh3YT6A3 BiHT5xu4gcG89SXUbLtzka5VVaRW4ODEFTByZFNLAU+3hGICB3eo7w66r5+8Ch19QiGW o3ZHOoEb8QS196dzk9TG7WfqSRodWtDRixpCwOAltVJZ5C5C4PYzdniNz6Juo0AV30ly B6vWqEXuwj/jpg3nLI95Zr+anezdWRL0G92LNE5eUZMpVIL4K3w8zO6efp0h4xfaQs1P 8o+w== X-Forwarded-Encrypted: i=1; AJvYcCVw+Q03dehXk0MB3t56mRQ69ce7N/5x44TEHr+6zPh7bHlmGvM72Ps74ZZKGIJb6KyL7AJ9V+CrCgUQsFQnIrQ8@lists.infradead.org X-Gm-Message-State: AOJu0YxW+k/ekJTHvmnz0Uzm4xSFw+ha0sUXHfnnb9Ci9riqnq64PbUG RCfK5MhOuBQYeWS3vISJ1lGoVn/PutTGcktdfHfxnRKSSTmljuMq X-Google-Smtp-Source: AGHT+IEpt28WqlOtcR7JiEHn62be6MZu+AUL/8FkJVzMqj9pgksgxOIMj1aGELxQfKwtgbaEsgCMfA== X-Received: by 2002:a05:600c:468b:b0:42c:bae0:f05f with SMTP id 5b1f17b1804b1-431255db4b1mr61558305e9.13.1728817710963; Sun, 13 Oct 2024 04:08:30 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-01f9-6cb5-d67b-9d29.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:1f9:6cb5:d67b:9d29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b9180f8sm8269238f8f.115.2024.10.13.04.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 04:08:30 -0700 (PDT) From: Javier Carrasco Date: Sun, 13 Oct 2024 13:08:27 +0200 Subject: [PATCH] soc: imx8m: Fix missing refcount decrement in error path for np MIME-Version: 1.0 Message-Id: <20241013-soc-imx8m-of_node_put-v1-1-515fdb85765d@gmail.com> X-B4-Tracking: v=1; b=H4sIACqqC2cC/x3MQQqAIBBA0avErBtQy4iuEhFmY80iDa0IorsnL d/i/wcSRaYEXfFApIsTB58hywLsavxCyHM2KKFqKWSFKVjk7W43DG70YaZxPw/UqjHStmbStYD c7pEc3/+3H973A2Ui6V5nAAAA To: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Xiaolei Wang , Lucas Stach Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1728817709; l=1748; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=/Ct3FGY7j5Fv5z63HvviD2bGOyouMPvYri4nmXi1OT0=; b=WwBORZEjEFmsgtb2S7roLxpu2+aWUj2PwcFQFtk6exJ2ohyiWfhp9Y2N14NodRpo3feqkB7wm fXpaRhtkZ1/AVUdxRQ7TsRMaakqSB2sVzjll/IpvPiS04nOiTyhlDI1 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241013_040833_311175_2B31F821 X-CRM114-Status: GOOD ( 12.47 ) 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 An error path was introduced without including the required call to of_node_put() to decrement the node's refcount and avoid leaking memory. If the call to of_clk_get_by_name() for 'clk' fails, the probe returns without decrementing the refcount. Use the automatic cleanup facility to fix the bug and protect the code against new error paths where the call to of_node_put() might be missing again. Cc: stable@vger.kernel.org Fixes: 836fb30949d9 ("soc: imx8m: Enable OCOTP clock before reading the register") Signed-off-by: Javier Carrasco --- drivers/soc/imx/soc-imx8m.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- base-commit: d61a00525464bfc5fe92c6ad713350988e492b88 change-id: 20241013-soc-imx8m-of_node_put-526a1c8ab540 Best regards, diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c index fe111bae38c8..ba8c0bdd60aa 100644 --- a/drivers/soc/imx/soc-imx8m.c +++ b/drivers/soc/imx/soc-imx8m.c @@ -99,12 +99,12 @@ static u32 __init imx8mq_soc_revision(void) static void __init imx8mm_soc_uid(void) { void __iomem *ocotp_base; - struct device_node *np; + struct device_node *np __free(device_node) = + of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp"); struct clk *clk; u32 offset = of_machine_is_compatible("fsl,imx8mp") ? IMX8MP_OCOTP_UID_OFFSET : 0; - np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp"); if (!np) return; @@ -125,7 +125,6 @@ static void __init imx8mm_soc_uid(void) clk_disable_unprepare(clk); clk_put(clk); iounmap(ocotp_base); - of_node_put(np); } static u32 __init imx8mm_soc_revision(void)