Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795999193; b=DfWNpHIuGRHlXXXFFxpJz10Oqy7sF74NfmqJL6Qle4kYcQspxdkcbnlfF1xcNO3bKtvT prWKcZzv97XMOsvRSJrMVs44ub6kh1Q6WM0qUBngPR0CfiWQHa/xOwzlCZ8v0lOt9xF6R EZYwsKZKaAPcCmJJI30c67W9dUqCi1CzjS7r1HzuPLJXXAXKzWhTqEBcDkkZMVOYjCOTd J+fDRviJoEmck/x9OplB+bjdv8b2HJXs0fTXAWWkP4JIB1ijDOgVyCWWcHq1aERaIouuf NHQxG8sffWG71u45PcY/4V3Xy2yF344XqK1Yoy7pDnhsCJAyCykDGjDCVPPySVFM/+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795999193; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=IZy1xEUfmIMswYdWRbTrX4hWKuKGz/ZAfFL/9Lro5sw=; b=Wj03etZXD3ibnY7vdUA1KT74ZlwWFBcwBHcX3LUWBhRTsXYgdkGHJKEIvA8VrTDzOvKl USktZVV9mmHn+GpfFtp/f9OzEpFZLIdCe6rokOqyn18p9VW08+qjWzLlofxauczbkpMrw YsagmjsGBiHRAq46Mf+sOKbT1Q6ghWy86D/m+Davbimid1WDcAPNY44/S49zG6OvmFEVe UmLQA921P4g3NYuq+jDB23lZiOgY4H4AHorhFA0S5wTYgq9a/BOVMMIFM3NkSOetft+ij HNk61jM3nh6a/U0FmvYAzg+aPPe+edmTkICWobHoK8JRM2PXABIhZRDbxNTfqGWN8vw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G1J8sFtl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20C25606A31C; Mon, 30 Nov 2026 00:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G1J8sFtl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7053D1F00897; Mon, 30 Nov 2026 00:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795999192; bh=IZy1xEUfmIMswYdWRbTrX4hWKuKGz/ZAfFL/9Lro5sw=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=G1J8sFtlfaLfj+ObF/ap0J3nTUZ/maBsHqInXxv41pK9wtrBXIgdHnij0HR6PvHli elhCjqVNBv26648vkNXYYcY5H1Xl153f+/mMpuMtMLPA2jR8M7cGptdES1nEIbJLRR EQMo7LyCH+vm1MBi12Jtp1Gk/1spXTd7cETm2Abdn6a0YTiabUrbzeUMiggEsYT1i0 a4XeHZsf8OMPHKiwXO4o+j+4j3HpJb964uYOmWZTJbo7Vy16q8Yt4dP5v7gHrXfRbs nKySIb0BKPJqCEa2mnFboofzjXalJnI7HZXzWOd80+GJueYxP6eQhv0hpa1GTiZUf/ pQMotFmYYvzdw== Date: Mon, 30 Nov 2026 00:39:45 +0000 From: Jonathan Cameron To: Arnav Kapoor Cc: David Lechner , Nuno =?UTF-8?B?U8Oh?= , Andy Shevchenko , Andy Shevchenko , Gwendal Grignou , Stephen Boyd , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/6] iio: proximity: sx9324: reject negative hysteresis values Message-ID: <20261130003945.0afa767e@jic23-hlaptop> In-Reply-To: <20261128115534.558478-4-kapoorarnav43@gmail.com> References: <20261128115534.558478-1-kapoorarnav43@gmail.com> <20261128115534.558478-4-kapoorarnav43@gmail.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 28 Nov 2026 17:24:51 +0530 Arnav Kapoor wrote: > sx9324_write_hysteresis() copies the value into an unsigned int before > comparing it with the threshold, so a negative value becomes a large > one, passes the "val >= pthresh >> 2" check and sets the largest > hysteresis instead of being rejected. The comparison is done in > unsigned int, so this happens on both 32-bit and 64-bit architectures. > > Return -EINVAL for negative values, before converting them. > > Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support") > Signed-off-by: Arnav Kapoor Related to this, I don't see anything checking val2 at the caller of this function. Should probably also reject val2 != 0 to avoid odd things like -0.999999 being accepted as meaning 0. This is an unrelated fix though so doesn't need to be in this patch. > --- > drivers/iio/proximity/sx9324.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c > index 3f2f15d237e9..ef217f055472 100644 > --- a/drivers/iio/proximity/sx9324.c > +++ b/drivers/iio/proximity/sx9324.c > @@ -646,9 +646,14 @@ static int sx9324_write_thresh(struct sx_common_data *data, > static int sx9324_write_hysteresis(struct sx_common_data *data, > const struct iio_chan_spec *chan, int _val) > { > - unsigned int hyst, val = _val; > + unsigned int hyst, val; > int ret, pthresh; > > + if (_val < 0) > + return -EINVAL; > + > + val = _val; > + > ret = sx9324_read_thresh(data, chan, &pthresh); > if (ret < 0) > return ret;