mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] rust: opp: clone cpumask before adding OF table in from_of_cpumask()
@ 2026-11-30 13:17 Bilal Hashim
  2026-12-03 10:09 ` Viresh Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Bilal Hashim @ 2026-11-30 13:17 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J. Wysocki
  Cc: Zhongqiu Han, Miguel Ojeda, Alice Ryhl, linux-pm, rust-for-linux,
	linux-kernel

In Table::from_of_cpumask(), CpumaskVar::try_clone(cpumask) is currently
called after bindings::dev_pm_opp_of_cpumask_add_table() succeeds. If
the cpumask allocation fails, Table is dropped before table.cpus is set,
so Drop does not call dev_pm_opp_of_cpumask_remove_table() and the
C-side cpumask OPP table is leaked.

Clone the cpumask before calling dev_pm_opp_of_cpumask_add_table() so
that an allocation failure returns cleanly without leaking the OPP
table.

Fixes: d52c7e868fbc ("rust: opp: Add abstractions for the OPP table")
Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
Changes in v2:
- Drop the unreachable Self::from_dev() error rollback hunks in
  Table::from_of() and Table::from_of_cpumask() and keep only the
  CpumaskVar::try_clone() move (thanks to Zhongqiu Han).
- Update commit message and add Fixes: tag.
---
 rust/kernel/opp.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
index 62e4467..1236ce3 100644
--- a/rust/kernel/opp.rs
+++ b/rust/kernel/opp.rs
@@ -687,6 +687,8 @@ impl Table {
     /// entries.
     #[cfg(CONFIG_OF)]
     pub fn from_of_cpumask(dev: &Device, cpumask: &mut Cpumask) -> Result<Self> {
+        let cpus = CpumaskVar::try_clone(cpumask)?;
+
         // SAFETY: The cpumask is valid and the returned pointer will be owned by the [`Table`]
         // instance.
         //
@@ -696,7 +698,7 @@ impl Table {
 
         // Fetch the newly created table.
         let mut table = Self::from_dev(dev)?;
-        table.cpus = Some(CpumaskVar::try_clone(cpumask)?);
+        table.cpus = Some(cpus);
 
         Ok(table)
     }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] rust: opp: clone cpumask before adding OF table in from_of_cpumask()
  2026-11-30 13:17 [PATCH v2] rust: opp: clone cpumask before adding OF table in from_of_cpumask() Bilal Hashim
@ 2026-12-03 10:09 ` Viresh Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2026-12-03 10:09 UTC (permalink / raw)
  To: Bilal Hashim
  Cc: Rafael J. Wysocki, Zhongqiu Han, Miguel Ojeda, Alice Ryhl,
	linux-pm, rust-for-linux, linux-kernel

On 30-11-26, 21:17, Bilal Hashim wrote:
> In Table::from_of_cpumask(), CpumaskVar::try_clone(cpumask) is currently
> called after bindings::dev_pm_opp_of_cpumask_add_table() succeeds. If
> the cpumask allocation fails, Table is dropped before table.cpus is set,
> so Drop does not call dev_pm_opp_of_cpumask_remove_table() and the
> C-side cpumask OPP table is leaked.
> 
> Clone the cpumask before calling dev_pm_opp_of_cpumask_add_table() so
> that an allocation failure returns cleanly without leaking the OPP
> table.
> 
> Fixes: d52c7e868fbc ("rust: opp: Add abstractions for the OPP table")
> Signed-off-by: Bilal Hashim <AeeSec@126.com>
> ---
> Changes in v2:
> - Drop the unreachable Self::from_dev() error rollback hunks in
>   Table::from_of() and Table::from_of_cpumask() and keep only the
>   CpumaskVar::try_clone() move (thanks to Zhongqiu Han).
> - Update commit message and add Fixes: tag.
> ---
>  rust/kernel/opp.rs | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 10:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 13:17 [PATCH v2] rust: opp: clone cpumask before adding OF table in from_of_cpumask() Bilal Hashim
2026-12-03 10:09 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®