From nobody Sun Feb 8 16:31:15 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 4129C2D249E for ; Fri, 2 Jan 2026 07:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767340331; cv=none; b=n5XLHzA7FzRLc4GtRLiS4XNBbH0bQJ3d7KrCmctTko5geF2m9rpvn62AnedS80WfolqP0QPFpJs/VP8Vy1Nh2LT16Js/GP4fhV42DcUOFy2/ySHDH5n6RvyrQhGtco3YSUdRDPILU4UcCto/lk7EndweGS5Hv5snr4T3WoQZtb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767340331; c=relaxed/simple; bh=PYqFtCJKewiwotOHkWKODCOViU3vbaITARfsgFWgfPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K++QkZ3LbVGCt1XHmC+sVVoE1qIN4WPH7MTBV+66kKBsPv6z+AwEIJA1r0vw9PBIPFReSIDdLdZKvjzZfCjWYbWfKlAhnjmWE11ghdSxib9MaDYFkx2/tTOKpeylrlBataovVhvvLhKFGLLOFcVdnyj+H+WI5WTSCrfK3LArxPM= 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=ETdCK1Mo; arc=none smtp.client-ip=209.85.167.48 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="ETdCK1Mo" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-594285c6509so13026372e87.0 for ; Thu, 01 Jan 2026 23:52:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767340327; x=1767945127; 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=1GrDXAONfhMHnF8PgdBj6M4DUOiVSl4risTQaplS4W0=; b=ETdCK1MoFyeVcTxBTTKYbnMmfcHInxvKFDIbLfRDFMseCeSX9qF3BSoR4dSMgqWCM7 gcAJ3L/7fvHK4syoJBl8ZlhNhvhNOvZlTTpgAGQRA5sTgTqJ3eTAVAksHt9s68ZtINBC onhefNY64mJAbfNFbFkA42XL1+GkYTRYqcplte+PeLMGSauoVRu4HFAWWt+UcyQZAfq5 auibF6ne0A6AGwBS1bwdgD2xoZgDPEdoZtHlq68mKvNVJrXiiTpfPoGJq+gS8SmAMXQc JzAkLChcxF5gm5s1hShnGA/gOywLNrBeC2squIAPc7hgj2wB93tBycJNnVv9ApyL6Cbj mvRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767340327; x=1767945127; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=1GrDXAONfhMHnF8PgdBj6M4DUOiVSl4risTQaplS4W0=; b=NOb5gxGMLuccAQD+Ry1mG8SdcfdFrN3rEciXA+C+bOeIKLu8CZlU7ZXsAnW0Jef6Je nbL3j3LupI8MgTiazdP1MsIg7eiuplcWJAaTr8U5oSRfkFja+9Ycf1jzfu3XS4dT7BRq RVaOFU5Myz5uwL9eSVerWuxsUdbfBT53OoxazUGTxfr2/Kke0mledWgwg4RPeWXTrlOI u8syGkIEaeFBh1X6hFIcUwlLAKl6sCO/+EZ4/nQ6c5hDu+/RkbaDWOYK4a8SeT6C2mKJ aGQwmcP7vu8fzgZI77ZpznvwDNZ3xS5Urw4desCsRPktH+7PxpSKGSySggBbXVQyNsfv 19Cw== X-Forwarded-Encrypted: i=1; AJvYcCW6+8LI7u7M7WL0nI1z3GawqyCgIR7QoAGAa4lCJ0tOUrZu6VGy+BIltQ8laeSVwtU5ZHVgZjF1Xet2KT0=@vger.kernel.org X-Gm-Message-State: AOJu0YyULVZl3lwVu5mxuRyWQERdXdYF3uuvm6oVic5vEj3XAuDAD2ua C8rmIJNB+zYQRZXzXLkrG/hG6O6rMbIFaxmoG7YtnE6SlZ0ENQUZ07pa X-Gm-Gg: AY/fxX7QI9Q8SLUjA1bxh1rKSIWIMT+1x1W5CG/BQfliGXNFypRlNR5YzMKcgE04UJT Lu4wVxF/tuU/oveYODwSztxGDhRWd9Ao0JdM0CzjgHVFTzz454L+eM3hYePpM7+z+qBEwbC+K77 tSjcg+md/0jKWYvv18H6wYvruKAFD2XVFV3dSh/IfnpBnUWa2nXQfDdYatVaZumv6/RaQrrUF/q e5XN2fswx3Itu5GqRGPZQf1E83fKes5x1cCvA3RDV5NuzZIoXFpSN8X62RNZhskUYAUSIHShPy4 kd4qQOXuA+c36KapqQYkbV94a/HPd8f/rRsPGioNx4ShWXCS1OWMq8cw8E5iUi+P/N8ICrwGsqa 04jLqxXYQbcAbz/FY3TBui/Wq2HZgb7BldtTRbFocV2wHX3WnrkRD/Tg/YWnJTldKJ1HFUp83hR IbHd2lt8sGQ21JvHJXnhQZDNGJAaCyLPFNo4Dax8Rzg+VcGwz9baxzKyk= X-Google-Smtp-Source: AGHT+IHZBBGt5sKspmgCfNLehnDSWf+0n62iK2Sq8KrVSTfY8+ZnEykfoNZ0znpWjPtd8Ie+jPvN8A== X-Received: by 2002:a05:651c:c8a:b0:378:e097:e16e with SMTP id 38308e7fff4ca-3812167c644mr123565041fa.36.1767340326940; Thu, 01 Jan 2026 23:52:06 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com ([83.245.248.13]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-381224de35bsm107688061fa.7.2026.01.01.23.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jan 2026 23:52:05 -0800 (PST) From: Kari Argillander Date: Fri, 02 Jan 2026 09:51:41 +0200 Subject: [PATCH v2 1/2] rust: pwm: Fix potential memory leak on init error 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: <20260102-pwm-rust-v2-1-2702ce57d571@gmail.com> References: <20260102-pwm-rust-v2-0-2702ce57d571@gmail.com> In-Reply-To: <20260102-pwm-rust-v2-0-2702ce57d571@gmail.com> To: Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-pwm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767340323; l=1349; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=PYqFtCJKewiwotOHkWKODCOViU3vbaITARfsgFWgfPk=; b=89gkDf+zZZ6JvqrUEtN9svv3pRzZGZqV8d1YP6ws29DFXx5WFdB/t4HAng0JNcH5B2TDaXUmu ki/e0mshDXDCcXPSOYqwQprgpqFr4BYKGEpCkPdJqDen4a9Rbhzk70W X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= When initializing a PWM chip using pwmchip_alloc(), the allocated device owns an initial reference that must be released on all error paths. If __pinned_init() were to fail, the allocated pwm_chip would currently leak because the error path returns without calling pwmchip_put(). Fixes: 7b3dce814a15 ("rust: pwm: Add Kconfig and basic data structures") Signed-off-by: Kari Argillander Acked-by: Michal Wilczynski --- rust/kernel/pwm.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index 2dd72a39acb5..4f683158fc08 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -607,7 +607,11 @@ pub fn new<'a>( let drvdata_ptr =3D unsafe { bindings::pwmchip_get_drvdata(c_chip_= ptr) }; =20 // SAFETY: We construct the `T` object in-place in the allocated p= rivate memory. - unsafe { data.__pinned_init(drvdata_ptr.cast())? }; + unsafe { data.__pinned_init(drvdata_ptr.cast()) }.inspect_err(|_| { + // SAFETY: It is safe to call `pwmchip_put()` with a valid poi= nter obtained + // from `pwmchip_alloc()`. We will not use pointer after this. + unsafe { bindings::pwmchip_put(c_chip_ptr) } + })?; =20 // SAFETY: `c_chip_ptr` points to a valid chip. unsafe { --=20 2.43.0