From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 078562853EF; Fri, 20 Jun 2025 11:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750418968; cv=none; b=mQDEzhGenSMUo+HZFfkul3KICuo0s+qM3unQ3WnDOUaVF4E6aoYMBwxpm+JXaagFd2KmNorU0ZTqlS1WMxw3Mw94lGXi4D9sPprzpgQc/8QBDn1DwuTyq/26NvRsf9kO3pznt3v1XLRU4B8XYetv0a1MIuTuuEsB30S2L/JOzjk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750418968; c=relaxed/simple; bh=toY/8RlMvZbaSXxFKcYu2G72F3PE0BpQoMJH1XDj3DE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=U1K1UXJixmF4s5ZdEYb3FvlSpMSfiik+zRXTsYpoh8WpVj6jaH/syH6P0gy2Q7Thi+9V8O1gpn7btMEIMHgcD2X2lSZQM3tyYivLw6vaQAr7kPYUN54x40S5iuezIVnN+vlBYCbredDyhk7TQxcEz47LLEjZrgne9ASWavNYVSM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rACp/zYB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rACp/zYB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBC79C4CEED; Fri, 20 Jun 2025 11:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750418967; bh=toY/8RlMvZbaSXxFKcYu2G72F3PE0BpQoMJH1XDj3DE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=rACp/zYBSDuBwdyMyauNMZ+PtNQx4mAX0MagrZFICgxBbzDorvHD3BbX77sBhT4+z YCKWHq0j+0+7Zr5yt7rwmQvq3WFij9ipXbZQbjNjdazhhQgANwugyh0Y+imrI/ov+Z TjDQjEBI9Mib/oZvblQav2X4I56jy6I4qisn4X5YdmcsF/gBpuNGzWhDljGMtJP8Bb WfKA9JqMokqJYELT8W93LE13kleX7tRhc+Io20uMLYH7sXMilpkZT+qVZFmF/89NKy BSRDXanCFJqHjtmhuqOtFFGz0sdptrc9+v0y1dAvwYTpvqLWm30FazxxM7FSfPvmcb V15wQSiEcZpeQ== From: Andreas Hindborg To: "Benno Lossin" Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , "Alice Ryhl" , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Nicolas Schier" , "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v13 2/6] rust: introduce module_param module In-Reply-To: (Benno Lossin's message of "Thu, 19 Jun 2025 14:55:03 +0200") References: <20250612-module-params-v3-v13-0-bc219cd1a3f8@kernel.org> <20250612-module-params-v3-v13-2-bc219cd1a3f8@kernel.org> <87v7or7wiv.fsf@kernel.org> User-Agent: mu4e 1.12.9; emacs 30.1 Date: Fri, 20 Jun 2025 12:31:05 +0200 Message-ID: <87o6ui66xi.fsf@kernel.org> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain "Benno Lossin" writes: > On Thu Jun 19, 2025 at 2:20 PM CEST, Andreas Hindborg wrote: >> "Benno Lossin" writes: >>> On Thu Jun 12, 2025 at 3:40 PM CEST, Andreas Hindborg wrote: [...] >>>> + crate::error::from_result(|| { >>>> + let new_value = T::try_from_param_arg(arg)?; >>>> + >>>> + // SAFETY: By function safety requirements `param` is be valid for reads. >>>> + let old_value = unsafe { (*param).__bindgen_anon_1.arg as *mut T }; >>>> + >>>> + // SAFETY: By function safety requirements, the target of `old_value` is valid for writes >>>> + // and is initialized. >>>> + unsafe { *old_value = new_value }; >>> >>> So if we keep the `ModuleParam: Copy` bound from above, then we don't >>> need to drop the type here (as `Copy` implies `!Drop`). So we could also >>> remove the requirement for initialized memory and use `ptr::write` here >>> instead. Thoughts? >> >> Yes, that is the rationale for the `Copy` bound. What would be the >> benefit of using `ptr::write`? They should be equivalent for `Copy` >> types, right. > > They should be equivalent, but if we drop the requirement that the value > is initialized to begin with, then removing `Copy` will result in UB > here. > >> I was using `ptr::replace`, but Alice suggested the pace expression >> assignment instead, since I was not using the old value. > > That makes sense, but if we also remove the initialized requirement, > then I would prefer `ptr::write`. OK, we can do that. Best regards, Andreas Hindborg