From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 2D7033EDACC for ; Thu, 9 Jul 2026 09:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783587844; cv=none; b=M/apdp8qVIdQK87EMjnaO+uKauFtsdQGlmNPQ+ogoFeV+D2vsKrZSADfXzC4SAGtiVzPSYFExmg1MCqX6WalDEBqfUdCry8YCf0u3bgWIHIbSbBLHaknq4X/QFhte/XYr8CfQvWgPTsLpgKrfAfO0/N3c967wiXih8NcOoeocbA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783587844; c=relaxed/simple; bh=8p1SlX4Y/tAMtxoktfOY4hYUbJ5KdrvxJ/hf35CLJIY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GO2Eeo5QBe5g5AqRXMnEiqTFj5xH1QRoauoe4E5MmEqnIZ7PQB3F2fc9V5GuS4zlSd5mYHuvDLD7M4TTTX/M4vlIK4r0N8fMc9wP2AChx7bVcaylT6ctalrx+37xVwfF1CYTQjfYLcipBSTOtQIL7n4Yl/d2qz8Ih8L1SCd0+mY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Fsv8Gy4b; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Fsv8Gy4b" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-492488f8583so7677565e9.2 for ; Thu, 09 Jul 2026 02:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783587841; x=1784192641; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UHb/QYDUeRjEZWmoAxhxicuHQ83r8Iogoxy5g/5DRs8=; b=Fsv8Gy4b/uP/7OacJuAO8xISx0jXUEg9vqT2NfRIUK4eQfkMomnF/WR4TG6U2Eh/nI Rkq2lDbFHEY0j6EBq3C1aeu7dSyvNOgJuYho8Wh1pPRIBbAQ/T+rKwdjDm8SW+wXdA+L WbDIdVpEftjedvDY9DDuUsAXNfTClQsHJZDnh5HKAVYHTc1UE4ZcYIJ+UG5/vxaEqBSA E8p8u297W1/KoEYUoJHdVmSMF6aNOvFvUNDsmAYttuirgcE57pnXN7fkMXiCls4wTvHF nHO0HCQGbaYST5NcRFHNbtlfhOpuWMCrZmtdvKoRges7M/2SwzIu/ZHsXCzUPxZZBh89 h+Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783587841; x=1784192641; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UHb/QYDUeRjEZWmoAxhxicuHQ83r8Iogoxy5g/5DRs8=; b=ocxlDjVZxs/9HT9OUp6+y+Q3cXHUL2ubZexwOsEYs/J1s6MEpaYfd6LE920N+q6CyQ Jys+8W5PKbFpmTd6KO6NflmHZ8PO8L6Top672NgD5TfM1fIhDcZFHQ+1zcbT7PuNw1/M 5D3yUmnH6AfC2JY3Zllnqy3JPeY262JsO7XGO/QMaYhJGkS095qbw0Hkn8TtjRcNGvV5 pn6fvgo1dld/kfS0l0uHhWnkU3+a+ndrbh896Fiy4ekV/yD1Cn/wjiekWa8yAUk8e7U/ qWycHs/mmKEncZDNCEYLV860tU0RyC+xfHz9uv6zoBPSc4UWoftITjLTvKfmh/xYsLwD vtSQ== X-Forwarded-Encrypted: i=1; AHgh+RqjKAnVgB6coXIMXnKPhosn5O85PtXsw5TZy96iuLzbTkFoRoONz8is6nP3v6/ax3ebNYrTXb6LxjT0gAw=@vger.kernel.org X-Gm-Message-State: AOJu0YzhvcL2lMhwNRKTSOpgak74fdhESpmzrKAVzznJYrelfnKyKy8Q W9WnWc9mgV8fFKRq64Kn4vKc5cgSIgNjAgkAQi+NCvPB5QPifgzPB4LuiGcxfh/qDUVgcQmXSC8 QSi/NyOHyDMJvSYhixg== X-Received: from wmer22.prod.google.com ([2002:a05:600c:4356:b0:493:bea4:1b1f]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3e8e:b0:493:d26b:1575 with SMTP id 5b1f17b1804b1-493e69b0dbdmr59666475e9.27.1783587841386; Thu, 09 Jul 2026 02:04:01 -0700 (PDT) Date: Thu, 9 Jul 2026 09:04:00 +0000 In-Reply-To: <20260708214738.25008-3-brucer42@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260708214738.25008-1-brucer42@gmail.com> <20260708214738.25008-3-brucer42@gmail.com> Message-ID: Subject: Re: [RFC PATCH 2/3] rust: power_supply: add power supply class abstraction From: Alice Ryhl To: Bruce Robertson Cc: rust-for-linux@vger.kernel.org, linux-pm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel , Miguel Ojeda , Igor Korotin , Gary Guo , Tamir Duberstein , Boqun Feng Content-Type: text/plain; charset="utf-8" On Wed, Jul 08, 2026 at 09:47:37PM +0000, Bruce Robertson wrote: > There is no Rust abstraction for the power supply class in mainline or > rust-next. Add a minimal one: > > - a Driver trait carrying the supply's name, type and property list, > plus a get_property() method; > - a generic extern "C" trampoline the power supply core calls back > into, recovering the driver's private data via the parent device and > dispatching to get_property(); > - a Registration that owns the power_supply_desc and unregisters the > supply on drop, freeing the descriptor in the correct order. > > Property, type and status constants are re-exported so drivers need not > reach into the generated bindings directly. > > Signed-off-by: Bruce Robertson > +impl Drop for Registration { > + fn drop(&mut self) { > + // SAFETY: `psy` came from a successful `power_supply_register` and has not been > + // unregistered. `power_supply_unregister` blocks until no callback is running; > + // `_desc` (dropped immediately after) is then no longer referenced by the core. > + unsafe { bindings::power_supply_unregister(self.psy) }; > + } > +} > + > +/// Register a power supply backed by driver `T` against `dev`. > +pub fn register(dev: &Device) -> Result { Should this be &Device? > + let mut desc = KBox::new(bindings::power_supply_desc::default(), GFP_KERNEL)?; > + desc.name = T::NAME.as_char_ptr(); > + desc.type_ = T::TYPE; > + desc.properties = T::PROPERTIES.as_ptr(); > + desc.num_properties = T::PROPERTIES.len(); > + desc.get_property = Some(get_property_trampoline::); > + > + // Stable heap address; moving the KBox into `Registration` keeps this valid > + // (moving a KBox moves the pointer, not the heap allocation). > + let desc_ptr: *const bindings::power_supply_desc = &*desc; > + > + let cfg = bindings::power_supply_config { > + drv_data: dev.as_raw().cast::(), > + ..Default::default() > + }; > + > + // SAFETY: `dev` valid; `desc_ptr` points into `desc`, kept alive in the returned > + // `Registration` and freed only after `power_supply_unregister`; `cfg` valid for the call. > + let psy = unsafe { bindings::power_supply_register(dev.as_raw(), desc_ptr, &cfg) }; > + let psy = from_err_ptr(psy)?; > + > + Ok(Registration { psy, _desc: desc }) > +} This looks like it should be a ::new() method on Registration instead? I would compare with existing Registration abstractions and mirror how they do it. Alice