From nobody Wed Nov 27 02:24:11 2024 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA33D231CB2 for ; Mon, 14 Oct 2024 08:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896216; cv=none; b=jsBpfQ+Xsf4wZY6p8E9X2scipzD7YG9WqduOhY8OoVYXyp+U04wO/g6iS1uKZt9zYaEEAsgDz3uXTC8OTQZo4PquTvZA2qaYTVYyrAGullcfVvKCLAZG8uMSgM9aqNkGRm/b2BrepjLuqMV+ByOWvP8SbDtubDFokoaJglCCamo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896216; c=relaxed/simple; bh=xGtdnRt3Vj5TJFE+xPUs3ODpILN2e8JGFrFZ5HwFyn8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F18QRs9LyjH7ge3wSUoYIW20N3lA6nvOiZy7IQYdVUNyrI+s3SKowbfZNjqyr/Zpg81P0aUsnwEr398MieD5A+u/ritxhRsdptL8/t8weTlnZVkUe3m9e38hoIL8qoC7TuCSNizEziytykYsgfRbI2QmuSua6gQg9OyZpKzDlf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZWZHK0MI; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZWZHK0MI" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c9404c0d50so3976227a12.3 for ; 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=vger.kernel.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=ZWZHK0MIrZFXLTz3RapwJpbO2D1DpTPq4k4Fw4Co0SV3CyM0AjLJKcLuS8i7cYmMgf 0ImJMuXfj/7PsHNJbBLVfUs8ziHl5H4cHnp4Ogb1q1OG3LAYCm4QV944RRrd/3qK6G8V YFqtXSG2Rs0fqDdiygCPXlORsMVs7M+MCYllOG8LIGD/7+HJWWYCksh9e0CgE5iahAvH Zd3S0mx0ZakhAWWLSeztbVLpQiK2fS7zBZQgjkdtWHaszHGEuZr4so8ojrf7nbzgR2ge ldqK/0Tc7+CXIsg2uK3Q+xaS2ily1yW706szIIOaMbXTJNTdpnodHF1iHw54CGFThyPL 9YSA== 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=ujJf6DFPHsEyxmzQ8CDpu2J10Czo48vJ/cdfBwmyvqGdhd48vf8sChgKsRS4n3kVY3 ZdjsfHIx2O3yjjTK9gg5njWCfyi0Woous93bwvU4ZP0TuhO4nx8Wklh3J8YbBmLIvKGo DdLGDlb5z6wxt/Ht4JjzE88YbBHgaES50tqDJzqd1TmkH3TQ1tygUlXZGSgjnMCTZl/s lDUk2dnZ3CEhH6hP25UV2iDq6e9+8AFUdlusaA5rj3X+7yGHAPz6GmHJLPvKfV7h+BWN L3vsSAY0s17ZUGg0kyHUpehwCAeOn5zVgZ8HlVOnETzSuVtiV9X8Q6lRyaA5xTWv6syt QVMQ== X-Forwarded-Encrypted: i=1; AJvYcCW+aZMjtWLBjwd4dqsI8UAkJORFEUQxB0lFt3Yvd9IJXXYPen68lQm2jktlMipCKhBLX1gh9jUiSdyw2f0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4vcuNUu6MxRZtd48y7vcS0mPDF7jerCpQQP2xtjJJnSUJRBps 7m9F0V7TOmzBQ+cV9eYGspmqoRsC5dh+/15cZsnY+qf7CXauXX7s 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() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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= 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 Reviewed-by: Dan Carpenter Reviewed-by: Umang Jain --- .../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); =20 ret =3D 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; + } =20 vchiq_debugfs_init(&mgmt->state); =20 @@ -1376,18 +1378,13 @@ static int vchiq_probe(struct platform_device *pdev) ret =3D vchiq_register_chrdev(&pdev->dev); if (ret) { dev_err(&pdev->dev, "arm: Failed to initialize vchiq cdev\n"); - goto error_exit; + return ret; } =20 bcm2835_audio =3D vchiq_device_register(&pdev->dev, "bcm2835-audio"); bcm2835_camera =3D vchiq_device_register(&pdev->dev, "bcm2835-camera"); =20 return 0; - -failed_platform_init: - dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n"); -error_exit: - return ret; } =20 static void vchiq_remove(struct platform_device *pdev) --=20 2.43.0 From nobody Wed Nov 27 02:24:11 2024 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB1E9156886; Mon, 14 Oct 2024 08:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896218; cv=none; b=cJYLkz1junxp2S2xboJx1JCS3UqNUWUYQksv14zp54uFDZjDzx71NPPVtnwCP6ZGl+J01O6+FpONmQeEn9sINdv9Nu4wDkfQ1diCNWVAscRHSxAgqRZ6quoCDMsTTKde0a8ewOhEhYQIt3gr8kWCmi+xZCUtemsKxDIkkOPdA5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896218; c=relaxed/simple; bh=cgQO1UwCPIWBof6xKNlDEdY6kW2vr7t1iwZgCtqmWls=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GSyc71/TRRmVeqhiUT/q3LTzSTPLauQTilwmGZq84I4BfO832JW0b1rOWE9Iv6rlQ2NpYXs0eMGdHWroRKk6OUKPLmCE6BR40JvDhmRHSUvA1xa4BYhMAofgbGBjbJ4pfdNu+ptOj6ZrDzbk2WQMMK5avzl/xwgQJCpWSH/NyrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VC4QX28a; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VC4QX28a" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c97cc83832so936268a12.0; 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=vger.kernel.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=VC4QX28ahK5JDVM7d6zKx8TUQnCikKVY6CSjOUBmbFs2kR4mBFCBVUufTD5PvgldJm OM04/qvW+Hs1v+QgFXSu6Usvr79CDVczcgFZvEGf75MVJPQ3oVVrJhbv3o1jBZbllnUK o1HKBzToRmw8RSL/I6NkQSz/fu/F+SqWYYnBGMkkKMOCCx0EVywEq8sng9z21xSzWE2P gP83KfvfgKmF1Ey0hE10EVfAXg8OD4x7wQpFB1r82TwGw7Eeg1+JxjC3/UNM6shitSWC 3bbo3mvISj2DbRiNrMA7hbQ/YYVQJkSsI63P+iXWCskfUS7+9cRQCJywWtClIsOgMD3I rPsw== 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=niJNRfwfP2WukCCx4RFbBy2LX0SHsTzHqtyif5SHJqUDHXciUya6QLMQ57EadzbVET FzkSNTd0UFbqCL6yZ/yv7KM4L1eUsrVlDrh9Ir/H20//BXJjvMkeT9ozj0I6j44B07aS lBVvP/PrgFyryrmmDw/tujD48HVy9WBoBfjcNo6wYD5lM/y7Ogyz9UMiOjZy3G2gn8TS KXV9sDDw5/yG/CZw9XnBqe2MfILmtN1fptitOAW+ouMaIK7fCj3yT8Y5fLWiA+kS5Tq/ t3A5u+7D+huVkIlTQGbFBB9MaDAAKTEldbdr+NVBVWMhaAa5nGR9Mpzmp0l0aRxqxSPJ fspg== X-Forwarded-Encrypted: i=1; AJvYcCVojqSnaf8su8KY0j2UT9Qhf1F+rW8cfaETb86d6qZuzmt4iBRcuRHZzzmNHAx8e87IuBjqbe36@vger.kernel.org, AJvYcCWsS3ZLKELpl6ZhJq8mdnR85tZj5wbxq2JxJvS2OKNeqdD//ZIB3ZvC5rXpkN6bBAKn2zx6qeBOGwCv6Fs=@vger.kernel.org X-Gm-Message-State: AOJu0YwJ79j0WMREyiIepP5vdiyLxQpvwxHlGF2swy4TRI+PzjT8D3ds 4gIcRXFDBjxI2fCwlBMSww/MyAuAjF8046EaiwV4hcLece19HBJj81PwONOc 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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= 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 stati= c and runtime data") Signed-off-by: Javier Carrasco Reviewed-by: Dan Carpenter Reviewed-by: Umang Jain --- 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); =20 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; =20 - fw_node =3D of_find_compatible_node(NULL, NULL, - "raspberrypi,bcm2835-firmware"); + struct device_node *fw_node __free(device_node) =3D + 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; =20 mgmt->fw =3D devm_rpi_firmware_get(&pdev->dev, fw_node); - of_node_put(fw_node); if (!mgmt->fw) return -EPROBE_DEFER; =20 --=20 2.43.0