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 3E6BB8494; Thu, 10 Jul 2025 14:46:17 +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=1752158778; cv=none; b=TufyShAV02Ua7pURE+OcrdcBTsbVxcl2EHCs2Os4uhQOvOZdbJ1MYwwfTY+/GMosXq2Q69RQBa7v/LV9XlUcpmBORdzPus4/7v2T+mgMNW3nGYybF+KuJCjdlotCVHDpl8IbETLU2FUf/j29kgHpbPpo1sqwJ5bQ7eGQREyft08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752158778; c=relaxed/simple; bh=brhr14jY/gN0Lk6V2R7qKb/J2aIEWY8RBJhBb19zIuQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pt7eor07K5T0w7Nu1kSxBEhlU3n4FGyubBpiYhMC/N+q6WrYMM7kX55PKcjYuLaYRoitJ78eNDISR0AUYAcc20ihRkg+X8sPWpoULcA2gS3nUkDk/6sSef1aC93HypO/PNDfFi0LDKObIsu+5tXtK1piloE2sn3OIeSPpq1iaKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JRIDZqHe; 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="JRIDZqHe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6B9CC4CEE3; Thu, 10 Jul 2025 14:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752158777; bh=brhr14jY/gN0Lk6V2R7qKb/J2aIEWY8RBJhBb19zIuQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=JRIDZqHeeaMXqfsYZtBekh/YtBJmJ7IsdZ+AzfClQuk+TlLMZWRCICqMBg89nh7BC 1i4sx4Y4n2Gb2tXuSPhijmFTotDfp5y7LK1aaRx3I8Mq7CCo2gGLuqWAhnvDgpsi9e onGiylNArc14s2pb7PafYjN30x1VIxcmOZqJwWUdSaefz7KsYeSNCGYnGNHYB/mP7Z jnsAeUHB9TW0AcypF5HpR6F0k+dZnf9hys+VNptHtnbQibL51bh9HHaVsZAo+pwkqM 6gH+3kcUMtjih1hxdoQ+Ori1ZzBIbDBjMj2MsyCHa1UpXkesW1+k8H6wjczcmoQIlM kcXpI2Gu2opyg== Message-ID: Date: Thu, 10 Jul 2025 16:46:11 +0200 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/4] rust: i2c: add basic I2C device and driver abstractions To: Igor Korotin Cc: Miguel Ojeda , Alex Gaynor , Wolfram Sang , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Greg Kroah-Hartman , Viresh Kumar , Asahi Lina , Wedson Almeida Filho , Alex Hung , Tamir Duberstein , Xiangfei Ding , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-i2c@vger.kernel.org References: <20250704153332.1193214-1-igor.korotin.linux@gmail.com> <20250704153657.1195687-1-igor.korotin.linux@gmail.com> From: Danilo Krummrich Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/10/25 4:04 PM, Igor Korotin wrote: > On 7/4/25 21:16, Danilo Krummrich wrote: >>> + >>> + 0 >>> + } >>> + >>> + extern "C" fn remove_callback(pdev: *mut bindings::i2c_client) { >>> + // SAFETY: `pdev` is a valid pointer to a `struct i2c_client`. >>> + let ptr = unsafe { bindings::i2c_get_clientdata(pdev) }.cast(); >>> + >>> + // SAFETY: `remove_callback` is only ever called after a successful call to >>> + // `probe_callback`, hence it's guaranteed that `ptr` points to a valid and initialized >>> + // `KBox` pointer created through `KBox::into_foreign`. >>> + let _ = unsafe { KBox::::from_foreign(ptr) }; >> >> I like to do that as well, but I usually get asked to use drop() instead, let's >> do that here as well. :) >> > > Danilo, could you, please, explain this one a little bit more? I see the > same pattern for all the implemented subsystems so far: auxiliary, > platform, pci. > If this pattern for these subsystems is to be changed, then I'm fine. Yes, this is because I wrote those and wasn't caught not using drop(), but `let _ = ...` instead. :) It was already changed by [1], which you want to rebase onto, the changes are in driver-core-next. [1] https://lore.kernel.org/r/20250621195118.124245-8-dakr@kernel.org