From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795921721; b=0O28kolKv50idTmVeMo3b0FbScXkcIboO7ctBpixedlZrQnNfcxF3FYsRj67JXHddGHM WTczIq51V7D8Ai6JK6baDHsqxztN4WoFtgLFQh9x37oT/c//gUDmlHB51MIcf9gXcztuU NEmvqrYqpLCWROZJ7VGtsCtKzFAjVLl4IO7wc41HqKzPFvEpyBXH4Ue+1LzMz3lovINHk ZAC/Po2bf7SxyrU01+DTtE81mNIVHp+f/uEei47ZUJcsRT9EpzT/6UT+ukvHGdTmpWWvU 5hwHZY80cUEyTL6sztvxHOFXfQS8mfrVps5PpU8NOGZo0v9kVXO80eBKOLUL9G7u0zA== 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=5QAoJ3csYdz0I76Ej8IMXR5U95Bm5qt3cUVB+IVEohvDRflK/zOnscOt2oi1GjDFHwgh DrHkNSgrlsOAdMjF7zxoICAVSVeVC5QqN084ZjlK+HrZ9C0weJD31+8bT1HcK/F92hLCN aaIajIlyDJMaHwIW0oMGuGSca/XLnBmdnytsx7v4A34XoNbIUR3g6fRMBEwVN5oQ2X8Zk iy5pFiMQJprDkgJoc00DVJHCw70c9dDbivOF8ddmybOZXPgrNtcls6S+XK1Dlm0uakxV9 MYX/w9SGx/dcFXxhvLoZwT0Be+mG0f4Hvtj+PAO6pbRRUN5bO3g++r4vUqZ0caMBIxw== 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.50 Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50]) (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 D1243606A326 for ; Sun, 29 Nov 2026 03:08:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1243606A326 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-f50.google.com with SMTP id a92af1059eb24-1b563e32936so4967940c88.1 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=xQmvHw8rkh7nqjC/K7mSMoC7Y3Mbhk8gC9fpIel2aTuc/cXnpSpmiZ2i/5I+HFQxcR 0iA6rQyx365e1i9gGAMjc+ETHVaZ404OmtHL/m7OdskAMEkDEmZlyFI9nS9xV/s4qDWe hLWpeC1zfuxnqtysDiXkoPE5RQKdtq6nfWCvj7Uh/+GLBoXG4HKqHK5ErmVmQtuPh2AK fsowLDd7TDq/6SzVxzvcM5UL4Rl/zl70IhjPsKAyeJM+6E/zoj3Y4o/kXMtkT/Ik1sAC y7K0bSo11StTDuMuUgNle+AaHoVlZ01V0iaKC8UGEo24wsRdz+WYvvz1p/7sLNUrwBKi USrg== X-Forwarded-Encrypted: i=1; AL+hErFwDfuBVvpyYkk6tMjaz5Yxf2Mh7oJFlqkNQpDaw4ZGUmEHxWGMXkki6IcxBKyIoMZOHtppCK3O/Ft/uNxyU4FFv9gl@vger.kernel.org X-Gm-Message-State: APuU4Z8fj/lgf82ueO6Tln/NT9xIVB90Mcwe5NcSMbOB612kcRS9cx/W H9r0/9DcNt6J2+6zTpyRlchHcOZiUtw/cet8dyC6jqUKHA54cWvnqkdg X-Gm-Gg: AZFdTZfTkKCx2DSt3W+your+EwD3aWhop8yFiBGdLb7/nqe0wbrbeRtgln4tsBXGh+K 0m8mB15MiLsAtNBWH5NbWTPznNYEhdgijVmr8RPUBaf93+gTdud5jof3UNfaVAQAR7gRijHE33f aOzl0Qd5GyuxEMHdSdzSVNCfX6LTtCwaJ2qEqo/1jH8cHxc4/lNUuSaaZ1foPMBWWF31ls+U1rm 6Xg6Sjbs4WxvCB4DrESzqhShTEfL2KLx6lfEVjJNKlwoJZs2WlRyEeqTQaw8Ifjs+tNQeJEQ5ky XNvjPDxCffgDxYy7o/vhkgNTQCRdMtUL3IuCBbA+qS+A2Vw00K6mdoDaHpFdRY36QtMQzr8PjMO mtJsnUwKLSdcrVo+XwzNPE2b4otE5/0OsG4gLHzK/40MRmOtcVXQhTDvSldynUJRCr9mKKho/+b LURNLFj+Eisnrx8vQt9rgxlsmjrVWk+j2fW5AAsYkphi5PQCP6gH1SOzLt2ohZOobgWwYZ518KF Mu6yz2EYrG1tx+fJsp6EsXEhFvtjTi8zDVfE38yYIIWncvxMw5q9gH0cCEV7NJA2sAtjyWe9cze +djfhhvf+uWKGLP84CZu7+03+aD7CSUCn4hdMAp3sSY//2sYjzukPlrX4RJWpvllHs6ob6U= 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: platform-driver-x86@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