Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795921721; b=nsqFS2xBrez2QjmY3435iX8cQBzo+TXh2UgloEH4+JCWrXrAmPBff+Q3f8kzXKUbYCd5 nUV2HyQiCH03JsWuxDaqOFkacwmj+NEfzZwIhzxhXcwlFACBd9sz5CFI9I/0BmEmRT/M5 Y9WyO83ksR8vTUTrXoWOlXDJ/zHYJJFoH0M3yNXwruh6EPlwFJfl+rHgmFydz5Z9Nm10p Al+ElbBpVT8ycAc82sbzr5DlGAaJGwmbN37RJn22EeTYgvy3mcbJx6E1m8lRMK0ugyk1V ZtLriE+pkS4v38uYORBX4QBSbHmzfuLtzg9MDIlkkxgAZ/tQnTF6lAeYF4OfkEMGXTQ== 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-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=mOzRJZb2o3DVqB6j8/6xUTXvQdqW8Y0vqY4GVcCndMA1/EmLGlcimqg1ujRC2bNc9JuU OYwN+HscoHeQEuNWa5YTyl1roVZNwA01/fxWHWhjhMawWQdLFNeSc3lvld2HQXf+F4786 ODbdhH+3orDM8gm01RTJTgUMlThlpiIaNsK7fJ7EpZ0dv9Unj0CxMeOIt7Jll6BFrHaFE rvP1JwxLNa5vdC5/sdvFB5Goe55jrwvM+WeDy1ptfrPzDeULPs430oaqDls1eTYZUEyGn 487anLWHVtWqlyx3lrwiw1aCdU2U/H0C8hwhjW+QxpWCOVB8eyfe53u1ekMvNmjJ6pA== 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.44 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (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 CB636606A325 for ; Sun, 29 Nov 2026 03:08:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CB636606A325 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-f44.google.com with SMTP id a92af1059eb24-1b5786e099cso8501127c88.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=pJZ8SAZiQ1dlSZkyfsLTBY4qb7a+rNosa8/nZp1h/XTHXujluUf4u+Y4M04teCL3sf rxvnpp+RveTc02GaAyOANYj8a15fw8HXgaFl4X1NaKdXoDWATy6/J1/TOakJpluaDmxK T0w4Be2+owA4GTtFdCe/SywMydrOfaTQLEFHenh+yhj1Y7of/nl2bh7GOscwa+BDUWrq lAl6UwUI432pP5KxmpgkKfQ9awyT+m1VWyMs+ToD+KETugv74QFCBwYYz0Jvz+d7ueQG 8w2fnD1HHqQk7qCPk/c0keoq9RpOwl+lZNPJFMLw1MVRLppn7/+RRwIu62Ao4TRHM+bH 6kqw== X-Gm-Message-State: APuU4Z+Z3MKv0v0UVwg+dYu7aKqhVN/b927Gt/sNut9XLRRY8RKN6N4h 6hKcnVL0ifsLbnEIx0PBLQ4mgM+DbavCh8UuHK9Gk0wEORU+yDxy9pvf X-Gm-Gg: AZFdTZcnExyU4sEqmUPPV6+kBAEHaygnQrz6OErlxur5gx0ZNf3bFitLyNllAl2uTuZ pU7sborUO0BimSS1jHtkKpCvcEZfEHjtqoqhwhphWptL/jOeq1kHDdUNFzJP34HXYWXgprEXVXN 4xnSCu1dGPEEqmfvtbXkrciPmLraWSVt4VLrQqoIniEPOBicZcCs5m0i4aIHRFZyy/JX5J7gLYy h85fBZ8Us+ZEN/KK+k4C1hIPx3pUCeDU/hiA6NdzAdk2G17FLnoHlKC6im4gXIW7RtEomnGCyH3 BxJCjWQ29AKYJq2Two6m0cbkXztjaozYWpP3G5HGZ1+33e5kA6MH+tv3fK6XsoMfxC/6zPiWLdi gHqJ+BUr9SJSXolCvCt7F3q4vpv8z2hfA3BWPbG7c8Kps9vl9B7EeI3ybFacmbQ8uZtmkfC1Fu3 IcjltfNiF87eQK9o5GVJLbXtkQ8dXGNDGX8LX3g+LGiML5KZ1wRSp2a2yWv1yu25mC8BnsNgKQO 70fgu/qPRCxyU41psyR4GdgDgFFE5LX58hvxivyZvj9c10+S5M5K638ucQJC8qsAztq7SFmNiUM HW+AttEkx2zYPCb27zcIvhMfsw3OXLPYMuCtOymp9Fs+Wuj1BUZvUoT+kRn6ZtROquExomM= 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: linux-kernel@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