From patchwork Tue Oct 1 22:30:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13818811 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (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 534C919CC39 for ; Tue, 1 Oct 2024 22:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821850; cv=none; b=d8mRQ82WQQeZx5JiF8K9PIp4ERorYIROhmmhRZnunDnjPJOJHnqgCQHMFnsz2Zw6SJ66Fy49LNOC3z9r6TTOyH7Ok0SaDnqptS2OXbX3k8cREXBq7aCqSmIW4g2iXnghmuc+4wVg8I7OtVNDMyfsJQjFcLqUpiWFTttVTM+9iqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821850; c=relaxed/simple; bh=JGTFl5VoZdw/HMSx+xMjDWjUeDuNOPJLXAn6T5BdJYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=swLOsKtOgZHQvWu3j57xyzKsug2SKuCiAZ8JQdbW63IccUqRJVjutF9TODuTGmRSn1sHq74kvjN4f6C4jPylo1WDUghCtWA+ZY5iGMwKrW85kdx7Ikjc3YvjD6DWsANvdKycwRE+fLK9IuyQ1r7FJxtp+egfDcrGe6gC6HK1ka4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=npXPjI8S; arc=none smtp.client-ip=209.85.167.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="npXPjI8S" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3e033e66a31so3831116b6e.0 for ; Tue, 01 Oct 2024 15:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1727821847; x=1728426647; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zQt8/ibZGmr7UQAMTn5RryHz2eZfh/xc9yurTJPgOaA=; b=npXPjI8SwU0So5l8m4ZN22qFUG5G5lrl0EmQJvjDGAMv1HD4W1YIGL+lxt7dk8ORkr +x5ztrLQI6JfDh/TTWOXO3gyT7ZHhRSFeoMG2dkmkDgv72S/JCG9NjYfPsP0cQEYjYcJ rjn4WFgKBtvDIHMN2h2LwDukfBnUbSTI9RwODUaA/6qu8vl6pfbSzW9WybkCdit2LAAs vcGfpZsqxryP/Kx8tkWrUipLgj8sQk7SYTYbqDTadMjcHjsoSwBGoDZd2x5daE18Zazl 55EG1RBU01GJqCAFBXuV5KmkEXNyS7cwC79go7xvJoWl3Q/JIESh0DIk/f/cJx38BB/d 8Dug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727821847; x=1728426647; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zQt8/ibZGmr7UQAMTn5RryHz2eZfh/xc9yurTJPgOaA=; b=CEDi6OjeanvMl13muGC7TR3PMqoGmGM4ixm23JcIotj1Gk7u3RM7eyU1k0C1mAdJjs 2XmT6mtP/caO7WdpJcaX6M/XolM2hK99YH7RsWzhGYjN1Of5LvoROm4pEedELcZigPQU ZpOFQAkOHZ43Ll3lnVFlNEwJCweUFOf2BJvUOMBOmeaB6A3kByShkoHdnFTOmZNpBwYJ j9Vd+qrSZNeoQQfWSfrnvhW7wsD76sFp7oeIyBhepgDZ3+75mJLIm7QsNd2UXelC1WHR GtvOz+JJGSp6sOau0Rk9yr3RTIaOybH412h4FQak0aNu4Ft80+vOlTLYqsHJMqFHrkRS mdnw== X-Forwarded-Encrypted: i=1; AJvYcCVJSWL0bmIaAL/n78vdyJjqgpUqEMXvJdJCjURh7b6zwudR0h82YxVJIkMhkVtGgAmm/5up2w/S6w8=@vger.kernel.org X-Gm-Message-State: AOJu0YwXT+toNwjI9wVZx4CfIMzGlzIpg2/vv2rDYapIqK9nDzuqeg++ Jb+tojAeJoO2XUmoJ7If780CmAwWtJ6+D9sbPNEKC1Ww3aGeelGaQm5SHn72CqY= X-Google-Smtp-Source: AGHT+IGhvVHHB1hJmRFs6zxZiSrw/UPrPWpHoFtdU1cOKU7mjPFozjX8w0AobKNYjmXrmqNGa3i2Pg== X-Received: by 2002:a05:6808:1493:b0:3e3:b10e:c2c7 with SMTP id 5614622812f47-3e3b41879eemr1066223b6e.35.1727821847469; Tue, 01 Oct 2024 15:30:47 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5e770eaa056sm3002097eaf.31.2024.10.01.15.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 15:30:46 -0700 (PDT) From: David Lechner Date: Tue, 01 Oct 2024 17:30:18 -0500 Subject: [PATCH 1/3] cleanup: add conditional guard helper Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com> References: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> In-Reply-To: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> To: Peter Zijlstra , Dan Williams , Linus Torvalds , Jonathan Cameron Cc: =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-cxl@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Add a new if_not_cond_guard() macro to cleanup.h for handling conditional guards such as mutext_trylock(). This is more ergonomic than scoped_cond_guard() for most use cases. Instead of hiding the error handling statement in the macro args, it works like a normal if statement and allow the error path to be indented while the normal code flow path is not indented. And it avoid unwanted side-effect from hidden for loop in scoped_cond_guard(). Signed-off-by: David Lechner Signed-off-by: Fabio M. De Francesco Reviewed-by: Dan Williams --- include/linux/cleanup.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index 038b2d523bf8..682bb3fadfc9 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -273,6 +273,10 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ * an anonymous instance of the (guard) class, not recommended for * conditional locks. * + * if_not_cond_guard(name, args...) { }: + * convenience macro for conditional guards that calls the statement that + * follows only if the lock was not acquired (typically an error return). + * * 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 @@ -304,6 +308,13 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ #define __guard_ptr(_name) class_##_name##_lock_ptr +#define __if_not_cond_guard(_name, _id, args...) \ + CLASS(_name, _id)(args); \ + if (!__guard_ptr(_name)(&_id)) + +#define if_not_cond_guard(_name, args...) \ + __if_not_cond_guard(_name, __UNIQUE_ID(guard), args) + #define scoped_guard(_name, args...) \ for (CLASS(_name, scope)(args), \ *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1) From patchwork Tue Oct 1 22:30:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13818812 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 3508E1CF5D1 for ; Tue, 1 Oct 2024 22:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821852; cv=none; b=ANR4B1Om71Q6oO1jJ1kjV5oGsmkUZSodUxeiIUkQxE1o5g7qMbqNL1wGfGVPtdDSe17bhyyWII+eNb+tucYV26J4yjuSiCuMq3mKokav1aiIi/8aHp7/1ua3EdfzTsBOkjIOQ839lDcW4S7BBxI154FEw8UapVZXRLxKffdDgO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821852; c=relaxed/simple; bh=yEmxUF8NvIZhxJNK3VZlTS7eTyiN+Ut8yjRJbZlxock=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nsw6JgTyW84bSyUlgt7arx5BocquAywGDzHTvbOk5OUbmEKgWMBu1z8vue+CvEdlW4pBPGjN2PYP8nRhLCZW7j8LsxqL1rYaP/bX5LHnrly96/Tq7TuxItdUmrUPeXl+D9CE5fT5PYjb+vkGBsunH9xdn2owDU+id43FigpNCB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=aM/IKUO2; arc=none smtp.client-ip=209.85.167.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="aM/IKUO2" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3e03a5ed4d7so3178437b6e.1 for ; Tue, 01 Oct 2024 15:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1727821850; x=1728426650; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rpf61w6aK144lw1gfwbrMjBFwopIsPReXKSdcPJBI24=; b=aM/IKUO2mZ47JhOKG+XEVxc4/yjYb/WrSBVfs8PhBbcXvfLftZZ9PioyRk1QRUfh5Q PxI14cpa57I1oiBR87vuHYwB2hY/yToaDEeVgdSVBellPWWQY4WVskKrSR/FgLYQo1j9 4kr7RawAIcFQtjNdqVO0JA/O+S3CXptj/Ys/hWlXf/RjLEQUVOrtf7FyFh8NYVsOnQyB J5aJlT4WRU9lVplkrPYngIuOY/fUBxjlvjlyflsb+VLwKsPuLXfRE7Cj8tsyKYdHLHo7 kH01atRr2VDju1NBVynqVwSlP8N9HyhlNHsRQG/q/7xRJzJ75L7O2evzpSvejvLsQ9JS rP8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727821850; x=1728426650; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rpf61w6aK144lw1gfwbrMjBFwopIsPReXKSdcPJBI24=; b=rMlIVk26iWiNlr7QLAkO8aoSCn8AgRnwEHb0ADdX4j08Gwrt0k9ZP3tEqjozFg3+an L2K2SDC1WrcnJ9QKx0BW18ckwXiClOoxmzzRwS0etYxDErUxnizhUEvaKOGBCz/Ef/Uk QNoWCIFxdPJyeav+R7HWBpyHkacwnKWYc1mijQ/nvvvR2el7URAo29t8aZdYhxJasmyk FHKQ5Pe2aI2Vf7wVbeiusTDlp5Yc+YMv62BKiBtC8OdKcnYzDDBAhWWOEcagoXO4QC5B 99NDhzLUXMwhPY3aNm3HfYTydoEfYM7FyO2qSMviXCEPrjB1qdTWpMqX7ccbeTuCtL/S vZnw== X-Forwarded-Encrypted: i=1; AJvYcCVHlMPYuGi4jIMrcPCl3arEyH23HoOZXK9V27gMqExs/5L5qNoLgLOUC28jLze6E+xfl80O2IPi4Yw=@vger.kernel.org X-Gm-Message-State: AOJu0YzgIOJ8nFJSEys8Hby6T1gna+ob3nK8EBfXkmIw8y42XVbDTCz8 cxC8KGVEuyUE0GbrVwQ1zY4l8w9mftBg7K6td6ronmFzQLXVpJ1P6Yg48i86ueY= X-Google-Smtp-Source: AGHT+IECe1/6DpxPJtyNlXLYmMWiHW8Lt0uF/1UH+h2LA80+tHG3gxfcLs3eXm7cgXnKvbptv7D51g== X-Received: by 2002:a05:6808:3009:b0:3e2:8be4:49da with SMTP id 5614622812f47-3e3b417b5b0mr1293101b6e.42.1727821850348; Tue, 01 Oct 2024 15:30:50 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5e770eaa056sm3002097eaf.31.2024.10.01.15.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 15:30:48 -0700 (PDT) From: David Lechner Date: Tue, 01 Oct 2024 17:30:19 -0500 Subject: [PATCH 2/3] iio: adc: ad7380: use if_not_cond_guard for claim direct Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241001-cleanup-if_not_cond_guard-v1-2-7753810b0f7a@baylibre.com> References: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> In-Reply-To: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> To: Peter Zijlstra , Dan Williams , Linus Torvalds , Jonathan Cameron Cc: =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-cxl@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Replace usage of iio_device_claim_direct_scoped() with if_not_cond_guard(). This makes fewer lines of code, less indentation, avoids having the error return statement in the macro args, and avoids needing to use unreachable(). Signed-off-by: David Lechner --- drivers/iio/adc/ad7380.c | 70 +++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index e8bddfb0d07d..19a942035e93 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -569,15 +569,15 @@ static const struct regmap_config ad7380_regmap_config = { static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg, u32 writeval, u32 *readval) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct ad7380_state *st = iio_priv(indio_dev); + struct ad7380_state *st = iio_priv(indio_dev); - if (readval) - return regmap_read(st->regmap, reg, readval); - else - return regmap_write(st->regmap, reg, writeval); - } - unreachable(); + if_not_cond_guard(iio_claim_direct_try, indio_dev) + return -EBUSY; + + if (readval) + return regmap_read(st->regmap, reg, readval); + + return regmap_write(st->regmap, reg, writeval); } /* @@ -820,11 +820,10 @@ static int ad7380_read_raw(struct iio_dev *indio_dev, switch (info) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - return ad7380_read_direct(st, chan->scan_index, - scan_type, val); - } - unreachable(); + if_not_cond_guard(iio_claim_direct_try, indio_dev) + return -EBUSY; + + return ad7380_read_direct(st, chan->scan_index, scan_type, val); case IIO_CHAN_INFO_SCALE: /* * According to the datasheet, the LSB size is: @@ -909,31 +908,30 @@ static int ad7380_write_raw(struct iio_dev *indio_dev, /* always enable resolution boost when oversampling is enabled */ boost = osr > 0 ? 1 : 0; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = regmap_update_bits(st->regmap, - AD7380_REG_ADDR_CONFIG1, - AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES, - FIELD_PREP(AD7380_CONFIG1_OSR, osr) | - FIELD_PREP(AD7380_CONFIG1_RES, boost)); + if_not_cond_guard(iio_claim_direct_try, indio_dev) + return -EBUSY; - if (ret) - return ret; + ret = regmap_update_bits(st->regmap, + AD7380_REG_ADDR_CONFIG1, + AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES, + FIELD_PREP(AD7380_CONFIG1_OSR, osr) | + FIELD_PREP(AD7380_CONFIG1_RES, boost)); - st->oversampling_ratio = val; - st->resolution_boost_enabled = boost; - - /* - * Perform a soft reset. This will flush the oversampling - * block and FIFO but will maintain the content of the - * configurable registers. - */ - return regmap_update_bits(st->regmap, - AD7380_REG_ADDR_CONFIG2, - AD7380_CONFIG2_RESET, - FIELD_PREP(AD7380_CONFIG2_RESET, - AD7380_CONFIG2_RESET_SOFT)); - } - unreachable(); + if (ret) + return ret; + + st->oversampling_ratio = val; + st->resolution_boost_enabled = boost; + + /* + * Perform a soft reset. This will flush the oversampling block + * and FIFO but will maintain the content of the configurable + * registers. + */ + return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2, + AD7380_CONFIG2_RESET, + FIELD_PREP(AD7380_CONFIG2_RESET, + AD7380_CONFIG2_RESET_SOFT)); default: return -EINVAL; } From patchwork Tue Oct 1 22:30:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13818813 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 E252B1CF5E6 for ; Tue, 1 Oct 2024 22:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821856; cv=none; b=qY3tDRW57ZCBnm1gokHeavC9HemdHrYstCkv3At9V5Ws1ArPbNHeaFhWSY95G8dlWUBjxhQqrbfohpuh+KFZKJKQZNPhjMw40ElbmPtVvfLbefPz/Mex77KCPdOboWEyxDFoTL433eUilCzCa/y9ihtaRtHzT9lFxb2JB5c6xBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727821856; c=relaxed/simple; bh=V9Njp+Hss1MP7IhsB17a7/LmI6/c4TSAPkMBpdvoTI8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JY6/UXz3AVOmEBrX+zIzjKcg9yY4mXPGTC8xAnLqfJduNxEbl4Qcuz5Hf7mlEGzIM+lo0iJUa9gXogEpFIl812hkZKod9Uf+ZPm/DaXd6gIOF9/PhVRs4FvP4rPMAA7jQaoeU9HHNDCLi1xYKDilflLe0bWHFodoHwYlOZ7wMHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=PTaISppF; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="PTaISppF" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3e0438e81aaso4110014b6e.3 for ; Tue, 01 Oct 2024 15:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1727821853; x=1728426653; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=A9Sl44lq8X2WGm+oVf4+6IoQK0XVriOutR+vfMIV4VA=; b=PTaISppFa54EdVufO4rTjF1hU+hLTnfaBDct/jgGkOGPZRE60gyg9sn3vs6mDxFiup TuL8SJcZ4y72K0ubQfWqNSOct1/iBB9nM5mgiddpVNRZFJANsxDdEqUtyfF05Wvmz6iZ 4mi3gXxki0o2k7f3CIhqb21MY7O9EGB+9Uw/C3+9Gnzx7Tfq46G9/8QHezW561B566Nq mvpWWUilg2r1hlDdKwNuQg8bDtjf++w11ZwNpeOLu44cwUPmPJn08/uU/ZIh6M0yh9sK +NSX8Zh2EK3G7vN6Rtdmu0aWDj9zapKa9G1YvqMBn31oyRKJdcPKcqqPxcJDXeOs65Ki gPYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727821853; x=1728426653; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A9Sl44lq8X2WGm+oVf4+6IoQK0XVriOutR+vfMIV4VA=; b=KH0+2aJLgE6js36tT3A8oP1DFD5+wQMF/FH0eb5tIrpS4m6k/iFtcmmkOl/cFwM1x3 K1+ciQiBy95BSWk3GyyAKvTlq+q4A6EEj3xXr3owkZz7KK9Yeokli7Bt/Nm4GRPDVAEq Ilg5VSQKN9ies4KR6gYmgzNOkDlG3skxVbi/ZIPlZOeFi733Yu1bb1YoCeyQo3mE0Gww M4YxIjNH+BVRTNockbKUYlyTXEOX70leBRyE6OlOqYVZitAu0A+yw+veaTCrZvZS9ZeU wl64E7wzhwjhJmPSHHj3Z9/Lymq2n4Xq8hRkcFPL9JkUV/66aB4ftIIXmHAbi+G3NbH2 72HA== X-Forwarded-Encrypted: i=1; AJvYcCVMLRNmb7co7zt4ew2d2JzoVC65AFYSEw9+ZyRTG79b6xpjDbhLafFHvQZA3sa9wEyg8w1m29uix4U=@vger.kernel.org X-Gm-Message-State: AOJu0YxjxqbgBS0tVzw6oxk32jzRzw+TlWCfai1zGunmzNs6r9vSY0TF IGVQ8l9NNdoktcC0ypvvunzkCv4BeOx9GgAtICwFptNDXItk1u4mNF3AxPyhgYM= X-Google-Smtp-Source: AGHT+IEN2pfHky00i0eXvdOYYGLR6DqqFZpSA+Qwe2ckMPGBiP2uT0h9yCZCjMfnku65naZhHJqcAw== X-Received: by 2002:a05:6808:3a15:b0:3e2:7b57:9930 with SMTP id 5614622812f47-3e3b41631b4mr1047352b6e.36.1727821853123; Tue, 01 Oct 2024 15:30:53 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5e770eaa056sm3002097eaf.31.2024.10.01.15.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 15:30:51 -0700 (PDT) From: David Lechner Date: Tue, 01 Oct 2024 17:30:20 -0500 Subject: [PATCH 3/3] cxl/region: Use cond_guard() in show_targetN() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241001-cleanup-if_not_cond_guard-v1-3-7753810b0f7a@baylibre.com> References: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> In-Reply-To: <20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com> To: Peter Zijlstra , Dan Williams , Linus Torvalds , Jonathan Cameron Cc: =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-cxl@vger.kernel.org, Ira Weiny , "Fabio M. De Francesco" , David Lechner X-Mailer: b4 0.14.1 Use if_not_cond_guard() to avoid goto and rc variable in the show_targetN() function. Suggested-by: Dan Williams Suggested-by: Ira Weiny Co-developed-by: Fabio M. De Francesco Signed-off-by: Fabio M. De Francesco Signed-off-by: David Lechner --- drivers/cxl/core/region.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e701e4b04032..e7c0221edeae 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ +#include #include #include #include @@ -770,28 +771,21 @@ 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; + if_not_cond_guard(rwsem_read_intr, &cxl_region_rwsem) + return -EINTR; 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"); - else - rc = sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); -out: - up_read(&cxl_region_rwsem); + return sysfs_emit(buf, "\n"); - return rc; + return sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); } static int match_free_decoder(struct device *dev, void *data)