From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 C573B2D5C68 for ; Tue, 14 Jul 2026 04:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784003354; cv=none; b=JnUDMiFcTibJ3mkSXObNOK/r5O1fc9Gp0pvICDTadR1RptW2LCkouz7p4pkR2UwKVhYKnLy24n7wfroHfGhziUg0Ddl7RoFV5QzdaB0AoMqeWNx+E+bDS1Dd8YRSW6SsgILZGW0uanKGUE+rm40q1gL/r18NquWJKTpS324nprc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784003354; c=relaxed/simple; bh=QJOPYkRvIadfRFcGP8v6wXwTJZ7TicjFOV8r1Yj1qH0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ejQ26JuUeqkQKxBTt6YNLBpGZxTGfMQ0+inmENEt6lo2b505r4xVE28rlTMj6ED9W3dC6CxXsLm/dJauMi7i5y+4ZHi3lKBaZ9f9NwwVXRJNBP0dy8be/7AjW4naL6pMFnRmKX6cvHTb8BiyZLliuKVyAUVhHwmAtuQZHbdVoHA= 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=IO8K3XFz; arc=none smtp.client-ip=209.85.216.53 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="IO8K3XFz" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so4042372a91.3 for ; Mon, 13 Jul 2026 21:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784003352; x=1784608152; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8taiq1gh/0OoOQDBR9j9Bhwzd7P+6aji1UgJtYLJxrs=; b=IO8K3XFzVzBTc0toXFHqYU2GEUClzPOL7ex1l8voUsryvoGpDdv9ickB8oTmFCdOfw UkPCLTTXxrWS+AmPg7RfFne2qGsfB8qmwHl/ijOJhV+JFiobGMw/CleiProYj0ghEaE/ n15sZclzmmd081M4P/lTvgKpL9jgfXr6c2zne/pYpLh+SEzik7NmLVpzeabESl4eTFtu MpVn4RQb37UetoqSmqktFIEj/vXINVQ/dKM7mxsaQc28ZGziD23k6z8EQtWdeqPOvzLF vduLrkAnAZ1l+x7WhFCLj7mp5vEvHC13suPs1QmGpuUoOpt8aLmW581rTswBqbwUpQHD Z/1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784003352; x=1784608152; h=content-transfer-encoding:content-type:mime-version: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=8taiq1gh/0OoOQDBR9j9Bhwzd7P+6aji1UgJtYLJxrs=; b=EeDaZty/j5An4r0nwohNIdGHtgo4/7QnKRVtoQDxADTEumkKu3M4vJPlrj4YikkFia EZwri40A/sz8vI2BFWQeyAQN7wlCvz4mKRiSMV2PmdUeOStjvOSQZVJ7TwT4SClplkl1 x57Q+isilbafMrd1120JZYy2lJGAJzXKG55YcfWuD3yMjr7YPvXk6b94d7Y1ceaufNmY 4F++q23Ql6w6P0OakIaVB+rhAL9L+tU9gKp2ktdJlIrPFnFEGu48c+DiOzGZHWw1RiHw 31cH11ShfmzU8DZclOPX6KpNYPGIDkKRu4lJRZOxKWEB7OLy6cViF3NHo2jC+WjBFvhl z2gQ== X-Forwarded-Encrypted: i=1; AHgh+RojaVohfjDxAAhwTKBENZ/I9DEIYIFvcykC9ym5jNjWFayYRFO7FGXgtrYLx8Px/w3owRRRND7yTcrU454=@vger.kernel.org X-Gm-Message-State: AOJu0YyB53KiL1V60r65jkQt/ZAisithfTaClvK5YxiZIoARDiKNhmZ0 m52k6Tjc7ftmmToXANN8SEBZjSOGvKfndElyWNIDIhrsPwPfo1ckDoRf X-Gm-Gg: AfdE7cmNDp/l/UVG5eoVhwehlUeShnG9EQuIZBmRL2e1neC13QQKHfTrG1SVU1ES0u+ jA4HudBzLEF1zQRnZGlbA8WbFpzWywJqcEPCF22iFiaq868wLYkM0nx/2Pmuq07OaxBYt86I8wZ Rh+MF/CkUDSGtbMLn8NKBfq2k3YmMV7o0gndJcfuSx2rjP7LAiNHPDzjHVn9gM9bX1EI3YSHlek dMEznvmUeXtAXpb9bkAGYqd7MebVr/tk4Gt/4+T8zUezVmkN2JgfLYJaSfHjxRx65nzhEOOCKHQ xvwr95lH1cFXiH/ZHMsW9LEFjGDcx4p4uD6jqYJSwrmXbkauve3NAumtyAwErJbiIxwcXCNhDoN HulVMIZRo41EHWT1QpYujalLBk7RpB5h1hqCa7gIC6OFCUBKj8CLsRo7I9suUMwdS4YD53Qi4P3 /n1IYCFVIEMcrJ X-Received: by 2002:a17:90b:54c4:b0:37f:db06:2299 with SMTP id 98e67ed59e1d1-38dc777b804mr11414344a91.21.1784003352088; Mon, 13 Jul 2026 21:29:12 -0700 (PDT) Received: from kdev.. ([108.180.130.139]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38e172cba1fsm766340a91.5.2026.07.13.21.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 21:29:11 -0700 (PDT) From: Babanpreet Singh To: William Breathitt Gray Cc: Kamel Bouhara , Jonathan Cameron , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Babanpreet Singh Subject: [PATCH] counter: microchip-tcb-capture: Fix DT channel validation Date: Tue, 14 Jul 2026 04:29:10 +0000 Message-ID: <20260714042910.7-1-bbnpreetsingh@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mchp_tc_probe() reads the devicetree "reg" cell - a u32, per the API contract of of_property_read_u32_index() - into a signed int, so the bounds check "channel > 2" fails to reject cell values at or above 0x80000000: reinterpreted as a negative int, they compare below 2 and pass validation. A malformed devicetree can therefore drive a negative channel into the ATMEL_TC_REG() offset arithmetic, making the driver access syscon regmap offsets outside the TC block's register window, and into the "t%d_clk" clock-name formatting, where it truncates clk_name (sized for "t0_clk".."t2_clk"). Declare channel as u32, matching the API contract; the unsigned comparison then rejects everything except channels 0..2. Adjust the format specifier to %u accordingly, which also resolves the W=1 warning that exposed the gap: microchip-tcb-capture.c:520:56: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 6 [-Wformat-truncation=] note: directive argument in the range [-2147483648, 2] No behavior change for well-formed devicetrees: channels 0..2 take identical paths before and after. Fixes: 106b104137fd ("counter: Add microchip TCB capture counter") Assisted-by: Claude:claude-fable-5 [gcc W=1] Signed-off-by: Babanpreet Singh --- Note: struct mchp_tc_data's channel[2] member stays int — after this fix it can only ever hold 0..2, so converting it (and the QDEC-mode comparisons reading it) would be churn beyond the minimal fix. Happy to do that conversion as a follow-up if preferred. drivers/counter/microchip-tcb-capture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 19d457ae4c3b..e53a8390756b 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -483,7 +483,7 @@ static int mchp_tc_probe(struct platform_device *pdev) char clk_name[7]; struct regmap *regmap; struct clk *clk[3]; - int channel; + u32 channel; int ret, i; counter = devm_counter_alloc(&pdev->dev, sizeof(*priv)); @@ -517,7 +517,7 @@ static int mchp_tc_probe(struct platform_device *pdev) priv->channel[i] = channel; - snprintf(clk_name, sizeof(clk_name), "t%d_clk", channel); + snprintf(clk_name, sizeof(clk_name), "t%u_clk", channel); clk[i] = of_clk_get_by_name(np->parent, clk_name); if (IS_ERR(clk[i])) { base-commit: 3b029c035b34bbc693405ddf759f0e9b920c27f1 -- 2.43.0