Message ID | 20240208130424.59568-1-fabio.maria.de.francesco@linux.intel.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-58103-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp198885dyd; Thu, 8 Feb 2024 06:19:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAMvuAXQzv1Fodn+u2BVkZJPNszoUeJsuvA82s9nCMXF1GRS7+vbZ3r42JnopcPW5XcZjqoVCXwUv9XP6My9xiVairSA== X-Google-Smtp-Source: AGHT+IG4fIRwCTiLHoIceX2ZlLswMwK9cZ0c2+IOPnMI89idz6GUKuwwncEyJCAOviwObkpooyCd X-Received: by 2002:a05:6a20:8406:b0:19e:99be:c53e with SMTP id c6-20020a056a20840600b0019e99bec53emr8475124pzd.48.1707401952267; Thu, 08 Feb 2024 06:19:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707401952; cv=pass; d=google.com; s=arc-20160816; b=Ad2GFSWRb7J4Vtj9ePxUODOJnWTctOfYl3FNOLDvRRShmS9aEHGrVcCdW2hqkbDrWe C1fu6Ya5VAdU+LfmNBPScr1vwba+3l7iXt+ZNAE1JzM4s5RXvZUw4K5FF/imuT9JyJCf A7SnPBl/AswvWprzTiNt5GYC/4jqrEKXNRuEFTWmvGaVcqby/xRwEp+2WJclcbtNV5m7 WNA8eX03gmWbQ1NbESeoVDc5FkLsvpEPQK/ris9W2/2J+U4e8SIbcXEl8rZgPdqbiSUP Oi3isc/eytY3QB3qD1D9RFO3l+6pCE3SWMAHPuVvVI26txo7574xbphBp6Yv/jpQ4u9N 7UTA== 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=DpBnXZZ0z3Clzg4vpQc3iWUMWCuQsKjW2B5BToW0Le0=; fh=wEhF4dBFK7JSPdzftSul1lQ0NkLDA4iI6nJwizjbWq8=; b=zoE0uh+u1V502Wfs1WZ455zZJh+0W8Sp7ACSQEqv3us4TTb9bmjCZRLlD1Shy3SCAA OZgU75JPL8Bls/oajVN/YMzuZOn2yon5lC1JX5vy0MRh8CIfw2hmAC8g0bHL1K59LcSL QGjEaxfDXAusd0Q68Aua/E2+PuL9VxiqSxfec5meOUO5bkDQeXIDg1oa+A/IaKpqhIye xth41YyrRFKDPsxVHOnG7Q9bqhYU4zFfRD1OoZ2xkbmsqaY27e3XJ1wrlsYNcPN8JQSd qIj0QTiEfuzNGy4aQUibcqqr+6a4smWM92I4IPHtmV6fDBqc8bsGF+tJxJJYDc7BAM6D OGFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XUt2vObF; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58103-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58103-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWVd66ntk2fF694xc+44/i7+/9gYp6LRKzhDn1cuUx6M3Z+E8c23HYqIahp/G7sLv24yIz+LxYE9s9jjEIJLxjLrxrGPg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 5-20020a170902c14500b001d941c96b6dsi686458plj.647.2024.02.08.06.19.11 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 06:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58103-ouuuleilei=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=@intel.com header.s=Intel header.b=XUt2vObF; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58103-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58103-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4133DB257A3 for <ouuuleilei@gmail.com>; Thu, 8 Feb 2024 13:05:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE2C91E4A1; Thu, 8 Feb 2024 13:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XUt2vObF" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 25304763E7; Thu, 8 Feb 2024 13:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397478; cv=none; b=TR7knlI0r7dmONLNtp0dsUkMDpQk1PxAsQvMP6orctXlNB/oqPsb6r2/vZSXgGZxQBXFOkiSrIeydLzit2fGuCHWqXUInQ9sFJ7wMd6ob/Grn7nQ+xZHdjzD4BYaImGWs14Y+Z/MDB2mrSb1/yn28FqyficLtdsnml2ymy7S8wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397478; c=relaxed/simple; bh=h7hT0zAQh1US2oNbTzNgMEdve8p7uZ7zf8jzekAxRAs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kMyR6m+wQArPC6nnfGV9U081kuwUIsar47vABuCIAOIWZ4QY6vjSuiL6lU0mZqSu6saFfFFT1/lTxiWV+j5lROYyfrjg4/mrB19atbUfFJuetNAUSiZn85Pz+pLGT44P3XTTSpZ2NCTsr4I4rwGS5bqijzqaTALuCKEZhMf9ANs= 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=XUt2vObF; arc=none smtp.client-ip=198.175.65.18 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=1707397475; x=1738933475; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h7hT0zAQh1US2oNbTzNgMEdve8p7uZ7zf8jzekAxRAs=; b=XUt2vObFtyYejNQSPSVDwZvFxKJ+Xfylt6kU8aLM+pa5yMijHGcUpE9h obttGQc/0/ZDNxzYWxg8wgVSjrLU0ZhvsefDzhDVeHYOIGS52u8J2eL0l c5LUe7FrDGxpneI7k2feODklkksH2Cv5ziHCA7hAYxrxmXgPcLjHCqoEk 0EYjPFYefv5DdN+x2nOm2MnwhgGOP/ZjqHIMn/l3NCvjNPig2wc6ymOhW yLnJvo0Hh7vRcecEHJQFkYWpRDYrEqjdv3TM13CFlmOLa6Hli2l5Kz397 HXi5M2kW3j3y189PwcZd2U3Foe5e8Mkelo2R65NlMrnRzSe2/3OkHea7s w==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="1354943" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="1354943" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 05:04:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="1884027" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.intel.com) ([10.213.2.200]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 05:04:29 -0800 From: "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com> To: Peter Zijlstra <peterz@infradead.org>, Dan Williams <dan.j.williams@intel.com>, linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Ingo Molnar <mingo@kernel.org>, Dave Jiang <dave.jiang@intel.com>, Jonathan Cameron <Jonathan.Cameron@huawei.com>, Ira Weiny <ira.weiny@intel.com>, "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com> Subject: [PATCH 0/2 v4] Add cond_guard() to conditional guards Date: Thu, 8 Feb 2024 14:04:22 +0100 Message-ID: <20240208130424.59568-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790340709274123611 X-GMAIL-MSGID: 1790340709274123611 |
Series |
Add cond_guard() to conditional guards
|
|
Message
Fabio M. De Francesco
Feb. 8, 2024, 1:04 p.m. UTC
Add cond_guard() macro to conditional guards and use it to replace an
open-coded up_read() in show_targetN() and remove a block marked by an
'out' label.
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fabio.maria.de.francesco@linux.intel.com>
---
Changes from RFC v4:
Changed the interface of cond_guard() to take a variable to store
a return code, the succes code and failure code, to enable a
later check of the returned code in that variable.
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).
Fabio M. De Francesco (2):
cleanup: Add cond_guard() to conditional guards
cxl/region: Use cond_guard() in show_targetN()
drivers/cxl/core/region.c | 16 ++++------------
include/linux/cleanup.h | 15 +++++++++++++++
2 files changed, 19 insertions(+), 12 deletions(-)
Comments
Jonathan Cameron wrote: > On Thu, 8 Feb 2024 14:04:23 +0100 > "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com> wrote: > > > Add cond_guard() macro to conditional guards. > > > > cond_guard() is a guard to be used with the conditional variants of locks, > > like down_read_trylock() or mutex_lock_interruptible(). > > > > It takes a statement (or statement-expression) that is passed as its > > second argument. That statement (or statement-expression) is executed if > > waiting for a lock is interrupted or if a _trylock() fails in case of > > contention. > > > > Usage example: > > > > cond_guard(mutex_intr, return -EINTR, &mutex); > > > > Consistent with other usage of _guard(), locks are unlocked at the exit of the > > scope where cond_guard() is called. > > > > Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> > I like the defensive else {} Agreed. Re- Reviewed-by: Ira Weiny <ira.weiny@intel.com> > > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > Cc: Peter Zijlstra <peterz@infradead.org> > > Suggested-by: Dan Williams <dan.j.williams@intel.com> > > Suggested-by: Ira Weiny <ira.weiny@intel.com> > > Reviewed-by: Dave Jiang <dave.jiang@intel.com> > > Reviewed-by: Ira Weiny <ira.weiny@intel.com> > > Signed-off-by: Fabio M. De Francesco <fabio.maria.de.francesco@linux.intel.com> > > --- > > include/linux/cleanup.h | 15 +++++++++++++++ > > 1 file changed, 15 insertions(+) > > > > diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h > > index c2d09bc4f976..7b54ee996414 100644 > > --- a/include/linux/cleanup.h > > +++ b/include/linux/cleanup.h > > @@ -134,6 +134,16 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ > > * an anonymous instance of the (guard) class, not recommended for > > * conditional locks. > > * > > + * cond_guard(name, fail, args...): > > + * a guard to be used with the conditional variants of locks, like > > + * down_read_trylock() or mutex_lock_interruptible. 'fail' is a > > + * statement or statement-expression that is executed if waiting for a > > + * lock is interrupted or if a _trylock() fails in case of contention. > > + * > > + * Example: > > + * > > + * cond_guard(mutex_intr, return -EINTR, &mutex); > > + * > > * scoped_guard (name, args...) { }: > > * similar to CLASS(name, scope)(args), except the variable (with the > > * explicit name 'scope') is declard in a for-loop such that its scope is > > @@ -165,6 +175,11 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ > > > > #define __guard_ptr(_name) class_##_name##_lock_ptr > > > > +#define cond_guard(_name, _fail, args...) \ > > + CLASS(_name, scope)(args); \ > > + if (!__guard_ptr(_name)(&scope)) _fail; \ > > + else { } > > + > > #define scoped_guard(_name, args...) \ > > for (CLASS(_name, scope)(args), \ > > *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1) > >