From nobody Tue Feb 10 17:30:43 2026 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CAF015B547; Tue, 2 Jul 2024 14:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719932001; cv=none; b=eydRVeVJcz3ra2HmKVFCneHyNL9mKuvefT2pjrBd3f1jnf5dne650x1evqnfhKlZKhvqzDTHnRlVowzK//xt+cZzPDbtjfLp13AbOR1iDZmmHZU+flYkbArreXIGOVyF2WKzE68dxAXdjM7hZfyrsSR1P4sGpuwtAuayQL3TQN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719932001; c=relaxed/simple; bh=zcCtez33jxnSqrsoNJ2ilJIZSKvzvgLXSNJz43K6oog=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=un6w0aIvUP8kSqyYR0z40UXP1Xa+JWdwI1zH9ePRtgxsiNNj7/dsIg//1HWKgoCfGHWOWV3TqWr6/Ux/G02R3rL6KDuIb16EoxoAoVqTwoHLYgL1S1WUl9pA6/HeWqstul57LJ16RWUYLanhWWAt6lHrAAHeDiXp8q+HcHyvK14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=PRbmnxhV; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="PRbmnxhV" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 462BkNNo023818; Tue, 2 Jul 2024 14:53:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=qcppdkim1; bh=dKP+ucAMMUbfxe8W55+nUzpQ OhfSVnudwj8XPSpegIM=; b=PRbmnxhVWm5heIIvRUNM8ZNh6NXabXWj6jw0Vosp HCNLorGmCFinDPJLbqbkvEPMXFElDc5ER4XPzYzF6obkvCcPNi0mSgQFV/nX6OKA YV5rfvu0IEB7fIAM+82FFW1tIVKz328EFiVXwl2Py0fUC/2LMFoH6yNgmk8f7hV/ VpS1R6pDg3jjfIy2pvRdSoaA5V/8slesLxzeJrOA8uHtUCNMJO6YHTm6A6RFYAX/ ld59m2kEQ0BVfa2+Za4l0BnZgKWMKNpg4xoyy2bdTJIZUNNsoZncz2/P3b6veevN N9sdTHejE9usj9b3TdNyeXEzgo0E+qee0fNpiHgwnIQNKQ== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 40297rrqj6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jul 2024 14:53:12 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA01.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 462ErCCQ014703 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jul 2024 14:53:12 GMT Received: from zijuhu-gv.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 2 Jul 2024 07:53:09 -0700 From: Zijun Hu To: CC: , , , , , , , Zijun Hu Subject: [PATCH v1 1/5] devres: Fix devm_krealloc() wasting memory Date: Tue, 2 Jul 2024 22:51:50 +0800 Message-ID: <1719931914-19035-2-git-send-email-quic_zijuhu@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1719931914-19035-1-git-send-email-quic_zijuhu@quicinc.com> References: <1719931914-19035-1-git-send-email-quic_zijuhu@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: xzUWOC4h4MF3GOcZirwnSTiPlnc3L6bF X-Proofpoint-GUID: xzUWOC4h4MF3GOcZirwnSTiPlnc3L6bF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-02_10,2024-07-02_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=799 lowpriorityscore=0 clxscore=1015 mlxscore=0 suspectscore=0 spamscore=0 adultscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407020110 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Driver API devm_krealloc() calls alloc_dr() with wrong argument @total_new_size, so causes more memory to be allocated than required fix this memory waste by using @new_size as the argument for alloc_dr(). Fixes: f82485722e5d ("devres: provide devm_krealloc()") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu --- Previous discussion link: https://lore.kernel.org/all/1718531655-29761-1-git-send-email-quic_zijuhu@q= uicinc.com/ Changes since the original one: - Correct tile and commit message - Add inline comments and stable tag drivers/base/devres.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 3df0025d12aa..ff2247eec43c 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -896,9 +896,12 @@ void *devm_krealloc(struct device *dev, void *ptr, siz= e_t new_size, gfp_t gfp) /* * Otherwise: allocate new, larger chunk. We need to allocate before * taking the lock as most probably the caller uses GFP_KERNEL. + * alloc_dr() will call check_dr_size() to reserve extra memory + * for struct devres automatically, so size @new_size user request + * is delivered to it directly as devm_kmalloc() does. */ new_dr =3D alloc_dr(devm_kmalloc_release, - total_new_size, gfp, dev_to_node(dev)); + new_size, gfp, dev_to_node(dev)); if (!new_dr) return NULL; =20 --=20 2.34.1