From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m.foxido.dev (m.foxido.dev [81.177.217.87]) (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 1F4B533B6FE; Fri, 9 Jan 2026 11:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.177.217.87 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767956507; cv=none; b=IIBV0+9U2yfU1lp5nj8bzYFEoykzoYlDL5LE3hdbTHLvcGazOks8sHYlyV7Me0WUp6u8ntAQbAD1cKb+yBcpWIj6yuJIjglKdSU3vboPSr7MBMe24u/bAA6Al8Kqfx3x2QaLCTR2ehOUuGxO9M9UPGywQVD09b8pvQBdHt1p5UM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767956507; c=relaxed/simple; bh=MgdDRhOX289Jvru5sc60n2UQcHf+WqOnCsD6DPlUQfw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pylGT8/GJtFLj3qiIGjXg/5D/Q7kIvvKcU7VRjGgz12L8ue7ZQ7mqWaM77BQTesw63x590dw2w5DeF//hTq9oeu7aOZtoEKrDavo+0D2NUy1eeBX8HX4c0Og62BEKIfXfI3ol+Mr9nq7/7og1GpB2XUekG0+akpg4x4OuFuxd2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=foxido.dev; spf=pass smtp.mailfrom=foxido.dev; dkim=pass (2048-bit key) header.d=foxido.dev header.i=@foxido.dev header.b=pOwUdcUs; dkim=permerror (0-bit key) header.d=foxido.dev header.i=@foxido.dev header.b=z0zefi5V; arc=none smtp.client-ip=81.177.217.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=foxido.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxido.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foxido.dev header.i=@foxido.dev header.b="pOwUdcUs"; dkim=permerror (0-bit key) header.d=foxido.dev header.i=@foxido.dev header.b="z0zefi5V" DKIM-Signature: v=1; a=rsa-sha256; s=202508r; d=foxido.dev; c=relaxed/relaxed; h=From:To:Subject:Date:Message-ID; t=1767956480; bh=gI6MZQ7/iz2bg3zwj8e+wkv 2PcH8IyIJieSl0rYYyFQ=; b=pOwUdcUs6C68jl4kbnH827ZBTPO4EK9IBCcBxcDi5XHh6ZAcau 6RTNgNPNjxLrgpzJvu1JuOX53kYPEO/8TLPhQVUyU3BMBe35tOxKzglVENPg8uhE0ELDHOP++V3 YgDbre9kr8duMrkVdc+czxipK/W4/Loz4EPklX+BK35tl7Gd4aSFfCq51kgOxtOLTP58AxQlxWh iXlHItsuUs9OR5SF+Hl6qtArD0CW/N92FjfyXPd4+9bL/mBpQbr9dUpTpdL1bhMJAw3lJMfv9RR /CPUVSUtaiYjl8m2WcB4EuwwwBXWXfXqxlkpj0titm6xVVCV8juToDbHerr59r9Lb4w==; DKIM-Signature: v=1; a=ed25519-sha256; s=202508e; d=foxido.dev; c=relaxed/relaxed; h=From:To:Subject:Date:Message-ID; t=1767956480; bh=gI6MZQ7/iz2bg3zwj8e+wkv 2PcH8IyIJieSl0rYYyFQ=; b=z0zefi5V/vZmm5UV/oZOBZYDs09wdumVf7FPBpV1oi4SDgQJU9 tAklbcqp3sWqho1v9bNZE9iJx7kpBl22VDBA==; Message-ID: <670cab36-3d32-4769-8a3c-a5d3e1bdd74a@foxido.dev> Date: Fri, 9 Jan 2026 14:01:16 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] rust: add WMI abstractions To: Kari Argillander Cc: "Rafael J. Wysocki" , Len Brown , Miguel Ojeda , Boqun Feng , Gary Guo , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , Armin Wolf , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org, foxido@foxido.dev References: Content-Language: en-US From: Gladyshev Ilya In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/8/26 23:48, Kari Argillander wrote: > On Wed, 7 Jan 2026 at 22:56, Gladyshev Ilya wrote: > > >> +impl DeviceId { >> + /// Constructs new DeviceId from GUID string. >> + pub const fn new(guid: &[u8; bindings::UUID_STRING_LEN as usize]) -> Self { >> + // SAFETY: FFI type is valid to be zero-initialized. >> + let mut inner: bindings::wmi_device_id = unsafe { MaybeUninit::zeroed().assume_init() }; >> + >> + build_assert!(inner.guid_string.len() == bindings::UUID_STRING_LEN as usize + 1); >> + >> + // SAFETY: It's safe to copy UUID_STRING_LEN, because we validated lengths. >> + // Also we leave last byte zeroed, so guid_string is valid C string. >> + unsafe { >> + ::core::ptr::copy_nonoverlapping( >> + guid.as_ptr(), >> + &raw mut inner.guid_string[0], >> + bindings::UUID_STRING_LEN as usize, >> + ); >> + } > > Just use while here so no unsafe is needed at all. Then probably patch > 1/3 is not needed. Overall this operation is still unsafe because we are constructing C string in FFI object. So for me avoiding `unsafe` via less readable (imo) loop will just mask unsafe operation without any real benefits. Ideally this function should receive c string and just validate it's length, but IIRC I had troubles with build-time validation of C string length >> + >> + Self(inner) >> + } >> +}