From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.17 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796034019; b=FlBd52FRfdUoZaps7f7xROtBzJZecHeeHkOCbUFIDn8I/V/GQEq4rXCuivt4evoL8PyZ 0Y6AM2WJS25pG95hNjwOxFrQavPoaVN8jhl3u+Yb+fVP2Nrsqk+a1ltOsEbw/euMTVEJU y7hHstHCnpq45fHmrxwkhZ1LK09xI6VflIGMZw40QBeK5hXYP16vEUxKJhS4VUau6nThc /EC3vaKuIIQ8nIJle9zqOgLrRdEtQe3ae6srPbo7uqy1J7Gcx6WQkU8L9O+b+2TOf9jFQ jstf1Aqeq2Ytd4/4mWwq8gab3moK/qr8F6PWjLi6IVz/0TEC2vO/RQSeOiJ+qSr+2Jw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796034019; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=Ff1k7Cre63lsY7OzWnUHwRRLjl4bc/C8Tk2QzqGRJPg=; b=uawr65+Y7ryrsyteggZsZi0fWAtrJqgWiMp6eXqEXQgFdSVAvA9bRi/4M7Y9mKtcUpnS fmPiV/mttNvs+AGobVctzgROfIz/bmOUpnhSGhpYzOpwEpHX0W6xmJzRy3SZ5sqxEk+lj RE9RabqbmVpXZU0KwKTJfiO4L8+Wi9RGqiEbLNkWna/PObJGhMbM2Rf2L8B3wWbR3m1/V NckEx348IGrnszhbKIoJnWlaMr/IszoQ4p3e5jJQ5nTAhvYOnnqMuCelpOu2plo2EG1Zj NgEK8YZsbYZskgaw8zT3wGzC/5WMkuC8VkDZX8hP/8sioLLs9FPnTxFfXdcqcbdUScQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=qoQJ7ggH; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.17 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012017.outbound.protection.outlook.com [52.101.43.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C49F606A33F; Mon, 30 Nov 2026 10:20:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C49F606A33F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=qoQJ7ggH ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IHZd0UdwAMB2Okxbq7RbUC2Q8jsq+tyepvz8OfOO8OABq6rh5GKh0yHThy45SRlWVfaOgS5098hPsljYy4aYZv+nzGJYeoUv7NXhmKy2ivm1n3vDTQX4eLjn0rZ++IYJPQgZ9Gle1urIWgoPRrdiZd4xOoGaaT3PtLwfdH5KVF9WkAZz5l8M3Rz4N2rBCWHFsR9o3rMUbYdqkI0WDW3YA0lSI0TEPcORzeW6ppHWmKQyqKYycHeiEh2qlxQJZYLu9DNXOEWFhYluX5f/luRfjj26lQZ1wLK3t8wVooZaIUZ4+tWoHpO08VMsZX7yze2MuELW9iYc1AuF7K7sHlcagw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ff1k7Cre63lsY7OzWnUHwRRLjl4bc/C8Tk2QzqGRJPg=; b=gqIv7xl6IUtRzCfRFLnWdjZQNGetNw4vsBKZdRiage1ZXvkrc3Pww5fX6Ed6r5Z2y+x2G7eQU0nk5kDZi+DZ8Ngz+UCC6cW9EWFUZJdL+zxNFGu6lE2VFWvt09pO87h1TV721Ce2ZzJuzqdFLrAwl6FF/4TrRuKZtCypMPNdU+7nP0hhvGJWl5g6zV+Je5/ravlyXhEFWJOfXS7LTrpwqcWetVr9EzZyLx6IoeL0mMckDybl3eWKk+iLQs0j7OSquFFIEqNfuEsgse+1sL+cQ4NdE8RyDA1Cpb16hW38BBBybc4dEtXDz5Berqpk3421PP+PV7PX2Km0eM1/jRzUmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ff1k7Cre63lsY7OzWnUHwRRLjl4bc/C8Tk2QzqGRJPg=; b=qoQJ7ggHLmQ1AiF8aA2qwMf7Sp/6Ogbb/9VFZiNxPfQyNgXd9xKnFVqoBe+b3qrQd7Fv6qS/uvemMn/0dt+feZZ55Dq4FpldIez7TocC8066FcE/J+upt7SkdwYTITWbIQZkjMOJuuIjQZxCoROstcJ7It2VjvjKzVh3OXaibrY= Received: from SJ2P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:a03:5db::11) by SN7PR12MB7909.namprd12.prod.outlook.com (2603:10b6:806:340::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 10:20:12 +0000 Received: from SJ5PEPF00000207.namprd05.prod.outlook.com (2603:10b6:a03:5db:cafe::96) by SJ2P221CA0008.outlook.office365.com (2603:10b6:a03:5db::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.13 via Frontend Transport; Mon, 30 Nov 2026 10:20:12 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by SJ5PEPF00000207.mail.protection.outlook.com (10.167.244.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Mon, 30 Nov 2026 10:20:12 +0000 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 04:19:56 -0600 Received: from xhdakumarma40.xilinx.com (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Mon, 30 Nov 2026 04:19:53 -0600 From: Amit Kumar Mahapatra To: Jonathan Cameron CC: , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Michal Simek , Sai Krishna Potthuri , Prasanna Kumar T S M , , , , Amit Kumar Mahapatra Subject: [PATCH v2 2/3] iio: adc: versal-sysmon: validate temperature hysteresis Date: Mon, 30 Nov 2026 15:49:36 +0530 Message-ID: <20261130101937.1022383-3-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.44.4 In-Reply-To: <20261130101937.1022383-1-amit.kumar-mahapatra@amd.com> References: <20261130101937.1022383-1-amit.kumar-mahapatra@amd.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 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF00000207:EE_|SN7PR12MB7909:EE_ X-MS-Office365-Filtering-Correlation-Id: ee3549fb-2cfc-4d03-b403-08df4ecb8503 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|82310400026|376014|10067099003|56012099006|261026121527099003|261026140227099003|261028144727099003|261022075727099003|261022105027099003|261021123027099003|261021121427099003|261102123227099003|261009223027099003|261009221227099003|18002099003|22082099003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: SSEmjw0dUp6cXhG0XE5zgP7IB33hNMenTxht/TvmRcNShoHZuvaHTd92iKAZtENPb3Jas9ginYyBQnXwANIFdlb7R4sxjKMfHSG7WgKpAwskGmDqn1ZOpu7K7ZuxCVuUa2WhepuSoAsuJN2WthTi5TNceSKCLszD+8KaYjHIfW5+cpziylS5L849clpKBGMOtX1xkl+aZXtdq8pZx3buQv80OZ2pOPumRSAi4LwoCNw/vElRS1akcSKmGcRaO9VlBcph/uFlBqbn8I3eOKAPPjwhXcYoVUjZnoSZmrW00Yxs9YO/oN5D6GmFztCBe6YE5w0XhOKGY8HKuk5KAJ2yutjpH2iVIsfj6veSna5RFPhgU16EuQgSswkoXez7cyfqhiFrQmwPBxGctvjdIFepr6GjpVoUIiY9ucvDqti5r6U60FwAHDUKToswprlQPT19KTd563xNLjoq1DNdNiFopoOn45GuXrr9vzO8Dh7Ua3wTfGQtde7vGXQPI2IIPiJ4jVL1vjj7KAI5Nsi7Dsk5TZIig1J2zjPrFJDL2pnI6jLwNpx+XbQ04LdU24Q8Vvo9Dxdl73uTJz9AD40IwDEis3SNdVgmuHSOzpoJKOg+fH2uq0MsQcGVCQvaN1kKGgA1KiJpQyMptCQMEzfN9J+2Za0kTUbRebLaMb7Rf26cHQkLWDSUNl0Yai7srivGsbIVL9Af81r/BbudCqGLR8QndA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(1800799024)(82310400026)(376014)(10067099003)(56012099006)(261026121527099003)(261026140227099003)(261028144727099003)(261022075727099003)(261022105027099003)(261021123027099003)(261021121427099003)(261102123227099003)(261009223027099003)(261009221227099003)(18002099003)(22082099003)(11063799006)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bAqeHlR5SNhc4ygJxekTFPupt8s42EujjbV2528MLwlI7P+ufII8xyWKo87Pc02RQgj3hL1INmuKCtexQ/1rZ3pr/5FWKiDnEyInGb1Gh4gLzUZMKGGV72MTvCbla1LZ0D/RqVEoMe08FYxR9cgQXcRvun98aYCup478LF4thqx5m1dFbLsHZocEo9PaS3jSFrFWxRY/T4ARy752jg/qJ5bBBi6YJ4+XQpi8fFj8L/5Di6DWbCv6iu+tx/NDgigoH/IsgqOymAaxUB44b2Pwl6zd8beafITXOwoJ8YTNWhhD05XWxDVT0giHmsqgRI1u1iJSiv91iHU4rvInzc9DYemfO1Lohk+W8CCc2LHxYFsa4sQ+0alVUNtmq76pHt7aFvjTKi/uxb+Q0simTaQSQCRP8iBN8WIF21WR2eQXJKxrXGITAx+Xf2oE2oJxNGc4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 10:20:12.5563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee3549fb-2cfc-4d03-b403-08df4ecb8503 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF00000207.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7909 The hysteresis written through sysfs is only checked for being negative. A large value makes upper_mc - hysteresis in sysmon_update_temp_lower() overflow before it is clamped. Reject values above the full Q8.7 span of 511992 millicelsius, and name the Q8.7 temperature limits so that the span and the existing range checks share one definition. The cached hysteresis is seeded at probe from the threshold registers without checking that the lower threshold is not above the upper one. These registers are not described in DT: at probe they hold either their reset values or whatever the platform firmware programmed from the design configuration. Failing the probe would take away every voltage and temperature reading over a comparator setting the driver does not own, so treat an inverted pair as zero hysteresis, as negative values are rejected on the write path. The next threshold write then restores lower = upper - hysteresis. Fixes: c7f7eb10638f ("iio: adc: versal-sysmon: add threshold event support") Signed-off-by: Amit Kumar Mahapatra --- Changes in v2: - Explain in the commit message where the probe-time thresholds come from, and why they are not rejected at probe (Andy) drivers/iio/adc/versal-sysmon-core.c | 10 +++++----- drivers/iio/adc/versal-sysmon.h | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/versal-sysmon-core.c b/drivers/iio/adc/versal-sysmon-core.c index a7ff65075d7d..2bbc6808132c 100644 --- a/drivers/iio/adc/versal-sysmon-core.c +++ b/drivers/iio/adc/versal-sysmon-core.c @@ -352,7 +352,8 @@ static int sysmon_update_temp_lower(struct sysmon *sysmon) return ret; sysmon_q8p7_to_millicelsius(upper_reg, &upper_mc); - lower_mc = clamp(upper_mc - sysmon->temp_hysteresis, -256000, 255992); + lower_mc = clamp(upper_mc - sysmon->temp_hysteresis, + SYSMON_TEMP_MIN_MC, SYSMON_TEMP_MAX_MC); sysmon_millicelsius_to_q8p7(&raw_val, lower_mc); return regmap_write(sysmon->regmap, SYSMON_TEMP_TH_LOW, raw_val); @@ -429,8 +430,7 @@ static int sysmon_write_event_value(struct iio_dev *indio_dev, case IIO_TEMP: switch (info) { case IIO_EV_INFO_VALUE: - /* Q8.7 signed range: -256000 to +255992 mC */ - if (val < -256000 || val > 255992) + if (val < SYSMON_TEMP_MIN_MC || val > SYSMON_TEMP_MAX_MC) return -EINVAL; sysmon_millicelsius_to_q8p7(&raw_val, val); @@ -443,7 +443,7 @@ static int sysmon_write_event_value(struct iio_dev *indio_dev, return sysmon_update_temp_lower(sysmon); case IIO_EV_INFO_HYSTERESIS: - if (val < 0) + if (val < 0 || val > SYSMON_TEMP_MAX_MC - SYSMON_TEMP_MIN_MC) return -EINVAL; sysmon->temp_hysteresis = val; @@ -838,7 +838,7 @@ static int sysmon_init_hysteresis(struct sysmon *sysmon, int *hysteresis) sysmon_q8p7_to_millicelsius(upper_reg, &upper_mc); sysmon_q8p7_to_millicelsius(lower_reg, &lower_mc); - *hysteresis = upper_mc - lower_mc; + *hysteresis = max(upper_mc - lower_mc, 0); return 0; } diff --git a/drivers/iio/adc/versal-sysmon.h b/drivers/iio/adc/versal-sysmon.h index bb9a75bf71c0..930b7e7d21ce 100644 --- a/drivers/iio/adc/versal-sysmon.h +++ b/drivers/iio/adc/versal-sysmon.h @@ -75,6 +75,10 @@ struct regmap; #define SYSMON_FRACTIONAL_SHIFT 7U #define SYSMON_SUPPLY_MANTISSA_BITS 16 +/* Q8.7 signed temperature range in millicelsius */ +#define SYSMON_TEMP_MIN_MC -256000 +#define SYSMON_TEMP_MAX_MC 255992 + /* Bits per alarm register */ #define SYSMON_ALARM_BITS_PER_REG 32 -- 2.44.4