From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F885661 for ; Mon, 1 Dec 2025 10:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764583951; cv=none; b=ruj9XzWV3S6ijGcDC+mFUvpj1p/13CWftqzl7qMlP8IKD8ROR6pVETdx9Ug5g0c6FbUhCxf+MNPzgH05O4BdEDT3R7Hunshk+UExFnxkjtrMVs/CoirKyN8/NU4PnguGBGI1tTqvhlQcQ2/fjlnMyHRqJAlbQU0UWPxRIwIvFxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764583951; c=relaxed/simple; bh=b726nZknlbe9H+/++lomsJdo+2jt+ZOW4mKUjJxRTd0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t0raL6e7DmZ8gy3RH/xXw+vPPMsmEq3ugNvBmosTiuRY01ooUp3zyjl/qCf4yudA/lM+pMFYnbdDuBpvMlLksu7mFIQEsHKHDBn8FETvnkUuUwP94Za8aM2Nf0P/HOk/RdE3idrvvqvn9OrHso180SY61jB/yugD5ky91XvYYwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HeKGAKL/; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HeKGAKL/" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b735400de44so359878566b.0 for ; Mon, 01 Dec 2025 02:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764583948; x=1765188748; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zWRwUejBm9BKXVzUoav9cs2vUob0rmYezsnq2zTgDKI=; b=HeKGAKL/u1tXrpFZanaSDksDnHfmskTg2G0vIU3PqNg+219TmMsveVTqhLQ2QwL4Es thvnTj6LG/dd1oyJtvhm+LD1v+zu3NArCnA9DO73Bw56/xLyh8SrN1k/vUQjBp0VO21M fYVHFil5azHQpQj/d8Gh17oq/ViuyMiYpb+Ekljxve5/5vRsi1UCExa9ErQ5ml2ZHQqY adfqkVY+szwrbOoRQr6Ny7WgKshYXH0/0EZlQ7A2EXn0oCSZvJ6Y9IrcCqDOILs/EhRc ooAzCTdyiRCKBcznrrSLXAsdH+MVUYtRwmYkXK0oICiI2evAtLC/uQfXhke9LFOK+vgl xQag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764583948; x=1765188748; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zWRwUejBm9BKXVzUoav9cs2vUob0rmYezsnq2zTgDKI=; b=gNczzKQuLOfAexiw2v9k/2MsJ04EIinTN17KCPe4kbtn+mPnVvXwPzijW4miJU8lF+ i2acH91k4Qfj+27NHRSMih8GL5aiazhxpbn5/m7MYap4KxklR4EMapWSaIgOKGGfZ6Ui Dw8njcyzLm1e5c7AlK6Hgi9h8lO7cIj3OKUUIT6FRE/k7yosHfCWkJQD3Acdacmy69jI i9fFBFFb4UmThKHl1Fm4jInhdsuwEFeMmcIhH8gpDwoyVRqEkZjiAGjT1NjWMmglesBu hZ1pG5vQ8jl3luJWVNTWvUl2Cmr7WF4/ltwgXFzsYGNvJyDiT8zMddFCydKExHTFL793 N+zw== X-Forwarded-Encrypted: i=1; AJvYcCXRqIjHJ3EF3oNxDoxV1QAmcBtUVnPxPzb7L6jRNgcq+VOX0Ncs9B3U0JJVygsSNJKt13fyTH44V3WuxrU=@vger.kernel.org X-Gm-Message-State: AOJu0YynYwiJnZ98k4RZQllWCqYWVdzmLfy4X8Gfid7252bAxlLOfELb 3C3rfwMbTG8yKwicVz/XWNS3WgDjwwgeiVL1jnPiJ44r+E9d4sVZt5bMiO58GQ2CUtoUFUvhwrW sCJnfIax4oyw62pNTOA== X-Google-Smtp-Source: AGHT+IFXoejl6BlNF4MzrCpuVuIpCdgqw9CGI6wR6ByG6Nhg/Q2M0hoVPH2SzRL1V5qyn/aHMEZ4oktF9KaI67Q= X-Received: from ejcsn19.prod.google.com ([2002:a17:906:6293:b0:b70:bbcd:93e8]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:6a22:b0:b73:8c6e:cf6f with SMTP id a640c23a62f3a-b767170cccemr3988317866b.32.1764583948141; Mon, 01 Dec 2025 02:12:28 -0800 (PST) Date: Mon, 1 Dec 2025 10:12:27 +0000 In-Reply-To: <20251201062516.45495-1-yu.whisper.personal@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251201062516.45495-1-yu.whisper.personal@gmail.com> Message-ID: Subject: Re: [PATCH] rust: num: bounded: add safety comment for Bounded::__new From: Alice Ryhl To: Hsiu Che Yu Cc: Alexandre Courbot , Miguel Ojeda , Yury Norov , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Mon, Dec 01, 2025 at 02:25:16PM +0800, Hsiu Che Yu wrote: > The `__new` constructor only performs a bounds check and stores the > value in the wrapper type. It does not perform any unsafe memory > operations, so it does not need to be marked as `unsafe`. > > Reported-by: Miguel Ojeda > Closes: https://github.com/Rust-for-Linux/linux/issues/1211 > > Signed-off-by: Hsiu Che Yu > --- > rust/kernel/num/bounded.rs | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs > index f870080af8ac..cde1b8ba6880 100644 > --- a/rust/kernel/num/bounded.rs > +++ b/rust/kernel/num/bounded.rs > @@ -284,6 +284,9 @@ impl Bounded > /// > /// The caller remains responsible for checking, either statically or dynamically, that `value` > /// can be represented as a `T` using at most `N` bits. > + /// > + /// **Note**: This function is not marked as `unsafe` because it performs no memory-unsafe > + /// operations itself. I disagree. For the same reasons as str::from_utf8_unchecked, this should also be unsafe. It creates a value that violates invariants, which may be used to trigger UB combined with other safe code. Alice