Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp767045lqe; Sun, 7 Apr 2024 02:54:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmYNX+ODIKBjsfXntDHMxsdjKmCv/aquhP4GZQaV9MLIZ8cqo38IZKTVIXqUp9HU244xU3B+6VZst0ALVIFRcHtTXEMy9OrOBpFc9UVw== X-Google-Smtp-Source: AGHT+IGI2fLL+pYZSedasTE1WbmYdaFzSqlH2pbA2vxo9QdwVICXCMbARpSZXIlXdmzAoNwtuqZU X-Received: by 2002:a05:6214:1cc7:b0:699:2028:f573 with SMTP id g7-20020a0562141cc700b006992028f573mr6806122qvd.54.1712483682904; Sun, 07 Apr 2024 02:54:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712483682; cv=pass; d=google.com; s=arc-20160816; b=ksblntUT27ls0V27Uh5Cuwdc7lm1E/PkZjCWwODJ1Qrj4wtQiBNGvEBLWYSwR2YgyJ DNC+oFe9GPI1xj52IzVi7qDBhqnQS58UkKUtu4AYaoxX1mPttLxyfIWr3lm55s/3QIdb j1QsJgizYgvxasZrr0IS7tPp9lOviQ76rjT0xzROdF3WGxOdfS18F5+ylbNvIEnKuhVd vwYLOdKlLGp2QWu7DYaXOGuzgi8+BU8RGAeretN1ZjNvU1LK+GJCeUrUUptA0/OibOCN TFJxIn9CoZ0fyaJuK+ql6kGxRswYixXopNGHgTKnxQpHqQ613xOlbjjSgfkyUU+8PVIJ K17g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=FpPOsxrlm7kGglog0YaejIMtnmrT68wmHt8AAfV1foA=; fh=lO+3lTSuJk3Ih5lt8xfvTVzi8d2qSzEmTikflhdm7zU=; b=h8DgMsb2aqB11l18GEvGiQi8CiSSyR6DKTkYhJSN5J0WNxqbKz/B8Na6GAX/2Yq18n RdgfgVuQJbJ9H/kekHQCdnhwvsyViu35/cHwCdn4Fl00OJ7DaGXslrLFt2rJPP5uRQb2 spwlDhZklt21KzZt6G4bPjf+nshZx8rDnov9kRfkagGzv1OV3gEyDbO98MCNXsHD1eSo jekOAuWpsLZTr58gAek8pJ8WbacIAVtKU7n8lCfDLZGmRFLuzIu4t/SlTQOeSDcM8LWZ 6MoqM/TYfr9C0RN6QoiswEzYjUTmz6qNgBiuiq60UX6RsIziR/ccYvmC4CcLPHaDQ81S pyPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="loS8/9k4"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-134312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p14-20020a0cf68e000000b006915032b1f1si5730898qvn.568.2024.04.07.02.54.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 02:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="loS8/9k4"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-134312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5EF5E1C20BE8 for ; Sun, 7 Apr 2024 09:54:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 597BA1803D; Sun, 7 Apr 2024 09:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="loS8/9k4" Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9B96125D6 for ; Sun, 7 Apr 2024 09:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712483669; cv=none; b=UjN+l3XfVqzdsUIZmEvAYQ8luUfOpPVsJ19YEUY7CWVlr4jQyzVsUzSevI80znrtUreEdTpTD/BoNyjBpbBeWnY4yoEKLgdDn5ZrB5D8TNnh4yhmPk4rGWHtkT8SCxz0BUukh1xxKwNET/16kTMjNtTKBGc0do7g101JkydbRIA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712483669; c=relaxed/simple; bh=i8Pf56totbaL2ToXcQKolVxiIZ/TpmMBAZ0t/LCkK3w=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rhonBt7I33DAy3G2CIYqRWZqLmalo0Efb8Fbms11oUw0ShCQrxIQbkl0PX0wGyu2dKkyo3DzVd9zlzAnFoQZSd6tRSSUQ/LcjARqTboBS3+9DgQpZOzdSLJBiFa3ObWu53aaRNER8tJygYStqC5TU5DyeDShvQsOwv2VOijLybA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=loS8/9k4; arc=none smtp.client-ip=185.70.40.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712483664; x=1712742864; bh=FpPOsxrlm7kGglog0YaejIMtnmrT68wmHt8AAfV1foA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=loS8/9k4aV1FTA3BHgGAukGuWqqeBVljBwDIWzkAUljm/0zq6hSqJ8lBwn2P5rfB7 7hgv5H2yThaIDK4kSj+MbPpjK7d++cHJcljgs/mFixr8gzLtHjkP/88V2kHVawH6js 7P3nOU6SklxAWyFecLxPypNogf82q7zCbK7g2raSQfhM4Ov7Py6moiNoNxkxRwWR2e MmkVjKt1ESsQQMsKZEFCIQwNNeUCgVQLjaUEB7KskCCP5DUYbizydYKDirxFuoNagl v4xhZwOUDNXemN2PNDfDaWK9UrfSplCR2bBZk8bxfFt5paquQALAo39ev4FS7oslvb tv2kLnKfdTylg== Date: Sun, 07 Apr 2024 09:54:19 +0000 To: Viresh Kumar , "Rafael J. Wysocki" , Miguel Ojeda , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl From: Benno Lossin Cc: linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , rust-for-linux@vger.kernel.org, Manos Pitsidianakis , Erik Schilling , =?utf-8?Q?Alex_Benn=C3=A9e?= , Joakim Bech , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/3] rust: Add bindings for OPP framework Message-ID: In-Reply-To: <06bb914eae00671a69b393bf86bb01ddec86c16f.1712314032.git.viresh.kumar@linaro.org> References: <06bb914eae00671a69b393bf86bb01ddec86c16f.1712314032.git.viresh.kumar@linaro.org> Feedback-ID: 71780778:user:proton 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 Hi, I took a quick look and left some comments from the Rust side of view. On 05.04.24 13:09, Viresh Kumar wrote: > +/// Equivalent to `struct dev_pm_opp_config` in the C Code. > +pub struct Config { > + token: Option, > + clk_names: Option>>, Why are you using `Pin>`? The vector may reallocate the backing storage at any point in time. > + prop_name: Option>, > + regulator_names: Option>>, > + genpd_names: Option>>, > + supported_hw: Option>>, > + required_devs: Option>>, > + _data: PhantomData, > +} [...] > + /// Sets the configuration with the OPP core. > + pub fn set(&mut self, dev: &Device) -> Result<()> { > + // Already configured. > + if self.token.is_some() { Why does the config hold onto this token? Would it make sense to consume the config and return a `Handle` or `Token` abstraction? Then you don't need to check if the config has been "used" before. > + return Err(EBUSY); > + } > + > + let (_clk_list, clk_names) =3D match &self.clk_names { > + Some(x) =3D> { > + let list =3D to_c_str_array(x)?; > + let ptr =3D list.as_ptr(); > + (Some(list), ptr) > + } > + None =3D> (None, ptr::null()), > + }; [...] > +/// Operating performance point (OPP). > +/// > +/// # Invariants > +/// > +/// `ptr` is valid, non-null, and has a non-zero reference count. One of= the references is owned by > +/// `self`, and will be decremented when `self` is dropped. > +#[repr(transparent)] > +pub struct OPP(*mut bindings::dev_pm_opp); I think you should use the `ARef` pattern instead: #[repr(transparent)] pub struct OPP(Opaque); unsafe impl AlwaysRefCounted for OPP { // ... } Then you can use `ARef` everywhere you use `OPP` currently. --=20 Cheers, Benno