From patchwork Mon Oct 14 08:56:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13834576 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 0DFACCFC52F for ; Mon, 14 Oct 2024 09:54:47 +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=Y/JEhqoZl4E0cyUUh/uV9OIb6kXsx02RuLl2MX4iZIs=; b=44gbNq4EiI/oD2PPPViIY/GYYD 0vAJA2GMxaDQ+t85M1JXr+dRGFMNF2HcBIrQq1emCzTCbT+M1ru5MJx0eWvASe7SLRQFW7bU45IYN sRMcoNWPxgpXKSM29JZBJwXY2gn9Qen/Bvl/zfN/WBw8hi9vLVmOs2lCcjk0VtaN/WV3w6bRfiljW OH+faSq+c+gvbNhrpFSaG53y6mQodNs2JacOXV64U+cSxjWyyvOvqbt6140x4IGXD/vieIaqf3eFS LPuUnpymQD5t874dD1vIZ2epS3cp9uFZvIZd1Xklqvz76P1bLVzGAH4uPWu0njEchSQ3sowN1XtdR poyExL2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0Hme-00000004bxN-0jlt; Mon, 14 Oct 2024 09:54:36 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0Gsn-00000004OCt-3C5a; Mon, 14 Oct 2024 08:56:55 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c935d99dc5so4295078a12.1; Mon, 14 Oct 2024 01:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728896212; x=1729501012; 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=Y/JEhqoZl4E0cyUUh/uV9OIb6kXsx02RuLl2MX4iZIs=; b=GmLwZmVoaq/bh5PkQraWTNKBOSARvOUxOYRJmrDqonjVSbn90v+7z3XpoCE6IoHjhg NEGOQ7LFkDSRAbDosm/5+7NBB3PPLCVJnCCb6DN7mkpp2RLCv34Fb+jfBH8CTCWa4Qje dcHDmVJQnx00eeMwtrH261jQ1ccc4Rakph9YA/0jq13ksP4TN/ZxQBUqn1Dg1QyTYNZi +Od95gd0Cx+Sc5iA+ZShK2dVwIXTz4h8+mulgn6RGYgpnH/HoaGxFKhj+Y/5+ArkXs9y /GkXWC5w5kjyPiN4Ohe9M8zEjY/u+sWH5lIlqVKYZ1gI9y/zaxeP9fInbK76BukIwcPy 093g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896212; x=1729501012; 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=Y/JEhqoZl4E0cyUUh/uV9OIb6kXsx02RuLl2MX4iZIs=; b=TsWhFTGoULLBq6iHqIsz9QefZoL0KTySFCkb0B77HOV1Q5xHSPuKCSBEMwRc7MhYkS RFt427RXcn8ycbYqnXPVbdqMx9o9shhymjco/hx/K4A0mk2jynf+/lzoQJLAwkuuYq2E jMGe4hLzplekg/DpFum/yTGFK0xujebPF8V661qzOeAiaMSjXjBx9rcnOWpNI0EHDXG2 7H6EGs158IxtOKAOHCfXVcDNOcDma5DsULGuWNPWrnKLopn9jSqUXfQCg2fVHChtBzGi JrC79FC7kg+RADqTQ5pAdwYyV+E0yuFNCV69blWDShDwlEdsTpcuSYH6dRc0wZK65sO3 eyYA== X-Forwarded-Encrypted: i=1; AJvYcCVF3CPv3moT31o1j7RDRGJOmDolQKVEYNK56M5Q5eEA3nToJ52yXAtWrEC0iv0Xh7NBHR02mdZvxkS9SRMAeOgW@lists.infradead.org X-Gm-Message-State: AOJu0YxhIwTda/PM1BlqD6qwO+xklKC/Am+zNS+4xdIDYFAbO8aD9y8f qFBIwmPr/bU8fxlYUJ2LevdmbFG8nxZXSIsb4L3b/QL5LN+sZOgD X-Google-Smtp-Source: AGHT+IEFn6QtuxV2uIFTjjx/8oPht9aHKpTC7u9qcL44bqP67ILGm5a+ZBNPq+GHrpBB1J5epP0+nA== X-Received: by 2002:a05:6402:34ca:b0:5c9:68f9:8af3 with SMTP id 4fb4d7f45d1cf-5c968f9a259mr4404776a12.17.1728896212102; Mon, 14 Oct 2024 01:56:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:56:51 -0700 (PDT) From: Javier Carrasco Date: Mon, 14 Oct 2024 10:56:36 +0200 Subject: [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe() MIME-Version: 1.0 Message-Id: <20241014-vchiq_arm-of_node_put-v2-1-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 X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1728896207; l=1704; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=xGtdnRt3Vj5TJFE+xPUs3ODpILN2e8JGFrFZ5HwFyn8=; b=qS4TvGWBJCdTNKcjEj/E2YkKBXpwxQCEeub3CsxnCOFRi2PGAsVjTmZNKf7cV1VqYhMDxnDHi aZvTdlM8d5+DTAOddmqFmYTCjnf7qZtGg7jjKKm1cJ57YkZ8DO55+/t 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_015653_872956_1D46F27B X-CRM114-Status: GOOD ( 12.74 ) 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 The 'failed_platform_init' and 'error_exit' labels do not simplify the code, there is a single jump to them in the code, and the actions taken from then on can be easily carried out where the goto occurs. Signed-off-by: Javier Carrasco --- .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 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 27ceaac8f6cc..81b2887d1ae0 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1361,8 +1361,10 @@ static int vchiq_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mgmt); ret = vchiq_platform_init(pdev, &mgmt->state); - if (ret) - goto failed_platform_init; + if (ret) { + dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n"); + return ret; + } vchiq_debugfs_init(&mgmt->state); @@ -1376,18 +1378,13 @@ static int vchiq_probe(struct platform_device *pdev) ret = vchiq_register_chrdev(&pdev->dev); if (ret) { dev_err(&pdev->dev, "arm: Failed to initialize vchiq cdev\n"); - goto error_exit; + return ret; } bcm2835_audio = vchiq_device_register(&pdev->dev, "bcm2835-audio"); bcm2835_camera = vchiq_device_register(&pdev->dev, "bcm2835-camera"); return 0; - -failed_platform_init: - dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n"); -error_exit: - return ret; } static void vchiq_remove(struct platform_device *pdev) 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;