From patchwork Mon Mar 31 12:12:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033516 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A0DDB339A1 for ; Mon, 31 Mar 2025 12:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423221; cv=none; b=tJV5oeon9fR1SjvlP4CKPdAF0Vzetw1QRmcI+ZOBoINYEL2vfPY+K6bm4k/pvt2GcKxA1fy3QxFadgV4A0tbOCfd0dD5bzsTylGLDRxz7khuYJH2quq+uglBthrxLa4eX4Xtf0DD3Ww079SZVUk/LbkoA1n4KrzoaaLQUYUlf6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423221; c=relaxed/simple; bh=FAKwMydjlxwNgnbyXQ4JWVNy4HlxKhM9Afm/NQ6kDo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZMG0SL2QoFiIOWGvXLOhQYWBXovWOdT/jL3Oo5fEyigHi/E/RxuOcXdPp/WhHgcVJ3AU/Fjb+cV+fF2liGSWN05GlpETrqAzFI5karg5nq5SrCe8o9dNsa12MrejZ4YjkyPeXkaG4H+l0Z3C5D75/qcyhlAZfgJd9OQBo/HKgJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aNfH/iPI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aNfH/iPI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2D6DC4CEE5; Mon, 31 Mar 2025 12:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423221; bh=FAKwMydjlxwNgnbyXQ4JWVNy4HlxKhM9Afm/NQ6kDo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNfH/iPIw8uAqXGO2FmaRYKz3H/OO2huqosRe9wXUIUkXFKtBZw/hoAJt9LL3jsKc kGdWygh93DR58hKSzIX401mmozJyXuz96eeWSjX0bnJLrIGIQc8PUDiigyWDNTxYiD mvBuA5VoHTfjI7BnYDL/v+hhb6N+A90gYh1qoXJlequmlgPVZG7cwYCHEt0E6KgtBg Fb148KemdVHfEcRiqg1rdt30CAH2A/0Y6muh6g7rDB313Lk/PehGljSKdN5c/Rki6P 1c+sUUsVSejlgFVMeDP/gWs+FAiRe4neFvJm4I1+05rnCOQ5vVFPEc+JbPvkgSWnV5 BCjYL8cRIhuCw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:41 +0100 Message-ID: <20250331121317.1694135-2-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Cosmin Tanislav --- drivers/iio/addac/ad74115.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c index a7e480f2472d..edccdc9cf34b 100644 --- a/drivers/iio/addac/ad74115.c +++ b/drivers/iio/addac/ad74115.c @@ -866,15 +866,14 @@ static int ad74115_get_adc_code(struct iio_dev *indio_dev, struct ad74115_state *st = iio_priv(indio_dev); int ret; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&st->lock); ret = _ad74115_get_adc_code(st, channel, val); mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } From patchwork Mon Mar 31 12:12:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033517 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 60B481E32CD for ; Mon, 31 Mar 2025 12:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423228; cv=none; b=atEyfYLmSXbCms4wxVX9z8xRpeXeFEXUmd9CONzOUcu3v/bCrk+Gm2ZhsCPUMw4wMWjJ6KiSVmWDkxO/et7KRMfeLhyKuXSZLmkIc2AaoK6m5hySrCEEmUU4L0EHWx83fSj5aIsXqD8I3sJnk+0k6oU6TZMqow6aH33mxm7TmYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423228; c=relaxed/simple; bh=6iPQidScwC0vjegJMlujed5SswG/grxVLRzfUxxCCdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GXY6JXv6IszYDKyK2mQthVTOA59mF+2WIvaPB+uJa9Tn6XwPPtj96NYKTHnhJ/1WJAEIDc8jS6wCvg0A/cH6OIk3n0RRKhD9R7PncFkNRCa+0A4f32OqWi0VcWVKeGwQ3mqJ+ojL/bfSUVwQs2rYRw/0dihkUUBjZlrjuLeDCLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=joGhdd6S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="joGhdd6S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F02BC4CEE3; Mon, 31 Mar 2025 12:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423227; bh=6iPQidScwC0vjegJMlujed5SswG/grxVLRzfUxxCCdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=joGhdd6S6LinKIjquXqWApQlU1HU688lmi3y7TLqkdhyCIKtURC++zdBvXyRQ1zzx G1vHeU1IzlsxuwLTB7Ff35rXlko3VqvcwB2vOCNZSex0Aw+xTP/VRbTxwAEGoNlhwy HI8VpoTdNSmNBMMMvBduxGDhOnpQTCZ+6GsZDwLHN1jROnGSvj2a7hp9kXU0/F31eC sIIikkBA66nAS57Nv1n9kwHdfvqPZr89J2IOATdVUtYy2ftPuYVEIfX7ppb/16hW4O OunRECalZMcwRgGVwyDSus9S0DAdRDspnc63gbKbAYvou0zRW7BQnvd5cevQJUjC+0 GnjNgHUECxEmQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 02/37] iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths. Date: Mon, 31 Mar 2025 13:12:42 +0100 Message-ID: <20250331121317.1694135-3-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Factor out the implementation of this part of read_raw() and use guard() to allow direct returns, simplifying both error and non error paths. Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/ccs811.c | 72 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 451fb65dbe60..75b0cb05dd86 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -15,6 +15,7 @@ * 4. Read error register and put the information in logs */ +#include #include #include #include @@ -214,6 +215,40 @@ static int ccs811_get_measurement(struct ccs811_data *data) return ret; } +static int ccs811_read_info_raw(struct ccs811_data *data, + struct iio_chan_spec const *chan, + int *val, int mask) +{ + int ret; + + guard(mutex)(&data->lock); + ret = ccs811_get_measurement(data); + if (ret < 0) + return ret; + + switch (chan->type) { + case IIO_VOLTAGE: + *val = be16_to_cpu(data->buffer.raw_data) & CCS811_VOLTAGE_MASK; + return IIO_VAL_INT; + case IIO_CURRENT: + *val = be16_to_cpu(data->buffer.raw_data) >> 10; + return IIO_VAL_INT; + case IIO_CONCENTRATION: + switch (chan->channel2) { + case IIO_MOD_CO2: + *val = be16_to_cpu(data->buffer.co2); + return IIO_VAL_INT; + case IIO_MOD_VOC: + *val = be16_to_cpu(data->buffer.voc); + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + static int ccs811_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -226,42 +261,9 @@ static int ccs811_read_raw(struct iio_dev *indio_dev, ret = iio_device_claim_direct_mode(indio_dev); if (ret) return ret; - mutex_lock(&data->lock); - ret = ccs811_get_measurement(data); - if (ret < 0) { - mutex_unlock(&data->lock); - iio_device_release_direct_mode(indio_dev); - return ret; - } - switch (chan->type) { - case IIO_VOLTAGE: - *val = be16_to_cpu(data->buffer.raw_data) & - CCS811_VOLTAGE_MASK; - ret = IIO_VAL_INT; - break; - case IIO_CURRENT: - *val = be16_to_cpu(data->buffer.raw_data) >> 10; - ret = IIO_VAL_INT; - break; - case IIO_CONCENTRATION: - switch (chan->channel2) { - case IIO_MOD_CO2: - *val = be16_to_cpu(data->buffer.co2); - ret = IIO_VAL_INT; - break; - case IIO_MOD_VOC: - *val = be16_to_cpu(data->buffer.voc); - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - } - break; - default: - ret = -EINVAL; - } - mutex_unlock(&data->lock); + ret = ccs811_read_info_raw(data, chan, val, mask); + iio_device_release_direct_mode(indio_dev); return ret; From patchwork Mon Mar 31 12:12:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033518 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CB86E1D89FD for ; Mon, 31 Mar 2025 12:13:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423234; cv=none; b=Ig4hOK9fw57EtBU9+ZvSNpHZiJOHB+GOvyFWKXVHfB7mKDl4irex7q4+mcqRjSLeIwDoKAUKNR1WG2Z0V9QEMSvOK3mxac/M9z7sfpk2E3SoD9XENG8cp/+jW7KkHA0vISmCAacgxbGQx4N5FoawscVKSMXO1+2uWrnsYhuX5OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423234; c=relaxed/simple; bh=jEyMP4M6WeQnyIY2iM+tZzfcMeqjGyxQBd48I1lM9Os=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NVuHGT34M3t10f0LUB5+KFc4I/9hcTqrQztw1Wf3lRMYQpX0mZGxY89F8qPv6ZYFOChwC2RinA30/dfx2fv2qakPwLMgPSSwNGkX75a8mIeLw0/bKjXus7zwJPRZEFq4foqVWwVdykItaSmDVfIStYqADkn92Q05X8Gcj2wR++c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cGrEuT9B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cGrEuT9B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AE49C4CEE3; Mon, 31 Mar 2025 12:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423234; bh=jEyMP4M6WeQnyIY2iM+tZzfcMeqjGyxQBd48I1lM9Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGrEuT9BpbQ16FzTW5lFyoGnEAUMDJfRfoJ/vdcWwYOGU3gMDdoenTfnbZL3R2CS5 NGosyzLWxiPamMGLs4fJJRpyB3kB5KC0OZvmUi5Xva2cyzGIWHYY4wy0yCwGPOJoNb WF+EsiUfC4MuQqg/LFU+O1BgZNN04fVZnxwobbqgXcHeTbyqnJg8wkaFX2l4vDI/E7 fJfNiQ7VBeK+AHExkhxuQcv+H97xAWv+kfwYJPd5c+4iy5xEndEUMCqB+51u+GFw9s 2hHahPbTgNE1yGaQt++sP18bq50Gqx/xNldsZXM9t/xMzZqk1jezSzT62Gpj0Z0oDW Kl6jVbvtv4oKQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 03/37] iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:43 +0100 Message-ID: <20250331121317.1694135-4-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/ccs811.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 75b0cb05dd86..1eab256a1e00 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -258,13 +258,12 @@ static int ccs811_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = ccs811_read_info_raw(data, chan, val, mask); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; From patchwork Mon Mar 31 12:12:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033519 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CE84C1D89FD for ; Mon, 31 Mar 2025 12:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423240; cv=none; b=FoCrpgfbfDDJil6A7hn1r3TLCqPehmvJHx9NjUt5Ke9afv8wgSo0CcrkFVwQlCJlUPuZdcW5FhQ4gGQjmyAqaQhq6sLggXHErUse/WS0XTgFGq3JpL8dwl28FT802T4gzxabEa/g9uug5QAgXpNqgcNnSplS0MuA+w9Nn6W3z4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423240; c=relaxed/simple; bh=S+UO7pDjMSe60bELtyH22FxPeOII+K59wEySKfowcMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=onHWRLm9eCS5V2hz6V5vBb4NRpoEx+dN2DeDiO4pyvlJ0hYsaK4bnBNf++r9/cET8VU7fa2mdtbiAVETetWJJiw2hQhgkSwC3479dOv4F/zlflVWbQlwPPnBQfwaiMjJMrB7kATE2PQOaj3KgvGtlc+kBcRRNBXVHcsdtWmF/6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sCoXOTL5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sCoXOTL5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 136CBC4CEE3; Mon, 31 Mar 2025 12:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423240; bh=S+UO7pDjMSe60bELtyH22FxPeOII+K59wEySKfowcMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sCoXOTL5f3tqKESGwIARSAD5Q/XXAKECLg6NdfZKfivWZ1A9RjkJlTj0f0ZU/Soyh itXPyl5mTRy7YgUCasuqcXlkM7t/tBRMF3r0Y1v6F0ckSmGOgBhDa7+klnJxWEey1+ OGH0ZSfEyjZORrALl33GOcn9sin0TvKhmuRDNweidmnO8szlIS/d4mGR+xJJB/rp9o eB2tesgy+wIfPgVvLKc3OX8yR1jCUZzigZ85qQ8FXW7ZkuPpUcGY3wULCev9CYLThh W1SmfQ9vpiUy8b0pwd+tN5zmvO3KgAtYSelUrvyQpzTTGo17YrsqLPxmidx86IZuXC pEcbEinHtiOig== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 04/37] iio: chemical: atlas-sensor: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:44 +0100 Message-ID: <20250331121317.1694135-5-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/atlas-sensor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c index baf93e5e3ca7..593b73ccbeb7 100644 --- a/drivers/iio/chemical/atlas-sensor.c +++ b/drivers/iio/chemical/atlas-sensor.c @@ -518,13 +518,12 @@ static int atlas_read_raw(struct iio_dev *indio_dev, case IIO_CONCENTRATION: case IIO_ELECTRICALCONDUCTIVITY: case IIO_VOLTAGE: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = atlas_read_measurement(data, chan->address, ®); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); break; default: ret = -EINVAL; From patchwork Mon Mar 31 12:12:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033520 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AD7E578F2B for ; Mon, 31 Mar 2025 12:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423246; cv=none; b=nNc7Rzid/Lvrj9oPiEITvdY54P7iwVox7Wsj/odkOzTtSqK5+7/wh/1RxSBDRGnyFFycfK9+lLRk0ykVkcPd/t8u9gbhNNVyRGrcbWtxqJLfk6eELKdrGsT49JA2yhm7DFK5wiG2ZPVQmagfvi8uxm9Dt3VuwSoFAlpGbMzGi0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423246; c=relaxed/simple; bh=BHrhbAFBX1TcGWm0wx4g1ujM5RoQN26rnafQTzyIoOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XkeYrbLn52s3m8OdAioV3Z8m7bTv2pB5dEOG1K8DPslp0NyGSXipItBKckl94h1j6EzpcBRqwV2/SFUCYTmFvBbO72NvYvdJY8Mw1lC9iAp/QEb4UNuKFavpv3hoiEQ8tgXRQRxbdJBqDd5/43qz1i6LbusEOT1lOgSSz+oJ3o8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eUIPKJpL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eUIPKJpL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04C8CC4CEE3; Mon, 31 Mar 2025 12:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423246; bh=BHrhbAFBX1TcGWm0wx4g1ujM5RoQN26rnafQTzyIoOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eUIPKJpL8unbxGMmplk9TXgWts8dc+F/r/jivB4jPhgY26Z2IT9P0YIHFM3XHFUwB g1T6ZV9zDcATF/ulzVTVmpuIMCWKdd7MmenLPLj3qv0nOYhbedGmU/YIOMd45k0oUP DXbXb2kxKQlThyPkZgGOX52/82UBvkQUeEVn29hnkXGTxjZXHgAoZdEwb2b5Bk22Cj T9kazmqYV/1JpbfMXwL/8w+lEvn6NKQIpxFJ5hrSK+//Wc4x0se+oa/UrCzf7y2S7E mietHXs+4OYMNaOBGUKXPJO0BZl5cOwV+GXCfwtpAl0h6wcFoKT9/EgzAN6rRLc1IH 6T/etl6BAXFhQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 05/37] iio: chemical: scd4x: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:45 +0100 Message-ID: <20250331121317.1694135-6-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Roan van Dijk --- drivers/iio/chemical/scd4x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c index 50e3ac44422b..4877bd3e907b 100644 --- a/drivers/iio/chemical/scd4x.c +++ b/drivers/iio/chemical/scd4x.c @@ -358,15 +358,14 @@ static int scd4x_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&state->lock); ret = scd4x_read_channel(state, chan->address); mutex_unlock(&state->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret < 0) return ret; From patchwork Mon Mar 31 12:12:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033521 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4B61A1E32CD for ; Mon, 31 Mar 2025 12:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423253; cv=none; b=kCuu/hV/mKNJD3X54rya3OAw57YskgxSy66ZIdZaYlB7teg0kSvtmL7ox0GyCEJN6NZRaYrS2fK2KGrntIZCuMYCNDJtO01mE/SYe1Jg6kPn0uj4v/vrkxtrcLYMRxNC5ZFS/EWyDg5n28ZIqd0JtQnenptUrGA0X2KylW3izOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423253; c=relaxed/simple; bh=Pg3aMTMJ2LBBAhyRSbi3XbBfL7zwCX4hyNaXNC0F57Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C+PkaXYoIEKWY25hCxyJ6fCQH6PKZtARzHX0xLDd6g2LZsO+t4wdEqW0+GHlYuV4fn7fFfSp20HXs9Cgd73mJCyZ20qgtYEr0et1tw+1JVUESLMW1HjuRtiVkz9QaaOo6tmRHQjGZweRQ7lIuwnDLVM6mV1n08/pQ45HF5OZ7/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N+ZX9cs5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N+ZX9cs5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9C78C4CEE3; Mon, 31 Mar 2025 12:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423252; bh=Pg3aMTMJ2LBBAhyRSbi3XbBfL7zwCX4hyNaXNC0F57Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+ZX9cs5ZsHRvQtmzv2L3opQ8nudKzeLTL026Sye6gZQKXsVI9aLL6fEx2R6+aHJB bVYKmd29nc9mS5eD0cF9WzxSE/zExPT9qdGnCDPz8z6QxqduBzKCAuDbRZboAoDPgr S3OR05ZqVWah6YtIqUFcktRxjT+I2AHSwXkXwUsNrofK7Fd9V3IcYYYtA678/Ir8OR JbY7wNIpMZERdALNeGu82ol0wiCVBtCAevSAZRgGkTvmz/giESHQ0sSTJC1gzVRrQ3 Sn0BMxPWxFIRHY0X4J3gRFwY69zs94aGn/n8mE0YKLlWwfRiLgj13vnDiP0hqmT/Me bN6oAxhq/yQ6A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 06/37] iio: common: scmi: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:46 +0100 Message-ID: <20250331121317.1694135-7-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Jyoti Bhayana --- drivers/iio/common/scmi_sensors/scmi_iio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c index ed15dcbf4cf6..1a62dd902f05 100644 --- a/drivers/iio/common/scmi_sensors/scmi_iio.c +++ b/drivers/iio/common/scmi_sensors/scmi_iio.c @@ -351,12 +351,11 @@ static int scmi_iio_read_raw(struct iio_dev *iio_dev, ret = scmi_iio_get_odr_val(iio_dev, val, val2); return ret ? ret : IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = scmi_iio_read_channel_data(iio_dev, ch, val, val2); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return ret; default: return -EINVAL; From patchwork Mon Mar 31 12:12:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033522 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A12391E32A0 for ; Mon, 31 Mar 2025 12:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423259; cv=none; b=JgYWKhKeZQu9LJcowoIMxLqmvvrrjC4dBBuqjPQhPNoetL3YNnC/O3CnrUf8G+pTpDWv2ucOCxavuYiExXj8/Apl6tE+i4V712mb6duMY52DafSVpMwEB1AobEtV7SX07zlhH9piDE3Jg8hcXXTXuhKOfdy/OWjtm80QD3bIdmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423259; c=relaxed/simple; bh=Ob0O353xdKJM4VuAfqQkzmXiz4hl4zoxauKuKmY56+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyvBCGSVGDFkYIg1iZtyAmqMMStg7WRZGUt+5TQM7R/+GLPdIM9mGWoO0jA7+pfZyab5SytpOBaQebCubggWvQVWFLrhuCy2E8TCBegvdqgx2tgjOMGt7bFFbC0dzwFrlSaJVwx/x79yPflQxei2SZU9/gSIC9s8nfXdN/WnYPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f/ISQ8AK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f/ISQ8AK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E1F9C4CEE3; Mon, 31 Mar 2025 12:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423259; bh=Ob0O353xdKJM4VuAfqQkzmXiz4hl4zoxauKuKmY56+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f/ISQ8AKyVaZLe+xh4Rik6p4SHGYO/6UvvbOWLwbT6fdtS73UgK+MMZQItW2sOO4E M4Tj+/Ga6yLZMtcdoMLjnum23SYm3XbOXwr7aJki2WeCVGF6g+jvX3qCpHhEAM1xHD SqSfMAKw/RcmJ1lvJ/IuRhlBoPA6dQhBvnO1IHkXa4j1vW03apHOma5l9nFUdHDqnJ GVyZ0NwxATlHL9anaYhCk3ma7Is9JIdXa0QboiAvgdA3vwaP0S8QElV3DkWCj/4tyf bFw4QZfuw1RhMwiJ+rB2z8H+ugafiOx4NnH5XVEJk7wvTUHPqXvA1BE5iFVzk9RbQr jS93euW+cGUEA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 07/37] iio: common: st_sensors: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:47 +0100 Message-ID: <20250331121317.1694135-8-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/common/st_sensors/st_sensors_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index e4f5a7ff7e74..8ce1dccfea4f 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -530,9 +530,8 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, int err; struct st_sensor_data *sdata = iio_priv(indio_dev); - err = iio_device_claim_direct_mode(indio_dev); - if (err) - return err; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&sdata->odr_lock); @@ -551,7 +550,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, out: mutex_unlock(&sdata->odr_lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return err; } From patchwork Mon Mar 31 12:12:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033523 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0B2691E32DD for ; Mon, 31 Mar 2025 12:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423266; cv=none; b=sKXNzowwMtLtlQI7NaTm4Q2545VSQ3KuymwAqBAy2yhl9orEd6MvsUss99pX2JYFjftGMdXZJiLtxPzEo5iOX02sWC6B7F9HlBSrDZSQmSJzCAeFXWoMUTgf6lz2bPp0QPE9O5/DshbW8u3PqgX4LdQ0uAztACg4JqPE312wzv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423266; c=relaxed/simple; bh=1G8+RedA+cYnYN6BK8VVC6Ap1ZihZtFWfZ/E2J5ieZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cbpi/cx6UdKTPfwGoYs5xa/wATRZKFGfLKBtBr4TeW5JqvgQ5A3cwiyVizglj6PgdzlQnYTb0FDRspOwCGmov0y9DsHxBMPQFpDGKoZVYWggyvkkMK/XIFlRbJoSHyb3y135qDj3mMRBLeh0bcP13fBWZlVygEKsReNKzUxuB0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RhCEl4/q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RhCEl4/q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB07EC4CEE3; Mon, 31 Mar 2025 12:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423265; bh=1G8+RedA+cYnYN6BK8VVC6Ap1ZihZtFWfZ/E2J5ieZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RhCEl4/qfzQQRC2+6iPm4HvCTrLdv5bobXZQp49aLUiMKUKQ1PfXr8V/URUdl0psz dsOmMDkqzSGYrHjRuNXnkb13311FidaofioGmttaDeXw6mSxXJLnGLuPV1DiqA2H45 2Ou1pZ2RBQX1AGmYVOGadEEqS3kIKIUYR7DedMKGr8lQr4SsWaz8dqIBtQh9UzvgOe 0z6YLPxEyYDr2HQ9Ku2UaVgxuwfUY3IX8IUYc96vk1lZzk/5ocogm4ZjO1BIEGF86Y Q0davvvZQ2l/Y2enZxL/22pS+L5ufQmzKw3/fx+oOpx5bPp9uqgf4DevE0zp/oMWTf FMDPkZpw0M+NQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 08/37] iio: gyro: adxrs290: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:48 +0100 Message-ID: <20250331121317.1694135-9-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Nishant Malpani --- drivers/iio/gyro/adxrs290.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c index 223fc181109c..8fcb41f45baa 100644 --- a/drivers/iio/gyro/adxrs290.c +++ b/drivers/iio/gyro/adxrs290.c @@ -290,9 +290,8 @@ static int adxrs290_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; switch (chan->type) { case IIO_ANGL_VEL: @@ -316,7 +315,7 @@ static int adxrs290_read_raw(struct iio_dev *indio_dev, break; } - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { @@ -366,9 +365,8 @@ static int adxrs290_write_raw(struct iio_dev *indio_dev, struct adxrs290_state *st = iio_priv(indio_dev); int ret, lpf_idx, hpf_idx; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; switch (mask) { case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: @@ -408,7 +406,7 @@ static int adxrs290_write_raw(struct iio_dev *indio_dev, break; } - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } From patchwork Mon Mar 31 12:12:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033524 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4000B1E32A0 for ; Mon, 31 Mar 2025 12:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423272; cv=none; b=bYd+dV7WZDnTL+XLbRIISHeVsddAoWAVy4hrT5OJdJooag4nX/SwvieFWcvbzPSa02ChY5/RuvyVGSV9XygAJqLiQsr0+1TFFc00PMFxob5EwKOKFLZ4b6EjjI/lh9q7AEDjWPiY0Z+bvCJ1VHeOOvlYwd2vLSQda1M2BHepUus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423272; c=relaxed/simple; bh=PMhnEKlnga3mxdWZiMXvLCRVbwuIgA20A9EgmuvdvjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cdBKcXSDu2jcZxPcBHvVd2tA6jgV7akTchQvmXKQ3Ow2vVhMKF+fArUfYpgWf87WvzUf9AuQBFlxDc/Ib3QolDC1YajtzkvyoeTATPJAhsrezmcVRU7fQPfa5m0fPCULGiqXQ/KbbNUGXL+srRb6tky3uxev58BbyXmrL1GF++w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e2J2y7gF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e2J2y7gF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34BEAC4CEE3; Mon, 31 Mar 2025 12:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423271; bh=PMhnEKlnga3mxdWZiMXvLCRVbwuIgA20A9EgmuvdvjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2J2y7gFjQctSnyeDnXpe+1SD2o1IWPgeo8RPV1L/1aQaL1W7QT5GotSTjkTdFsXa DE1inXNCMdx8DvYGifqkLRaM2z9kuWlFpcOizoMfWTtErAmPfadrBI+w1LKzlg7aha /a2nkll6GyEOUhwvWI8sJnNHwZuUyvYD1JegfrArPt/zxKTv/ucZEXVTgCymx75bX9 DwZYY0Z1CM9yu1vOeKbZJbL5JkUp97Yu8qlOxiNqwPYIjvRvsWcO370kzO8xSMNCKy HXC05cRX7LnSKZl87p3cCaiKwWL7pugYPBp9CzyYb0W2TuY0Oe6GwKG4FlshQHao4v RhCHNL8PdMTBA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 09/37] iio: health: max30102: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:49 +0100 Message-ID: <20250331121317.1694135-10-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. This particular case is about ensuring the mode does not change rather than ensuring we are in direct mode. A follow up may cleanup the buffer mode claim. Signed-off-by: Jonathan Cameron --- drivers/iio/health/max30102.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c index 1d074eb6a8c5..dacc489f7293 100644 --- a/drivers/iio/health/max30102.c +++ b/drivers/iio/health/max30102.c @@ -484,11 +484,11 @@ static int max30102_read_raw(struct iio_dev *indio_dev, * things cannot concurrently change. And we just keep * trying until we get one of the modes... */ - if (iio_device_claim_direct_mode(indio_dev)) + if (!iio_device_claim_direct(indio_dev)) goto any_mode_retry; ret = max30102_get_temp(data, val, true); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); } else { ret = max30102_get_temp(data, val, false); iio_device_release_buffer_mode(indio_dev); From patchwork Mon Mar 31 12:12:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033525 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 982BF1E377F for ; Mon, 31 Mar 2025 12:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423278; cv=none; b=CxtwEFoTJpog8j7ovOuF2mXgLHdkQHRpvyMbuviTxU3DMwFy8ZnpK7FPRNFHcMM3oUDmLqiPO/Y/02EI/Bi0ZT3xFdvbuQdqaOULwIvwE0RZGruiOqtp9jDjtVhmtCJ1BoJ9cq+iGcejxJkOuxGvMroQEVI9QZclfbuaXCa1GAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423278; c=relaxed/simple; bh=DfgN0kHZTotamsLbyfGFm/gx4q9zb++LGiw4XwXHyUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A18owY8p9bpyBgVWcH/sMFMaFtl/OkKkAUAbqfdlAvVGn/lc9PBshORD8Pchu4lRUDT358inFGDlNV6V388NsFCMFXVb4l6XyJmu6tRWWxFfg98qCf56fzJY8mMft8DtkcT/Ok6TXlnIv4fqbIezxslFMBnxbKxal3T7HR8gh5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q7451HGm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q7451HGm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89B2FC4CEE3; Mon, 31 Mar 2025 12:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423278; bh=DfgN0kHZTotamsLbyfGFm/gx4q9zb++LGiw4XwXHyUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q7451HGmcUehBr5UNLRfnKfHK0Ymf4ItFdvNt5UFkNAt0NbOu0HA+WvdWhG/Lhx3N QmnJhWnVqti3j01/kzLh/4WipKJ8KV2rpsLxgcVp0Kgr5mnJLa9lDk+2msPYHoDM0B z0Xy2+QmsFuDQZMwLr7IzrJHK9zY/7mfvcplOr46lr9nO6o2NxzuvAE/JzOAF3ekCo lwiZRkd2a1vLKftjl7F6rsHzVFNXMF5sPjRpuLgLU/4Fg+DdPTasfE38y1d12hTOeY bX0oaun+2bAGVObKX/zlWw5x7pwiVkAFwzIe3O2BntbBAbj5eJIzQpfRbC0GwNExlC rcCDRsI/APFZw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 10/37] iio: humidity: hdc100x: Use guard(mutex) to simplify code flow Date: Mon, 31 Mar 2025 13:12:50 +0100 Message-ID: <20250331121317.1694135-11-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron By using autoreleasing on the lock a number of paths can use direct returns allow earlier exit from functions. Signed-off-by: Jonathan Cameron --- drivers/iio/humidity/hdc100x.c | 69 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c index a303f704b7ed..fb8584423ad8 100644 --- a/drivers/iio/humidity/hdc100x.c +++ b/drivers/iio/humidity/hdc100x.c @@ -13,6 +13,7 @@ * https://www.ti.com/product/HDC1080/datasheet */ +#include #include #include #include @@ -206,26 +207,21 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: { int ret; - mutex_lock(&data->lock); + guard(mutex)(&data->lock); if (chan->type == IIO_CURRENT) { *val = hdc100x_get_heater_status(data); - ret = IIO_VAL_INT; - } else { - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) { - mutex_unlock(&data->lock); - return ret; - } - - ret = hdc100x_get_measurement(data, chan); - iio_device_release_direct_mode(indio_dev); - if (ret >= 0) { - *val = ret; - ret = IIO_VAL_INT; - } + return IIO_VAL_INT; } - mutex_unlock(&data->lock); - return ret; + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + + ret = hdc100x_get_measurement(data, chan); + iio_device_release_direct_mode(indio_dev); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; } case IIO_CHAN_INFO_INT_TIME: *val = 0; @@ -256,26 +252,23 @@ static int hdc100x_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct hdc100x_data *data = iio_priv(indio_dev); - int ret = -EINVAL; switch (mask) { - case IIO_CHAN_INFO_INT_TIME: + case IIO_CHAN_INFO_INT_TIME: { if (val != 0) return -EINVAL; - mutex_lock(&data->lock); - ret = hdc100x_set_it_time(data, chan->address, val2); - mutex_unlock(&data->lock); - return ret; - case IIO_CHAN_INFO_RAW: + guard(mutex)(&data->lock); + return hdc100x_set_it_time(data, chan->address, val2); + } + case IIO_CHAN_INFO_RAW: { if (chan->type != IIO_CURRENT || val2 != 0) return -EINVAL; - mutex_lock(&data->lock); - ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN, - val ? HDC100X_REG_CONFIG_HEATER_EN : 0); - mutex_unlock(&data->lock); - return ret; + guard(mutex)(&data->lock); + return hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN, + val ? HDC100X_REG_CONFIG_HEATER_EN : 0); + } default: return -EINVAL; } @@ -284,27 +277,19 @@ static int hdc100x_write_raw(struct iio_dev *indio_dev, static int hdc100x_buffer_postenable(struct iio_dev *indio_dev) { struct hdc100x_data *data = iio_priv(indio_dev); - int ret; /* Buffer is enabled. First set ACQ Mode, then attach poll func */ - mutex_lock(&data->lock); - ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, - HDC100X_REG_CONFIG_ACQ_MODE); - mutex_unlock(&data->lock); - - return ret; + guard(mutex)(&data->lock); + return hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, + HDC100X_REG_CONFIG_ACQ_MODE); } static int hdc100x_buffer_predisable(struct iio_dev *indio_dev) { struct hdc100x_data *data = iio_priv(indio_dev); - int ret; - mutex_lock(&data->lock); - ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0); - mutex_unlock(&data->lock); - - return ret; + guard(mutex)(&data->lock); + return hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0); } static const struct iio_buffer_setup_ops hdc_buffer_setup_ops = { From patchwork Mon Mar 31 12:12:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033526 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D5C181E377F for ; Mon, 31 Mar 2025 12:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423284; cv=none; b=ULHXKD3BvRehXVXuO/93WnQpmBQbgqfZwyu68U6DV7gakRyBv2yJ2xC9Q2wcUy2PwAF1mUShvYwtKU7SufRUSTdJlVcKSgeV2grwxSUfVwDp57QzzgEMPR5lPZiVzb7UXPY71yxVk/LtAOAQVTfJnyF0Bm9aTbhE5/Nre/s5uUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423284; c=relaxed/simple; bh=4oPsywMeiF36Vp5tgpV6wJJcJj8jP1JxM+zu/c34YXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qTPSCQbXQKmfpv5ikGd5bKRW3cNUFcdoc1rAiJ5EZKc+xPTMchi2zi61mmD9cSrdtyoF/8Ki75Ywm1TPxbD4YL8o5FtMmP7ikO5zKEl26nAIxNRsANKRZif/YUt11UciuMgexDFQd84DMIb5AH9QxkevoO0rjmBZ9Eg948vnk+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPgFjLl7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KPgFjLl7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5DFFC4CEE3; Mon, 31 Mar 2025 12:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423284; bh=4oPsywMeiF36Vp5tgpV6wJJcJj8jP1JxM+zu/c34YXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPgFjLl7Rh1QbaZhYbfDzH/brpaTHmzduebpbrj74ZOyC1LDk6Pj/a9kRhyPeY/cT MjXMDTjQFxhSYgLHz/6BrAcwsoVXXA/NUpvSsAdPiitOLMxQ7voBmcgcS8TuaBUTko OS7vbg8xOpcM9R+KEg2Zn47mYE5dQPNEoKMehbECdI0xkfEHhcTnKz85RK2yyktLiu YExRZ9p9rvEJ0PskMZxqHLn05LOyRbS1VzTUz5CSOEDXZOyaWcturTYotMqyHy6YPd l6NUAWGwoOaA5+JmcnTSlTgoAJfp03cznvqNeSTtwRSSVbcCjhTU0epaVf5O9r4ttZ 6C6fzn1KOd9lQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 11/37] iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:51 +0100 Message-ID: <20250331121317.1694135-12-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/humidity/hdc100x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c index fb8584423ad8..c2b36e682e06 100644 --- a/drivers/iio/humidity/hdc100x.c +++ b/drivers/iio/humidity/hdc100x.c @@ -212,12 +212,11 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev, *val = hdc100x_get_heater_status(data); return IIO_VAL_INT; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = hdc100x_get_measurement(data, chan); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret < 0) return ret; *val = ret; From patchwork Mon Mar 31 12:12:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033527 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 42E5E1E377F for ; Mon, 31 Mar 2025 12:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423291; cv=none; b=qiG9onkr5wJ3u07fxdebnStwy72VmUgnMrAdlt7NtNk12JV5d886FEwzuewD3ZjhstTrAr/dYqpIvIHievZc2twSCTfIZkJDZSSdyPBin64w9Ho+ubtxIvuzrFXjkxTdNHm9DzYN9sqt/ZhQBKuSNAXDKBdblLTzzQ3X1Cy65Xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423291; c=relaxed/simple; bh=XHdwhv0AaXUg1kPAk8S0qAkPHuUhiza78tbUhyE/d/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jxD5UdyOFsjllzHtkQiJgZkVNH238RHOVc3ae3dE3QWF02nB0uSWJ1mvANH07CbNjHi2I0hozGPRaCWXQF0/hJU33PNAtFFT1YzrM3BoKjmtN6spZKA3EvJGApoIq2DM9RK/gXv3gr8RbROalTA+vqWZHcICb8p5QE7ZdqzACZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uTHBaHIv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uTHBaHIv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F17AC4CEE3; Mon, 31 Mar 2025 12:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423290; bh=XHdwhv0AaXUg1kPAk8S0qAkPHuUhiza78tbUhyE/d/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTHBaHIvddWblmAKVPLWTR4wEhaVvcepc5zcLM6vEhBYQ4IPjJ2vHg92jW85k+tiq bTAoQ2JrNYIa7LuUgplyEhEcFgsO4UMSKPVjLk0vWd34Fxmky/yIE56mjOEF1yYw8j MVOJkffYEwXskIl2wRo4HNWKiX28S6iK67OU3pbdyQmaYFCNoAsfcT6Gukno2d6DD+ q+Bi0uycs8v0cmQBLWIZk61fQcpVr3JR1HYH0Bcipy6xvL5HZEK8CJrYfDpbzM06sz aQZv2iVX9b/Ar7H+DPuzjR59f+OClY0tKXaSlgaUwZvndYAOQ1bxHdDpDfFggR9wsA qjxWmyaibMr9A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 12/37] iio: humidity: hdc2010: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:52 +0100 Message-ID: <20250331121317.1694135-13-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Eugene Zaikonnikov Acked-by: Eugene Zaikonnikov --- drivers/iio/humidity/hdc2010.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/humidity/hdc2010.c b/drivers/iio/humidity/hdc2010.c index f5867659e00f..894a8b4ab193 100644 --- a/drivers/iio/humidity/hdc2010.c +++ b/drivers/iio/humidity/hdc2010.c @@ -169,13 +169,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev, *val = hdc2010_get_heater_status(data); return IIO_VAL_INT; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&data->lock); ret = hdc2010_get_prim_measurement_word(data, chan); mutex_unlock(&data->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret < 0) return ret; *val = ret; @@ -184,13 +183,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PEAK: { int ret; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&data->lock); ret = hdc2010_get_peak_measurement_byte(data, chan); mutex_unlock(&data->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret < 0) return ret; /* Scaling up the value so we can use same offset as RAW */ From patchwork Mon Mar 31 12:12:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033528 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 50CFC1E3DC8 for ; Mon, 31 Mar 2025 12:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423298; cv=none; b=nV79kGzvlZoZzxLxNprX6F8VFyH+BpHAjshl79jbxztT/dM7KR+KXG55f0qozJF7kCFuNGCi1dN5zVoFiDWWDDFvFdlpIonxCrpWYjxOBLwZ1GdWRtgc0wlkgKezFL65TA4triL11bzolaO0TkaUfjn/JY2++k8j+Utb3MnG6KQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423298; c=relaxed/simple; bh=0DAhGbMUnpRdCeGbudpqzFmD25sMNs0GOAoM2aWccSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NG46Uvve9Pic8P/VAXSO/qMQt0KWY+t3pJze/YuTNM/eHsIkR1E3FF5VYSuHB9KNk4RBghfjCZO/AH+BQHlEE4GD6SjSubB2K3MyIKA7/vvewTRnl4lRoPHm0JPXfGdm4twlbWCBfRphG9wQPhWSaYcVjmLEtyK2BKD42ljWr+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o+PmDPCr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o+PmDPCr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BE56C4CEE3; Mon, 31 Mar 2025 12:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423296; bh=0DAhGbMUnpRdCeGbudpqzFmD25sMNs0GOAoM2aWccSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o+PmDPCr9mUwg9N95JKx4gS0XfGjEc8WIWqstYzA4VWx0PNMm52A0VXBf1y1hWYdb lHJBRTLoSwkPhNt89V4d8tZPbVzVnRAYif7+uhypxBI9VwQyAzbUxzTaywNGt3uzTx xLYlwgmiC0lTNkhq4jJidM1klXVil5gbYzJqNSn7wftvbOMZ+qX2Sc2RJYf1szYXFu MB7JLjqQ6W5Yf1EyCgZXFNR8PICE6QsU17o8VoLWwq7HATQxqoHNBzgegnJGHAYJpo g0UR8hH7uW+AY3jni49RcHmX+7t1ZG85uPHafSkWo7OCQiL/fdGFIVtLmcZ6tthkbx sEnbnBkgLZpbQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions. Date: Mon, 31 Mar 2025 13:12:53 +0100 Message-ID: <20250331121317.1694135-14-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Pulling out the functionality of read_raw() and write_raw() callbacks so that only the mode claim is done in the initial call allows for direct returns and simpler error handling in the new __hts211_write_raw() / __hts211_read_raw() functions. Signed-off-by: Jonathan Cameron Acked-by: Lorenzo Bianconi --- drivers/iio/humidity/hts221_core.c | 89 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c index 0be11470730c..ca4746f2ecba 100644 --- a/drivers/iio/humidity/hts221_core.c +++ b/drivers/iio/humidity/hts221_core.c @@ -418,31 +418,22 @@ static int hts221_read_oneshot(struct hts221_hw *hw, u8 addr, int *val) return IIO_VAL_INT; } -static int hts221_read_raw(struct iio_dev *iio_dev, - struct iio_chan_spec const *ch, - int *val, int *val2, long mask) +static int __hts221_read_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *ch, + int *val, int *val2, long mask) { struct hts221_hw *hw = iio_priv(iio_dev); - int ret; - - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - return ret; switch (mask) { case IIO_CHAN_INFO_RAW: - ret = hts221_read_oneshot(hw, ch->address, val); - break; + return hts221_read_oneshot(hw, ch->address, val); case IIO_CHAN_INFO_SCALE: - ret = hts221_get_sensor_scale(hw, ch->type, val, val2); - break; + return hts221_get_sensor_scale(hw, ch->type, val, val2); case IIO_CHAN_INFO_OFFSET: - ret = hts221_get_sensor_offset(hw, ch->type, val, val2); - break; + return hts221_get_sensor_offset(hw, ch->type, val, val2); case IIO_CHAN_INFO_SAMP_FREQ: *val = hw->odr; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: { u8 idx; const struct hts221_avg *avg; @@ -452,62 +443,72 @@ static int hts221_read_raw(struct iio_dev *iio_dev, avg = &hts221_avg_list[HTS221_SENSOR_H]; idx = hw->sensors[HTS221_SENSOR_H].cur_avg_idx; *val = avg->avg_avl[idx]; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_TEMP: avg = &hts221_avg_list[HTS221_SENSOR_T]; idx = hw->sensors[HTS221_SENSOR_T].cur_avg_idx; *val = avg->avg_avl[idx]; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: - ret = -EINVAL; - break; + return -EINVAL; } - break; } default: - ret = -EINVAL; - break; + return -EINVAL; } - - iio_device_release_direct_mode(iio_dev); - - return ret; } -static int hts221_write_raw(struct iio_dev *iio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int hts221_read_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *ch, + int *val, int *val2, long mask) { - struct hts221_hw *hw = iio_priv(iio_dev); int ret; ret = iio_device_claim_direct_mode(iio_dev); if (ret) return ret; + ret = __hts221_read_raw(iio_dev, ch, val, val2, mask); + + iio_device_release_direct_mode(iio_dev); + + return ret; +} + +static int __hts221_write_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *chan, + int val, long mask) +{ + struct hts221_hw *hw = iio_priv(iio_dev); + switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: - ret = hts221_update_odr(hw, val); - break; + return hts221_update_odr(hw, val); case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_HUMIDITYRELATIVE: - ret = hts221_update_avg(hw, HTS221_SENSOR_H, val); - break; + return hts221_update_avg(hw, HTS221_SENSOR_H, val); case IIO_TEMP: - ret = hts221_update_avg(hw, HTS221_SENSOR_T, val); - break; + return hts221_update_avg(hw, HTS221_SENSOR_T, val); default: - ret = -EINVAL; - break; + return -EINVAL; } - break; default: - ret = -EINVAL; - break; + return -EINVAL; } +} + +static int hts221_write_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + int ret; + + ret = iio_device_claim_direct_mode(iio_dev); + if (ret) + return ret; + + ret = __hts221_write_raw(iio_dev, chan, val, mask); iio_device_release_direct_mode(iio_dev); From patchwork Mon Mar 31 12:12:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033529 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 896671D618E for ; Mon, 31 Mar 2025 12:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423303; cv=none; b=SkAI/Henf+GUR8diwNwkTD+kx4/9IwSqpCX7aYzqkZUSfU7Cj4KJuB+amYVIl/71h317xqEv9kbIINktFDUaJX0+wDJCAJtx/xFmZQDCP9v+MHZmnZdyyR2n8JNCjZMdQ7vboZN0HYQS9TXstZQl26bNzKRM1YyD6MLW5Pkb2Rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423303; c=relaxed/simple; bh=pLMwio6p4cgakr7w7elqwXNuJ5aTmzh6oRZZ5EckWeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=URXQyGOwWrlNuW6h2OvNiM5S7Lj1o2fWs3AisvUkgYq7Bzh/vUZJ3LS6B9e8J3sZAAY8PaT3ZHTuPmjlbnHzdSEm9ixh9q7sT+/Vr1qaqw/Ew/RY4gtC1zMFET1hVM/m0uwN2UZA13DwZarqUu3cpfuhmt7mNYq4s1xyBttXjcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jGTgi5hv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jGTgi5hv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D10BC4CEE5; Mon, 31 Mar 2025 12:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423303; bh=pLMwio6p4cgakr7w7elqwXNuJ5aTmzh6oRZZ5EckWeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jGTgi5hvyp4VomJ81/yxIeQbrbBeBs7x595vNMIT4MyGlXzUtzeNiLJ3W7WEVZyHA c/hXuXDNZYDjIDFo3JkCzSF/ltG9unHrrQ1yNBfUYP9xyWisJu3MsOpPuzQSwp7xX2 SkZb7K3WgFlionnnzSKfCvO9vAqyOY2f1ibTxEyBN6hpbJQzk1ISE0+x/HdWxwueVM kJJzSgj9WQVZ+6uq/EnFpsp3d5zOLscQFQV76ESAsxrbYgROtr8LZM4qqQp76tUTH+ /dugkbCJhR71+oR9GX5NuhigKwCMRX42EBNU1AH2M4Dv1plFrxS6lgQiVwugZJ7lR6 JAhYSMN89BlAA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:54 +0100 Message-ID: <20250331121317.1694135-15-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Acked-by: Lorenzo Bianconi --- drivers/iio/humidity/hts221_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c index ca4746f2ecba..bfeb0a60d3af 100644 --- a/drivers/iio/humidity/hts221_core.c +++ b/drivers/iio/humidity/hts221_core.c @@ -464,13 +464,12 @@ static int hts221_read_raw(struct iio_dev *iio_dev, { int ret; - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = __hts221_read_raw(iio_dev, ch, val, val2, mask); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return ret; } @@ -504,13 +503,12 @@ static int hts221_write_raw(struct iio_dev *iio_dev, { int ret; - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = __hts221_write_raw(iio_dev, chan, val, mask); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return ret; } From patchwork Mon Mar 31 12:12:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033530 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2DF49165F13 for ; Mon, 31 Mar 2025 12:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423309; cv=none; b=QVMx/daBzS7JtjT719k48MKA4Z4iXOdP2tODZzvZwowtXZOssWLpWP3UCbM/MiTw2/zjl9P9nlMDYgq7/Ui0KPf105fTysU2LfBo3VceEvNb67UrjBqpcG6mUxdlOvJyT5g6dGePyKFX/TgWJlhuBwXmthdLlp4veON2b8gneAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423309; c=relaxed/simple; bh=Y9aSTD/po3NwLmiYivy/mMRxniwb43HjsKIJi01vf/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z9KwyERs7o7yMMLqU5a3cn8wKkq0pbfh0v7aoVJHBeezw+gGt6Ds/bgOv7oYPqO/OG4WiG7plpztGav8XKqFM/v1CaTA4X10+du9P4GIzUfiBCUPj663DW0e54aw0aUYM+a3g1ZPf5XtI62O30o/Tv5l9LvnYSkfcspQsc5NHK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z8Ow70ns; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z8Ow70ns" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1583C4CEE3; Mon, 31 Mar 2025 12:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423309; bh=Y9aSTD/po3NwLmiYivy/mMRxniwb43HjsKIJi01vf/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z8Ow70nsfZIrLr0PDGjibljA/cYBVTlq1nBw3Gco/ZymvPAIKWfLw8hX7tgFwN5E+ agXr5U7sVCPrEmo0w3g8yWj4sE5WgoQuABJHJrrgukkOCELwFQW+Pnre7Kwqju+wkL WBQvZ0j3niDH8g+IkXJcJWVGaryLKxWKBL/SRTZSEUah9WMyu2TEfoCWry7jIkmDCl z7g/g5+DTMqPjwNXy+oW0gufphDmXk5QU6q64HoHGWXDm7N+pz9JojNfhh5OuRhzCd o3DK2LT9RMwD4Hns01unJD3/7xgn+rf2UWIghvoTvO5uTiOLfgjLXUtGzuNIJngXxD gRlaXMiX1RXAg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 15/37] iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:55 +0100 Message-ID: <20250331121317.1694135-16-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Jean-Baptiste Maneyrol Acked-by: Jean-Baptiste Maneyrol --- .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 21 ++++++++----------- .../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 21 ++++++++----------- .../iio/imu/inv_icm42600/inv_icm42600_temp.c | 7 +++---- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c index 388520ec60b5..1a67f5ce1800 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -685,11 +685,10 @@ static int inv_icm42600_accel_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_accel_read_sensor(indio_dev, chan, &data); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret) return ret; *val = data; @@ -747,20 +746,18 @@ static int inv_icm42600_accel_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_accel_write_scale(indio_dev, val, val2); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SAMP_FREQ: return inv_icm42600_accel_write_odr(indio_dev, val, val2); case IIO_CHAN_INFO_CALIBBIAS: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_accel_write_offset(st, chan, val, val2); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; default: return -EINVAL; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c index 591ed78a55bb..70bac8ca28fa 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -591,11 +591,10 @@ static int inv_icm42600_gyro_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_gyro_read_sensor(st, chan, &data); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret) return ret; *val = data; @@ -653,20 +652,18 @@ static int inv_icm42600_gyro_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_gyro_write_scale(indio_dev, val, val2); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SAMP_FREQ: return inv_icm42600_gyro_write_odr(indio_dev, val, val2); case IIO_CHAN_INFO_CALIBBIAS: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_gyro_write_offset(st, chan, val, val2); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; default: return -EINVAL; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c index 213cce1c3111..f77645d92efd 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c @@ -56,11 +56,10 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = inv_icm42600_temp_read(st, &temp); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret) return ret; *val = temp; From patchwork Mon Mar 31 12:12:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033531 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CDE48153801 for ; Mon, 31 Mar 2025 12:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423315; cv=none; b=WLMU8102wuV+0zSCe5gfDGvZubp41/TezIFLo3o4FOC0Hm6jH55fGTHrgbqcKV/hB4xVDVQLmuBk3jOA2317vdWT/G0Z5baEkRUxzioH0K6tuZHnoQVyCTT5mKb16XXnvCQ5ktWPR/+6JyLgogcWhi0CG83fn3u/4y0E0MdG1Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423315; c=relaxed/simple; bh=JE4XuKAKGgE7k0/xEL8h1v5KsxeemlI6chjEJgf7m5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tP2V0Pd+Xi4rpvcWv7tHUYZ+byUr6hCUHxJP+TxjUGOvtn7f2u0LwRnRzgG3NvwY7vK+wJ27EsNyjWa+9IAk6BXdzSJCX157YV4ynj0t/Dr51XdL5LzG+yiJv6aygHTyMfGFO89EDJ30aZPyNaovkA7NmsE6SX+lNIWodN+yVEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FS+hRJy0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FS+hRJy0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC1ACC4CEE3; Mon, 31 Mar 2025 12:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423315; bh=JE4XuKAKGgE7k0/xEL8h1v5KsxeemlI6chjEJgf7m5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FS+hRJy0c7rHEkIWPlTQV0FFYhgctWse06SlgZSV9zTBfN8E7d7EV0Sxmn/JEmtoe oz5blDtRcXzIA2AQJkYSllGSfCjHK1EqaE/SIp2EY4c6rwtHmWm3LMZW1M3GebgTEW SIvRxse0c6fnii6tAG31U1DTkNwBWkeIyym3bWslD6gRN0lZfznRIbD4qHEUSqxCJb xj/yu28r0voGQ8dHcFQKujwX/fIQUUYWJAPWzV6LiNzwrdZNt27+W0agRIpy+ONA98 IZWT4fzVft+jNCYy4/FIaQ40lbPpiSoE2g8JRtJ2s8y52CjvtJFsri2EgWJ4Wx/R8M wmhCy3WwkOZLQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 16/37] iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:56 +0100 Message-ID: <20250331121317.1694135-17-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Jean-Baptiste Maneyrol Acked-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 5bcd5e797046..b8656c02354a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -755,13 +755,12 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&st->lock); ret = inv_mpu6050_read_channel_data(indio_dev, chan, val); mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { @@ -895,9 +894,8 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, * we should only update scale when the chip is disabled, i.e. * not running */ - result = iio_device_claim_direct_mode(indio_dev); - if (result) - return result; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&st->lock); result = pm_runtime_resume_and_get(pdev); @@ -944,7 +942,7 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, pm_runtime_put_autosuspend(pdev); error_write_raw_unlock: mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return result; } From patchwork Mon Mar 31 12:12:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033532 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5B32813B59B for ; Mon, 31 Mar 2025 12:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423322; cv=none; b=S1NHYqsvFdukBvkMm3EqLsinIrMYVPhjzFukSzzhhVo9vUDEqEhYxRb1Rv+be9WSifKKpIpcHGyJctwB2oqqcioe4cmg1nsKmQfkPJadtAq8PRz20rzxQnsQsnZYqLKu0B+ZzIS4Ul2bADmWixbaPqx7o5z/6QJc/M+sYH0JHhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423322; c=relaxed/simple; bh=bpsIp2noE6jHlEdhsxhSbTt+a7yPD4ddvtPST+nIEZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e0w2sGYirTOS1FdCqSxUqZEuMiYYVXP17guAQJYgcp1HCai4NR6RcAKqKA2sLDcuxpv/zzOBtHqBrKPR9VTmJlFTJJ7FZSN+qEuFZHdH0CDSaEtpCyz/w13FtP7MGlJ64i0yxD4C0yaN0yGF5Dn/0Obj6VXRfMIfLqKZuT2af04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UWiB5hQo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UWiB5hQo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13B35C4CEE3; Mon, 31 Mar 2025 12:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423321; bh=bpsIp2noE6jHlEdhsxhSbTt+a7yPD4ddvtPST+nIEZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWiB5hQoih6qp7zRiZA8E++8X1+TnV5S2ObaJPNk1jLcMI3i5oLtweqrPUHh67MaZ N0vaDu/Q2tQom1vgXp1cszErvr1Ue4b0DHyMErpdUwT2xVri67XErlsTgkYa85/Xoo CMm9dFx79CeSUmNSk1CCoA497vBhGj+jsrqui/PGmuxVDSj3ZMXGpOMBFQOnomrNul uiPncpMDfDbQ0BJLC9tB6MFX+xfr87pTLrjEb0bm7YOim9fZ26G9YPawB44ykZN0Pp cbWWBI5V2x8Zc8AirTRSzFNYUWhID7V5aF9rQnzMHtCVm7DI7wArlsh9psQEYE3DjZ FPYquaIOwz9gw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 17/37] iio: imu: smi240: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:12:57 +0100 Message-ID: <20250331121317.1694135-18-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Shen Jianping --- drivers/iio/imu/smi240.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/imu/smi240.c b/drivers/iio/imu/smi240.c index 4492c4d013bd..d159ee59acdd 100644 --- a/drivers/iio/imu/smi240.c +++ b/drivers/iio/imu/smi240.c @@ -414,11 +414,10 @@ static int smi240_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = smi240_get_data(data, chan->type, chan->channel2, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret) return ret; return IIO_VAL_INT; From patchwork Mon Mar 31 12:12:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033533 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 687DE154C15 for ; Mon, 31 Mar 2025 12:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423328; cv=none; b=pIihtEIm7CKNeTqXqCyRXASBVFb37pR4KfxOSB8SmQCjyYgF9IbKeTCR5Q5v6e4oDvHaZg6IcOB2w6CZ8qPvMe4PPc3P28X/dQziN9x1filRKfl8PCQxiedLIa8+KtWz8R0DiBZeiNIgdRgkvEurwAvUXwln2gvFYRLH+AqgOS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423328; c=relaxed/simple; bh=JjWPuy+b+QXmgLam8m5ZykHsPQVA7cECRMcOy85gTR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r4erCjn9MRgUlmxlLvM8QgdjDufXUnYjeEUpFQF1hm77jgXtQRzAO2/7SZmei0ocezcO9Ivu0FwVceQH3PiQNEZQHtdEQyWlMwgNFwiZhukzQdjtCO3yIaOQbRUApLscAwtW7yyR8OjL4IGehvWjq0oh5akkxDDe3ySAiDRCBR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kqlQ7Jzx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kqlQ7Jzx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 685A2C4CEE5; Mon, 31 Mar 2025 12:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423327; bh=JjWPuy+b+QXmgLam8m5ZykHsPQVA7cECRMcOy85gTR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kqlQ7JzxXzOQ48slTqRSTGIqW32LJAo0X2dd1rQgf4wWkIfA9flxQxqShXjVQ9Dc/ +xbmG7VOxBpcPWaq60K2jkCFUK+g0W4wUhKw94B8lV8lo4y/j91KvIzPp4f3i+Fn3I eqbqC8vXQeT2xiVIzR87h1cEJmv9A0o7XpTszxMh+hYnAage/tDQXbqmcWeRTIFO8/ M9sy1+ks7WYlJfJDs4+C1ieXtoIxoZ7xxq8M5Mi6oScRd7izEnzrHTf960C8wjrkcv HW6kmvrNAXUpTjjM4zPzozdIB+sspVyhulXUwH/EjrcekJcFjy5X70zXAjc+QBxh4Y 5YWYqvDbm7FsA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Date: Mon, 31 Mar 2025 13:12:58 +0100 Message-ID: <20250331121317.1694135-19-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron By factoring out all the code that occurs with direct mode claimed to a helper function, that helper function can directly return simplifying code flow. Signed-off-by: Jonathan Cameron Cc: Lorenzo Bianconi Acked-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c index c1b444520d2a..17a74f5adfc0 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c @@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, } static int -st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); int err; - err = iio_device_claim_direct_mode(iio_dev); - if (err) - return err; - switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: { + struct st_lsm6dsx_hw *hw = sensor->hw; + struct st_lsm6dsx_sensor *ref_sensor; + u8 odr_val; u16 data; + int odr; val = val * 1000 + val2 / 1000; err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data); - if (!err) { - struct st_lsm6dsx_hw *hw = sensor->hw; - struct st_lsm6dsx_sensor *ref_sensor; - u8 odr_val; - int odr; - - ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); - odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val); - if (odr < 0) { - err = odr; - goto release; - } - - sensor->ext_info.slv_odr = val; - sensor->odr = odr; - } - break; + if (err) + return err; + + ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); + odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val); + if (odr < 0) + return odr; + + sensor->ext_info.slv_odr = val; + sensor->odr = odr; + return 0; } case IIO_CHAN_INFO_SCALE: - err = st_lsm6dsx_shub_set_full_scale(sensor, val2); - break; + return st_lsm6dsx_shub_set_full_scale(sensor, val2); default: - err = -EINVAL; - break; + return -EINVAL; } +} + +static int +st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + int ret; + + ret = iio_device_claim_direct_mode(iio_dev); + if (ret) + return ret; + + ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask); -release: iio_device_release_direct_mode(iio_dev); - return err; + return ret; } static ssize_t From patchwork Mon Mar 31 12:12:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033534 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2CBD413B59B for ; Mon, 31 Mar 2025 12:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423334; cv=none; b=BgGMHzzpO6oxi1EyyJ6JCbP0OAFlvqAE6HPpUFwNeN88/wYqWIK/cmthrlMq1G1TWxO+6xMrQ0pe65ADJbkhKyDOmQKmT2/l3kQz97KPWSrB3SH55YSJWU6YHgMYsYnCH1//JQ6aQUGPH0/9xdSDKcQLVmBayYxwUhiYnLu5iq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423334; c=relaxed/simple; bh=jrfpwY9AnpDdjNfVj8WPPVFTu9qh9emfIv3+kOxZ45s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHo44cbC9S1zZs5RSccdVeHlOBktNts8DHs4CaZXS89ew78rU4oFZIPRUuOucoGe0rG24ZvhTv47t5M5tPD2T0+XQPqLTyrXdwfyHOat4iztfPjfJAKUI8XxCS1zpyPH4zOMOUYI3KzSD7vXV6V5f/Rpqcp/YFVRSR+8bdS5FVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HwsCch5C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HwsCch5C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7280AC4CEE3; Mon, 31 Mar 2025 12:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423334; bh=jrfpwY9AnpDdjNfVj8WPPVFTu9qh9emfIv3+kOxZ45s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HwsCch5CodVgMq5xjfpxQsfhS507G+Z8iz5C6Raci+pxR6iRNHPXKyn6At2DZw2vf rF5Q5+7ffe9ibEvh1G8zALKgN4+tET7TKlIfegrHjWH035yDitCnYkeuTAbyI16TOx gdUBaBEPyHMnzxgoxl2UX5uUK8689x6+IjyM32dXQQbsLoM7KcPKFq9Bx5d88+LcP/ ktDoRFJyYNDyNk8SWa/HAZ7LDrzvHzu325FNyTVCR5Lr0RjEHOgstQM7hKz4of1JkQ lOkmyqJ4fiZlrLwaSjLkbYUD5lQ21Klz3onPyOjPPONf2iXsyF7PPAxkaQbllZC+l1 jXv8fdtPa47hQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Date: Mon, 31 Mar 2025 13:12:59 +0100 Message-ID: <20250331121317.1694135-20-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This driver caused a false positive with __cond_lock() style solution but is fine with the simple boolean return approach now used. Signed-off-by: Jonathan Cameron Cc: Lorenzo Bianconi Acked-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 4fdcc2acc94e..670cd217eb50 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -1804,12 +1804,11 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - break; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); break; case IIO_CHAN_INFO_SAMP_FREQ: *val = sensor->odr / 1000; @@ -1834,11 +1833,10 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, int val, int val2, long mask) { struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); - int err; + int err = 0; - err = iio_device_claim_direct_mode(iio_dev); - if (err) - return err; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -1860,7 +1858,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, break; } - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return err; } From patchwork Mon Mar 31 12:13:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033535 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5D1A513B59B for ; Mon, 31 Mar 2025 12:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423340; cv=none; b=Ef3AKvxXwqO4umxBKxTSkj7BZ8QPSrBAzOyowAu02xJLfW8z6EFlB7fnUidFctnZPBDqqFkjlfmuJPaHamoQ/J9XE1gMxjuqbeER5KQP5lnbJO0nCSVPXSH/AsDiBB3j6KeVTufIpmwsaIq1dJYAtPANo6/IYBy81bbLuUK/b8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423340; c=relaxed/simple; bh=VR++2UOfr364mmXn8Q2zor6eP186CmZ42rR19LJy9Vc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NFKOejC3PJXxXEyFVVVSOSM6CibAZ36Bd5kuriAxPjHNtKLm1M+r/WXDynY7TkYmi+GhFNR9NxXx474mLWiicTMP6Fe+nngG6d0yYcrkKzLDh6DRDp2suvQdljYgtiszBe1L7SSUfv2jLpHV49oHZLiG4DaK/1N2OkdT6i5nYPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZByWwBfo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZByWwBfo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFFE3C4CEE3; Mon, 31 Mar 2025 12:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423340; bh=VR++2UOfr364mmXn8Q2zor6eP186CmZ42rR19LJy9Vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZByWwBfoitwNBET9/22z00D9iUPTwisDA61Sm/P/8fgFgH6jnUybVH+QSRChqhGtk FzI8cDc2WBWBh/r8Q3fuSbIl3Vm9jvpbwgCkvQk0Q1VgoTOElg0aowAFAXyhb4QfIO VezlGR+c+lSHatWpCzIZkToO4bURd/IxZGeM+TXCgNLrowngFcUA4RZ27ad9TVlndu 4ecEdTG1YP6V+S7avVPh4iAVcddtaQw2S1L5KVtF0vrIH8Ac8Pp6GVLF18CoHMyfS6 DgvE63DriZAYOZDTW97d7KyOEalrU7XI9L6kLZ0sbsl+FJVUxrgE8l2vCNoKB9MElz IZb4Fn1KdmuqQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:00 +0100 Message-ID: <20250331121317.1694135-21-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Lorenzo Bianconi Acked-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c index 17a74f5adfc0..3c5e65dc0f97 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c @@ -558,12 +558,11 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - break; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = st_lsm6dsx_shub_read_oneshot(sensor, ch, val); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); break; case IIO_CHAN_INFO_SAMP_FREQ: *val = sensor->ext_info.slv_odr / 1000; @@ -657,13 +656,12 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, { int ret; - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return ret; } From patchwork Mon Mar 31 12:13:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033536 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1526413B59B for ; Mon, 31 Mar 2025 12:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423347; cv=none; b=bfp6WUN6bxiWpYeULZb66qx3NxdeuxLZ64Ld0jJsZRxzdoZiOjCUDLbLQI97hj3kMqnqTl+HnMfuRPLb1W0RQ90t7xBkQobb+6XNFeWnKzc24CAPxNgHHWmHD3n8qXGr4QOfkK6ax35OqUG36ejRnp76kruYncwL9zmfPcW2mq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423347; c=relaxed/simple; bh=oXXPdmlxo+9iJaskNtKtTIIyojX65VSEdTnhD2H7kCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b0qzAnph7vWDWTOZEC4qiO7WeYRhwUMJ7GzijmK32K4ByNiXtAn4HNMOMb/7AInsRbJeoCaPbOwCduc/moFSXcgK+jrbj4PwQ+jvWxlbM/l0n1VXpW/VWMsgzyO5R4Dwcn3p0Y/kJnuk6SSdbs1wNtQFZaTsKDPmKcxegP1TlwQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XFc7hBme; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XFc7hBme" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FBB2C4CEE5; Mon, 31 Mar 2025 12:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423346; bh=oXXPdmlxo+9iJaskNtKtTIIyojX65VSEdTnhD2H7kCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFc7hBmelxZAUzVVwAjYmU3VzOKScLrVt/QyMIlLzd6gw4+D+0yl11lawRpLTP0m9 sl20TbAQ+KOJVpofsvwP3mUU6TsHudcQ9XBD3fR8XA5jAEDrR8qHVvhCRQhf/HmO56 4Ju/Qi+MiJLyaXz0ItQ1Sbnq89sOtUKVN9ogV9g90vIfWDLaIFnRJqTF5P+VymC6EL l6EDGuAoTbLcwfhvfu0YLk4mC1G22vlVPgPT6bE8zeClqdiS1ti8ssC1uf3HY+FQeE m1pzAzmheWjtK3q+wux4fYzLOj8mf7iIZeChzIHYKo8R4lURUEwcy2nCIuoMh1wgpa wn3JIyKC/aqLQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 21/37] iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow. Date: Mon, 31 Mar 2025 13:13:01 +0100 Message-ID: <20250331121317.1694135-22-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron The combination of guard(mutex) and factoring out sections of code that occur with the device held in direct mode simplifies code flow. Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/mag3110.c | 153 ++++++++++++++--------------- 1 file changed, 75 insertions(+), 78 deletions(-) diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c index 2fe8e97f2cf8..b633bdf793ed 100644 --- a/drivers/iio/magnetometer/mag3110.c +++ b/drivers/iio/magnetometer/mag3110.c @@ -9,6 +9,7 @@ * TODO: irq, user offset, oversampling, continuous mode */ +#include #include #include #include @@ -102,17 +103,12 @@ static int mag3110_read(struct mag3110_data *data, __be16 buf[3]) { int ret; - mutex_lock(&data->lock); + guard(mutex)(&data->lock); ret = mag3110_request(data); - if (ret < 0) { - mutex_unlock(&data->lock); + if (ret < 0) return ret; - } - ret = i2c_smbus_read_i2c_block_data(data->client, - MAG3110_OUT_X, 3 * sizeof(__be16), (u8 *) buf); - mutex_unlock(&data->lock); - - return ret; + return i2c_smbus_read_i2c_block_data(data->client, MAG3110_OUT_X, + 3 * sizeof(__be16), (u8 *) buf); } static ssize_t mag3110_show_int_plus_micros(char *buf, @@ -231,19 +227,17 @@ static int mag3110_change_config(struct mag3110_data *data, u8 reg, u8 val) int ret; int is_active; - mutex_lock(&data->lock); + guard(mutex)(&data->lock); is_active = mag3110_is_active(data); - if (is_active < 0) { - ret = is_active; - goto fail; - } + if (is_active < 0) + return is_active; /* config can only be changed when in standby */ if (is_active > 0) { ret = mag3110_standby(data); if (ret < 0) - goto fail; + return ret; } /* @@ -252,23 +246,52 @@ static int mag3110_change_config(struct mag3110_data *data, u8 reg, u8 val) */ ret = mag3110_wait_standby(data); if (ret < 0) - goto fail; + return ret; ret = i2c_smbus_write_byte_data(data->client, reg, val); if (ret < 0) - goto fail; + return ret; if (is_active > 0) { ret = mag3110_active(data); if (ret < 0) - goto fail; + return ret; } - ret = 0; -fail: - mutex_unlock(&data->lock); + return 0; +} - return ret; +static int __mag3110_read_info_raw(struct mag3110_data *data, + struct iio_chan_spec const *chan, + int *val) +{ + __be16 buffer[3]; + int ret; + + switch (chan->type) { + case IIO_MAGN: /* in 0.1 uT / LSB */ + ret = mag3110_read(data, buffer); + if (ret < 0) + return ret; + *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]), + chan->scan_type.realbits - 1); + return IIO_VAL_INT; + + case IIO_TEMP: { /* in 1 C / LSB */ + guard(mutex)(&data->lock); + ret = mag3110_request(data); + if (ret < 0) + return ret; + ret = i2c_smbus_read_byte_data(data->client, + MAG3110_DIE_TEMP); + if (ret < 0) + return ret; + *val = sign_extend32(ret, chan->scan_type.realbits - 1); + return IIO_VAL_INT; + } + default: + return -EINVAL; + } } static int mag3110_read_raw(struct iio_dev *indio_dev, @@ -276,7 +299,6 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct mag3110_data *data = iio_priv(indio_dev); - __be16 buffer[3]; int i, ret; switch (mask) { @@ -284,37 +306,7 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, ret = iio_device_claim_direct_mode(indio_dev); if (ret) return ret; - - switch (chan->type) { - case IIO_MAGN: /* in 0.1 uT / LSB */ - ret = mag3110_read(data, buffer); - if (ret < 0) - goto release; - *val = sign_extend32( - be16_to_cpu(buffer[chan->scan_index]), - chan->scan_type.realbits - 1); - ret = IIO_VAL_INT; - break; - case IIO_TEMP: /* in 1 C / LSB */ - mutex_lock(&data->lock); - ret = mag3110_request(data); - if (ret < 0) { - mutex_unlock(&data->lock); - goto release; - } - ret = i2c_smbus_read_byte_data(data->client, - MAG3110_DIE_TEMP); - mutex_unlock(&data->lock); - if (ret < 0) - goto release; - *val = sign_extend32(ret, - chan->scan_type.realbits - 1); - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - } -release: + ret = __mag3110_read_info_raw(data, chan, val); iio_device_release_direct_mode(indio_dev); return ret; @@ -346,24 +338,18 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, return -EINVAL; } -static int mag3110_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int __mag3110_write_raw(struct mag3110_data *data, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { - struct mag3110_data *data = iio_priv(indio_dev); - int rate, ret; - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + int rate; switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: rate = mag3110_get_samp_freq_index(data, val, val2); - if (rate < 0) { - ret = -EINVAL; - break; - } + if (rate < 0) + return -EINVAL; + data->ctrl_reg1 &= 0xff & ~MAG3110_CTRL_DR_MASK & ~MAG3110_CTRL_AC; data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; @@ -371,22 +357,33 @@ static int mag3110_write_raw(struct iio_dev *indio_dev, if (data->sleep_val < 40) data->ctrl_reg1 |= MAG3110_CTRL_AC; - ret = mag3110_change_config(data, MAG3110_CTRL_REG1, - data->ctrl_reg1); - break; + return mag3110_change_config(data, MAG3110_CTRL_REG1, + data->ctrl_reg1); + case IIO_CHAN_INFO_CALIBBIAS: - if (val < -10000 || val > 10000) { - ret = -EINVAL; - break; - } - ret = i2c_smbus_write_word_swapped(data->client, + if (val < -10000 || val > 10000) + return -EINVAL; + + return i2c_smbus_write_word_swapped(data->client, MAG3110_OFF_X + 2 * chan->scan_index, val << 1); - break; default: - ret = -EINVAL; - break; + return -EINVAL; } +} + +static int mag3110_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mag3110_data *data = iio_priv(indio_dev); + int ret; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret = __mag3110_write_raw(data, chan, val, val2, mask); iio_device_release_direct_mode(indio_dev); + return ret; } From patchwork Mon Mar 31 12:13:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033537 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1EE5913B59B for ; Mon, 31 Mar 2025 12:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423353; cv=none; b=QB4tZ8ooHuW7Ff2dYAQxrdDXp2Vwzx1YYtfMFIsqexoKXc3D4EsMkRQ34AgcS8LxSC7MvhCuuY3Gx2vhP6WBxd9RZ60+KonlA/yvISkKZRmKqzcayoEM+62bxCl/1CPcgbhc1BK+h8uqS2gD2PXj4xnIS89AqadXhOIBnzH9MaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423353; c=relaxed/simple; bh=wWP4OSLDet9MTXy562O5het7Nk518Oxk5Zy2gCcxGfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tyF0pheATNf4Q2V0Qy3eTpStARYiOx7uf5ux24pWx0sD1ccKLp4/tZsACQMkPsvGwnRw1XPJvBGZB9vg8Qgx90nbi6BpmpnnDYOgJG4QLEiZ9Vnk+BjKW+KjtLFvLTJvXCeyexRgB3inZpTNq4lWgpzmhw+haOfpJPoTGecGiYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UEpSffGT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UEpSffGT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D08AC4CEE3; Mon, 31 Mar 2025 12:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423353; bh=wWP4OSLDet9MTXy562O5het7Nk518Oxk5Zy2gCcxGfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UEpSffGTNQwgeiDrguQrPhHABBu57Fd/BZRXe1hVu5tgvtISE5qOrQoSOWs4d2g8R rK2yFtkAeR5xHCCM8Cpu8pPAL1ZJqWuvUIQd4pv87+iJwsSeNc5ynSNQKRJhm4hfrn TiK/hRSKxqF6gDCXN19v2uebUWc8sp4kCuUvKRsZ9EZ3hRWrEAcOi31Vg8zzzXrYLI RtaWRIi7j8HkseeIgq4S2wsy4W3C40DugYzY7kuX6UXCD9DbWQQi+eDAIZW4Cp5jOT /TXX6r2L3fu9Ehr2i1erbLIO+ISvOEACjWHdc01oXug6prsPd6bppOoMTPy9CXjXkD K332MY33w3VQA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 22/37] iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:02 +0100 Message-ID: <20250331121317.1694135-23-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/mag3110.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c index b633bdf793ed..92d4511ed372 100644 --- a/drivers/iio/magnetometer/mag3110.c +++ b/drivers/iio/magnetometer/mag3110.c @@ -303,11 +303,10 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = __mag3110_read_info_raw(data, chan, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SCALE: @@ -378,11 +377,10 @@ static int mag3110_write_raw(struct iio_dev *indio_dev, struct mag3110_data *data = iio_priv(indio_dev); int ret; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = __mag3110_write_raw(data, chan, val, val2, mask); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } From patchwork Mon Mar 31 12:13:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033538 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5BE4613B59B for ; Mon, 31 Mar 2025 12:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423359; cv=none; b=fiWLipaP7YIe6mgFv+tn7oNYXY4OK0ujv06ZSdA8KGhlqlqlDzgRKUBtZrtp2JBmPlIuCZIAz5hvwAmU4IQeERWsStPl6+dzRyxMY5TWRNOkLjW52WsW+pRidcoc2xL8HPWFqnfErVwI+tAQXYMJV2X8MUeB/QiIM7FCjXZvAAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423359; c=relaxed/simple; bh=QbPjGNiEH56YpA27SkR3HxIXYFc7fD2SJi0T8/AzEy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YnWXd+XaOTGDZtDGgPKxKIxWhcG8YII7lbwsF64oI5acmgd1mcZiDQGOa33w+RGp0oooV9QBao3fcFpDu20GWH1e8UxhJoiK/0GE2uSnmcKgnCRjhWl1RUWGFe7sHf4QviVMdnfe+2cEw95T0PdIAxAAXjtJ9P+WTIHyyk0vs3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pPRQIWbc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pPRQIWbc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA1C9C4CEE5; Mon, 31 Mar 2025 12:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423359; bh=QbPjGNiEH56YpA27SkR3HxIXYFc7fD2SJi0T8/AzEy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPRQIWbc9xraM8Ij5wFma0LAuCT2xhYhB64RTTV9pBjPPpODseSGudYTkOy+t12KM HSa7CveJUeiwoYWH0K7GLnfSnMFun+mz3c+hGiPrD5iwSGfdAETD5SLYohty2YoEx+ MWpEim4UIXKhy5VvYz0kyYEHVTwNnw53KtR75lrOa+cyN2g4yiG2IK427oXHBLArda ri5sKQcGE1raJY95kw3ihrqj2n29jB4EJbxjt6xLYbmCS8Ue53IKlZdAfP8mbyIJ4X WYeNWjn07nC2NtS34+su5qwmPIe71oPlkpx7jsw1/MJfYThpRiTK85uWcKbR07euI5 Hr/sbdeKc8OKg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 23/37] iio: magnetometer: rm3100: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:03 +0100 Message-ID: <20250331121317.1694135-24-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/rm3100-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c index c99694a77a14..e5162ee64e01 100644 --- a/drivers/iio/magnetometer/rm3100-core.c +++ b/drivers/iio/magnetometer/rm3100-core.c @@ -399,12 +399,11 @@ static int rm3100_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret < 0) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = rm3100_read_mag(data, chan->scan_index, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SCALE: From patchwork Mon Mar 31 12:13:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033539 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B12CE1E51E0 for ; Mon, 31 Mar 2025 12:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423365; cv=none; b=QPWFD7BMlA2878266ILqdiXUQm+OXM3bIOd/fpkeBvD8kjepVLDXbCAIEyX7/OA9iX2SDXmB6ZGvmZI0xwQ3Enwcr5IVH2qjJdZSpeYmrmsIXJRFKwEyx1VOs9jsipoQStE++IBXKJRirNUJhkgrp0d0FkreMBm+jovm+NJxIqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423365; c=relaxed/simple; bh=814EvMRx0qFMRMvy57rOwBUuqPy4LiyubiQe0S3b5I4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PZvCOaOaZibLIRiY1K8T1BjfAp4Fuxb2D+Il7cY0fMWTU8Pj3jpoY2PlHSSqjcSy4PoWYNCkI/G6WfUDAO3sRRrVANtO5FaPmygwizwRtadF1A1qSrdE2YNHtVuAHcbzlHI50pr2Slj1QZK6OU3eulf78fSUgVWQsagCnSl3svA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mhuPyIx2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mhuPyIx2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C413AC4CEE5; Mon, 31 Mar 2025 12:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423365; bh=814EvMRx0qFMRMvy57rOwBUuqPy4LiyubiQe0S3b5I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mhuPyIx2xUb8WxvdSNYMuxAz/iEs4IFVZDiHCOHn9C7lNFU3gw66TQoCwzuT8ZPMB XdCkQqtoTrFjluTylbqahz+qIGLDZt1mVUt0UdOsfJulh8IOrSmwhaQxI7NaU9M9ek OqGUn+nMmoNMl+sr0tUiO6HpZz0j7xJBAvn4EzLTcu1ylExIX/++UUXBBmwfbNUZta izOrJ33GtJhdtfKUnPyURXJHauMWeV8CBOEd4xfebu6uCjcd6gsU8c+bcI+g0M9uV1 Q4OyKm5vgr3F/FjYhg/Ms81pkHIkkwwDWiumroFQaA8J4WACd06ZWKiJ8lyVahb2sp OZZjBJO0XjNKA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 24/37] iio: pressure: dlhl60d: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:04 +0100 Message-ID: <20250331121317.1694135-25-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/dlhl60d.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c index e99e97ea6300..e0aa12949cde 100644 --- a/drivers/iio/pressure/dlhl60d.c +++ b/drivers/iio/pressure/dlhl60d.c @@ -147,12 +147,11 @@ static int dlh_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = dlh_read_direct(st, &pressure, &temperature); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); if (ret) return ret; From patchwork Mon Mar 31 12:13:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033540 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 60EC513B59B for ; Mon, 31 Mar 2025 12:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423372; cv=none; b=JGuYI3sEJFNdVji/ZLamzVEMYwFoT4Hnewga7lxfXZ8iqgLzbw5CG/D8sUgi9GjBiKV+2r8MTORETROggW0+FAd00AOk8jSgIB8IVX0GZvWxwMxBJIqbSFHjc6eu3Sm8tRQX1ly2X/7nuKkUbsZKdXtvrNYa9rVCCCNQrMJwqf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423372; c=relaxed/simple; bh=a22iHUVEWcITkEW175cLzjZ/93VY9FSxJOe3GeehRec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+gQ2OhGX6pYn+n2wCyxiMaIbfD3Ojtd6xR8rBqCQbZio0o4AFKg4xZ2duaTURbEYVxNHgszMVDFt1+Aox6zMGCRZhTjuY4za8R0B5qr6uAXc9GRkFMiBD9XYrOKEcaylC6XPOXVtqW3uRtkCjDd+s3PTiu2SfJr3IoOif91AIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BXDSZYTc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BXDSZYTc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58E64C4CEE3; Mon, 31 Mar 2025 12:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423372; bh=a22iHUVEWcITkEW175cLzjZ/93VY9FSxJOe3GeehRec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BXDSZYTctw4yB1dWpqvlYk2HYCqYel4f9dSYjOqtBLddq3MEJ1aT+/GKdkAvvDz1A wXNEji7D8h7mQia4JYlHMQiJe1KAID7g4wmI93p0FGArxadFAHxCZYZnCnORDmhCRI hDVa8SqDndsWt0MAN7NvyQ/Mqqgi4kVNN4//E+CvzFbstsGw+h4VXEqk9qlU7GA3Wt Spk3irfADk5xTXRPHgj6Oua/hmebFLH9YQ03ZKwojppn2gLyZPv6ZZF14kJvZjvh5L OijaFT8ClHc/vQMgwGS3ycLHWcOHWZ/NrFuElrS6oZcdut4IaSZ6anHKiXnZPE2HdZ e4WJD+WNKs7FQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 25/37] iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:05 +0100 Message-ID: <20250331121317.1694135-26-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Acked-by: Jean-Baptiste Maneyrol --- drivers/iio/pressure/icp10100.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c index 3e0bf5d31ad7..1951c1cc84cf 100644 --- a/drivers/iio/pressure/icp10100.c +++ b/drivers/iio/pressure/icp10100.c @@ -343,9 +343,8 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev, uint32_t pressure_mPa; int ret; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = icp10100_get_measures(st, &raw_pressure, &raw_temp); if (ret) @@ -370,7 +369,7 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev, } error_release: - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } @@ -439,7 +438,6 @@ static int icp10100_write_raw(struct iio_dev *indio_dev, { struct icp10100_state *st = iio_priv(indio_dev); unsigned int mode; - int ret; switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -449,13 +447,12 @@ static int icp10100_write_raw(struct iio_dev *indio_dev, mode = ilog2(val); if (mode >= ICP10100_MODE_NB) return -EINVAL; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&st->lock); st->mode = mode; mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return 0; default: return -EINVAL; From patchwork Mon Mar 31 12:13:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033541 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0B9451E500C for ; Mon, 31 Mar 2025 12:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423379; cv=none; b=lgWhkytMVZ8UYilpqTRnxHbfwHLqwdFX9AYeASmPa1Oq7PJfblKa6pr4e0WV35+gzXnIj21bvSQnlPQZFGiW1vAfctdtCzYYxeElapXl9yb0MTijAIaYdpD++yOizrAFbi17ii+1QOsGz9qmdW5VF0SiyHxtj8P472i1DgJhUSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423379; c=relaxed/simple; bh=maMHlrcpg9cp/PofwmTKahkmOwMVxbiFXs/Yqza8F2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOiS1foJL1nYQdPqt0ma+RAvGHwBhmbI7kuHyzWIRbYoxKRY6fImTB387ZVbWG56xibsv2w/YX0+CqD36PndYERQLOYi8BluyOxBuXqSVzfSAOMt23AQPNLkMIQnuSpK2tCwEAz/gza6MjD9Vni7rpzP4arcpE8HsayFAaTjtT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OL22rUjh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OL22rUjh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05663C4CEE3; Mon, 31 Mar 2025 12:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423378; bh=maMHlrcpg9cp/PofwmTKahkmOwMVxbiFXs/Yqza8F2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OL22rUjhslthYPKc4lX9GWBAyWkAfUjndMurUr19vBulTqscgeIUKrEuhRI38CiTN Rb4DM0MJoH6fOMJpKK6oqghcMfkD/BBiiU4S4WnEhgsi4Kaj8+eKHSgis0J7W0SCqe HGCqdQd2zqaqaK4YzXLBMEZWsg/p8uWO3lLtCIOFakXi3nQiEXiKx7PiS0byPaE06b gw3BGVinZCKCwv+/r9PaO7he7/yT2obM5KQC8HaxX5iuJUPSQZHiIMhBUoUYKz8y38 1lexiPRlNFnTNuZa2Xv1X4lboivkar2HnAZn71/IHkXdrcYm7L9Nb7OOmCVCQCr3ml FDEKza279opSg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 26/37] iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow Date: Mon, 31 Mar 2025 13:13:06 +0100 Message-ID: <20250331121317.1694135-27-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Apply guard(mutex) to remove the need for manual release of the lock. Factor out the code that occurs under the direct claim. These two changes allow for direct returns simplifying code flow. Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/mpl3115.c | 90 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c index 71ded2eee060..207031b5ff72 100644 --- a/drivers/iio/pressure/mpl3115.c +++ b/drivers/iio/pressure/mpl3115.c @@ -69,6 +69,52 @@ static int mpl3115_request(struct mpl3115_data *data) return 0; } +static int mpl3115_read_info_raw(struct mpl3115_data *data, + struct iio_chan_spec const *chan, int *val) +{ + int ret; + + switch (chan->type) { + case IIO_PRESSURE: { /* in 0.25 pascal / LSB */ + __be32 tmp = 0; + + guard(mutex)(&data->lock); + ret = mpl3115_request(data); + if (ret < 0) + return ret; + + ret = i2c_smbus_read_i2c_block_data(data->client, + MPL3115_OUT_PRESS, + 3, (u8 *) &tmp); + if (ret < 0) + return ret; + + *val = be32_to_cpu(tmp) >> chan->scan_type.shift; + return IIO_VAL_INT; + } + case IIO_TEMP: { /* in 0.0625 celsius / LSB */ + __be16 tmp; + + guard(mutex)(&data->lock); + ret = mpl3115_request(data); + if (ret < 0) + return ret; + + ret = i2c_smbus_read_i2c_block_data(data->client, + MPL3115_OUT_TEMP, + 2, (u8 *) &tmp); + if (ret < 0) + return ret; + + *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift, + chan->scan_type.realbits - 1); + return IIO_VAL_INT; + } + default: + return -EINVAL; + } +} + static int mpl3115_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -82,49 +128,7 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, if (ret) return ret; - switch (chan->type) { - case IIO_PRESSURE: { /* in 0.25 pascal / LSB */ - __be32 tmp = 0; - - mutex_lock(&data->lock); - ret = mpl3115_request(data); - if (ret < 0) { - mutex_unlock(&data->lock); - break; - } - ret = i2c_smbus_read_i2c_block_data(data->client, - MPL3115_OUT_PRESS, 3, (u8 *) &tmp); - mutex_unlock(&data->lock); - if (ret < 0) - break; - *val = be32_to_cpu(tmp) >> chan->scan_type.shift; - ret = IIO_VAL_INT; - break; - } - case IIO_TEMP: { /* in 0.0625 celsius / LSB */ - __be16 tmp; - - mutex_lock(&data->lock); - ret = mpl3115_request(data); - if (ret < 0) { - mutex_unlock(&data->lock); - break; - } - ret = i2c_smbus_read_i2c_block_data(data->client, - MPL3115_OUT_TEMP, 2, (u8 *) &tmp); - mutex_unlock(&data->lock); - if (ret < 0) - break; - *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift, - chan->scan_type.realbits - 1); - ret = IIO_VAL_INT; - break; - } - default: - ret = -EINVAL; - break; - } - + ret = mpl3115_read_info_raw(data, chan, val); iio_device_release_direct_mode(indio_dev); return ret; From patchwork Mon Mar 31 12:13:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033542 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2070F1E4928 for ; Mon, 31 Mar 2025 12:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423385; cv=none; b=VEvuf1o6wMiatEtxTehMDOy9eStTeRLyTtt35bx4KE6WFq6FMmEy1n96q03X1Lxv/nURUbmCj8ZLf0DJUjvL+cYDC+hR5CEU1Uz2fnebOjCqvJTw0tVtkf4ArHGTIPttaIon4ac8RtQqzfIoCgs7A40iJEYyeNLyG8WmDRhSV7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423385; c=relaxed/simple; bh=ZcZGIii6/Ox7LyowmCk1Unk9ygW9GtczF1dAspq7l0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGI+RH3KlnVwM+wLrqt6ylb569N1gOlupm8hYc6azpJV7Vd4M+zTkKU8PR+ERGlglzfcucWWjBLZO8FhXxwABUl/CFiY1lI1cmamdZiwxq4D+MGu3xG60SNg4pvKz6XOMTIfM/tAKgn4vBJNh4/9WbrlT7TbYIlJnAx/y+oc/aE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z+BRhsWN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z+BRhsWN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71A4BC4CEE3; Mon, 31 Mar 2025 12:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423384; bh=ZcZGIii6/Ox7LyowmCk1Unk9ygW9GtczF1dAspq7l0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z+BRhsWNqZ4LGWlXzwDJtuGC2QvSAu32BnKXjoPOLFEy7wf6SpYEcANqUFK0g8+DQ fJvwpjWrRRq1hpSmUb43gKCZ80ikqpdpwj4QIiZiHXSBe/knTP/K0hWzPRSO2BxexF QQjZmJ3jf15bbryzp1e4DwJ/+o2H+vFIuqKHIX2VyOblCPipQvDD8xzlY1hddv8jSH tvKgnPvk0VXAHhvEZTHREFbWG7H0s/6qn6tqUetf+MjFT81bz7P7/NjOX6Xs7QmOLZ /7/Dy5XfExM9M+LFPfo5pwavJ7OyTmxxPN8g7WsKhkQY0r7PRN5PJm0Qg8LicwQNBx faTr4baFyvjIg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 27/37] iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:07 +0100 Message-ID: <20250331121317.1694135-28-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/mpl3115.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c index 207031b5ff72..8397155555bd 100644 --- a/drivers/iio/pressure/mpl3115.c +++ b/drivers/iio/pressure/mpl3115.c @@ -124,12 +124,11 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = mpl3115_read_info_raw(data, chan, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SCALE: From patchwork Mon Mar 31 12:13:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033543 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5146E1E3DFC for ; Mon, 31 Mar 2025 12:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423391; cv=none; b=FtbFepDL4kEE29zpOOnXoYpNCEXgN9VkOOMm6BFqVZeNeMRUmdakR81UvswbzJGyTedzNswM6rrJtwQS5QO0nl4aMbZgGmJ8VHzQp4KzaAFAKvYNeUkOwaynk1ZtxxvYhgqfN81wdwOvvqVbd4Y2eQJwaqePmLeF7he7UVVAdUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423391; c=relaxed/simple; bh=Iz4qiV8Ly1KzdhGnc1n/KWhYz9IveIFj9UfC1DZr6/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MAJhASxaSESVuW47uns921BpKmUCa7b/KOhL3SezhGAWpOlG5AqBiLDONdzfD86kbuFVLJizj1wKO7s6Jxrv1AkTtq6aERwpBJIhTW2/0YfnobssGhXtFMLBPESesNCbtrkOM/0J51mISFZ7KFE0AUKbLH7040iCAEAjuGB0+NE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JKnMD10C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JKnMD10C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73877C4CEE3; Mon, 31 Mar 2025 12:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423391; bh=Iz4qiV8Ly1KzdhGnc1n/KWhYz9IveIFj9UfC1DZr6/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JKnMD10C0ipWUvbEmYzf9KuRV+PqW2GYJBtrLWn7huLpojtVr0VvwDYQ99S5ZKyQG /wN7e3kvuEldkiJ+7Y04DfaO232SZyYzJlNocOqUmt286Cz0MbEKeh64hZrAZ8M5NW IymYWkiZjzv7T4xomYevTAlhpuMLdh06X8NkxZ+JAIbafjCtMduVvs5oR1qk1yyRAl 59EgOJoJA11spP4en2vAWwVOLH1bjMBn+f+OWG2nq2vl/5sS382fykjA5VAkmvLato eVNurZphBTegCr8lbhO3IjGGPVlKGLgU6IXacm/vLZD0ub3htAkH9camBhQXJsJdeA 0lzoawSby6J0A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 28/37] iio: pressure: ms5611: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:08 +0100 Message-ID: <20250331121317.1694135-29-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/ms5611_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c index 00c077b2a2a4..bdac27bd5a5d 100644 --- a/drivers/iio/pressure/ms5611_core.c +++ b/drivers/iio/pressure/ms5611_core.c @@ -308,7 +308,6 @@ static int ms5611_write_raw(struct iio_dev *indio_dev, { struct ms5611_state *st = iio_priv(indio_dev); const struct ms5611_osr *osr = NULL; - int ret; if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) return -EINVAL; @@ -322,9 +321,8 @@ static int ms5611_write_raw(struct iio_dev *indio_dev, if (!osr) return -EINVAL; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; mutex_lock(&st->lock); @@ -334,7 +332,7 @@ static int ms5611_write_raw(struct iio_dev *indio_dev, st->pressure_osr = osr; mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return 0; } From patchwork Mon Mar 31 12:13:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033544 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C03B813B59B for ; Mon, 31 Mar 2025 12:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423397; cv=none; b=UUgcOPX/J+3hYOgJSKxXCWTnuI91opR1sQGVvWraCS1Pr0o9duP5q+KTcLfvxDSSc/J03+7jv+1QaSnf5pf1qVJkOOLXXB0+L34vcl6KsHVPbf4d+PZVujiMmvbprcV1lf90jrribF0s7mHdTCh2iojbfmPVsBdBN6hfpKbsRyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423397; c=relaxed/simple; bh=bkUBroduMD1qkWRgXaqshRbm7zTAmRWl8fpL8iy7krc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sapshwv8BKTrop8F3FrS44CQwHIkvHYKhf3TxhSmDXGDU6dIRk8BDngdbI6EocEOyqp5394jqa0jAkQhZT50xZsPxypZXRvTEsrbYlHq7qWWGFG7ao18Y3UMAkzjv/Md4Wlk9Q22/Uf9/bRRHswBN0oOTG0AfcUZheFc8K8NziE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G4VrFSte; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G4VrFSte" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D22D7C4CEEB; Mon, 31 Mar 2025 12:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423397; bh=bkUBroduMD1qkWRgXaqshRbm7zTAmRWl8fpL8iy7krc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4VrFStesG4yZpJ0EP3T8TvA3/GAWfwf1ro1tZfqA7EOK6++lbOMtEICrsUGaCwMa bCga0mnQMwnLiUiFBr3pO4gru/gkODowb0us9NvqXZ1SZjupBgFfZFh7brGGDZNjuN L1HHrDo717bHq+vpAHGSlp094V+4635abvt2qt1rhBGctMLMiKhoXme31QOl1aoIUB HVOIHPE2o9aStiLhJa+U8Wx25cwM03Q9niEqc82xdcPTuYXvUaybEr6Z+rX8Z1ThHp hkSw1OOUc2+QX8uRXd8zxlaZ4C2j4vL+tbSay5fMlnzA5aiY3wq1vXWJcos1SnlMIX rly+R6yZrSI+A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 29/37] iio: pressure: rohm-bm1390: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:09 +0100 Message-ID: <20250331121317.1694135-30-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Matti Vaittinen Reviewed-by: Matti Vaittinen --- drivers/iio/pressure/rohm-bm1390.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c index 9c1197f0e742..c48231739f48 100644 --- a/drivers/iio/pressure/rohm-bm1390.c +++ b/drivers/iio/pressure/rohm-bm1390.c @@ -319,12 +319,11 @@ static int bm1390_read_raw(struct iio_dev *idev, return -EINVAL; case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(idev); - if (ret) - return ret; + if (!iio_device_claim_direct(idev)) + return -EBUSY; ret = bm1390_read_data(data, chan, val, val2); - iio_device_release_direct_mode(idev); + iio_device_release_direct(idev); if (ret) return ret; From patchwork Mon Mar 31 12:13:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033545 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 85D8813B59B for ; Mon, 31 Mar 2025 12:16:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423404; cv=none; b=REPcTfkRabt7JGGpM++tTqY2vNvDCRIu7kZhuElCBdnydMhgPys+JbpTOv6Xiv+YqALiP5HKIOrF25UsTcx/nZopbZUSi0jPRLH3OyrezDgBUUp2dAy3/Kw3saguYfLtpQ/y7RYr7Fq0FwQ+QaseKAAzGaZC+9hOvpYLgfp0P4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423404; c=relaxed/simple; bh=dnCGsUoYuKQ62zcc48laVLaiJRe3tyDVfJ4ijD3rWrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NAkUhrQyNjFwPexnwrHOGIZ0q6eCM4SENCLBLpPzalMh4JOzxglBSC2Gid4HKaxMo2LNnNTH5BPhExPR1L1F6x1vBz1Kj0jSLOu+Tx8Tr3t4yq3o6YjT40HfQHrwn3qjCV+SOrXR4ROjvmRVNPlFpxyDxetfiCuzXWIRu+a2EaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oBDiI7CA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oBDiI7CA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65502C4CEE3; Mon, 31 Mar 2025 12:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423404; bh=dnCGsUoYuKQ62zcc48laVLaiJRe3tyDVfJ4ijD3rWrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBDiI7CAfQSPE38PFgL5R9/BRGCI2JD4Y0SokKOh2rzj59Vb8G3ytTBNJjce7hoC7 NB9I1rsqgRjs16LYXx2EeFxUBSMP/rjQ3MR2naJ3fXo7kYabmCgqdhgbEW4Ycn3Bpl xXFr9kcvc/cpUnn6g+bghwFWgskCf5b4sdEiadfmgCldsyCgb7rG6gS7Hd7rkEBS1E tDnN+xIeB5LxL/95gWf1fy5/R2Q3OAy9GY7tQMaWlY8bW6uOurioeYWahMjd/1bYFA /fvwngg6BYH9Xq4BmZOR9n1+3hrYvggjalf7/cUShh1TTuN//ehvi2AVlpswlPrBPs jxkvtu79hgi7w== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 30/37] iio: pressure: zpa2326: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:10 +0100 Message-ID: <20250331121317.1694135-31-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/zpa2326.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c index 9db1c94dfc18..0a510d5fc1d4 100644 --- a/drivers/iio/pressure/zpa2326.c +++ b/drivers/iio/pressure/zpa2326.c @@ -1062,9 +1062,8 @@ static int zpa2326_sample_oneshot(struct iio_dev *indio_dev, int ret; struct zpa2326_private *priv; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = zpa2326_resume(indio_dev); if (ret < 0) @@ -1120,7 +1119,7 @@ static int zpa2326_sample_oneshot(struct iio_dev *indio_dev, suspend: zpa2326_suspend(indio_dev); release: - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } @@ -1438,7 +1437,6 @@ static int zpa2326_set_frequency(struct iio_dev *indio_dev, int hz) { struct zpa2326_private *priv = iio_priv(indio_dev); int freq; - int err; /* Check if requested frequency is supported. */ for (freq = 0; freq < ARRAY_SIZE(zpa2326_sampling_frequencies); freq++) @@ -1448,13 +1446,12 @@ static int zpa2326_set_frequency(struct iio_dev *indio_dev, int hz) return -EINVAL; /* Don't allow changing frequency if buffered sampling is ongoing. */ - err = iio_device_claim_direct_mode(indio_dev); - if (err) - return err; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; priv->frequency = &zpa2326_sampling_frequencies[freq]; - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return 0; } From patchwork Mon Mar 31 12:13:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033546 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F36491E51E0 for ; Mon, 31 Mar 2025 12:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423411; cv=none; b=jso1j214d4lE5eTpEYXLP7fJmsTo2itpY+edtYIV4eNp9mRL4PzHxtt+1DYjJN0Wtk3yQabdV9BmM41Ut+jFjzia6kHt2xdV8b3wnDmaSqkR7FFzI6ehJo4lX1h7/0mnYoK3gaS1slOg6mPBQuKDSP2EDIRk93nWSnh15ev7PGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423411; c=relaxed/simple; bh=t5zsMLD9acAVhrclDPi3bIflel+5AtGA4BotMrkH6oM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a1oLabBgocJtUE0Dv7iEUpknxYjTLuAcBZSfQOxaDYNtCPg4HztNEgMTFoB1PgyHV8J9kQPCQX2f03qycxjc59N4G5fz55caTvlHxJ4NG8KRKTrKZB/Se+cUM5DeEXXSi0/j9hImyQrjftUlwy/gqHQAH59/ccRAUJT9FhHWjNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N6d+RtQj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N6d+RtQj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9107C4CEEA; Mon, 31 Mar 2025 12:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423410; bh=t5zsMLD9acAVhrclDPi3bIflel+5AtGA4BotMrkH6oM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N6d+RtQjd24PCi0T5mrrSQz9uGECGIlOkSyqE2ekv8OZmvHNJzK+CfYh0wVZS07ka xSr7b15OIMa766P+TkqEtNUHniciudWgKB3jpGk8kvD/+hyycopaV8xhGgtm9Omi+o wu6SNoobLFd8EUfI4PZVaA2TbRpep3OqWJptQHBoNgT5Ad1HOM0nZyS02VZ71oHWgK W9cSMIXyEhFQ6MZ5So8YHKAnjJzelusBXiw4fATs6/Zq3mIuj+Eq3U3ZzXHWYae3xO S9+YC85Zg9fzZk/KnODTWRhrUJ/SiPYUAYiRpAxCNLayTQg22S1Wm2NbTppH/vZ4wI uUlT6rowx28hA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 31/37] iio: proximity: hx9023s: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:11 +0100 Message-ID: <20250331121317.1694135-32-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron Cc: Yasin Lee --- drivers/iio/proximity/hx9023s.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c index 5aa8e5a22f32..5be5f4986347 100644 --- a/drivers/iio/proximity/hx9023s.c +++ b/drivers/iio/proximity/hx9023s.c @@ -701,12 +701,11 @@ static int hx9023s_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = hx9023s_get_proximity(data, chan, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SAMP_FREQ: return hx9023s_get_samp_freq(data, val, val2); From patchwork Mon Mar 31 12:13:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033547 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 692801E501C for ; Mon, 31 Mar 2025 12:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423417; cv=none; b=iG6ye9rnZhQK7SAVvqy40yo6T7mYHLcCiXDuM6ZkySFj9DlYIxoZZQKBR0YDpMvOLUFkw0eVCXSfClTx84yZxFItuvlZV/4nOJEVWZnXT608I+7yQjCsUg5+IlLuHqHOiUrighqqI+qF6PYhqbshBP54jhmE3QvilFrM2XIPP90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423417; c=relaxed/simple; bh=tHXW3fpW98HEs9SmLkvRst4eFbAgpU4tqdgmDSr65lY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lst+M6LN+SG9LehGtiZcSQajGjQpTspT4XOBGxeW2n8N6XrIKbGsXM6kArxw5Pbg15OhvB0X8lRO/d2ww4cdTqGYSrXRNwrO88Tya0+vIyoxDhcuNfhkYVefhz1FbZ5JM1DJuqUAQP3TlPb+hUCZimMCgAiff5QtaMLK+p1NKEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZtczAyQI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZtczAyQI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34DA1C4CEE3; Mon, 31 Mar 2025 12:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423416; bh=tHXW3fpW98HEs9SmLkvRst4eFbAgpU4tqdgmDSr65lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZtczAyQIBOw7/EiSJ7Z+BtPLCOjbTBKR3Xnx+0pfFX+Xlb93U5YXUUvSvsgP/Vpkw qo0o0MpQV+e3N4CfS2RNndO4BhLhgoaO421sdXYZnviS40/TZzIyQkm0finQdnmOA5 kL95msN1OZMtB4VUJAEoX6ZP6566qjuIAWnusmiDO6mxVOHiRdCITiTEekzmbnVH8g GZeFwWCl9cp4LXop25+oJFX+bCP2t6GE7kmvYVKAnozkuOMDfMBpLJbjBx8Eona4+n F/86evhBR9X0npXMeNfvIz0DpW1x4E5coUSeLAhoL2zJvkawA6g94Pl4wdBtSsrbsY 8iUH1e17F69NA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 32/37] iio: proximity: pulsed-light: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:12 +0100 Message-ID: <20250331121317.1694135-33-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c index f3d054b06b4c..fbf9f8513055 100644 --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c @@ -208,7 +208,7 @@ static int lidar_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: { u16 reg; - if (iio_device_claim_direct_mode(indio_dev)) + if (!iio_device_claim_direct(indio_dev)) return -EBUSY; ret = lidar_get_measurement(data, ®); @@ -216,7 +216,7 @@ static int lidar_read_raw(struct iio_dev *indio_dev, *val = reg; ret = IIO_VAL_INT; } - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); break; } case IIO_CHAN_INFO_SCALE: From patchwork Mon Mar 31 12:13:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033548 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B3B8013B59B for ; Mon, 31 Mar 2025 12:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423423; cv=none; b=b9tvWQ+JcN+xiqUMMK20ww4DEUvzrJRb5TVCGSPAAXLaT+ny4dA3BlyySnTUC83kIZk9tObdv5TU1Qakblflm9JYjyLMX0LnaRWSWFFCFHQIrndT4lFhT1YkEJ3nw3/4sFdGCxSYzbfXHT+gBfNC4auhcMtGd2r7Qr3nBeTI/iA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423423; c=relaxed/simple; bh=Y42zDixZT89OhcJYjVbeP9CphLImDf1gNHjVV/eU0pA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D5btV1oXYXUPzJTQPqvADffGGSijpaYFeMNrBUu4jg4yb4JZnHW5dhRcNOFNigysFGAM2epeUMmOZSbaBc2j9DLdFJFMzfkQ74k0vjrf9YbIYmZ+cFGpmWlsEBb11g252H1dIEOXHhYxAIn8sWPIObdsbKPZMWwcwLC6aR5430s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CKO4ryLQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CKO4ryLQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FB42C4CEE5; Mon, 31 Mar 2025 12:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423423; bh=Y42zDixZT89OhcJYjVbeP9CphLImDf1gNHjVV/eU0pA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CKO4ryLQBlRRmETc1s1+4mkf3+aXIpYUYPgl/jivDj+iT4PYxDzoLB42ZP+eDnulB TCVMp8fuXbuq3SFtKwL1BA5lJfLuLpqewn1ULJOModkr01rgzn7fiF7lKqUMivINMW 7YljFFoGni4TKF4I0PMhJ8WzpLSac0hK4Pobl6r7Yv1BHaHXLlvQcL4k4B0oPDmaIf 7Q11XIGnIPayVqEtrQlP/3yjnQ4Yotgbf+zVcRTQ3lOVb60Z3hWgzuTBeo6/+C6kO5 +bIQ8w/Bky6vxUTU2DH+6PeAQSRacITEPnf+LPB3aptt2EducpWKf1NsN4G7+mlRFY BO+gXFnII1j7Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 33/37] iio: proximity: sx9500: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:13 +0100 Message-ID: <20250331121317.1694135-34-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9500.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c index c4e94d0fb163..b5e2855975ee 100644 --- a/drivers/iio/proximity/sx9500.c +++ b/drivers/iio/proximity/sx9500.c @@ -387,11 +387,10 @@ static int sx9500_read_raw(struct iio_dev *indio_dev, case IIO_PROXIMITY: switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = sx9500_read_proximity(data, chan, val); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9500_read_samp_freq(data, val, val2); From patchwork Mon Mar 31 12:13:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033549 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 29CD713B59B for ; Mon, 31 Mar 2025 12:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423430; cv=none; b=Gk+8dke6HovXK+cQR9+Wf7sAhpeblb2QIPHFtuf9ue7Z2GjKM29pzRSxTAIPz3xthDNpqBpXU5fbuHcFMSuuA7sVIWiiFPnA2KV0yYo3Sv+K2/loDTvWWOf5xil6q0aSsZ6dHD16QZq91Q8HMiyWvfZp3/546ib0oUM5OURm5eY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423430; c=relaxed/simple; bh=xblcPfOMh6aAs8TN16Jsn6pxnoWcn5GCCb3XLYu3Bsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M25WPhOz2lPS0EdwZbfJvSUS5/V/EDXLy7b5CvZ/vBnxHD27ySSWo9LLyDPqRsSWWrborwNzeJKoKhEjvUF61ADU8s9bHZyUH8qRcGEutBYxnAQWTbhEQ1GqA5/tJD5iZ4yg5WieJIqC9nKcb/v1rCa7woRbnwObvD2oBnGC13o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KeiMFdPt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KeiMFdPt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7F95C4CEE3; Mon, 31 Mar 2025 12:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423429; bh=xblcPfOMh6aAs8TN16Jsn6pxnoWcn5GCCb3XLYu3Bsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KeiMFdPtcgUBM8DGK17oYRvA2RW/3hxkClHoVJZ2f3FmvUet3kkkUDHoNE9p9SZoO KsARWnvwCcPbDYjZGMPDTYgtrw3o/58A8JixWhifEcVy6GqmQlxZLnv67KiGVPHgD4 msk4Ie4iOYDFNw6QgtiZMdTqeVS427ZSrieqxL/NC8y4tzPlL5UKO4Rw0mKOvuA4qq 9esVAS6w1b0zS0c5PRJGMdk1nHJ59T4E0RfyzIKasqgVRgiXQ/W+jLgfC8MMjQKNRT lSQ+QfgmrOk0SAPh8kZ2Ff95CVFm/+lnSITcuSWjKlo6T8zElHot6NvXkjvpa7UUB5 l/oUFCBJYC6kA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 34/37] iio: temp: maxim_thermocouple: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:14 +0100 Message-ID: <20250331121317.1694135-35-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Tidy up a few direct returns whilst here. Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/maxim_thermocouple.c | 29 ++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index c28a7a6dea5f..a1c213d5c469 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -183,40 +183,35 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct maxim_thermocouple_data *data = iio_priv(indio_dev); - int ret = -EINVAL; + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = maxim_thermocouple_read(data, chan, val); - iio_device_release_direct_mode(indio_dev); - - if (!ret) - return IIO_VAL_INT; + iio_device_release_direct(indio_dev); + if (ret) + return ret; - break; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: switch (chan->channel2) { case IIO_MOD_TEMP_AMBIENT: *val = 62; *val2 = 500000; /* 1000 * 0.0625 */ - ret = IIO_VAL_INT_PLUS_MICRO; - break; + return IIO_VAL_INT_PLUS_MICRO; default: *val = 250; /* 1000 * 0.25 */ - ret = IIO_VAL_INT; + return IIO_VAL_INT; } - break; case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: *val = data->tc_type; - ret = IIO_VAL_CHAR; - break; + return IIO_VAL_CHAR; + default: + return -EINVAL; } - - return ret; } static const struct iio_info maxim_thermocouple_info = { From patchwork Mon Mar 31 12:13:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033550 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2BC1513B59B for ; Mon, 31 Mar 2025 12:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423438; cv=none; b=Pr9HhJ5O45HPJE/AKyzCHa+37Dk43t3axnu3FmJs83U1JlHpeLOOMbbHvrqrGiEoxgrkGDGfeZQIYgg0L/rEP0ax2RK1bs143tkG7yeFGouGUpOgdwlaRfEMXjp4Hw4a9Yr2cQeWmqLncTtRx3AGmmt3Ls/Ddxi4gYRQoi623PI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423438; c=relaxed/simple; bh=63bsLeNRCvs3h9uskeEtJydLXLceBFgeQFJiyYQhQvA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pXaOM3cpvMm4zaXMYG6FPG2kZ8vA2WTVPGe0RU8fZIKcEZpgTjPD45h63J875/YJ5ZDoXNlcOCwJm9j7yqREnT0jOyopUsN0Tq10f0ev5mcCmTzencwdoxs2Guq0doJtKQjVYAa9PJgx1ReREU4eIA/tm7m2zR0vKXm+s4jKb4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=luF/nWhI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="luF/nWhI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2708DC4CEE5; Mon, 31 Mar 2025 12:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423435; bh=63bsLeNRCvs3h9uskeEtJydLXLceBFgeQFJiyYQhQvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=luF/nWhIZSLoTCu1nzxx5o6aQXXCqm5RcrxmDoHl6MhPpWD9vSpi8pqrBvAO4pSJM cG5LDLR0q4Mj6RtIlvgCwNgFBFYQoOTjcr/vQgW6yLHkwd3nNYlyCffz5fwPV4Rx0d BFBE+r9rkbjtlnpCIaLKUBE0JRGq3ZhbZccdIcKU5S7XLfghtf+Li4OhLpCGniIJVS NrSUfxTI0VTWwiQDXwfu3vQVcIzdbE/JeJQS4uqdFe1HwISZ1Go+Taz04zu7cSZZ8W qT3exbO8j9RoweuSDniHhGFrxmC4U72rqlH5FsTdT7c01uyW2qFFBNE/HKrCHJ4TTY ECtN/M+eJlMQw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 35/37] iio: temp: maxim_thermocouple: Drop unused mutex.h include. Date: Mon, 31 Mar 2025 13:13:15 +0100 Message-ID: <20250331121317.1694135-36-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron There are no mutex related calls in this driver. Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/maxim_thermocouple.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index a1c213d5c469..a13efde76397 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include From patchwork Mon Mar 31 12:13:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033551 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8662F1E51F3 for ; Mon, 31 Mar 2025 12:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423442; cv=none; b=Ejp49fhEKEm1r40UovprgVNYdBeb7onCjXSlbJA4b3FOGXXJ3JiFFgC6/U+Vo0xov9fHGNhJvn8qCIx9nwhQQPTwPP1O/r04uJR/xTsXZEOecO8QTi1KspzTxBWcPATj0nByBLEcuQju3ZHXrngCgnOC/R5AtDfsqa1hRdOrWXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423442; c=relaxed/simple; bh=DHd94nGDnYSPb9QKvVExslBDhfDX6ifKjxIsWc983VY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=REOgFD3114F06WKILTlUykVfFAEV2Cp9WXKNOfycPJx+0Jn2xft0q2xb6vH/pVM0h0qbp4Hyzp9t1NUt0or0/buWZO6CQ2s+nMIaCZ5GbAtYVJzmFLWKD5fELve8AlQjeu88mnGVOe6o79cv2YjHr2VhSSjGyEsUiugJF1vcfSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fx4sQHh8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fx4sQHh8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63157C4CEE3; Mon, 31 Mar 2025 12:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423442; bh=DHd94nGDnYSPb9QKvVExslBDhfDX6ifKjxIsWc983VY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fx4sQHh89jJw2QdrxGxe3yiv30Dhn+BnuXoi2QJMy9jlCE3BxRc7YLRUOW3rkhAzz 57sWHzqTqGxrbnmvEFBetU2oq3AD2O28XQOBAaIBd7W2I0x2eRctMRdr9F6HgG0OSZ 1FoOvz1xuuy3w9Ex0XteV3StTZm23f+mSufbAE6e3JOGCbYAOMT6VtVz/4aQq8zkp9 1JxUkRi6fVhLZRw2uZEF4eWgFjlnS9P+LsxwkBp5Ebqdlc5irNez7hdTD2LzKh4fJv 3jF+C5xREUwpmCCns+dnJOpSZkr6laKuwLICUAUpyRMVSVUMKberEht2WP/rEeAWCp UsLSjYKPFCTKQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 36/37] staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct() Date: Mon, 31 Mar 2025 13:13:16 +0100 Message-ID: <20250331121317.1694135-37-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron These new functions allow sparse to find failures to release direct mode reducing chances of bugs over the claim_direct_mode() functions that are deprecated. Signed-off-by: Jonathan Cameron --- .../staging/iio/impedance-analyzer/ad5933.c | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index d5544fc2fe98..5aaa43e94c52 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -271,11 +271,12 @@ static ssize_t ad5933_show_frequency(struct device *dev, u8 d8[4]; } dat; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad5933_i2c_read(st->client, this_attr->address, 3, &dat.d8[1]); - iio_device_release_direct_mode(indio_dev); + + iio_device_release_direct(indio_dev); if (ret < 0) return ret; @@ -305,11 +306,12 @@ static ssize_t ad5933_store_frequency(struct device *dev, if (val > AD5933_MAX_OUTPUT_FREQ_Hz) return -EINVAL; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad5933_set_freq(st, this_attr->address, val); - iio_device_release_direct_mode(indio_dev); + + iio_device_release_direct(indio_dev); return ret ? ret : len; } @@ -384,9 +386,9 @@ static ssize_t ad5933_store(struct device *dev, return ret; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + mutex_lock(&st->lock); switch ((u32)this_attr->address) { case AD5933_OUT_RANGE: @@ -438,7 +440,8 @@ static ssize_t ad5933_store(struct device *dev, } mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); + + iio_device_release_direct(indio_dev); return ret ? ret : len; } @@ -506,9 +509,9 @@ static int ad5933_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad5933_cmd(st, AD5933_CTRL_MEASURE_TEMP); if (ret < 0) goto out; @@ -521,7 +524,8 @@ static int ad5933_read_raw(struct iio_dev *indio_dev, 2, (u8 *)&dat); if (ret < 0) goto out; - iio_device_release_direct_mode(indio_dev); + + iio_device_release_direct(indio_dev); *val = sign_extend32(be16_to_cpu(dat), 13); return IIO_VAL_INT; @@ -533,7 +537,7 @@ static int ad5933_read_raw(struct iio_dev *indio_dev, return -EINVAL; out: - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } From patchwork Mon Mar 31 12:13:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14033552 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5FD8E13B59B for ; Mon, 31 Mar 2025 12:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423448; cv=none; b=BmJpnhgSUa5myQVBm4MqwIO4CNlo/g0UwtOXzvj/PM1+jMtpx3pkexfdHlqL5jS2n1QZWKkDr9fWe5/tQvgZsrTatvphHv6U3qaoyqtjZ4dSoK70LIrQH5k6Gtc5bM9cGDbccoahYG5FqKCxbePpGqWt77vdvysNPM3eoSkpOGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743423448; c=relaxed/simple; bh=gyRG0WSpnGxX1JfNmcWVKw7XM9R86VTb7f+w/nMow0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u77Ts/0NIBqR2MoJ9YU0Vv/X597k+Z4NgvJ9JppwCGol6nghbQigBgQ8FAfqcDPUvQX/0CSl6D1xiaiitIWxHxXovGPC4xJ1oag3alCzsJCerb1YMBUHDkp5yxNcAvAPTfwNLBcnHHqAsnv2OHEo9nJZaaka0cv5ytv8aOO6Rxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lu8OROTx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lu8OROTx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69F2C4CEE3; Mon, 31 Mar 2025 12:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743423447; bh=gyRG0WSpnGxX1JfNmcWVKw7XM9R86VTb7f+w/nMow0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lu8OROTxQAh45oFcKsuL5TlJ3+XeQMY8SWpD9e7QCH2hoOCcREpY3QhQhbcXIqnhq jYn1fYwMk6cvJ/dvU97HgqTit37xof/iqxGYCL5SFGRB6J3tboCD4VGNIlIL2WlsA5 I1gBJAV0h0AnzaKw7p+xE97nXzB2z80+8b88Fp6me8stKz4uyEe8TOXvy897XT0Duj KN9+4OqZZ+DU4xLPNY8tzUIsHBOeKL/aXlHt0bKhNeb1+pD2K/kFB+qdOa5iDDYhbn LinJnQ29wNSS7Vwww8JaUlhH+AVWwfgdmkj0tZCYvCRosmSsmYAatnqVmu+KJN+0+Y UPwzj1ur583HA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Roan van Dijk , Jyoti Bhayana , Nishant Malpani , Eugene Zaikonnikov , Jean-Baptiste Maneyrol , Shen Jianping , Lorenzo Bianconi , Matti Vaittinen , Yasin Lee , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API. Date: Mon, 31 Mar 2025 13:13:17 +0100 Message-ID: <20250331121317.1694135-38-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250331121317.1694135-1-jic23@kernel.org> References: <20250331121317.1694135-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Now there are no remaining callers of iio_device_claim_direct_mode() and iio_device_release_direct_mode() rename those functions to ensure they are no used in new drivers. Also make them now return booleans in line with the sparse friendly static inline wrappers. Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-core.c | 28 ++++++++++++++++------------ include/linux/iio/iio.h | 10 ++++------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index c9955a1c1090..c1921b55cfc5 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2157,17 +2157,19 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, EXPORT_SYMBOL_GPL(__devm_iio_device_register); /** - * iio_device_claim_direct_mode - Keep device in direct mode + * __iio_device_claim_direct - Keep device in direct mode * @indio_dev: the iio_dev associated with the device * * If the device is in direct mode it is guaranteed to stay - * that way until iio_device_release_direct_mode() is called. + * that way until __iio_device_release_direct() is called. * - * Use with iio_device_release_direct_mode() + * Use with __iio_device_release_direct(). * - * Returns: 0 on success, -EBUSY on failure. + * Drivers should only call iio_device_claim_direct() + * + * Returns: true on success, false on failure. */ -int iio_device_claim_direct_mode(struct iio_dev *indio_dev) +bool __iio_device_claim_direct(struct iio_dev *indio_dev) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); @@ -2175,26 +2177,28 @@ int iio_device_claim_direct_mode(struct iio_dev *indio_dev) if (iio_buffer_enabled(indio_dev)) { mutex_unlock(&iio_dev_opaque->mlock); - return -EBUSY; + return false; } - return 0; + return true; } -EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode); +EXPORT_SYMBOL_GPL(__iio_device_claim_direct); /** - * iio_device_release_direct_mode - releases claim on direct mode + * __iio_device_release_direct - releases claim on direct mode * @indio_dev: the iio_dev associated with the device * * Release the claim. Device is no longer guaranteed to stay * in direct mode. * - * Use with iio_device_claim_direct_mode() + * Drivers should only call iio_device_release_direct() + * + * Use with __iio_device_claim_direct() */ -void iio_device_release_direct_mode(struct iio_dev *indio_dev) +void __iio_device_release_direct(struct iio_dev *indio_dev) { mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); } -EXPORT_SYMBOL_GPL(iio_device_release_direct_mode); +EXPORT_SYMBOL_GPL(__iio_device_release_direct); /** * iio_device_claim_buffer_mode - Keep device in buffer mode diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 07a0e8132e88..638cf2420fbd 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -659,8 +659,8 @@ void iio_device_unregister(struct iio_dev *indio_dev); int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, struct module *this_mod); int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); -int iio_device_claim_direct_mode(struct iio_dev *indio_dev); -void iio_device_release_direct_mode(struct iio_dev *indio_dev); +bool __iio_device_claim_direct(struct iio_dev *indio_dev); +void __iio_device_release_direct(struct iio_dev *indio_dev); /* * Helper functions that allow claim and release of direct mode @@ -671,9 +671,7 @@ void iio_device_release_direct_mode(struct iio_dev *indio_dev); */ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) { - int ret = iio_device_claim_direct_mode(indio_dev); - - if (ret) + if (!__iio_device_claim_direct(indio_dev)) return false; __acquire(iio_dev); @@ -683,7 +681,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) static inline void iio_device_release_direct(struct iio_dev *indio_dev) { - iio_device_release_direct_mode(indio_dev); + __iio_device_release_direct(indio_dev); __release(indio_dev); }