From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796259467; b=03T4OR3ZmX9KQlXb2SHWmTTActq4DBZEOfoNb1tktstiEKHkp+GSojQWv93+tAiB7FdQ Urjen+npj8gpOBm8HGk3j4y0P4OEIAxI8yX3+A8tJGsF7aVRLhI69fyEoKglbsOLi0xcS K14iDtE9LXJEZm3WIUyrt53MXXIuF43tcgATNpMtRGaHrY+rbERLwsvPuvAI8WvOV6tod 1XmLE6m/G8wl85zE7JbtUOlEt/93fPMnpYCUeHJJaf+spFtuob/NujC84o+sLGGM7B52R jyDHPrxtStk7wX7l8E7BlQD43qmca89brl+XrWAcazoRDCAssyQgeNaW64iz618hgMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796259467; 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:MIME-Version: Content-Transfer-Encoding; bh=0qr3Mo1yJfO99dnvSpyOGPrwt4tLZUvmZU5hF6uBUig=; b=um2hBiEDDfZ7qYawgtopTsIXp3Ri43O4EhkcVv7J3MFaV0sH5AmZIQ5Fqkw5Aoksb11S F6lullog2AWsnFejQDLbJyMjUtL3Vnd/PvbQlPlJx+ue3tRUFMwjieUwr7Cjw1X7Ou+2Y KTDWauN6o4kj5lIu9hDWSbVF2yhyiT6inG5aINCelkThF3K8SwJACU+7CSEvlAvnNmuch vkCoIFDjQVv/k2BKmvIZCmy+uzMjflBhLUXvOmislB1pIY0eRTutvz8oQLDpbrX+hR+dw bNV8FZCyPGsDS9Ohx+RT/PggVBRl2dvrclnFkFpI43ihq4zu7SYeB41kFa2x2lTK4pQ== 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=bZle9Qk3; arc=none smtp.remote-ip=209.85.216.47 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 F3D52606A322 for ; Thu, 3 Dec 2026 00:57:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3D52606A322 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=bZle9Qk3 Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3b567ae3c66so2431734a91.0 for ; Wed, 02 Dec 2026 16:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796259466; x=1796864266; 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:content-type; bh=0qr3Mo1yJfO99dnvSpyOGPrwt4tLZUvmZU5hF6uBUig=; b=bZle9Qk3C5/32WOR2Pfs9G9L40jjAHcg1oPBV56bMe30ZpDlswrmuru+J17zfcjYqw KLtIWs1yNtpy3X7b4h+M3ngsozUU3yCTKgAGcqpX4j2/SBCyvMKqC/YtAnllR7HTPWEV r0gGG/0gvB70Yqy9E/9wM839UeZZrH36kmxJ7oO3o2d2dIJoTMn7Tlz93U34azXOg7Yx ZUE2wEHZppPZ3aRZ+/YshfCnE8A6oUZS+rkBcyEveQZ3ZEJDjJ3E0iuvFSvo/63vPKJ5 AAxJn0kmCzkRJUa+t1mXUnd35904wBawEyuTrwwxVvgplq+0CKXKZRagcGp4Ls3qzZLL qj4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796259466; x=1796864266; 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:content-type; bh=0qr3Mo1yJfO99dnvSpyOGPrwt4tLZUvmZU5hF6uBUig=; b=Q2rq4uRKrCEj1aOsipXcDVkdMecgmeOU9c7Qum8/jqM1V/H7PrrBQR43mEmAZEIFK8 KPxtg0LUdtgCM6Gg82HIS6xG6DFBSkC6A6dgtKZx+qRa7Dpr1mMOZDiJ2s8OKj05FcJT N0i3tzMkbg/OTX6nMAS0opP6DcaTGZpLiF+Oi07f9glmzL9+kWp9OodNhvo3MWHvtrLP tYMwV84HwDhSs/FmGJvr1doPDl9tMDhLD4xR6SHN84qykfhfeibOBa6k9hPMVQ4zN0O2 p5Wp8DfuvNEPKKujGltJ8m2kulvZJW+yMxxjDCuQLMetXRBM5Kxx0r5EH6ulplORJPB3 d7MA== X-Forwarded-Encrypted: i=1; AL+hErHF8tnvSSQukQEN5S2UE5cwLrBiTWsqEFYuXuolnzseDMGocUQBtm6tejzasLvoCZO7CQ4mboj79qLbNVg=@vger.kernel.org X-Gm-Message-State: APuU4Z/aDguNVzygC/DmyLX2LtzT1zTOknufpXp2IqPdjvan170CB/Wz jrHXHhvNokjWRjazzjyI63Dw5LXejGm0IJovFKy2Im98xT+k32TYTbKe X-Gm-Gg: AZFdTZe5jBdJck5xX/QGyK80oafXSWF5GOBDG/hPY7Y4WA0ExqdnIIUe/6MYo2caFtQ +67VfK9p8649pTJ9HqPxtQBATHPX+OlTX9ltpjlWGLSl2ms9gDvLePpCd5mWBTOYxg/kkbZ9AI2 1eL/G+TXr01uvzKL2p3w/o9IwMTcNH1JSipAcin5IEwHCuBxSHQbcLOCg1756yswIIK+YxT7NJL dKA015Byb6Bo5Zg2s5XlymQ1fhfVeMgNZBbIV4WSdoBvCQpbwuYWV6CmvRlfVdEcTIwkBbg5mA+ T8MdHEO6MJTAXA0sVNOxxaIRcvdP1z0jfHP8mzU7qGzf7HqzyqPAWI1bVvvz+Tddb8AQi6G5Boc M8lgs3Pg2yDQy/kNrjW7SoGSdhoB9c+ErAJVZw/HyWOY18b7MJFXMRLV+vd51T9hxHmSWWDzBpW j3jpRrQfotmJcvEI2HGeVt++8RPbpY+0gJ6nJmxCpTiyoncf3WK1ka4c/sdLb+OJTPC0TY+P6Wq pDF9tER5a8jckMgevPYpaZpxHa46ij4368KL/4YsVw8YhnouZwc0Bw6oJauzKUcS2gOyly7KBwq aPiG7CwQ9jpvJ7sLxjsYtPa4iHiNXCiFdv9MeXXkW4Ym7iQDyHHUR5/ebBEi3kocXDefiQ== X-Received: by 2002:a17:90b:5109:b0:3ac:97bc:4c98 with SMTP id 98e67ed59e1d1-3b41c9bc501mr40325554a91.64.1796259465998; Wed, 02 Dec 2026 16:57:45 -0800 (PST) Received: from eric-N-A (61-220-246-151.hinet-ip.hinet.net. [61.220.246.151]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c78561fesm1556196a91.8.2026.12.02.16.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 16:57:45 -0800 (PST) From: Eric Yun Lin Chiang To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich Cc: Johan Hovold , Bartosz Golaszewski , Andy Shevchenko , driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, Eric Yun Lin Chiang Subject: [PATCH] devres: update node debug info on in-place devm_krealloc() Date: Thu, 3 Dec 2026 08:57:04 +0800 Message-ID: <20261203005704.3066960-1-ericyunlinchiang@gmail.com> X-Mailer: git-send-email 2.53.0 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 When the new size still fits in the existing allocation, devm_krealloc() returns the old pointer without touching the node's debug info, so the node keeps the size of the original request. devres_log() and the devres_log tracepoint then report a stale size for the resource: a buffer grown in place from 1000 to 1500 bytes, or shrunk to 600 bytes, is still reported as 1000 bytes. Commit f813ec9e84b4 ("devres: fix missing node debug info in devm_krealloc()") added the debug info for nodes newly allocated by devm_krealloc(); do the same on the in-place path, so the recorded size always matches the size the caller asked for. Fixes: f82485722e5d ("devres: provide devm_krealloc()") Signed-off-by: Eric Yun Lin Chiang --- Notes (not for the changelog): - Tool use: the problem was found, and this change and its test drafted, with the help of an AI coding assistant (Claude). - Reproducer and test (UML, KUnit test written for this purpose and not part of this patch; base commit below): devm_kzalloc(dev, 1000) -> devm_krealloc(1500) in place -> devm_krealloc(600) in place -> devm_krealloc(3000) new node node size read back after each step: without this patch: 1000, 1000, 3000 (test fails) with this patch: 1500, 600, 3000 (test passes) Data in [0, 600) is preserved across the final copy in both cases. W=1 build of drivers/base/devres.o: no new warnings. Not tested on real hardware. - Locking: the node's debug info is updated without taking dev->devres_lock and without find_dr(), matching how this path already trusts @ptr for the ksize() call above. If preferred, the update can be done under devres_lock after find_dr(), like the new-node path does. - Stable: before v7.1 the helper is still called set_node_dbginfo() (renamed by ba424bc2c7bb ("devres: rename and export set_node_dbginfo()")). On 6.18.66 the change applies cleanly but needs that rename to build; with it, the same KUnit test gives node sizes 1000, 1000, 3000 without the change and 1500, 600, 3000 with it (UML). Older trees not checked. Happy to send the backport. drivers/base/devres.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 9d9842fc5a19..d1baf7c44435 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -1010,10 +1010,14 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp) /* * If new size is smaller or equal to the actual number of bytes - * allocated previously - just return the same pointer. + * allocated previously - just update the node's debug info and + * return the same pointer. */ - if (total_new_size <= total_old_size) + if (total_new_size <= total_old_size) { + devres_set_node_dbginfo(&container_of(ptr, struct devres, data)->node, + "devm_krealloc_release", new_size); return ptr; + } /* * Otherwise: allocate new, larger chunk. We need to allocate before base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d -- 2.43.0