Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1811204rdh; Tue, 26 Sep 2023 04:30:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFqVxnL+Zmqsaw+KhNACnd0puH5YZ9d2YGUUbWqy+wYGVlQ6k8+tsAHU/aNwpip5EhUS1a X-Received: by 2002:a17:902:db11:b0:1c0:cbaf:6930 with SMTP id m17-20020a170902db1100b001c0cbaf6930mr12504325plx.54.1695727830556; Tue, 26 Sep 2023 04:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695727830; cv=none; d=google.com; s=arc-20160816; b=gfrhnxi2djOBytssWsu4xdpKfoD5iaBMlq9VkZcIO7MJdNHcAovxEbNrEGDLG5mgYm UkH/JhKJBHGH53Yr4zHl1bPUQFf6IGsGaQ02mVqY/mnBVswKVoeg7Zn1YfCFrg1+87pv LiXbteq+HuOROyaClDMS+cAP9NhlO425MEV5u0E4CJyUKrlpFSrMKh1x82MoZKdO9bNb y94SgDkHD9NHjGxoyEnfeD58StPNtQd4D5kEvmBflxE5+pKukWMWjlwC9pikMip1Zn6R TxzZUViPiQbyk9Jhptt7sXv6D6XmuSbU3AgUvEE+dgeGR/xRyhlH3lecPMTsD4l0Bgal 8MGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=PSjOVj3NEZLcZiR/Ha2dwc9eHr7RbUTNTjvX8TFLRcY=; fh=vIXIoZZ65TzKBG2LFnDykpLhCv5POYI/sfuX1nG61fE=; b=lkvBUYkeE4U3z7DtqLUoJfWIs37PRuLrjKqPM8iZEFfOfRCyq7OF2dUhYmFtOg1lmh kntD6enJucRYyUypuXCWiWL4rR6A8eqSAfGwSAZwlX2jmgzNPTxatrmvNPZIx1ye2sZy tSwM7r7mDZGOwcxiYcZf2c6ErdRw4sTPcSdB/wD84TCg9cFaB1vDKk4st1NlplSBPDnB NF2IkKK6njx2mwrTZD2F3t1wI96jDdtIobBwokD/tkS7DfS8ZTdJLOkFRIONlyWQ8X6r K1o62j53xSe28rkoZI/QCbMpNpi/5l+iHC2+9flNPOUdeRbO5HGNztkR1lUL56dQtQSH SdZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nWSZO9q4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id n11-20020a170902e54b00b001c5d1016b37si12956031plf.587.2023.09.26.04.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:30:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nWSZO9q4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5681F804C197; Tue, 26 Sep 2023 03:02:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234325AbjIZKBv (ORCPT + 99 others); Tue, 26 Sep 2023 06:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233494AbjIZKBm (ORCPT ); Tue, 26 Sep 2023 06:01:42 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B232BE for ; Tue, 26 Sep 2023 03:01:34 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59c0327b75dso150803427b3.2 for ; Tue, 26 Sep 2023 03:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695722494; x=1696327294; 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=PSjOVj3NEZLcZiR/Ha2dwc9eHr7RbUTNTjvX8TFLRcY=; b=nWSZO9q4u/q4IPDeRiji0HqLaHHPRM3kcMAkUSYERcswAMLYk0Abw+ivGlrsM9UCAm vr6+1ivoZ8r9z7WpBsLkVJtMZYS0tKVrUFgM4XYMvDfHbIQYLgPs/Gv0RfyJsywvxxrz XvbMlcvow/goO825R3+5SVuaeswEfStLGcU7A7UDvhs63XLxgkH9awU3BK1pnHsrYaPa ne2BuxxdGbi4agqR7kQb/XPB8qcK6dbelk6C2+NKJc+BBnefzQTVN76wCXy3Vbo/DPHN w/iQ0UhB0A3vJy9/abYbrE/umXM2aueFLzu2mH6KtkVyrcJgs/Ox90mutoEEPqooT6uN n7+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695722494; x=1696327294; 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=PSjOVj3NEZLcZiR/Ha2dwc9eHr7RbUTNTjvX8TFLRcY=; b=H7GN3wNVYLd4sQaXvC4Lqh9mMdmvOGjLgohtkOx0SBQxCkoCTAD0vwk6mwbw+9hQAJ 1XT+m7lc2mUpj4uk1xjGbUbxIojNdgs9WxJVOgtXWs5OSF7NdGiUV5ZwSJwgPDGLYojI TVonQNPrOszAQjjytK/oyviGa5JgGFulYkyOvGfQIhEc4OgPsxEOVSB8tToeUGi7DsN0 urEGciAioj3R9w3LzidmyM8g1UBEwMgWsLpwPz4R1i2N2r796mFqwtB5d/+aTa2nzdXl SsDFY6STep3binbBqOkWuF9lzcdmEmsyhAj/MQVknNWo3M6v4ZRBds9wPTDsOL31G3JQ Dg/w== X-Gm-Message-State: AOJu0YwhHo5kZawRfO3rNkVIjfMTTgxvEo3+VpEFo3fkJdsEXiZQW7mp UMzZaddzH7g8HitYeX6o6tAJEoYCRz1dtZY= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a25:9c44:0:b0:d80:16bc:4e41 with SMTP id x4-20020a259c44000000b00d8016bc4e41mr91493ybo.0.1695722493787; Tue, 26 Sep 2023 03:01:33 -0700 (PDT) Date: Tue, 26 Sep 2023 10:01:30 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230926100130.2213190-1-aliceryhl@google.com> Subject: Re: [PATCH v4 4/7] rust: workqueue: add helper for defining work_struct fields From: Alice Ryhl To: benno.lossin@proton.me Cc: alex.gaynor@gmail.com, aliceryhl@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, ojeda@kernel.org, patches@lists.linux.dev, rust-for-linux@vger.kernel.org, tj@kernel.org, wedsonaf@gmail.com Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 03:02:11 -0700 (PDT) >> +impl Work { >> + /// Creates a new instance of [`Work`]. >> + #[inline] >> + #[allow(clippy::new_ret_no_self)] >> + pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl PinInit >> + where >> + T: WorkItem, >> + { >> + // SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work >> + // item function. >> + unsafe { >> + kernel::init::pin_init_from_closure(move |slot| { >> + let slot = Self::raw_get(slot); >> + bindings::init_work_with_key( >> + slot, >> + Some(T::Pointer::run), >> + false, >> + name.as_char_ptr(), >> + key.as_ptr(), >> + ); >> + Ok(()) >> + }) >> + } > > I would suggest this instead: > ``` > pin_init!(Self { > // SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the > // work item function. > work <- Opaque::ffi_init(|slot| unsafe { > bindings::init_work_with_key( > slot, > Some(T::Pointer::run), > false, > name.as_char_ptr(), > key.as_ptr(), > ) > }), > _inner: PhantomData, > }) > ``` I tried setting up a patch with a few nits fixed, including this one. However, I ran into an error when adding #[pin_data] to the Work struct: error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions --> rust/kernel/workqueue.rs:192:28 | 192 | pub struct Work { | ^^^^^^^^^^^^^^^^^ This nit can be fixed when #[pin_data] is updated to support default values in struct declarations. Alice