From patchwork Mon Jan 8 20:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yueh-Shun Li X-Patchwork-Id: 186135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1256497dyq; Mon, 8 Jan 2024 12:23:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4slgz+EuDCYZBgiaGeZPmOyyyjMFXQVJS1W6nt9bQ61eJ18mOFANC28mYF+0Tn89Vqn2Y X-Received: by 2002:a05:6214:246d:b0:680:c880:6646 with SMTP id im13-20020a056214246d00b00680c8806646mr5742204qvb.22.1704745400323; Mon, 08 Jan 2024 12:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704745400; cv=none; d=google.com; s=arc-20160816; b=Eld/7lGfhTkZx67nfVGeUhJPSwgNHXZMgaPtDnLIAu70LBVR/cuizE4Ypdv3jyirum YWVVSB7EChi9hP0H+ullSCqtOuYVALjR4kZpjRdhUGL4v+F38bSnHeuBWY/7oe6Di4Bb Ks27cn0GyvMrKRFYmyVA1fuf1uVrn42XMebeUsRpFDA258SGuxg3OPWVK9uKoJrzoqkq zcqAyntHuaDMaedOuIWz0x7uFP59/oZM1+0yzeXXhObkcMd8Phf5HSqoVaXL9/z4VU/w h/Dq7bB888vtlgrE0ofhatgV7TnTOEafb0HUrNTOdbtTcX1RNlFkj7YbFEOzhhTtjnxf nFwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JIcavdlfH22AA/FlMSBQE8gSgd49+tscvTR8Cc4zf10=; fh=BITo/uEZRYT9j9W90zPFjCGLSRb+JfMPRXikTk4wLPM=; b=XJRKIvcBXQ2PJ4WOkfmCq6PpGY0/NUE5PyK5p9/6PlS2AONku97+yYCOkyvtk1+RGL PAzhjJKC8Ne8FogtHivb0H5rDs6cEMNEnQepqAsUOyI7OfwmBaax/dxqI/TswBK8MdvO UHAjqjbWRIyFM4oVc/LnZbV/eheYCoz5C8N6DkUBCmnmDxnZC41/vwbmRIfmfz3Ehx+5 VDf51YbXdgRcVM967MRZuofFsjKL72EX8QH1Cj7bhZcHmFPpamylqsIwwkHE0AUgh1Fv ebNLRFfrQPEWCWWFtWW6phIDvIEb3NKiMZ1cTclDk/DKOvbdlGYneKFI/lPn7zNw1zPZ f5JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=f+mLiayT; spf=pass (google.com: domain of linux-kernel+bounces-20085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20085-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x12-20020a0c8e8c000000b0067f86979518si623921qvb.573.2024.01.08.12.23.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:23:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=f+mLiayT; spf=pass (google.com: domain of linux-kernel+bounces-20085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20085-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1FF521C230AA for ; Mon, 8 Jan 2024 20:23:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4149746541; Mon, 8 Jan 2024 20:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="f+mLiayT" X-Original-To: linux-kernel@vger.kernel.org Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (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 567535577B for ; Mon, 8 Jan 2024 20:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.net Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 733F5240108 for ; Mon, 8 Jan 2024 21:22:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704745375; bh=QdXdfx57ZJPNwppUDVSfjTZfO7rtid5cQ8dOF8J1p8o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=f+mLiayTkIkdCQsqNYeLNTSKdh8rsjRSg6AeDgKXVYiI1APjpptqojbY+foZ0Slb2 nwx3XVXY4HOc9dPKRQwSMmWDUlW02MLw6DtSQLdI31ZP1ajx+Nl7vwPlqnFceTsRLS MkHp91rftJvk7PK9P0KZVJOoqd3E1/uHfVFHYEvfu0Hc2bbmRsmY5vwAuxj/9NHmzF hvxAeshXsxW0hJ4pVxkl3BvjTb4GYfWGSh9tBHdVHNyqBJy3Ls3tv3Lrp80TpkHZ3N P2wV20OUPUzW5bjd3FiU2fuaMSgWFE4RwWS3wCnhLeUcRdD1jPEcEyNrkNZZKdh5IG C7zflfrmmtZMg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T858k6p49z6tyS; Mon, 8 Jan 2024 21:22:46 +0100 (CET) From: Yueh-Shun Li To: Jonathan Corbet Cc: Yueh-Shun Li , Randy Dunlap , Hu Haowen , Alex Shi , Yanteng Si , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/1] coding-style: recommend split headers instead of kernel.h Date: Mon, 8 Jan 2024 20:22:08 +0000 Message-ID: <20240108202217.191839-1-shamrocklee@posteo.net> In-Reply-To: <20240108201851.191604-1-shamrocklee@posteo.net> References: <107b6b5e-ca14-4b2b-ba2e-38ecd74c0ad3@infradead.org> <20240108201851.191604-1-shamrocklee@posteo.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787539594048237702 X-GMAIL-MSGID: 1787555112872811962 In section "18) Don't re-invent the kernel macros" in "Linux kernel coding style": Recommend reusing macros from headers inside include/linux, instead of the obsolete include/linux/kernel.h Change wording - "The header file contains macros" -> "the header files provide macros" Some macros are intended to use inside the header file only, or are considered the implementation detail of other facilities. Developers are expected to determine if a macro is meant to be used outside the header file. Signed-off-by: Yueh-Shun Li Acked-by: Randy Dunlap --- Documentation/process/coding-style.rst | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 6db37a46d305..2a5c4f4c568c 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -1048,27 +1048,29 @@ readable alternative if the call-sites have naked true/false constants. Otherwise limited use of bool in structures and arguments can improve readability. + 18) Don't re-invent the kernel macros ------------------------------------- -The header file include/linux/kernel.h contains a number of macros that -you should use, rather than explicitly coding some variant of them yourself. +The header files in the ``include/linux`` directory provide a number of macros +that you should use, rather than explicitly coding some variant of them +yourself. + For example, if you need to calculate the length of an array, take advantage -of the macro +of the macro ``ARRAY_SIZE()`` from ``include/linux/array_size.h`` by .. code-block:: c - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + #include + ARRAY_SIZE(x) // The size of array x Similarly, if you need to calculate the size of some structure member, use +``sizeof_field()`` from ``include/linux/stddef.h``. -.. code-block:: c - - #define sizeof_field(t, f) (sizeof(((t*)0)->f)) - -There are also min() and max() macros that do strict type checking if you -need them. Feel free to peruse that header file to see what else is already -defined that you shouldn't reproduce in your code. +There are also ``min()`` and ``max()`` macros in ``include/linux/minmax.h`` +that do strict type checking if you need them. Feel free to search across and +peruse the header files to see what else is already defined that you shouldn't +reproduce in your code. 19) Editor modelines and other cruft