From patchwork Sun Oct 13 10:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13834010 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 167BFCF2576 for ; Sun, 13 Oct 2024 10:44:22 +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=sI0NVFrf3pRuZLAIx9mivd2k+klWW713Wqz1uXcf1I4=; b=AiIIm9S3nw53+cUCPOUyM0Pjz+ rhCTpiOFpKxOPhAGPoJR1ztzVGWLciMm8ml77coZ9PLF1ZONOO4w6q+rJHuwdnSK3O3vpCaNSkKXJ dYZ983wWU+0u6Ayzfxba3f4tYiSG52zA4lKUnWMfsM6uJ0gCkbacGgzOqqLb/eJMwtppniojWOdHD iUcwvsp4wvEcgIuZPW7Cub947dvZxjvuZwKzHTxNHx72BHgS+W9pvSL3O4hSbdXOzIxkWYinx295Z 5tP2guKogo/Sw4CSG5QNF3oWbGnSfi//xQizWM8c9BEWtVVs/jQSNM67f7PMQFP3FioOb8+yBXVfJ DgXK94Iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szw54-00000002XKm-3gy7; Sun, 13 Oct 2024 10:44:10 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szw3c-00000002X6R-3dQv; Sun, 13 Oct 2024 10:42:44 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-431195c3538so21755575e9.3; Sun, 13 Oct 2024 03:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728816158; x=1729420958; 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=sI0NVFrf3pRuZLAIx9mivd2k+klWW713Wqz1uXcf1I4=; b=evLrG+icnwVG8ofnv6Zxmd8+TJnBQF0XrHesePGwyk2Xhb43lUJIhwW4SXZdhxU89A g8OX9Id4kmLM9Ji1zZ6jvXHiYOyDPN/GmBAFVSWDLvfRrMKgdQfOOZnVZfs0FvC6uzTd 4IbggFdEOlrXvulvikuLGEmqTPKhgD9jF/j9dTf0thALOwt0akpKETx67PltYcwx6PAq yZaBfN9DtOLwmRgYD5MREB+QmMyyVFrW72mu4UrnYOfIihLAV2GB8cQBp/Mq6Z8n/01m hinsxkV4tKq7gzeB5bC0w2DIAW9JHG772bIQIf0hnoZ8YjhMtwpt0usrYGTwirMvrwe2 6pCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728816158; x=1729420958; 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=sI0NVFrf3pRuZLAIx9mivd2k+klWW713Wqz1uXcf1I4=; b=lJ9TlOcBJ2sz2rZIgHzViiOq4s32B1GJGX09DTRfRZ589zWo4xXv4q+wq6x8IfBFrg zpwbLmZBN0f898mE4PZuEfVkM7kBQVbc5FfUgNQVMAo0BsKxOJInJTpXvusX3AaSuOAl GQncVSJaMcYRdk6OldAvwhFvHKQOLXC8ZntdgEhW+nZG6RrqU512Bur6PNPjm22JLwKl ahDK2dmLUoy3A6dRv4dSFYYEvIRx1Q24I8/X3sScp/fGJY5kJc3IgpkPXgzgj7XU+Ikq cOOay4Gpm7i2I23a3gUizU72NfeM2PjH4SCw7kH+aVaWNFBTcMttlPe3h6KWUjEiTcPG mjhg== X-Forwarded-Encrypted: i=1; AJvYcCUGQeP6Er1WrPtPGQ8qQbPbYLNDEyvHtitsfZKwPsJUop+vwk+3CqFSGZOsSomdQBvH7SnVfD9uaCULc7t4eyWi@lists.infradead.org X-Gm-Message-State: AOJu0YwzeYbNL0C7zsK5N0NAIaM9fTNwGhZ7xGF2vSKw1w6/9qB+MuyX kIZeqZfhc74FF/2/f3T0Rz1PnmLffjnKdjOieMScXN3HlZd7TY/n X-Google-Smtp-Source: AGHT+IGufmCYtx1yjlM7P4W+1+XvlivxR/a4dbQTa29lFsAyi/NYHTq2CdMAlBpQXoURmLlJxn9+RA== X-Received: by 2002:a05:600c:1f8c:b0:430:c3a5:652a with SMTP id 5b1f17b1804b1-4311ded53cbmr62215745e9.12.1728816157942; Sun, 13 Oct 2024 03:42:37 -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 5b1f17b1804b1-430d70b4462sm120913475e9.30.2024.10.13.03.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 03:42:36 -0700 (PDT) From: Javier Carrasco Date: Sun, 13 Oct 2024 12:42:32 +0200 Subject: [PATCH] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node MIME-Version: 1.0 Message-Id: <20241013-vchiq_arm-of_node_put-v1-1-f72b2a6e47d0@gmail.com> X-B4-Tracking: v=1; b=H4sIABekC2cC/x3MTQqAIBBA4avErBO0X+gqETLkWLNIS0uC6O5Jy 2/x3gORAlOEoXggUOLI3mWosoB5RbeQYJMNlawaJVUt0rzyoTFswlvtvCG9X6foJLaEiNb0EnK 7B7J8/99xet8P1l9UCWcAAAA= To: Florian Fainelli , Broadcom internal kernel review list , Greg Kroah-Hartman , Stefan Wahren , Umang Jain , Laurent Pinchart Cc: linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, 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=1728816154; l=2125; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=RvVa1Hdz0npBvLce7iPzTIjWN+LlLgRw3t8ryHuP8Y4=; b=dZJuhHm54XpgX1j7LLyPpshdmuzxcgLz23pgRbrWVZwDHB9bpO03XnysqoYVpQtJCGkni0cTr qRM3Pxgi1HIDmf8HV3buNwX3ZwQ1Q1xohQbNo14frQOy1FR4vcIeAH/ 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_034240_966608_C093F099 X-CRM114-Status: GOOD ( 11.66 ) 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 kzalloc() for 'mgmt' 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: 1c9e16b73166 ("staging: vc04_services: vchiq_arm: Split driver static and runtime data") Signed-off-by: Javier Carrasco --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- base-commit: d61a00525464bfc5fe92c6ad713350988e492b88 change-id: 20241013-vchiq_arm-of_node_put-60a5eaaafd70 Best regards, diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 27ceaac8f6cc..792cf3a807e1 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1332,7 +1332,8 @@ MODULE_DEVICE_TABLE(of, vchiq_of_match); static int vchiq_probe(struct platform_device *pdev) { - struct device_node *fw_node; + struct device_node *fw_node __free(device_node) = + of_find_compatible_node(NULL, NULL, "raspberrypi,bcm2835-firmware"); const struct vchiq_platform_info *info; struct vchiq_drv_mgmt *mgmt; int ret; @@ -1341,8 +1342,6 @@ static int vchiq_probe(struct platform_device *pdev) if (!info) return -EINVAL; - fw_node = of_find_compatible_node(NULL, NULL, - "raspberrypi,bcm2835-firmware"); if (!fw_node) { dev_err(&pdev->dev, "Missing firmware node\n"); return -ENOENT; @@ -1353,7 +1352,6 @@ static int vchiq_probe(struct platform_device *pdev) return -ENOMEM; mgmt->fw = devm_rpi_firmware_get(&pdev->dev, fw_node); - of_node_put(fw_node); if (!mgmt->fw) return -EPROBE_DEFER;