From patchwork Mon Jan 8 16:03:22 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: 186066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1120286dyq; Mon, 8 Jan 2024 08:16:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtWlgcBqmmOCSplIW2IkXXMKuq6Ytm/M4TjK30vHbgNzZw8U+Tmn9XFs+X46e1fb81W2gq X-Received: by 2002:a17:902:7485:b0:1d3:34cb:2324 with SMTP id h5-20020a170902748500b001d334cb2324mr1715344pll.88.1704730600323; Mon, 08 Jan 2024 08:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704730600; cv=none; d=google.com; s=arc-20160816; b=zO32PZhGru0JGPr9tC4bPS32AQmo0F1dhmPUWtT2I+gk61OO2yUbz9/UaI3Wcg+um+ P/io13F7OM9dm1vtpmVA7t/9EX/W+3Kt5igIgVedZHuayWxJiTefiNo5kapkpxnrlQCM vrMtHihl8tl+qGettPJPrl+ymwps9xXmJ33gumyMRB4B/7OGBCfaIXh1iOrk1VwKH1D1 tcKoghXQ7NegxQWIMNTYOxEcSd71XqwUafny21pLZ6xrOKZZ/BeExG+VB+SBozCLU3Ue 075wlQtm8eKJY3zEo9BW4uUSpAXFK2RamDca4M50aRbsJRaojaEWkYxqnbDk9UWCRM8C 6Xxw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19827-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jw3-20020a170903278300b001d3714f17easi99621plb.37.2024.01.08.08.16.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 08:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19827-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19827-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1056C283F9C for ; Mon, 8 Jan 2024 16:16:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0CDF53813; Mon, 8 Jan 2024 16:16:16 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787539594048237702 X-GMAIL-MSGID: 1787539594048237702 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