From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401383; b=uhlG0ZgkstZX49AjbjORosdbKGYbdHVXK7GXdW4/1GiazJ5A4FB/FO6VPlxavBEN0no7 8wpUt4ZyORLcJtujJDdd+LqZdjf2sg77ubLrgmm+Ha1mQACLIwZXo9D7vDwjibtG+Uqsj 2s3JNC9q3wfjalES5+ZyuDgZHZVnSDotbEGDjTw7wXVckVCfEolonTI3480x8YEEBR8tO ro4oWJq9TEt3BPtLaivqSAncPq4Q5PKwQYAdGuyohHIecUkoabBBIuobwKLyX6s0uGN2Z dPoqa5bctOG5tH+LwtcgpOLnMVstpPaxqvhtpKGBmnR+UgEeO3upyEDXaqdKfdZRbXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401383; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=PB4osKMjsTLkJ9hRpvjyGI4Abzwg0lewvL8aKBJi/wM=; b=ODw9LXEOrMJ1VmKnYmc/6N5xoLOdzbZyebF73Bg6PEdsSAYLevv5nNgKTr/WsQtFx4J3 A+VWwluwIWyN4ndumRajWAuRWjw3hQeUseyV3Wg+EDm9tIobZ9MBRS/gJHg+cxoYERxaH Nh8ZrmATlh2b6IONqkNDQ3hrF/SXOjHbiKk2N8oTJJQ9vbwYC815xRfvrWM98IM5Q3K1l 7BHdQr7lTreP04qq5krxfP9HlnG2ecjReOB7m8OeW9Vi85gXK/+pCy9g2Xf4tzIHGQDhU Gh3tE0JRFKkXu5NZEC49JHIxDpDLos2YpsH626cKepKQnMByBBrgHO+BJuPLFyxf9tg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0hcxGY+I; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DA67606A322 for ; Fri, 4 Dec 2026 16:23:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8DA67606A322 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.a=rsa-sha256 header.s=20260707 header.b=0hcxGY+I Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-387504e1934so1220870eec.1 for ; Fri, 04 Dec 2026 08:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796401383; x=1797006183; 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:content-type; bh=PB4osKMjsTLkJ9hRpvjyGI4Abzwg0lewvL8aKBJi/wM=; b=0hcxGY+I8V5vOclunRAL2j67TBiideCrV1ky8fNyRJPAZXlWx+ia7yUsjcIGlYiimq JvCwXi/p92KbqEsrjd+6Nb0lA9jRuQsJQbhy8HNcsE1+GQwGYgGuu4Faaiye7NLCNEPr gG7dnoey6YNCdzMa9fT4XA7IiXLc1slbpAXXpbFlXpnQfAYJEOv5+wHHwDKOUXUtivfw +JG++mlVDyZKsd1uj6WurkcliINtHeD93mAoN37vVlUiA3roOlTiNf0qYtn4S2928FSz uPVD/aSPcYYwrujFTi8RL0O8OMMesvrGRnbbA3hn9ER7MUYUeACvkhSAulv8HLIxzsIJ 7Ecw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796401383; x=1797006183; 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:content-type; bh=PB4osKMjsTLkJ9hRpvjyGI4Abzwg0lewvL8aKBJi/wM=; b=LZOgtqtioCPDnn0I/cgYa2adOJk5oc5+sPE1JqMgX1oGK7x0fp+HPscLT8oHiA3mvA 7FJY7FBSvXuYFLf2AV/TPjexSRgV8CZe2XK986XUPZSI/69fXp55ulXYV9kv4o9VuHx0 6jkI8S1UATqFREkTP8AEbje0pMdZZbNj/FockYHn+Vj1SLumLJetlUToH1YtH9g8tCuK t9p2FwvnFRUrHk8maQlcq/hCNWyvVPKdxhZFotOgd6kv4v8/7tVBNqogcI/DTFCnIgrw +H4rAKeZv1WH82DLeItg/UDPsCRGVlmQPMV4tUoeM5VPs8FlkKjdGGMWpNRK7elJTX7m mgcw== X-Forwarded-Encrypted: i=1; AL+hErH2TE23+MWRW+YbdG6WVSPcrj4oGgTfqqf+jbKeolDpTc44a0xDpD7JOvtxmrYqgzLdWNQkBQ0U3oBceVQ=@vger.kernel.org X-Gm-Message-State: AB4q+uEVRuUYt7v0VWrovOVsReRF5KPNCgPE/G8mKjsNIvEvS8RHr4wy Qi+B1gHCQkU4LtDF1ip/ioxXY+pU9HvWCxfuHebNqQYkLYgl2YSxUiOg X-Gm-Gg: AZFdTZe/wXW5fxJhpWAHvTMAzQF7FHsjr7kSWbF1hOVuySroSoMzBhzWjocprz58Gd6 dLq9qO8tU/PZP/J8mDmZgSwz4Oep2LRMFtNJll9TWqd/Qf/WpzUNTJXHvAuylTO0x9x/0EUO54T RL8psSEF7f2t/frZPsK8SbW6pvI7OFB/e9ccdnp214eimxP0pcHO0WPFCOP4rsIa0YY+uj+hemT 4qJ1CyKtDpxNRhd03LrpPLVGzc6M1Gkvv7rzReBaytfdjg9H3sV5NAnadlswBvO7IZAZSOG/lrC Isb/TDoeABj4M3A1hTfmzDGK9TB/2UKFIcIPp0715AWuy7nolO283ur4lsGG5sT/SLvKmLZ5WQa ytgEi2RQ/XEG/XhaOVSEtTT8ukf4+PNaxVyoH6eygRab3yFNrGQbPF4lehI7n7R8KBRd5ThH0jC utkDZwXQzz49uCiPCmmxYoYQj3b+KB4oJ1VClGiYQr1AkYGDg/9xOBroRcz1UMgSA25jgXeuv9U 6PYaFqcXy0qQgyH5fYMisfayRRtMkWRb55vgmAxaZnqwi/BQ1QGqvOrTLZztschEvp5KEs91Go3 IwSKERK4UDRqFFrd8/OAFv9KYO4HY1YZW/K8yBZ+AmboagM4Egk+sPcmtBe5VH7KY1lrhgWe9dq zkvWJvZHMkCtVbZmjwiJzBXZDXzESBP0EuFuGwLOZh6KMcCtc67PDtg5v99bRco7Uq2TGLCP7nL PNwlmNf6c8wH/Rizde4w6+nhrkRFarqXmkfUKnghwLEg== X-Received: by 2002:a05:7300:83:b0:387:50d8:f9aa with SMTP id 5a478bee46e88-387521d80e3mr2353654eec.37.1796401382525; Fri, 04 Dec 2026 08:23:02 -0800 (PST) Received: from kapoor.iiserb.ac.in ([203.18.51.239]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521c17a3sm11834807eec.11.2026.12.04.08.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:23:02 -0800 (PST) From: Arnav Kapoor To: Jonathan Cameron Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko , Gwendal Grignou , Stephen Boyd , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Arnav Kapoor Subject: [PATCH v4 6/6] iio: proximity: sx9360: reject negative hysteresis values Date: Fri, 4 Dec 2026 21:52:19 +0530 Message-ID: <20261204162221.923093-7-kapoorarnav43@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204162221.923093-1-kapoorarnav43@gmail.com> References: <20261204162221.923093-1-kapoorarnav43@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit sx9360_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: 1cdb4c47f7f5 ("iio:proximity:sx9360: Add sx9360 support") Signed-off-by: Arnav Kapoor --- drivers/iio/proximity/sx9360.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c index 9c2dfe5fec0f..63a8dc7f8f51 100644 --- a/drivers/iio/proximity/sx9360.c +++ b/drivers/iio/proximity/sx9360.c @@ -542,9 +542,14 @@ static int sx9360_write_thresh(struct sx_common_data *data, int _val) static int sx9360_write_hysteresis(struct sx_common_data *data, int _val) { - unsigned int hyst, val = _val; + unsigned int hyst, val; int ret, pthresh; + if (_val < 0) + return -EINVAL; + + val = _val; + ret = sx9360_read_thresh(data, &pthresh); if (ret < 0) return ret; -- 2.53.0