From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795921721; b=tqcLQ4Ob4Q+DEYQavZXAehIW7GjAVgr0qAArgo2MrPxWUwIyAv0cIejJ5KnJDV6HHvS7 qWwJYShli6ITUV5P8EspuIKfWFZ7MSwp8QXCGwS9OftZIdXBlBt6cXIRt3iFLRgOCMtUt V77W8arvjAVIa6fxWtTxUn/Vh7XVKa2n2J0MgLPyPPcubMZbsQz8lULt2813bTD9Tbioc GsXnkm6ZrFk1vzIA/pKPeem60M+rvnHwZ+tR/g91f4mw3QaryWAqdoP6PXVrwfvAdqyx8 2q74UJsVMi8ZN+kQwWfyJijW5mmbmKtyhgp0jyrIAdKNFS3+lk/v7068B9uWUFHfcCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795921721; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id: To:Cc:Subject:From:X-Mailer:References:In-Reply-To; bh=nts57ja+akcxl/LRN10e02WA6w6YV6uHmI48hzpJJPY=; b=V407/CGZLzndMdAJxvpgydi5EGqkpPQz6azMyYEWAAfg/1crm/L4aEVZl3u1+pZfh4mw XeC+0FJzJACESXJxgAOgTtMt0SF7DwWjocIvIBXG/Lm2vQUtLQpcXBRZOf/eK2Os5V0aJ NkGF5auPt02u4ji/XEZerS5I+FMAElbvk5VEgjI338HDAnYULt6jnINm92hllIOMbHHDf Tv70ZB/YTJJhn4dL262SvFK/FJGySr4/LcVfF4hhaBx3mpKgAX5APMLds7HUy8t09XAk7 WiZnynM9tvq0mWxMFZsnTfBaGzUs4eKWH6rgp/PT1B+MhjsKb4fO4s0vZkbVU42gDxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vvii7wkm; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D253F606A327 for ; Sun, 29 Nov 2026 03:08:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D253F606A327 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.a=rsa-sha256 header.s=20260707 header.b=vvii7wkm Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1b5786e099cso8501137c88.0 for ; Sat, 28 Nov 2026 19:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795921720; x=1796526520; darn=vger.kernel.org; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=nts57ja+akcxl/LRN10e02WA6w6YV6uHmI48hzpJJPY=; b=vvii7wkm1JKrFLKQk9up9bnGtemoEDOU5+/bzKhbS1OIH58Pz0i9i6oZVWuHB4dtGD TsyXOpZ9jzNt7NpQf2v8TQPb9bYlSDBTmpk0O7GwYioERqdpF55oz4r8CVvYYIA77tmW 18cDReugujXu7mV3pVdekYtS/tzMnu1MevEBiB7Sw3GvvbzLDV5JNp09UGCKYN7jbvwe Hs2MlWuV4c/WRTvcevEixKyPA6vtTlZ9ob4ZmyY0+m9JvltK6Nkb2tkZyGEH0ZyFmIgX TbUDBAjSI7aW5YQCcG7ZytjRPZQfq8x+CiyDxeoTJIlpkFN/41EGte3EK4qISlhF8y5m bw+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795921720; x=1796526520; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nts57ja+akcxl/LRN10e02WA6w6YV6uHmI48hzpJJPY=; b=lGHQWsj9v//vTuWKuJw9L3SnjYWuTP85gyY6Q50h0G4cYw+SkDjGcX0OAQfeFkJ2mx KnomSq9+CgzKEbjS9M/G9UmN3uAvYEFcPj5BT0UHD2oHSdiCZ7skxqiu48anKjERK45G rkAiwSEY3DAQFKDJNyYvArEi9b/38xKONszKkXyXS9qf91+C+f+lCFIgjl+pE9LI0XhC ZJ0mtl4rFAnY1LjHCwiqA7KXanNDYUXZcfTCv2TyCXWZ8AA77gIlaMseVA/UrnL1Rixr ms8QNJpbQBPjIWREydgoBbQohTa2MAI/QSOW1QFDCHskYDUzNGOeRATZY30gzYqWs5ST v2ZQ== X-Forwarded-Encrypted: i=1; AL+hErEpWMsNUahH3X/nYv0gzLwv9OPjCA+fPCrpsHegvVgbx+kiB0PLs9KLbX1qQJxeZK4lFB+xDQ3PSQThfZyQ5Q==@vger.kernel.org X-Gm-Message-State: APuU4Z8nFZT93Oz/UoR9lMqx4S6zcmyUdvans5ejy3O9P+HxPwtYbqau J5MJijM59Wgi9hgwZH/ErUIXFJgNEFceEBYdVGzqiOdTolAA0I0W7WXV X-Gm-Gg: AZFdTZdfZ5d05cGAiQRXwu60UTZUUTgUr/tP3SCEoKfe7JbBlK1aVgU5ENMYScBFMiG 5yr1MLupDT1Zs7+gF8NKPyq4NwO9G9qJiLuPXSVNlZA3F5ggycRdLOyckiRl7WdbY8aW6dtrixO 2YLRT6QO6hwQJA02KNo8sWNZ7T0Wro73Ajnr4k9FWcPNmeA8/pQ5Cf4d6Sgco4nH+VOmrP3QSaj b5ZotucSB45fEVEPv8z0MK97amY+RUCtBMHjNjQjXRd3x81r8bMtFYOAExtWcvuSI1C5hy6EHlr pPTJIgfIpkd3m+89LnedHUebKHBsXm91meYTnqIklvtfZQNKhp36mdIy4P7KdN7EtevZGpWoHTW jb8r/kMM+OPDGZ6nFfF7SDBJqp6ZMJGFvyWtRHgoW+UukD/tGslsYQj7iK9LK9UK247mByFyOa7 2vGQFW4+wZxiZU9pX030VDMhhKPtUk5BjRqR8WW9SLiiXfWTCHj5E0ZJedtK+9w1z4VXiACB7Dc mkpIjDhZgf7Po3PFRScVJOTVVOQ2Py2hdU2Z1jq80jVj2wGqlhB7Bn4RKQEdoXRPFCP6VZgDE8X MofUXbAOs9hiAFQLeMxXbrLocRsAXXp5X+1yd4ZInP4W/4IxQML+KsYTPcTt1EcvTwOK7UA= X-Received: by 2002:a05:701b:4541:20b0:1b5:6e71:3f0b with SMTP id a92af1059eb24-1b56e713f86mr20065403c88.18.1795921719760; Sat, 28 Nov 2026 19:08:39 -0800 (PST) Received: from localhost (61-245-143-184.3df58f.per.nbn.aussiebb.net. [61.245.143.184]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55681301asm67749052c88.8.2026.11.28.19.08.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Nov 2026 19:08:39 -0800 (PST) X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 29 Nov 2026 11:08:31 +0800 Message-Id: To: "Armin Wolf" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?q?Onur_=C3=96zkan?= Cc: , , Subject: Re: [PATCH v2 4/4] rust: wmi: add Buffer and Device::invoke_method() From: "Nick Dowsett" X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261127-rust-wmi-v2-0-5bfafabd6a6e@gmail.com> <20261127-rust-wmi-v2-4-5bfafabd6a6e@gmail.com> In-Reply-To: Hi Armin, >> +impl Deref for Buffer { >> + type Target =3D [u8]; >> + #[inline] >> + fn deref(&self) -> &[u8] { >> + if self.0.length =3D=3D 0 { >> + return &[]; >> + } > > Hi, > > this might not be necessary, because an empty WMI buffer from the subsyst= em will > never contain NULL for .data, instead said field will be set to ZERO_SIZE= _PTR. Good to know - thanks! Would you be open to me adding a doc comment in C as part of this series to reflect this - or is it kind of implied already? I'm not super experienced in C. >> +impl Drop for Buffer { >> + #[inline] >> + fn drop(&mut self) { >> + // SAFETY: By the type invariant, `self.0.data` is exclusively = owned and >> + // freeable with `kfree()`. >> + unsafe { bindings::kfree(self.0.data) }; >> + } > > This is wrong for WMI buffers used as input for wmidev_invoke_method(), b= ecause the data > might be statically allocated. I suggest that you keep struct wmi_buffer = internal and > instead return a KBox<[u8]> from invoke_method(). > > IMHO struct wmi_buffer only exists because C does not define a standard s= lice type, > so there is no reason for exposing struct wmi_buffer as a separate public= rust type. > > Thanks, > Armin Wolf Note that the Rust implementation of `invoke_method()` actually takes a Rus= t byte slice as input and converts it to a `struct wmi_buffer` internally, so the `wmi::Buffer` type here was just to be used for the allocated return type case. It was my initial thinking to use KBox here, but some warnings from an LLM steered me away from this. From my own research, for regular Rust Box types it can be a bit of a safety minefield to convert from C types (see https://doc.rust-lang.org/std/boxed/index.html#memory-layout) and I am unsure if KBox is in the same boat. I also couldn't see anywhere else in th= e kernel where we construct a KBox from a C type either. So my preference for now is to keep this unless someone from R4L is able to advise otherwise= . If the naming is confusing because wmi_buffer is also used as input on C side - would you prefer this to be named BufferOwned? I agree that looked to be your intent so it would be very nice to return KBox in future if possible! I was a bit surpised there isn't a generic C slice type in the kernel btw and wmi has needed to define it itself. Cheers Nick