Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp151709rdb; Sat, 17 Feb 2024 02:59:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfq+hem9M4LkF4FpvnCHh9Iz5GtgnJ59KqxZYsGIyLiL8p2uJtUomi8HYDQy6srrrTnMwkOgk8kDjGXeSyYaKBmVChUZDNqBl1d67Gdw== X-Google-Smtp-Source: AGHT+IE4VXgjpDL8F6cNsT1XfsEAauZ0IG8VgjfZWHactqJB14ofhnK7R4h8YbdbRfxlFGhQ7+TL X-Received: by 2002:a17:903:98f:b0:1db:b59a:fc5b with SMTP id mb15-20020a170903098f00b001dbb59afc5bmr3106272plb.39.1708167567564; Sat, 17 Feb 2024 02:59:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708167567; cv=pass; d=google.com; s=arc-20160816; b=UGwnOsGuLJtOuGHBzD4zenSzSH0siv3XhEGptf/77JuYRT25Gx5Q7+NlhEyOsI8Uf0 E56v7wsZlvleYF8H6+L7Yrr9Gh5MZt591m3iqC5fznJed19Vi3F7mq3nRvTVMWKpmjZJ XDVKpDvZOENeNSnag6z8NKF3MVrHxfnrp5kbxavqzZz98/yMr1CMIyXidDIlutABGDEG d97IUzIjzIPwABHRABPYKZ+FOUUif5OEb3zJWryVViST/c5ftf+5HgVi5B6sjUQE20Br G/i4s7aL24I2QpUthjzqieB00zA/kqv7p7BnDyD+TZ340P77Ro1peLsPRkx8ZPX8ZVXb 6ZkQ== 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=q6Z777R4HNb7RCEHRAfmndCx7rT0UxkUX1F0owGBi1g=; fh=tt9aLUCPtZBDntIGGgm0DfYgLXsZUYzWtYgxP3QUZ1A=; b=VVApJUJe1S2hT0tuxe7f/vBavi5dYZ3ASq3rqKSj0+5LbA5bI1oRDPxw140KeT6iWF 4BIHDgHaa8tq7ETyB0CSz4tGCHGsg525aDR/JVUsxUG2hfG0ntZ5iCFBRFWxL45zfaJx CI1npNy05pUZi3tYOmlr/8MWo1W+5xKU1iHbWBIf8FAiIv0iHWv7xY61oUiLpzCedCCg gheZTjLqUwuWowbAm4N0KwzM38vjtwDF35bpN4MKZwA2Y9OnPhvqFp5Ldp4o/bxCM+xI fbMnQ9rkzJwlErCScehrNNT8J0aYpH9MQ4WkmCaQsl642tRP2e4iuIqi0/nvw3c2PfWH FKZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="DV/tyjgM"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l19-20020a170902f69300b001db57f32f49si1321010plg.460.2024.02.17.02.59.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 02:59:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="DV/tyjgM"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49343282448 for ; Sat, 17 Feb 2024 10:59:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0079359B62; Sat, 17 Feb 2024 10:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DV/tyjgM" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 5646059B52; Sat, 17 Feb 2024 10:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167560; cv=none; b=tLMq9eenzFEwJ0tIpRj9YFK/CrmT/N62tZ2+5iKT5B98Nu03Ozcls+AfU2hNBUW6zgk16saR9cshVZ+bmKB4hmYISIzR5CA8+x2kZ6CWAxoww8lTJF1dN+wkDo9zJO1B0ix5279qIb7qW0pGgz8xRtVi/FGy0gUkoEONW65YAzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167560; c=relaxed/simple; bh=GdLaoOmmqrV/IjtLPmRhjoptn9Egef0+L9PbSHcVQLA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=i4kH3Q8hVqe0hNlUu64JNQi7C6Lj8PJC7XOGVfNF+jG8reFABArG8zFhVhCJ7hlc1oJuGKUw5gECKxdJatAdW368w85UJU8iyVfB8JspAAYZ6TWCJKQm5wPxL2GxK0hm2oK1wpE3+B4hEEkKepNty3TcsyxaLf3/M2QGFiv3oN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DV/tyjgM; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708167558; x=1739703558; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=GdLaoOmmqrV/IjtLPmRhjoptn9Egef0+L9PbSHcVQLA=; b=DV/tyjgMsin7VMgLJ5uofVOxLB4Tot1fZhQU65LvxR8w2Suo/ZjSHUgF qZp7UYhYfnAmxNnECa0wlN2NNrbUo1uXdlgrbyeI+eOIRuLmCAqoOrqs4 rwzAA98BIs54CxsVltbjgDO6LPb6k04UnqkACf1rtfFkpmCLtm+1eUlp+ xSJqY9AJUSg605dNxxGBXvtUJeXsOXOUwGmJccA7jeJLF5yOLWpfogx8b 7c7QlnFUHPWEQ2KtMXt27R15sQ9hcBNNrpS9x/T5onmko++5PuBgCL7X0 Bz65nms6Zfmt9UbHSsryJ6czJumnSsYbVJ8XtjUQ9Nd188TYfwJI6Pgdt g==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="27746701" X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="27746701" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="4348703" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.3.209]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:14 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Ingo Molnar , Dave Jiang , Jonathan Cameron , Ira Weiny , "Fabio M. De Francesco" Subject: [PATCH 0/3 v5] Add cond_guard() to conditional guards Date: Sat, 17 Feb 2024 11:59:01 +0100 Message-ID: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add cond_guard() macro to conditional guards. Show how to use it by converting two functions in drivers/cxl to replace open-coded up_read() in show_targetN() and in cxl_inject_poison() and avoid to 'goto' to a cleanup block marked by an 'out' label. The second conversion is added with v5 to show that the most recent implementation of cond_guard() can also be used more than once in the same scope. Cc: Dave Jiang Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Suggested-by: Jonathan Cameron Signed-off-by: Fabio M. De Francesco --- Changes from RFC v5: Changed the interface of cond_guard() to take a statement or statement-expression as its second argument to conform to Dan's suggestion (thanks). Changes from v1: Fixed a grammar error in the commit message of 1/2; replaced the name of the second argument of cond_guard() with '_fail' according to Jonathan's comments (thanks). Changes from v2: Changed macro's implementation to add an 'else' to protect against it being used incorrectly within another if() block. Suggested by Dan (thanks). The Reviewed-by tags on 1/2 are not forwarded because the implementation of cond_guard() has changed. Removed a redundant 'else' from show_targetN() in 2/2. Changes from v3: Added braces around empty body in an 'else' statement in cond_guard(). Added Reviewed-by tags (Dave, Ira - thanks). Changes from v4: Made it possible to call cond_guard() more than once in the same scope. Jonathan suggested a more elegant implementation than the one I had thought. It uses an exhisting helper instead of creating an ad hoc one (thanks). Added a second conversion to show that cond_guard() can be used twice in the same scope. Deleted the Reviewed-by tags from 1/3 since the implementation of cond_guard() has significantly been reworked to allow multiple calls. Fabio M. De Francesco (3): cleanup: Add cond_guard() to conditional guards cxl/region: Use cond_guard() in show_targetN() cxl/memdev: Use cond_guard() in cxl_inject_poison() drivers/cxl/core/memdev.c | 19 +++++-------------- drivers/cxl/core/region.c | 16 ++++------------ include/linux/cleanup.h | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 26 deletions(-) -- 2.43.2