Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1299988lqt; Tue, 19 Mar 2024 21:48:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyKgnt5C4sabczZ3PlOA2Ykcte/gktHXRdfOP0L3smOMgyOz0e1/8rHCHpZs5PWzvod6tbWVT4yI50i9hXax3wlgMlAlREidqfntXCzw== X-Google-Smtp-Source: AGHT+IEYMb0xowFM8wc80NabDCoW/quM+0advK/nEyppFgKWoYj2Hi5H8j8rwCBUHRHJGFfKp/jI X-Received: by 2002:a05:6359:4591:b0:17e:bf0e:14f with SMTP id no17-20020a056359459100b0017ebf0e014fmr17089199rwb.6.1710910082161; Tue, 19 Mar 2024 21:48:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710910082; cv=pass; d=google.com; s=arc-20160816; b=zLG46uhi2i86vwDa66wOTr0Ma3EQYrbk5VggLTOwYS5pMAgCbPuFzHItrYlWSaUgb3 VSGrwidCnqF/PAKvcnrKU4QPC2MvFZXqPaLlXTuyyu6DvVHuzT+6Qlm44SjsRf78pE4+ N/SwrwDDe1L3M2pbwr28kGYisb0qyHTebQRHTFp4yyR6Y92kPqHu6VlZtAoLLj3DHYpZ TMb+JMRrDeD8ScBMUTNkkQzY5pPkMqZgj0p9ZJpBiVa9haHDmMQF2ullzUPT7MXm4cYY 7Vrii3avKB7Sa5u439r5Pv6UUZ2SWa5V1DJC3ZAPYtwNRNcut2cv6H1ndnOORMvwWkx5 hzZQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=tPbVgKP5amVDL/H/263LqoT3iBwntJ5V0hOrQ9MDAog=; fh=kiFL94tUSmHr0BwOiuDPFbD5qXCijH6oIzDwwHG+8/k=; b=pZbCFjpSF55rlDD5JudXNz43aMTE+iLBQO3etyQaQQQHrLukEsn9g6h6SsnqemKrA5 stQxU/75pHk14GGU+4ZSfFJ9fgkUTkhZlS489hwYjgebVtXfwh2yi6Mj8mTxy11dZFGy 6r+4hHoeZlYt6U7AAOpvhDGyHKc0rQQb+J9ECIDsmu8Dm1yEYpx+zujl2vOOIfWwVyTC yRh5E/a5/6AOdK7s+LBymOS+3rPdPA6TT444zjsUzi/+gRQxjBkg/zM4jfcLjXoXqRey mbkwpMAtYrZxIV76ybp+wLyie/TZAhhVEpFCjpb4bHPa0c1ZDqe8wmYvxBSJ/B6bN7YX psqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rg8145UC; 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-108432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108432-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n31-20020a63591f000000b005d8b48044d3si11689292pgb.723.2024.03.19.21.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 21:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108432-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=@gmail.com header.s=20230601 header.b=Rg8145UC; 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-108432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108432-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 792A7B21F5C for ; Wed, 20 Mar 2024 04:47:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E82E12E52; Wed, 20 Mar 2024 04:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rg8145UC" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 E140E17548; Wed, 20 Mar 2024 04:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710910069; cv=none; b=tG1vpZfwbAn3mkZqZOr0Vgoy66iFZS9utx96rxfJt8W/WOkdgdG/Ea3ii6Sq2/umbbDuRQUndJkJyNBiD1ASyHNUgiBc0Fs4Laj+UNzA0OD9tHrFxDqFMyW2kUh3t1swZjXOQRDNwVcabmkN+jWbsFR5ZgF6H8BzrFA1iNrjJhI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710910069; c=relaxed/simple; bh=hZ9LI06WzRxbiXskd40G3Xe6ctWb+KfDJG0pwUMm4Go=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qvk/VmaPK3ltLQgbv5qs1mTnqfu6C5gNjNAxdFPUKSSGYPBZjVT/2f9D6lQZU3/HGe3qFrzmvI1XbxqizYcG5nS8jR96cwklWOJVrwkxZmP4a8rk8CPlXreDpQLQ0D1SWPKP5peNzoYKVd9CpuMlaU02O05HtBQSGKdrXqhSwiY= 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=Rg8145UC; arc=none smtp.client-ip=209.85.214.169 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-f169.google.com with SMTP id d9443c01a7336-1dddbeac9f9so43576535ad.3; Tue, 19 Mar 2024 21:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710910067; x=1711514867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tPbVgKP5amVDL/H/263LqoT3iBwntJ5V0hOrQ9MDAog=; b=Rg8145UCUBjkO6IwbgLYQHAj8ugQLIr3FEktTPRYtuUdYZPDYp2JeGt0wwSWnaXd1f 4Yo3JP7Kf+JTEB5gftnQDdomw4LdM6pVbObwT7Z6N6QeNCsUBvEBaIf3qHZUddid+CAl PmUsLDbHjWXo2LUvajLD73lGU0vmvxBfI2cLPH6+j5mnJAJ6o77wHIMlGoFKdX/oIhbM YznjCi3wqq9XD8Ef9wqpyOouBQBfxAdZEj92k6TkQ2B0HTNRsvf+RHjStiaz0ExeJENK VtHpuz3LmZ9+Y8Z7zkVhTRv1CfpM9AYDBIbYnAfGhs8jG0Yx9+1oUwjkLbZ8UM0mnewW cZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710910067; x=1711514867; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tPbVgKP5amVDL/H/263LqoT3iBwntJ5V0hOrQ9MDAog=; b=PBEF8qjcbei42U/eF63ecRZrezqfiqUNDmomldgql3fGjdt7lc0h1YDNzgPN1NKYq5 GBuvklsla8YrjWglfqxzW2npkvYx2Sb4PZBL+KFphKaX2J0UGlJpBhA8UXc3/oI//tHb YrIufTS7Nj/aZU6qaWwlWsG3umEe11t2KuwfoQbrvd1DH4nV/g/Z9yE4gNvMHYnAk4dZ hGzCn/JVoQX65PalE0KyEmA4PjuxFwf1nNRAgaUqskKdDBaX2LcE8mjdnMt6HQq6jWD8 aGzqYDGd869Fd4sVoydS3PTcSvnu6NhnKLZDmizwusFD+UBaljWy2t54a76fsNgsmd4T mdfQ== X-Forwarded-Encrypted: i=1; AJvYcCVJI2EfgFqIg7lbjhU0FHcHlf4mVs2Jw19A3/Vc7oWyMXV/8dZ2F/m7MYeJGvyLAuUfLjCnt6yAIlkUkXIYphlCa2OuN2YTdeffHsqnAJK3l/T+P4am6t88bFz2Nsn5e9BhmC2W X-Gm-Message-State: AOJu0YyiN7JhmnjEVeW/+glE0LXLYMab0OkHF0/g76P9Bw14qZlp/BAm AqZ1yIxa7J2R6mrMPS8QFgVOZbW4xAhFRqyzuHuFLs+HeVZmUHaM X-Received: by 2002:a17:903:2450:b0:1df:df4:73e0 with SMTP id l16-20020a170903245000b001df0df473e0mr15298929pls.4.1710910067045; Tue, 19 Mar 2024 21:47:47 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id p20-20020a170902ead400b001dddcfca329sm12396465pld.148.2024.03.19.21.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 21:47:46 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, sfr@canb.auug.org.au Cc: linux-kernel@vger.kernel.org, Barry Song , Andrew Morton , Chris Zankel , Huacai Chen , Herbert Xu , Guenter Roeck , Max Filippov Subject: [PATCH v2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Wed, 20 Mar 2024 17:47:28 +1300 Message-Id: <20240320044728.20313-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 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 Suggested-by: Max Filippov Signed-off-by: Barry Song --- -v2: * add comment about the approach of using a static inline func, thanks for Stephen's comment 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..9e0507af6253 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 should evaluate their parameters, for unused parameters, +cast them to void: + +.. code-block:: c + + #define macrofun(a) do { (void) (a); } while (0) + +Another approach could involve utilizing a static inline function to replace +the macro: + +.. code-block:: c + + static inline void fun(struct foo *foo) + { + } + Things to avoid when using macros: 1) macros that affect control flow: -- 2.34.1