From patchwork Mon Oct 14 08:56:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13834522 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 B3A51CFC52C for ; Mon, 14 Oct 2024 09:34:49 +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:In-Reply-To:References :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:List-Owner; bh=IZtKiNo2Id4aizdmJ3+JWafU0x2IXYEJ4ykrMWfdUD4=; b=nQI2p+E5rW8TsHrUE+KAg+49e/ 10wU2kt9GVZsafpGuKaZ5p06bu90Do8ZWBPCWXksrbSwB9nQ0h8ZkgZb5957LCGYrGDyszCjs2dBU qMCmwtteMLsflcmmGdXJcj0eYtz3rRLQq6JsIU0NchJFeGKuTx2PqbNQPY3Atgk3VXXfxx6at8WVk AL3xU6rtG3YJyA/UW8KrUmBDOPOQX3vodxrHPqHwCRx5PyXx3LAVJvFhcth8o5VhX7nxfrdD/6nV5 gOCHybxqzhf/3XURORZPySuL01oprL+NLdPJoZqlIotOvfI75uhekLBWxYTqUGzmlPtcok/s1wLhI FlwDLsXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0HTJ-00000004XzI-1Dca; Mon, 14 Oct 2024 09:34:37 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0Gsq-00000004ODu-1QYF; Mon, 14 Oct 2024 08:56:57 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5c9850ae22eso294206a12.3; Mon, 14 Oct 2024 01:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728896215; x=1729501015; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IZtKiNo2Id4aizdmJ3+JWafU0x2IXYEJ4ykrMWfdUD4=; b=g0g0lUZveBvcaGjbmnB3ia8lswre1Vzv7XtC6xJ2yjmBuTQYxoM4cGydtml4J4tgdx PXISO9wF6o7NkhYkChJ6YybMbfAZIn0je/hU0dWa+laIC4NaMKhls3PVeepWclr0CL+3 +0VB0NYBGI0SvUSCgxl3mOC2sbBzvDFCokOve1HhcX5lwK6KEXd4dbmTSmpk/hwyWf9V CMv9smJUkEiAgxaL6DoHrmpixQB/5MskQTguZGVN2qYvLMQJGjev1/UyJld8LbtBmz4D PN1mKBTNWHpcqBPunjg5tLzs4JivlX3ZfG3ro6dO1Hon0hSpg6m7p7NGiJeaW/5RUSbl zg+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896215; x=1729501015; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZtKiNo2Id4aizdmJ3+JWafU0x2IXYEJ4ykrMWfdUD4=; b=F7NjnhEbesWktPAn+ESuR4vYyZFxUU7cUMDLdjm5TF8z1rxH/1RRKG7EEtAaYLmCmT JjLwbQkozXRA+iKuMRB6w22/42/nR0ZbOqrgcAsPtYnIWONXX1CZtY5YQMY1hKHiuxaR vQ6vepLeqlpRb/W+ouh3XG15L1t/iUxDpSrZCeIE2JZi4XEf8XYxVHULMIk+uL7VdHxA 8Hw/ZwXW893xfOTAQTgO4XduX8Z5CxuNz8PwVLRuHPcrtldCkmNphQST8+8/HJnIFDDm xQQd3adqXTYsjVJQg4XiMQFWdW0Cof3Hpm62iw8C0TQJa6F1tbY5sXZ/q0QYf/7gmOpe JQeA== X-Forwarded-Encrypted: i=1; AJvYcCUU7YUUkLKCUnIc9RqR3d9OFRgdOnNoo6vPTJ7m3hpgIkl1vzJdiHw44V6cXuFdXwrIFQlXYqy6Hytp0LmW8Yx4@lists.infradead.org X-Gm-Message-State: AOJu0YxE4pVapY/4sZ6j+xvedHESbbyBZpDguIKZ3UOeqio2xp8Y7Vrn oACxQfyEu0tNfpfVcRkMuNFzQSHV2G34ldQaadXqFTnVxZxpTjeu X-Google-Smtp-Source: AGHT+IE4Tebx2zedc1mf+9ffSBCm5CEIg+axVw0KgnFRYtSFdJGxxHajwNWdgYanJ3YncO+DPc1FjA== X-Received: by 2002:a05:6402:42d1:b0:5c4:14fe:971e with SMTP id 4fb4d7f45d1cf-5c948d58e4bmr8108654a12.23.1728896214496; Mon, 14 Oct 2024 01:56:54 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c9370d2296sm4635091a12.15.2024.10.14.01.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:56:54 -0700 (PDT) From: Javier Carrasco Date: Mon, 14 Oct 2024 10:56:37 +0200 Subject: [PATCH v2 2/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node MIME-Version: 1.0 Message-Id: <20241014-vchiq_arm-of_node_put-v2-2-cafe0a4c2666@gmail.com> References: <20241014-vchiq_arm-of_node_put-v2-0-cafe0a4c2666@gmail.com> In-Reply-To: <20241014-vchiq_arm-of_node_put-v2-0-cafe0a4c2666@gmail.com> 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, Javier Carrasco , stable@vger.kernel.org X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1728896207; l=1950; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=cgQO1UwCPIWBof6xKNlDEdY6kW2vr7t1iwZgCtqmWls=; b=z8dlOAj/8FIYM9IbUkY70cYe7S9l19ri5R7gxEkCqRIXIL34pJkUIGwLA8NJtm6fID+dxXhB9 l+cV2UsHREeCPEOwnnztwEcLzm2lYoVDIPK3cOQXJLAOnaP4gIN5z+0 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-20241014_015656_507837_32E4C651 X-CRM114-Status: GOOD ( 12.52 ) 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(-) 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 81b2887d1ae0..bf2024929d07 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,6 @@ MODULE_DEVICE_TABLE(of, vchiq_of_match); static int vchiq_probe(struct platform_device *pdev) { - struct device_node *fw_node; const struct vchiq_platform_info *info; struct vchiq_drv_mgmt *mgmt; int ret; @@ -1341,8 +1340,8 @@ static int vchiq_probe(struct platform_device *pdev) if (!info) return -EINVAL; - fw_node = of_find_compatible_node(NULL, NULL, - "raspberrypi,bcm2835-firmware"); + struct device_node *fw_node __free(device_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;