Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2119540rbb; Tue, 27 Feb 2024 11:10:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXjmeIofD0U0nM4/H53OQQL/foG9CoHBENrcVP62uBdUwCkwX2VqZytwk1JOD2qbX3r13/j66yxwpPCWZsmmb0S3WKbcw+u5/zLs+iDmQ== X-Google-Smtp-Source: AGHT+IE5NVAfry2flXj4+0QdRcSu3txiS/4rd5c1AuFqfkJhiq/ZR8+bNP7G5B/Md0mAuPnl6rmq X-Received: by 2002:a05:6402:180a:b0:566:4047:7106 with SMTP id g10-20020a056402180a00b0056640477106mr1725467edy.25.1709061052038; Tue, 27 Feb 2024 11:10:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709061052; cv=pass; d=google.com; s=arc-20160816; b=zngxNPvKT4QL8To3YqUcQP3+NuP5GBRM7pTIpLvJKIgjkVYxpvmw4Idwc6onPOADlM NOdY1ypGf+OVhpZPbW6Do9xLw4fYzp+iFdV1v86mJjfVh1QRWowXxkImV4UeYlFgPNFj wv6qJUQLX8LoKH+/BR1vXFOSNFb4mYkZOEbDVyoyggo2dr4um48qayrPHN30lgoEPXqp qaGzP7oIV7+dM6P2FPRqZhpBxl48dB/IqvOmdEkPszCDLy4EfP2Ha5iRiuhzU99jAfAG qA7svOkLGSGmU6c9jb5qaZ3wkxtdEt1mw9fdyUOd+99U4r0AbFb10pPvWtvBi2wgpB7c X7Rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=dHXV9Ly1sQdf88TxoYBnR+fTtJ69EeUYd8QJVu9nB3c=; fh=jl9/kuBYo3Gn2BBz0zErs9UPETds1jCciNhLeHU6Px8=; b=ebeHw2lswH+d9aVGRCH8hlesqi7VmszvRQN2WyX9SqfTYTvLOfqoVwq2A019Nld6fh B52TDDbK65I1fe3MYxJc2J55MT77KVoNlcw9R8Tg2KiMkDmpvebTWX8NTt5VONnl26ub 3nW0g/cqQAJGPGMXncBonMq0I/6TdkFwKu63oNEH/8eZ3T258DJ+/qoU8RAs4MRh8roM aMQnTYt9nFRGMKbRzofwZSIUyjX+U3/mDFJnbPcQSEfl9oDFMjYBWtjHC8K+QqzUggZR 78IoZXr6iMwJDsfXs/EGcF6PXiRcgNNDQcFfaMenjOtTrKSx/uB3q6x+LZu+1DmhFU6y 8yxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="sTzif/MS"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-83900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w4-20020aa7da44000000b00566358e2376si858926eds.72.2024.02.27.11.10.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:10:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="sTzif/MS"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-83900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8AA541F23065 for ; Tue, 27 Feb 2024 19:10:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B70065102E; Tue, 27 Feb 2024 19:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="sTzif/MS" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FDE34E1DC for ; Tue, 27 Feb 2024 19:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709061044; cv=none; b=o1VCD0NtE4YFuoYxKm4NGrZNVg6QqhFlBL3dHy8StcKhw5HgrwloqG/Vp/tnB8UqV/FSEm26UZLDvXVN8Rs/gVSIJCeh2QIA8+Roh3lkJB7qdydjQV8Yt8IS0kZt5wVZSu84cM3ozG1T0bWO2KnEr9Nr2FZfkHIxq3bvsoiRnl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709061044; c=relaxed/simple; bh=3qEYpQVEQQyEhmIlwWXIEf3W8r2LJW7QkiNvHIxXCrI=; h=From:To:Cc:Subject:Date:Message-Id; b=us3WBlDYCkby1GwL0lgD68eNMx9xkUFd67RscmMhaP2nbGiubNV1yuOa/UHHbNChG+xR27+DVGGOmvHsGfFoZFWrRwbBF/uzbBzezin1dt+KhzL3Ch76KPAng8MwJv+JpJ4286L++lnXzbAQPrHC16KmyACCPFx9ujQllknaEwY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=sTzif/MS; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from apais-vm1.0synte4vioeebbvidf5q0vz2ua.xx.internal.cloudapp.net (unknown [52.183.86.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 40FFA20B74C0; Tue, 27 Feb 2024 11:10:43 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 40FFA20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709061043; bh=dHXV9Ly1sQdf88TxoYBnR+fTtJ69EeUYd8QJVu9nB3c=; h=From:To:Cc:Subject:Date:From; b=sTzif/MSkVNv8hfb34KLtstgLFoccFhLMRoDXk/yZE5pvXTry6feyZkczkwJtaWvu ncpE62+t9eMoOR7SqoK8Cj36Iz68+nnABl2HN5ONUG8D+cM2TomaEwFj6HpqeBdxla s5yrQZrXcIKNHr25Nk0B3EuNEAoSQrIbP0iEb0Pg= From: Allen Pais To: tj@kernel.org Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations Date: Tue, 27 Feb 2024 19:10:37 +0000 Message-Id: <20240227191037.5839-1-apais@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: To streamline the transition from tasklets to worqueues, a new helper function, from_work(), is introduced. This helper, inspired by existing from_() patterns, utilizes container_of() and eliminates the redundancy of declaring variable types, leading to more concise and readable code. The modified code snippet demonstrates the enhanced clarity achieved with from_wq(): void callback(struct work_struct *w) { - struct some_data_structure *local = container_of(w, struct some_data_structure, work); + struct some_data_structure *local = from_work(local, w, work); This change aims to facilitate a smoother transition and uphold code quality standards. Based on: git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git disable_work-v3 Signed-off-by: Allen Pais --- include/linux/workqueue.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 7710cd52f7f0..aedfb81f9c49 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -527,6 +527,9 @@ alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...); #define create_singlethread_workqueue(name) \ alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name) +#define from_work(var, callback_work, work_fieldname) \ + container_of(callback_work, typeof(*var), work_fieldname) + extern void destroy_workqueue(struct workqueue_struct *wq); struct workqueue_attrs *alloc_workqueue_attrs(void); -- 2.17.1