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 D615B26A095; Tue, 8 Apr 2025 12:50:42 +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=1744116642; cv=none; b=eJuOJ8Tmt8339KJ8IPa5gK6Fos6iIpTaDzIib8h+btHrR+W4oL+iiw323YJYcFn4gEAh27fklUSxbObkjK2o9Hhxwzh7gUeUz+yfPuGkAr4JqKtI+DU0tQyYCRRGTDZCTwQ8OPi5NqqsoPPDhPmegiGoTjTuLpeI2ObwpKo3FUQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744116642; c=relaxed/simple; bh=oriQtcV3lg7bKXEegSNB+RftGYpMdQlrzXEf6A1TzSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MYqbzrGEb0pl6+pldV4pvFJZm877Ba/5OrcwT7yHzYk/2fVX1TNGHuAP9hojMfozZsdJOrCs/lc3GCw20mYniqb0iVhGBUce3xQNExarrM2ueAgCgNeG7FWYwDgis4dYCzNf34Bg4R73+eqOGl+mLLY1nfSKglOWkPz2woC48tg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=iRzCPNI/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="iRzCPNI/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B098C4CEE5; Tue, 8 Apr 2025 12:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744116642; bh=oriQtcV3lg7bKXEegSNB+RftGYpMdQlrzXEf6A1TzSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRzCPNI/sVaXUUCsE1dw20AVk1nb/YCfi8DWZwXjyZRyE7yDS6gqOCq3M/9fzgnus NWUpt0LwJHQYRSoO3jTYhOB0wmS8UxVNavdUan0abwLhLXG4zsDDsLfx8tHeKJc1qd A7/tA0GToJCqHxo8/ysq6GmUtuZjmzbAleUaiiJc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Lechner , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.12 178/423] iio: accel: mma8452: Ensure error return on failure to matching oversampling ratio Date: Tue, 8 Apr 2025 12:48:24 +0200 Message-ID: <20250408104849.890478255@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104845.675475678@linuxfoundation.org> References: <20250408104845.675475678@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jonathan Cameron [ Upstream commit df330c808182a8beab5d0f84a6cbc9cff76c61fc ] If a match was not found, then the write_raw() callback would return the odr index, not an error. Return -EINVAL if this occurs. To avoid similar issues in future, introduce j, a new indexing variable rather than using ret for this purpose. Fixes: 79de2ee469aa ("iio: accel: mma8452: claim direct mode during write raw") Reviewed-by: David Lechner Link: https://patch.msgid.link/20250217140135.896574-2-jic23@kernel.org Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/accel/mma8452.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 62e6369e22696..de207526babee 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -711,7 +711,7 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct mma8452_data *data = iio_priv(indio_dev); - int i, ret; + int i, j, ret; ret = iio_device_claim_direct_mode(indio_dev); if (ret) @@ -771,14 +771,18 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - ret = mma8452_get_odr_index(data); + j = mma8452_get_odr_index(data); for (i = 0; i < ARRAY_SIZE(mma8452_os_ratio); i++) { - if (mma8452_os_ratio[i][ret] == val) { + if (mma8452_os_ratio[i][j] == val) { ret = mma8452_set_power_mode(data, i); break; } } + if (i == ARRAY_SIZE(mma8452_os_ratio)) { + ret = -EINVAL; + break; + } break; default: ret = -EINVAL; -- 2.39.5