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 AC1DB391844 for ; Mon, 18 May 2026 19:49:05 +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=1779133746; cv=none; b=a030InLrr66S5mqh6xDkUA2R2Pk/c3zey8WzEazKfWTKbE+e6dj978Pa9pb9kDHoRWOCs22bf5nbtibDPHENq//6JF27v01wf8TmLO50FbYFkN3KF6xTnGr64SpVd3zOnOlMhyRZjsSwMnuWta5DpFfoeml/c09ZY8hK8ZTdWE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779133746; c=relaxed/simple; bh=hiEgsl0ul9FX/bsm/w64ZENgsu3+qSLhx3x08rD2js4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=TM7Ny9GoGHz3bmjZE0m1KV11cFc28sGEnTUAX8g5DOQSlaRug9Kw7avv3RB97JFjLdSiIHKCgjiZBbZhLwl5jM+MC4aCRWBejdVr77nGEbM8seveGZ2+RRk/6UWs8tDfkQsa5yHChJivewEUciQJBDPIjgWhNUAQsROv2WOGW+0= 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=MC+YVlYQ; 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="MC+YVlYQ" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-365cae89bf5so1051962a91.3 for ; Mon, 18 May 2026 12:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779133745; x=1779738545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CSdd+NX6WkTu8lhAsB8yG+c517QF020QYelPmR8Wkrc=; b=MC+YVlYQij89RWZ0cljYuuTlB/dbeH7YTPq00RDv3Osr1GKXar5znLQe810MRt1gFX qqfmPmMIEjDB9Ycuj88wLg0VXK9jv5rrHRVTS+A2VU3r/Pfeq8/F8tdeiboxky5EyU+u NRniCPklgEQ4uCPXHN17/KaDxlhRxJfpOhHWoevPZ4/aluQQfnYWjE6Ny5h9tcADtHWz xsQKKBwy2Bt/yxRtj9/OJwNIKPC40McRjPXSw3TN3lg4AF+eLgKH104D1HinX0CuFXrN iaxbw97tD4yJbM7/lDgOQI0ywChzCZyRlfDnBmCxU0OemsibRBsXZ9HsU9WuejNwROK/ deNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779133745; x=1779738545; h=content-transfer-encoding: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; bh=CSdd+NX6WkTu8lhAsB8yG+c517QF020QYelPmR8Wkrc=; b=SsBOWUfqFc00gpCePTtudD6JzvDSmwOslAhz6r+2vq3+oJrF8tZHVnlUHNfuokjQF2 JWlznhEfXSD3OQvk+NFjo19tpXKic8Qk3U207+ohYqcP+TtCtiChtSs0R1NdK0LoMt3M 0IORRKTVa/RxMQvORtMl8d91K3txJy0vEJlE42+bJd+taFfCJpGRP8mUq/a2uEB43rAT M+pBwtu3QBAQfb9xvEoBzRRr4jKYUPo9uPArBtdTULa2XRCNcXt49LUFPWx3+h0S29l6 oxjhO/WP36aN+9IS6KrB5TFCzFGwEBVyqCnHL3W4PEPaa/O0VfbHd0R2uO514PzCv5PN AjDQ== X-Forwarded-Encrypted: i=1; AFNElJ8YPNYnyITyoIMpwNC92BmEUK3H9TK1wKweS9T2yDdLnGqeMnvFQvaCU4dB+r5LBzKMTvRqemuDfCq6kv8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzq+1Rk4GHeinZYADXPwcBA/ygnFBJO3t6cKAX1bxWMGOpzF/fu MKOJKh8kf43nI3FJMqoCMqkQVLrxuiS3k7oZfrBLc+AWjWmR/gtSvgLe X-Gm-Gg: Acq92OGyysq1u49ftvNrSOV74IXbgvDF8TDw4Y7ZD+o5qEe6c6e6/LihsMepdiaEAXt YlVAMVZZXasUNucLnEjHL5/FdKrSRo2ZSvMGvTKGcVhI7ZAvtFu7KwnkXNSwUn9sJNtC90Q2iVr dp7Va7dCAwsNxsRkfO8tXFv6TVl+sYvBGRHabSjDlV2NgNDVLH9mGt+LT5b6NA8AEiAL44M9kOf u+wbBM/lAX25LuuQCYOSuXupQ7roAa1zzVjTcwYMBpk/hs2liyVywLzKc8zgRapQvB81sopyVpO Kws9r2BpKmf7ohtsUb0b8MScWKT5GeplYLCJzNBxwOyNrq8alwdEIr2Z5kWBfOvx+9I3A35B6Z1 kxz8KR5cfbwqpHIgfwlM/qDIh2SMMdhhHjG4xJr4QfpJB+WMsKQrsn+dOnsXq3ETJoGatRy+yud OY1waqheREUdjQE00NqkxlakDe0C07JDDOCplLVVZ9zOybvkkgu1DxIlmKg6Af+Aw0RnNhIA== X-Received: by 2002:a17:90b:1344:b0:366:4782:138c with SMTP id 98e67ed59e1d1-36951b971ccmr16986854a91.17.1779133744962; Mon, 18 May 2026 12:49:04 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369515895d2sm11635928a91.8.2026.05.18.12.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 12:49:04 -0700 (PDT) From: Maoyi Xie To: Lyude Paul , Danilo Krummrich Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: drm/nouveau/tmr: iterator used after loop end in nvkm_timer_alarm? Date: Tue, 19 May 2026 03:49:00 +0800 Message-Id: <20260518194900.1672140-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi all, While reading drivers/gpu/drm/nouveau/nvkm/subdev/timer/base.c I noticed something that looks like a past the end iterator pattern. I would appreciate it if you could take a look and let me know whether this is a real issue, and whether it is worth fixing. The site is nvkm_timer_alarm() (linux-7.1-rc1, around line 122): list_for_each_entry(list, &tmr->alarms, head) { if (list->timestamp > alarm->timestamp) break; } list_add_tail(&alarm->head, &list->head); When the loop walks all entries without break, list has gone one step past the last entry. &list->head then aliases &tmr->alarms (the list head) via container_of offset cancellation, so the insert lands at the list tail. That is the intended behaviour, but the access is undefined per C11. Jakob Koschel cleaned up many such sites in 2022, for example commits 99d8ae4ec8a (tracing: Remove usage of list iterator variable after the loop), 2966a9918df (clockevents: Use dedicated list iterator variable) and dc1acd5c946 (dlm: replace usage of found with dedicated list iterator variable). This site in nvkm/subdev/timer was not covered. A candidate fix would track an explicit insert_before pointer initialised to the list head (&tmr->alarms) and overwritten to &list->head only when the loop breaks early. The observable behaviour is unchanged. If this is intentional or already known, please disregard. Otherwise, I am happy to send a [PATCH] or to leave the fix to you. Thank you for your time, and sorry for the noise if this is not actually worth fixing or has already been spotted. Thanks, Maoyi Xie https://maoyixie.com/