From patchwork Sun Feb 4 17:31:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 196564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp509690dyb; Sun, 4 Feb 2024 12:00:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1cvBNR7T7WbxAp8w/eJbHajKUbOuNK0XVcAqMKPn87I3JGhNlRY/NTZPAiNmw9gIFK9+3 X-Received: by 2002:a05:6214:2262:b0:68c:3d2a:47e7 with SMTP id gs2-20020a056214226200b0068c3d2a47e7mr5684844qvb.27.1707076819057; Sun, 04 Feb 2024 12:00:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707076819; cv=pass; d=google.com; s=arc-20160816; b=qseJPjmejtGPehgkUMCNep9UTP+0XaA4y2FaNsgQLbboCAg7OUxb1iZ5uHBh37EP4x OK3/4w/K++yBMsIkh8HSq6yhLqAedOnyiR6sYKzL7AIeZzzYuVOh1BFpbTRaUSpyd08v 0u4T/g34zQyZeTFShCEzrVyJjOSKbzZFfAmHLvsolY8dQOzQS0TWJnrfHmwhbgGN5qgg jMti/lKzSirOm6GIoLcwJJhieNFI6422N8RhMSDqokND+xqOxwoYaGIM6sWmyKm1E2wN EYAtCCR1jZBpp0dsrrpkoBSzpQh3bySue9w/oGfmsnUtNEZzait/6IRmqmXP+ADvh52y i0SA== 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=kiq6XKO2s/Vt5J0mKGswTZctljVIo86+92I1/VjwfZs=; fh=RS1TV/PqVZeHwZnQt2atoNa/3Az+0y2NjyQZYRpJMUc=; b=a2yGElebGDfqCJDSUUCxT8JmOF2hvH8eSReKd/Jl5gJdWta3fyaYhDm6i08sdXayfH iqGND4zWD/2ZtEiyFzo0S4MbiEMyYQCIDboDvIAppU4J9VFjpjJ/cLmLh6e18RgWabFl zz2ikBTK2i5pEztCYw0yZKcZkgrADIQ+Irz5Ztyb4kEz+OyQkp3Q1up6v2lK0FMo2nP+ 6ckcEQ0PUK7W6uhOXmA5p+UlpITm/a4KkEVVcaebzDcjSfdOEUdqL7HHlLRkc3yI+ufu 3ghZfgyxPZwgG3xvVzCrgqIrg136js4vwXoug64m7Atw4KhtzasQw+a1Ucc2R/av6ukj +8WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MQXBhZxB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51828-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51828-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWPN06yCCv1j2bxFGqTz7UJew3WeSin8uKSQPxkBfMxSyHLrjubZKT59e1Cpw26SHHnfBSu8Ua4jS3aU7jQu0tuTRDLwQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x7-20020a0cfe07000000b0068c805120b4si6798766qvr.55.2024.02.04.12.00.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 12:00:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51828-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MQXBhZxB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51828-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51828-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8EC1F1C2201C for ; Sun, 4 Feb 2024 17:32:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C69C249E4; Sun, 4 Feb 2024 17:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MQXBhZxB" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 ED4F424205; Sun, 4 Feb 2024 17:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067879; cv=none; b=NuEzr8g4gS5OUkptRgPh9oZ5l2odzXYqTxvK8DPQnSqPwhtzcPJ4sGmjEOq9xYhME2or9hQiU3jTrTFUqys12r6dTwek9Y79RiLX6O0cZY4HuEWgNcQ+VpiQsl5X2mqVezbFQd7x8S5FtWgOKJhHy7eR8NslITOSnlZTZIrMYgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067879; c=relaxed/simple; bh=p7G9lDJWvB8+q1rJ6NP2F0RKeAhxis7arnOWlFYNUv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X9MTH/DTdUMxSDtJd+oR9I5i8dMioGWzL1byykEm+74p5xgTxSQNEndgeMMWguP2L5xVRr9kYdfuXZ2wmZcTsKD5gWk/RZwAq8JtWKmAR8OJXdyEAhHxn9/RFJFz0VQpvCfR5zElQW3tRozuLBzM8w3zl8pSMGFbj84e5Vrs5u8= 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=MQXBhZxB; arc=none smtp.client-ip=198.175.65.14 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=1707067878; x=1738603878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p7G9lDJWvB8+q1rJ6NP2F0RKeAhxis7arnOWlFYNUv4=; b=MQXBhZxBCG91LWkCi+TZggWjilUPfljdMBCBdwSoWijEhmeYJwejSJyR 6BuYhwcPLRX+z7zeUyp0mNPPxqzKDW/qcSNoD+LTM+m8jqY0Muu7g3hq1 k1DBN8UQ30Kf474K5FNEf/CTkJJE5+qTBBj7ESRjQp2EaUqoyYdPvkldy 60K9sJjQrzAdV8nvSGNF+rO0RaTEeS8UGST2ku99W5A/KKJ7rE4XgD9nz uWb+32zTI145RUVCysHoWrVv5d/3nDM1G52dV7UMbhb7875Axup3f0Suq grtY3RU+7VDkQSZ4ici8N20I01YzJhCl+KVdTM4ntSm2+e1SBhuIrwdGt A==; X-IronPort-AV: E=McAfee;i="6600,9927,10973"; a="4225903" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="4225903" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 09:31:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="31626383" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.intel.com) ([10.213.2.137]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 09:31:15 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: Ingo Molnar , linux-cxl@vger.kernel.org, "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH 1/2] cleanup: Add cond_guard() to conditional guards Date: Sun, 4 Feb 2024 18:31:04 +0100 Message-ID: <20240204173105.935612-2-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240204173105.935612-1-fabio.maria.de.francesco@linux.intel.com> References: <20240204173105.935612-1-fabio.maria.de.francesco@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789999782917231172 X-GMAIL-MSGID: 1789999782917231172 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 more statements in a block) that is passed to its second argument. That statement (or block) is executed if waiting for a lock is interrupted or if a _trylock() fails in case of contention. Usage example: cond_guard(rwsem_read_try, { printk(...); return 0; }, &semaphore); Consistenly with the other guards, locks are unlocked at the exit of the scope where cond_guard() is called. Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Reviewed-by: Ira Weiny --- include/linux/cleanup.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index c2d09bc4f976..3826e8ed4e09 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' are one or more + * statements that are executed if waiting for a lock is interrupted or + * if a _trylock() fails in case of contention. + * + * Example: + * + * cond_guard(rwsem_read_try, { printk(...); return 0; }, &semaphore); + * * 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,10 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ #define __guard_ptr(_name) class_##_name##_lock_ptr +#define cond_guard(_name, _ret, args...) \ + CLASS(_name, scope)(args); \ + if (!__guard_ptr(_name)(&scope)) _ret + #define scoped_guard(_name, args...) \ for (CLASS(_name, scope)(args), \ *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1) From patchwork Sun Feb 4 17:31:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 196561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp486779dyb; Sun, 4 Feb 2024 10:49:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/6MhdLFgoAvSx6L1bFnsr0IdGrF9+JwF+JS574NFsiJ9dh2UWugDLsLFCzpy+baVLMJM6 X-Received: by 2002:a05:6a20:94c8:b0:19e:5fcd:2faf with SMTP id ht8-20020a056a2094c800b0019e5fcd2fafmr3706471pzb.32.1707072590657; Sun, 04 Feb 2024 10:49:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707072590; cv=pass; d=google.com; s=arc-20160816; b=HtCm4S9njxGdNcbfv1Vq6+RCorA/szmbVzyI21X8CiW6NY+s567YhfFzFLxY4Bytf8 XdWTyLWD2WVfU1sor6mXcuoF7RWKI/2e5SLzRJrZ5L3sFKrVazTyDXT1PV2rnI5dJqOi jUyC6f6hr/l4TjLugtyZ6N1R6zRccjrw+jAq6r9mKPfp2etypOMBxk3gcnaH9Pt/InJp IAH+G5a+YkdesIBAq8OoJZXIa4hhn98y1rWJODJ5flrSq3RW/8qtLSRp3v17bIMraUvb vT1Wfk6cmw7sa8y5FwqdPRA28bGZlJh2UaRhO7RZi3BFgwyIc0KD4tAJhjHEoiQNd4pw mKTA== 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=QTa8tNa8jy3TVEJ6cWHQo+L4WauI+ElnUx+hUNLlCyQ=; fh=TGNLdNgL4f7q4fOC3FSAcoKqjK7h65ko3Ruz2h/7E6c=; b=nw81KkjxEF7psE7noL6kykNC7jrhKpSuztIyCcn8IxiA9thNpR9IBTTFa2sOpxfD1a jqI7ny5K1RsKW/2IZJjKEYUCUU/xB7ye6CnHme0xLWuo71ZGcM3QlW8HX1mMeuzSOl4A 0SHkglX5VkXtEosvmcCCAAAbdBOhHgTDFaHhoGdFOwbMLJwpWthkbjj6TfjLM7DCHJ1c +O01sJgiNCkWBDv2lFFs/rmuRV6ZzcgpJSd8OsxaxJ5NR8rmDEwJI3dsja4U34TLS562 rMKBK2j8muLQ+ZlDCiGYD5/03hSFClakyKzOa0VLiN0uMzCH/3yxCN22lU6uc4xwni1u VqJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZMxkc0Bj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51829-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51829-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCW86AOS31iPk5RJ5MEF5VD/BcDEdobLoftr8uWraGvvBq7F/g3kf4vb/DGtvHX3z8arUylDGtyjRlLQBmsWnsjdYU46OQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 20-20020a631854000000b005d5edfb42a0si4813839pgy.843.2024.02.04.10.49.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 10:49:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51829-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=ZMxkc0Bj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51829-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51829-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 5221BB226EE for ; Sun, 4 Feb 2024 17:32:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E40228E3E; Sun, 4 Feb 2024 17:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZMxkc0Bj" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 064522555F; Sun, 4 Feb 2024 17:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067882; cv=none; b=h751M6A+pLhtNhw+v9oePFwFjMJp/BH64EdcBu8WlmeOcSWMmj7QDDFLyt0wJge7ca414HhVkB6tMD2tZzRjebG8uoVcxdEAUFh22A6mWBKZ2DW0p+hJXU2Opfz9LExCUyOz7g9DFhS413WRCVl//Ef00iKBEH8Ecdp2G/HpEBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067882; c=relaxed/simple; bh=FPf3c+XFlSNb7MJJi6PdgXBeD5uKtm42qLdX4zSVwgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hov32Us3IJxqWeReI0HuelDWSzx4yklBPVyaFcTHp65rcxUMCV8SMWLwBZ0X97EG5g/ai16+kiVCYYCIXES5MxVRXXquv3roquXsTwid9DI7N7N4XPmBE9hpkKasOlKN2opsg2D3/SU92oorZfhGx6FkhvUQxlA0D/pSz0ohY7c= 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=ZMxkc0Bj; arc=none smtp.client-ip=198.175.65.14 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=1707067881; x=1738603881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FPf3c+XFlSNb7MJJi6PdgXBeD5uKtm42qLdX4zSVwgw=; b=ZMxkc0Bj8IwXyGhz+drDD2xmCxXDcKcMNa2mK+C+XhlilrP626tYWYzB ZmFcOnXjgmosD0TTTy9KSza+w80ZRUbUOdvQpG0Qkz/BMTuAh+SjCX29V 56//Dlu+TqHu/Aqwgi9GeDN3dzu5/fc0rXXhEMepdj63xRuMN+VCmWmre G/q+2+7jZX0fZ7zYdlVxCP7REmDy0pkkMyVC4lvQ5GSvKzJCXqzPqaP+b u2ni8EeKIhs/fp67gPwF6jMuzZ15TYktAvro36iqIfHzya7NWe6HO0zL2 mKlq882bWWPIBCMHHbD1nElG9P/iMcrMo4DNVVM7VPFswhoUZ97hHQzZC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10973"; a="4225908" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="4225908" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 09:31:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="31626386" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.intel.com) ([10.213.2.137]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 09:31:18 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: Ingo Molnar , linux-cxl@vger.kernel.org, "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH 2/2] cxl/region: Use cond_guard() in show_targetN() Date: Sun, 4 Feb 2024 18:31:05 +0100 Message-ID: <20240204173105.935612-3-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240204173105.935612-1-fabio.maria.de.francesco@linux.intel.com> References: <20240204173105.935612-1-fabio.maria.de.francesco@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789995348557826268 X-GMAIL-MSGID: 1789995348557826268 Use cond_guard() in show_target() to not open code an up_read() in an 'out' block. If the down_read_interruptible() fails, the statement passed to the second argument of cond_guard() returns -EINTR. Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Reviewed-by: Jonathan Cameron Reviewed-by: Ira Weiny --- drivers/cxl/core/region.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 0f05692bfec3..bd3236786a25 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -666,28 +666,20 @@ static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos) { struct cxl_region_params *p = &cxlr->params; struct cxl_endpoint_decoder *cxled; - int rc; - rc = down_read_interruptible(&cxl_region_rwsem); - if (rc) - return rc; + cond_guard(rwsem_read_intr, return -EINTR, &cxl_region_rwsem); if (pos >= p->interleave_ways) { dev_dbg(&cxlr->dev, "position %d out of range %d\n", pos, p->interleave_ways); - rc = -ENXIO; - goto out; + return -ENXIO; } cxled = p->targets[pos]; if (!cxled) - rc = sysfs_emit(buf, "\n"); + return sysfs_emit(buf, "\n"); else - rc = sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); -out: - up_read(&cxl_region_rwsem); - - return rc; + return sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); } static int match_free_decoder(struct device *dev, void *data)