From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.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 41E18302174 for ; Fri, 28 Nov 2025 09:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764322137; cv=none; b=FvsuqNK5voj7E+FrmbGFE2Wlx8b836OKo0H4lMIJMDt+5N+dBy8y+vDhumy4pHnpJshjSdC5qg6ubePVMKDbFWQz36qxRDEWgt4kK7Ird9bj47IrXx/jHsdEe3GZvAcX/CJx7OZaFmTO26+01h8ED4dL5WwZbj9JgK7YghtEvCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764322137; c=relaxed/simple; bh=BNgX/Kl8aLf31K9BhcMuloUt4smhu1Y8uRALWghyYMg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dRQs+9dH6U8lbvkEGGv2WYcUFxHVp4jwYm4HkmGV+xew4M4v7dkIv+KeWB0NAGpxAPXxVB37uf+Cniw/TcBriJB1g8/6I07n1d24jTtveP4Fgb6drKFFZo5xszRcSpIJuBcmVe6X/CBmt8GhXvJQUETIAHlxwtA5W8/EBMWi1sc= 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=CAEtnk/y; arc=none smtp.client-ip=209.85.221.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="CAEtnk/y" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-42b2f79759bso1108899f8f.2 for ; Fri, 28 Nov 2025 01:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764322133; x=1764926933; 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=BfB1+1n54EtAaQ0p4axZ7CMqQap0WXeaVLrFGnbDa00=; b=CAEtnk/ytGh0kBP0w896f3dUu6aG0CqQUaJSzhrrRvsZhvVcpiQNJtc6vn3RSkhToX 2+ZIP92Ku54QAlWaI0LqS6eyIVI8M5C8Ob5Yl2huGzUVlXa9RoplgWq6nQ2TyX5/Wcta pfzcnFMW5bTFCJh1usjPXruk2BBUHf94oeSJarGQNf7NO7LWYlKBO13QtfrsqgNc/f0t EMBU25viQ2EEceGU/B1zpU0RGLswU03LLPwFc2BKXpRMCNNmh+oMTdDjz9xj1zqwF7GO JeYRZzqKNGP/rIRchzIki6aHnMIYfHZZQLwJmNcsBjfk+DtFH1rXK5sE/iHwAQKVuW3y sagQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764322133; x=1764926933; 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=BfB1+1n54EtAaQ0p4axZ7CMqQap0WXeaVLrFGnbDa00=; b=C2s188WTOo2j6nDjkuHDFb2ccPl1wvF/FuV6eoxEd19q46bHziSSvPrurrn448yjig CPRYyCC2iwGiXy8+ctgh4yW90kAGlxYHJPhXS8yavTmkTO/IbKA/BrXcziokgoZQGBPr Qk/8ONmqPgkjseUGml1v9uh6Ilzpa+vwHRZtN3JEhlzD6RVaLDOCsyO8DwGO9cff/xwd 35LjwJzFpjHECc0y68pLn18dJIRmYEhZZN5DamptllhEl2TpwafkEz1d+dE7v8FMwPlX Tpes7YNrf7G7/Oy43+jVMkRvnNKLBryz+4upEvbGlpV6jIFiJnCkjf23t5cY0pwqcit9 6/Lw== X-Forwarded-Encrypted: i=1; AJvYcCWvU1yRB8HMV9vP4drQVVqgAVdmk/ouU0ziiKRoo5E/WXe/k8SFLoMbB9FCREjfemRMqbfHZNa9NraKl4w=@vger.kernel.org X-Gm-Message-State: AOJu0YyGkNLIUAIVbp3d1wWC38ld5AMcR9x3sM7fxln2vj2TTmOTqyuB WqrXjSnjh0FD75uA1vgD9v5o0EdF4XGHsd6aydJKEUJsZZzFPwNrD494Kf4E8Wectl9XlGUCB9n sh40YrfO1DWDNlFcQnA== X-Google-Smtp-Source: AGHT+IFiVYsI2OdISn6VZC7R1ztAkjTUn9DQuinLJur4JooHB2So2nt10pptXhN77fC9tVjIw7LQO6s8qx3FfOQ= X-Received: from wrhm5.prod.google.com ([2002:a05:6000:1805:b0:42b:2edb:9e83]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2387:b0:429:dc9a:ed35 with SMTP id ffacd0b85a97d-42cc1d3479cmr28776643f8f.43.1764322133683; Fri, 28 Nov 2025 01:28:53 -0800 (PST) Date: Fri, 28 Nov 2025 09:28:52 +0000 In-Reply-To: <20251127-pwm_safe_register-v1-1-d22d0ed068ac@posteo.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251127-pwm_safe_register-v1-1-d22d0ed068ac@posteo.de> Message-ID: Subject: Re: [PATCH] Move pwm registration into pwm::Chip::new From: Alice Ryhl To: Markus Probst Cc: Drew Fustini , Guo Ren , Fu Wei , "Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=" , Michal Wilczynski , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Thu, Nov 27, 2025 at 05:15:06PM +0000, Markus Probst wrote: > The `pwm::Registration::register` function provides no guarantee that the > function isn't called twice with the same pwm chip, which is considered > unsafe. > > Add the code responsible for the registration into `pwm::Chip::new`. The > registration will happen before the driver gets access to the refcounted > pwm chip and can therefore guarantee that the registration isn't called > twice on the same pwm chip. > > Signed-off-by: Markus Probst > --- > This patch provides the additional guarantee that the pwm chip doesn't > get registered twice. > > The following changes were made: > - change the visibility of `pwm::Registration` to private > - remove the `pwm::Registration::register` function > - add code for registering the pwm chip in `pwm::Chip::new` > - add Send + Sync bounds to `PwmOps` > > Note that I wasn't able to test this patch, due to the lack of hardware. Overall looks reasonable, but I have one question: > @@ -654,50 +668,23 @@ unsafe fn dec_ref(obj: NonNull>) { > // structure's state is managed and synchronized by the kernel's device model > // and PWM core locking mechanisms. Therefore, it is safe to move the `Chip` > // wrapper (and the pointer it contains) across threads. > -unsafe impl Send for Chip {} > +unsafe impl Send for Chip {} > > // SAFETY: It is safe for multiple threads to have shared access (`&Chip`) because > // the `Chip` data is immutable from the Rust side without holding the appropriate > // kernel locks, which the C core is responsible for. Any interior mutability is > // handled and synchronized by the C kernel code. > -unsafe impl Sync for Chip {} > +unsafe impl Sync for Chip {} Why was this changed? Alice