From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23DD2389DE0 for ; Thu, 26 Feb 2026 08:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772094351; cv=none; b=ZtZiRjKSsEatGhDkCMfrPlzplEu+nQuO+CGrLUizJHGNMP0ktHyr0zD/pVmhstHhp7yyCrNdusA4fD8qPhtDrzDRGN6VF6SP1GsNM5LLV78pBx4+EDoEyLhNSC4LC3J4twXzBTWoS9vJ5nUZ0Rj67fcIZ9KvW/8TfMSQjozEcjQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772094351; c=relaxed/simple; bh=TxG0f9exKqQbKSk0xa8lU/Cx6XtKZupuLU8VGhgW4v8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qubMpv2wzJCMV5rYl5PUNn01ChNTT1f6lrEfbzuyvC9UcxfJKtwheiNWJ4AUXuytjpPbo6PhCLeyncXrFG6bjWmXk3DhOqf+Y6brpKReXAW2ckGky+BgHEXf8vR2RuVyKh6UcIwzBDVL7OVq4gV2EyXmsYCJZpsLOo/sUyEyHsk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AliUklpu; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AliUklpu" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4398ebdf520so1073489f8f.0 for ; Thu, 26 Feb 2026 00:25:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772094348; x=1772699148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t2DXQgUmURVJwaYW2hiIMRPzTKSONvVLRn6L1AJLhT4=; b=AliUklpuYsENPancw0nVy4vDWnYA+EnVyj6+yUzyrJBEtLp11Gi6tIxHgd+Oa2cNCK 24gStdKA5aV7/FJG/syJeL4p5soOWehecdNtRGFzZ0vzkxgW33GHSNjhPKsOmW9IKZHg MRAffrkhEDaCApleGKQ7AiXhxFdKtNdm694N1k2ClHlGH81Q9z5Rjeg52MaIVaEMP3XR pBK8ISXusTxLFP+PtnGErrmQHL/Y7zAQankeiQV4auiDeTCZUFv9vptkhivarDljyWPq VCOoiU9XryeTFY9ck0Hz8fwf3DQ2ULlBowEtfRJXqKZ/uXjZ+qffK1t6XKuaJeIaTIoQ DWNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772094348; x=1772699148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=t2DXQgUmURVJwaYW2hiIMRPzTKSONvVLRn6L1AJLhT4=; b=I145y/1HjOS+9zj6ouZaFstQbTA8uxKmiJ5ndXkdp80SqAVRY33n2Ke9MjoVhXGbEX Wsxdt3eDU2ANuo35cnn5ZXV7L7pAf7tAAHjg0fYwv8eMtcONLqkWIqZQ9EkTbnelBO+7 cOO5+y2CC9UmdgB1lZ965UlUkswOEJ1IZwetjAMeyBx1aVvKprvDOEAv9LmNdCEr6GAD qtvjBLpN4SZZzuMp+IghPUpieLiuiu9+IRNxN81ZOes7+r+vVjkTIYDY4bauvwqfITBK JMSDGluRanlYV3i7A5IrhBoaodS2UwO1t0X2mOWvwIBe3ykQYJuDe2DpipdOCiqcE7JF vGCw== X-Forwarded-Encrypted: i=1; AJvYcCWzdg5onsz32lmsf8arE7kJTtlPsXAwnm1z1S/mPBfnIg3+uCh6acKNq9cxlvHnZ7+4J/Aqm4EPSULieug=@vger.kernel.org X-Gm-Message-State: AOJu0YzcoPykUPm5QOEWRI6pYUUoDMRhnJJ71gyOTplXn6Fd/EjwVgC7 3ptGtYqH7rBUdCayjlg2HFivWyuEQyMVFkd2JzlBsTUV8DZxhVivOGec X-Gm-Gg: ATEYQzxjHNApTCUBTYP836N22KvlkzpqpHsLXsFw6Wnv6oZt62zgT9aHIURkcBAsiiJ wiaMDK41ckNhnZCtXRqbm5aY5GAK6stukPRDWUdgpOzxjUd8D6j+gFLpuEZcLlZSjjvnUNFL6CA LeO/xz6YCqYKbiiFY7Ri1TZ8nhTSa7i62UuC14BkLiO9xmyKnWua5FhxiNX2EKHo+7icYjN/4Hy fb/rOMrM4/9yuJtx2W5FElT9tNw77dlC/8mWLfnbfGCfpWQXH3/AuU96TD0pCjbyp7gcLo7q5ST 4yvGqM+X01yGiKdWRmhRvsN9CTMsYVrQtATXWvqvChIfBBh+sone9k6gTiaY1K2Du+9QzpXH5jR UpryzajNhCyI5YcU++iGrF9SgX+2LVvmcyr4DHoXJVDkP+0i2mmTtJiy7ZyWTGm7gcexiah1hGg == X-Received: by 2002:a05:6000:609:b0:439:8c7f:712c with SMTP id ffacd0b85a97d-439971aead8mr3568173f8f.8.1772094348355; Thu, 26 Feb 2026 00:25:48 -0800 (PST) Received: from kimsufi.. ([2001:41d0:303:6f54::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970c09897sm40683939f8f.17.2026.02.26.00.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 00:25:48 -0800 (PST) From: Ruslan Valiyev To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Greg Kroah-Hartman Cc: David Lechner , Nuno Sa , Andy Shevchenko , linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Ruslan Valiyev Subject: [PATCH v2] staging: iio: adc: ad7816: add timeout to busy-wait loop Date: Thu, 26 Feb 2026 08:25:47 +0000 Message-ID: <20260226082547.69616-1-linuxoid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ad7816_spi_read() function polls the busy GPIO pin in a tight loop without any timeout. If the hardware fails to deassert the busy signal, the kernel hangs indefinitely in an unbounded busy-wait. Replace the open-coded while/cpu_relax() loop with read_poll_timeout_atomic() which polls every 5 us and returns -ETIMEDOUT after 1 ms. Per the AD7816 datasheet the maximum conversion time is 27 us (temperature channel), so 1 ms provides generous margin. Use the atomic variant to preserve the existing busy-wait semantics of the original loop. Also handle the case where gpiod_get_value() returns a negative error code, which the original loop would treat as busy and keep spinning on indefinitely. Signed-off-by: Ruslan Valiyev --- drivers/staging/iio/adc/ad7816.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 172acf135..9b4ae3ee2 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -85,8 +86,14 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) } if (chip->id == ID_AD7816 || chip->id == ID_AD7817) { - while (gpiod_get_value(chip->busy_pin)) - cpu_relax(); + int val; + + ret = read_poll_timeout_atomic(gpiod_get_value, val, val <= 0, + 5, 1000, false, chip->busy_pin); + if (val < 0) + return val; + if (ret) + return ret; } gpiod_set_value(chip->rdwr_pin, 0); -- 2.43.0