Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp983999lqp; Fri, 22 Mar 2024 01:50:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBWt0EkvE6yyEAwk8sBcz6iVn4omPw99wrTVWR+9RpSeBHalwWUEXe4vphPoFQu4fm2nTKCia+QZzqS7k7jjFH8id94cJELzmjW+i6AQ== X-Google-Smtp-Source: AGHT+IH6HcNfuYBc1FoFvCjphcr6DvI/bWuaqKJ3kj3skGH2v8efp4jXT1VsBTN2UM7aNuUHL57z X-Received: by 2002:a17:906:1b14:b0:a46:471e:c569 with SMTP id o20-20020a1709061b1400b00a46471ec569mr1097659ejg.50.1711097433284; Fri, 22 Mar 2024 01:50:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711097433; cv=pass; d=google.com; s=arc-20160816; b=chuzmZt69mL8f/fpzG6WL3jhffxXqWHInoZNxUbEFzXpstsa7kZz2fsidZzdk2VopX od/ZbdcFlMZlxtSFdsXxYBbKvw7z+L9TMIE6iSa9wE4S7N7shtHfOS+NdWt2cWq8W1gU 2T+V/o1rmPkxF2YKOFBMe8JoLOwTEMKtwzMPPufVwD7zs2fMQu5Mi4uKyK2KQ1n3zHWi Toi8Ao5DcbhIL5+HgY14HlcDh+Hw11zCvvvEI7BgLkUY5fLQkQu52ev2z+VSAQFN1gxE GtOmfyRwA+unvfNQkA2oDpAFozVQ1qhdUA+mtrAoCYaXtOlLwW0svFC0lSH9p9+2BK84 8qpw== ARC-Message-Signature: i=2; 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=uUTQQORTCNkJLIqJM+PvSaUWiqWoVca3nx315DNzuS4=; fh=3aZ9RFxck+FPetrwZ6VrJvZfVL8Yc2VZ9K90kiiIOgw=; b=GdIdGQD+kN8aZpfDcIFk4zmX4pxKb5rkqHAgVeJcvj+ICwY3Y+AolNbDPngP7tOXmX qp5mggxW5GaOuKKwCLb3EMfNmx1e324RGhSifJwxXCnIJ/JPs89cIG04V9E9euxYPUP8 RJ0yhvNEqtgBfkSMBSQv7no3uK1UjgPBuzQoMP+XV4ubw+vrv2bf32kifGqPZI3tc1rZ nPnW1fB0MHdiZgtxbJPAVJNr2cqmFywPd2c4WHG7wx4SUJHi9UPUEski9/QbskE+am9A OLDIagBjxOWCFyT9Sm3Y4JoD7hYVx7tnJjGXfOi1aRgNLPVPcobQXDqQ3BV+z9YcdUqv GOMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CiFEYJhP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-111160-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111160-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e17-20020a170906315100b00a4628a74556si679071eje.279.2024.03.22.01.50.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111160-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CiFEYJhP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-111160-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111160-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 0759A1F237CD for ; Fri, 22 Mar 2024 08:50:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C0841946B; Fri, 22 Mar 2024 08:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CiFEYJhP" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BD021863B; Fri, 22 Mar 2024 08:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097402; cv=none; b=S3K0qa2XzCtaMbakapyCfek/ZGo04n55db7lCR5Gu/GV3T1v0OtDHui/GPEEWuRoFhI1WBpaBmomViarosyEtTxX6ggHyiSDQfPp8jXM9vYnzQ2q6H2jyOIjw52kdbgsPV2jrqQnZliCya86hY30obxeVLE/wwbjuD4XJgIxBs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097402; c=relaxed/simple; bh=HJlrj6w3n1k06T38Le7twWxRKsTsn+pwv/gvS9S19DY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cSt2jarhRvRosqMQrV4heCJUvnNZIhHP80zggZ7sFu8c2kHJ3/fCJ8GiDsEn1lIwbf4PntW+CSaPoVhbdJeL17Lf8IYM9VFUceV24n+/4s/sIt9/HxZKo7bJAMWNyAdMVX6lx1fw9p3LPRm1JEQP3TgikrvLgcYchY98/AIY+fA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CiFEYJhP; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e07cd7b798so9894225ad.2; Fri, 22 Mar 2024 01:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711097400; x=1711702200; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uUTQQORTCNkJLIqJM+PvSaUWiqWoVca3nx315DNzuS4=; b=CiFEYJhPiudDPazq2+chTsPGWqqN1nICU7KWt7sXsbW3p8ZJX/W+CowtgCtntU7evT NBushbuzJ6rN13BVMOmWBi4gAUBj2HNTA0tJsgyp0y3aCVg2SIOQTepltthNPdG+bKRP uU4QdAJRSRcYUt/h83LACVS9rPbG7SxLe4HKeW5+6gtvaeVO+HlQXxB3Uc32ydBRuNvT Sr/Q59RylcH11SMdwWg32FBLFpzxcGVFIhsJxNyrnrIoscfTd5MKVwrhHC71cTHdvUqC IVr4hOQOVakkcE78xIur9IV4mrxNg6rjvwSSAQ9I72GUTWtqN2N7Yq//R10EErr4pxYY ngmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711097400; x=1711702200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uUTQQORTCNkJLIqJM+PvSaUWiqWoVca3nx315DNzuS4=; b=Qus1mT/R9sKOwmiLIlKM4zmdmcI30jenYvtQfTQgRKD/XDD2fNkjvNGzytP3t2KTwA 9kjBCj26Td/pvZ8fHe1WANmY6b5nESOnQUa5MtGWg8ePBnjrOKXWMjockgr86nbN9xbq MMUd4li4CrCNOvzknYDf/IOIry5WbGEkWm+oHoQcWojUqmUMFbEE+cR1GNtz+flGvJ+S xf5tQKREQxuofgPq4fDAqbXSpcZhWbpSfoZrhDjEqP0U/jG6VzHqRsFF+8FKk/RJnHp+ Uptd+//H9XXkuBpKzmcA1WIpliFpzNn4w8WtRhL+IzRJu9bF9Dhh+UHiypwKjSrHD0vb 4ndA== X-Forwarded-Encrypted: i=1; AJvYcCWxcsrh570UpEhdkH7SEcPcbdpfeXdcaiHGi0edZIYWMI/ggOIjJ/ehVJtH/dwrRw8248w7Fmu1MwaAnRuEGfCvo9Kxz4+QfbLkzUPuANPmp6CWwntmQ0c0FJCJDXUnRVY5ORFM X-Gm-Message-State: AOJu0YyJfajOksYh1hSvyUtrRSq6IYbdwp8dVKDyZAEDqexmqiaXK2ta U6FJ4BuPJkrLDUYRLw8AXX6Z8srVtzb3VnlsuKxtc1c6p3OogJ4j X-Received: by 2002:a17:902:d503:b0:1e0:185d:16d3 with SMTP id b3-20020a170902d50300b001e0185d16d3mr2523534plg.5.1711097399842; Fri, 22 Mar 2024 01:49:59 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001dd5a0a20d6sm1328165plf.287.2024.03.22.01.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:49:59 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com Cc: linux-kernel@vger.kernel.org, Barry Song , Andrew Morton , Chris Zankel , Huacai Chen , Herbert Xu , Guenter Roeck , Stephen Rothwell , Mark Brown , Max Filippov Subject: [PATCH v3 1/2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Fri, 22 Mar 2024 21:49:36 +1300 Message-Id: <20240322084937.66018-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240322084937.66018-1-21cnbao@gmail.com> References: <20240322084937.66018-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Barry Song Recent commit 77292bb8ca69c80 ("crypto: scomp - remove memcpy if sg_nents is 1 and pages are lowmem") leads to warnings on xtensa and loongarch, In file included from crypto/scompress.c:12: include/crypto/scatterwalk.h: In function 'scatterwalk_pagedone': include/crypto/scatterwalk.h:76:30: warning: variable 'page' set but not used [-Wunused-but-set-variable] 76 | struct page *page; | ^~~~ crypto/scompress.c: In function 'scomp_acomp_comp_decomp': >> crypto/scompress.c:174:38: warning: unused variable 'dst_page' [-Wunused-variable] 174 | struct page *dst_page = sg_page(req->dst); | The reason is that flush_dcache_page() is implemented as a noop macro on these platforms as below, #define flush_dcache_page(page) do { } while (0) The driver code, for itself, seems be quite innocent and placing maybe_unused seems pointless, struct page *dst_page = sg_page(req->dst); for (i = 0; i < nr_pages; i++) flush_dcache_page(dst_page + i); And it should be independent of architectural implementation differences. Let's provide guidance on coding style for requesting parameter evaluation or proposing the migration to a static inline function. Cc: Andrew Morton Cc: Chris Zankel Cc: Huacai Chen Cc: Herbert Xu Cc: Guenter Roeck Cc: Stephen Rothwell Cc: Mark Brown Suggested-by: Max Filippov Signed-off-by: Barry Song --- Documentation/process/coding-style.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 9c7cf7347394..791d333a57fd 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -827,6 +827,22 @@ Macros with multiple statements should be enclosed in a do - while block: do_this(b, c); \ } while (0) +Function-like macros with unused parameters should be replaced by static +inline functions to avoid the issue of unused variables: + +.. code-block:: c + + static inline void fun(struct foo *foo) + { + } + +For historical reasons, many files still use the cast to (void) to evaluate +parameters, but this method is not recommended: + +.. code-block:: c + + #define macrofun(foo) do { (void) (foo); } while (0) + Things to avoid when using macros: 1) macros that affect control flow: -- 2.34.1