From nobody Mon Nov 25 19:25:34 2024 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 5DAF21F76A6 for ; Thu, 24 Oct 2024 16:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729786340; cv=none; b=TgcTVQ2ZUQfObX0oV1t5tskDJyf5GIva06jTFLgtii0P9NGQHIvWszjTDAdmEqeRIUKuexez7RxtiqWRORQ9tZ7NUT0JzSKos5IbjC9Tvlom3epBHb1hgK+/+f1vSwnHcV73RasYQVaOH21aOqoWFSaG5lJSsjnPrPMNSQ+MLbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729786340; c=relaxed/simple; bh=YOl+jdRdLxBkVt8b/cajw2Uh9M6+GntmVhC8RkIqJwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Zv4/SE/v7HsH/nclmViX56M55LSwH2A12aHdW0dvOSGqRARuvZCw4JqPK/mVWZixeVt1SwxR2AyZkRkdQ03MWMaMB7lrIUUswV5OsXkc6GkUgIOMMM34iSLgq6JTVfdVQpr1s1tuwroKjM7KmN91XP7vobnmbX+cuBOvhXansq0= 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=avfvlAd+; arc=none smtp.client-ip=209.85.210.41 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="avfvlAd+" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7093997dffdso472296a34.2 for ; Thu, 24 Oct 2024 09:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729786336; x=1730391136; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=yqHRHn8vLXvapMZ39Cgc0iJX3AUAdIkxL0Txgf+Yb1M=; b=avfvlAd+9lCVpRyLauMnMF4xlycMe9EeRqZMmvuJaMCQ4AtSYSvO+OYQrJXjDDDLm7 4UCtzdfgYdt6ySFbtc15bBYQCd2ZbBXvrOsN/8sTnDuM20+JUgFFU5OTJnZGm69k1sts D+vV61sOdIXKk5YVUGbkg/pV9OZmJn0pyLVX5z55ymzMiV1Alyi+2XwFYoaeES4nYvZ6 2lqVkUxK3/eQqUhr50PCGFfC3Q9iU0pSsKd/MYR90aDkNkAeN4wF2RUhFgpZ1YHS19NW fX937TrCTzNh2KHtYpFSA+ZDYPLEPRv2J0tZVtUBhmpSIe3eZ0k2ni+PLIyJuDBH/Wxb Zb+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729786336; x=1730391136; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yqHRHn8vLXvapMZ39Cgc0iJX3AUAdIkxL0Txgf+Yb1M=; b=Tz+ito3uG8eMgS3FW+m3S0h7hq4pSUg0o8QnOvB9LdSL5owvBMT0dKrn4U9iaCVYEm Gr3V9ye/cVJnEipUZacFJTEW3vgfadI9nkZSYD/0srR+d42D14ZJLqyIhGsE1OBuwc1M yfc9lV+Q+xVDTScRIx43P4cPTr4Ro6iUaqPEB7aqJt0Kyu5P3mHv1/Rk1874zwvt6C2G XNtCAx/7+gnc2LKxRFVzT/VkONRvS5jVUgslVptjyjpZSgdpTJTtFoy2u69taXwnV/Ic y+NZhi5eZKRx3j+UqUd49wPZELzPPvzeCRs1sphvWztkH9brDHhEpKtuPhtHaU14AvMy eNuA== X-Forwarded-Encrypted: i=1; AJvYcCUnBtil+MW5fdDRD2CaWa/+oRDEk/q4upyv/sWs4c6pfQcVKQuO3r5XSgq5/6cTE66zhla94S24QBTZKV4=@vger.kernel.org X-Gm-Message-State: AOJu0YzJV1/nNMXCyzH2eRShSHF9VK6UyCtqkPWHJJrLZt5nqHNBiR7S DRt06lbdj8jTxV9HS1MXyvzeK8rsatj8p4wOzO3xATCtm5yWYoKGd+JpVoT762PywOhYtQNV0Q1 t X-Google-Smtp-Source: AGHT+IHFS2g+HAiwrBGtBUE2E1tTT5mJ8knQJc868BjEF+Hh0NWfqW+DfIUaRbNNK8gnX0OdGFIpyw== X-Received: by 2002:a05:6830:6f01:b0:718:10ce:c6a7 with SMTP id 46e09a7af769-7184b348e49mr5715982a34.30.1729786336306; Thu, 24 Oct 2024 09:12:16 -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 46e09a7af769-7182eb21b6asm2166675a34.8.2024.10.24.09.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 09:12:15 -0700 (PDT) From: David Lechner Date: Thu, 24 Oct 2024 11:12:10 -0500 Subject: [PATCH v2] iio: adc: ad7380: use if_not_cond_guard for claim direct Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-cleanup-if_not_cond_guard-v2-1-1bef98c9fd2e@baylibre.com> X-B4-Tracking: v=1; b=H4sIANlxGmcC/42NWw6DIBBFt2LmuzRgH1C/uo/GGIRBJ7FgQE2Nc e+lrqCf5yT33A0SRsIEVbFBxIUSBZ+hPBVgeu07ZGQzQ8nLq+BcMDOg9vPIyDU+TI0J3jbdrKN l/KGEVXdprVOQ92NER5+j/aoz95SmENfjahE/+091EYwzKW8XJXjLndTPVq8DtRHPJryh3vf9C 378CkTFAAAA To: Peter Zijlstra , Jonathan Cameron Cc: =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , linux-kernel@vger.kernel.org, linux-iio@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 --- This is addressing the build failure reported on Peter's locking/test branch [1]. I've done a test compile locally with LLVM=3D1 and it compiles successfully. [1]: https://lore.kernel.org/oe-kbuild-all/202410240802.VMztsHsW-lkp@intel.= com/ --- Changes in v2: - Add {} around case statements to avoid clang compiler error - Link to v1: https://lore.kernel.org/r/20241001-cleanup-if_not_cond_guard-= v1-0-7753810b0f7a@baylibre.com --- drivers/iio/adc/ad7380.c | 76 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index e8bddfb0d07d..34adc5aeb6f3 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -569,15 +569,15 @@ static const struct regmap_config ad7380_regmap_confi= g =3D { 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 =3D iio_priv(indio_dev); + struct ad7380_state *st =3D iio_priv(indio_dev); =20 - 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); } =20 /* @@ -819,12 +819,12 @@ static int ad7380_read_raw(struct iio_dev *indio_dev, return PTR_ERR(scan_type); =20 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(); + case IIO_CHAN_INFO_RAW: { + 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: @@ -901,7 +901,7 @@ static int ad7380_write_raw(struct iio_dev *indio_dev, int ret, osr, boost; =20 switch (mask) { - case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: { osr =3D ad7380_osr_to_regval(val); if (osr < 0) return osr; @@ -909,31 +909,31 @@ static int ad7380_write_raw(struct iio_dev *indio_dev, /* always enable resolution boost when oversampling is enabled */ boost =3D osr > 0 ? 1 : 0; =20 - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret =3D 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; =20 - if (ret) - return ret; + ret =3D 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)); =20 - st->oversampling_ratio =3D val; - st->resolution_boost_enabled =3D 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 =3D val; + st->resolution_boost_enabled =3D 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; } --- base-commit: 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e change-id: 20241001-cleanup-if_not_cond_guard-0981d867ddf8 Best regards, --=20 David Lechner