[PATCH 0/3 v5] Add cond_guard() to conditional guards

From: Fabio M. De Francesco
Date: Sat Feb 17 2024 - 05:59:27 EST


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 <dave.jiang@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Suggested-by: Dan Williams <dan.j.williams@xxxxxxxxx>
Suggested-by: Ira Weiny <ira.weiny@xxxxxxxxx>
Suggested-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
Signed-off-by: Fabio M. De Francesco <fabio.maria.de.francesco@xxxxxxxxxxxxxxx>
---

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