From mboxrd@z Thu Jan 1 00:00:00 1970 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 D28033D4135; Thu, 7 May 2026 14:36: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=1778164569; cv=none; b=FdDdCcjQYiD8ByqnFzK6n0vZKVtP4g3g2Ad3KqpIVT8TH3I52CsBTs1ApGX5fs1bMeV5vi9fjQ64OHG0+EnMnA+S/ogELvG9Y9TCTP7FDprIv8WBztQTmYhHDs8JVusp7GdyNnWdmLb+bfOugrIUNIMWlDk4Uns6GpAxOoFQoFk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; c=relaxed/simple; bh=ZF583aBtYGAJpHHeB0vOg6PUeXY1blXcxWsonJHvWrk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bjTnSwrw+yQrN2sTGM0lnh9aLV/x9ga9JsvMkSjZV5B83OXTrSck2NF0X+G05ojlybi0uuRnFWM7wsqny+4U+b+Ygm07gAWNjL158wcpnCgY3AnrECeMdCUX1590ZrBkAh8zFWdpd42NDcY8Su4rJW6liWJbuV1VbW8CUTLAt6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JlnwmEG+; 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="JlnwmEG+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 89853C2BCB8; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=ZF583aBtYGAJpHHeB0vOg6PUeXY1blXcxWsonJHvWrk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=JlnwmEG+YHBX1KfVPsg95EJulrhlgUfhJVuUsRm5w2qrvrMWZA6b5ylFXBjnuE9xp P+r0q4f7aVW/usGyB+U7D8PmWkKWMRpNuopIrBwavce+S2ADl8VP/4CHCt2Los7Bdd 5tj1HNFae/AWRDxDpvKV8q4iW7p3BOvM89NhbFHPXUnlz9X0PV5YFP1mpCO1c3MbRe CSXM513Hdq2uee3OBQ1TLDX2269WW+NMTW7Yeat9GgsG1W9O0a20BpGURwuOHYsKAt l9WPyG0No52ctRCCtEN2BDt6P7pHUBwyCz5pbeTmdXtSBIqe5Zu/KhhPT/wOdCKLDq LqW5ZHvnbo5lQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78B29CD343F; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:50 +0200 Subject: [PATCH 1/8] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-1-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=2895; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=WCXc9xJK2iqHW3SXYjHYZyCyWgILLVxm1tWrHc5KDy8=; b=KT/yu5fjjyrNeElOWHTLkNmsc4iTt0YnQZ35Z9FeG8UL5kKSjI+fWKz94tpQjSNsdNtqySU/d bTC1Oa4fWF8D9LnQypLodvIkGx9QN3Me6Vx3PCYJ9//BJoSqezfafL4 X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts The driver currently uses while loops and msleep() for polling during conversion waits. Replace the custom polling loops with readx_poll_timeout() and read_poll_timeout() macros from . This reduces boilerplate, standardizes timeout handling and improves overall code readability, keeping the original timing and error behaviour. Add for USEC_PER_MSEC macro instead of using magic numbers. Assisted-by: Gemini:3.1-Pro Reviewed-by: Andy Shevchenko Signed-off-by: Joshua Crofts --- drivers/iio/magnetometer/ak8975.c | 43 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 6be72e1cc0a8321e767da5e65d54c0fe88712304..b990c123e2808c2078abcfaf6b2ef86c09393e6b 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -649,16 +650,14 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data, { struct i2c_client *client = data->client; int ret; + int val; /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(poll_ms); - if (gpiod_get_value(data->eoc_gpiod)) - break; - timeout_ms -= poll_ms; - } - if (!timeout_ms) - return -ETIMEDOUT; + ret = readx_poll_timeout(gpiod_get_value, data->eoc_gpiod, val, val != 0, + poll_ms * USEC_PER_MSEC, + timeout_ms * USEC_PER_MSEC); + if (ret) + return ret; ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]); if (ret < 0) @@ -672,27 +671,21 @@ static int wait_conversion_complete_polled(struct ak8975_data *data, unsigned int timeout_ms) { struct i2c_client *client = data->client; - u8 read_status; int ret; + int val; /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(poll_ms); - ret = i2c_smbus_read_byte_data(client, - data->def->ctrl_regs[ST1]); - if (ret < 0) { - dev_err(&client->dev, "Error in reading ST1\n"); - return ret; - } - read_status = ret; - if (read_status) - break; - timeout_ms -= poll_ms; - } - if (!timeout_ms) - return -ETIMEDOUT; + ret = read_poll_timeout(i2c_smbus_read_byte_data, val, val != 0, + poll_ms * USEC_PER_MSEC, + timeout_ms * USEC_PER_MSEC, + true, + client, data->def->ctrl_regs[ST1]); + if (ret) + return ret; + if (val < 0) + dev_err(&client->dev, "Error in reading ST1\n"); - return read_status; + return val; } /* Returns 0 if the end of conversion interrupt occurred or -ETIMEDOUT otherwise */ -- 2.47.3