Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1724832rdb; Mon, 8 Jan 2024 08:16:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFF6tgcKFK7uwSuO6M/aMxlA+GpPhoYQwks6zLTeAlPgDk8+z7KkSMqQcpz1vT7+2GTJ2s3 X-Received: by 2002:a17:903:605:b0:1d4:25ec:5962 with SMTP id kg5-20020a170903060500b001d425ec5962mr1489177plb.49.1704730604193; Mon, 08 Jan 2024 08:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704730604; cv=none; d=google.com; s=arc-20160816; b=OFnt+o020n/oKO4v6Ph1HQ0uBoBN2QHKENKvl40yT5PwLgHbyF2BmE16p9NWzWk8a6 +T7d71540D9kQkuS8wh+g67n3LvP72ClTJiukDumS/Tf1gwAQwV6UXt98fyLL8C/MXF8 wn73B+Jx/dpgdVNtjDC6uT63E9oc9hikBmbYq6qb0v9AvQ4AEmNxEQfNbIxu+xJpcX3p VeQbZJ3mFGjaxCJ2LQCJRm8bu21kYHkxavYFJ5++ITAuWWVz/yCmHM8daZoyQqbs7JsL 0O1G9nlLv+nBrH80ajdMklbqp09NEHsB3IdDwGUaKpdiPS8MY0knHNtJ+naQBIAF9Kg8 aDng== 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=2TdF+w5zrhQUIug68C7l06/is8F2nhLEFMWbLaguDOU=; fh=BITo/uEZRYT9j9W90zPFjCGLSRb+JfMPRXikTk4wLPM=; b=PqwC1s7wZ2FpcO1KUQtN1qUJf+c78Gx1/oD5MFCZtfMfL5SlA3oBNL2jpmO0L4aSyo C72FamOPsqWK+9CeM7UyJExWxQ6QT4fFxMjUhqKRg/CiTjEfAmtzAVyAxBI89uYE2voI It1yWX4Y3oFWKSqkchV9BjIT/c5YiM9Go2R2oV3nrDK+v/6WWj2mE6JipfMQwKC3IVMZ L6Gi7QKue3emBISzkDUSbRE/HFXvS4gB6/uBgRW2AUBREGiVUefz205YmMzfnjhLxxLa NNdyMqMscEXjn66fTMUYPHeQX60rBNfIebpjtR+ZnxCS8OL2qRBawxgptcmK8FCYUzXe qP0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=oAR6Gwaj; spf=pass (google.com: domain of linux-kernel+bounces-19827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k10-20020a170902ba8a00b001d52198a844si73088pls.614.2024.01.08.08.16.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 08:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=oAR6Gwaj; spf=pass (google.com: domain of linux-kernel+bounces-19827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19827-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DB871B21316 for ; Mon, 8 Jan 2024 16:16:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 044CF52F89; Mon, 8 Jan 2024 16:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="oAR6Gwaj" 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 4E2CC52F61 for ; Mon, 8 Jan 2024 16:16:12 +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 87889240101 for ; Mon, 8 Jan 2024 17:16:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704730564; bh=X3VtHd5GjlJi8/Twrh4yAaOYDgw5xWt6nucsz68JnqU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=oAR6GwajS3y8dsWT0cTJzZ++cMYORHI0OiZFlheCvbx9Bz2WOu21/mJCYSGtxDwz4 h6k3yv1V0fWP2Fvp2A3WLR/Mskuz806PGtjJxfdhQO5XwjPOaZMtPIQcYnTrQfXZP1 /I1E6cdiqypmkVIDZb60H7W/6n1eyBNDcQTg9L447vqXWyPc7Tg8xYGYs+7UE8b/Gf GsLpP9ijgW8lf4vSUdF6tG8puOM3ifhROSGQj823ibDvoI0VR3NLUIn1XOZCeyPnmc rQy51/3RE6opGSEbI/kqmwQzt7vt6cl2TGREoSDpibLb9smIP5PihqRP3GLRCT5AJU pflgMcO7yXtbw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T7zh03SCsz9rxB; Mon, 8 Jan 2024 17:16:00 +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 1/4] coding-style: recommend split headers instead of kernel.h Date: Mon, 8 Jan 2024 16:03:22 +0000 Message-ID: <20240108160746.177421-2-shamrocklee@posteo.net> In-Reply-To: <20240108160746.177421-1-shamrocklee@posteo.net> References: <107b6b5e-ca14-4b2b-ba2e-38ecd74c0ad3@infradead.org> <20240108160746.177421-1-shamrocklee@posteo.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- Documentation/process/coding-style.rst | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 6db37a46d305..2504cb00a961 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -1048,27 +1048,30 @@ 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 in ``include/linux/minmax.h`` +that do strict type checking if you need them. -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. +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 -- 2.42.0