Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1750146lqs; Sun, 16 Jun 2024 03:02:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnbFEivMkc+WKVafpNWvchFfjwdv13PlUItZPIThQDwxojQyWh7VfpOwEg+wMSJFUqsgdihUWCfdt704yiK8eSPEG+BH/Owd70GRblmQ== X-Google-Smtp-Source: AGHT+IHsfyDrAn4LBJQF+urH2KVPUf12OykRltob02bIbG0oOmESLsJkVB3QR+7vSclSSIj/2RC9 X-Received: by 2002:a17:907:8b8d:b0:a6f:64cc:ca2e with SMTP id a640c23a62f3a-a6f64cccb75mr581528066b.44.1718532179581; Sun, 16 Jun 2024 03:02:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718532179; cv=pass; d=google.com; s=arc-20160816; b=sNwjGWKwg5upG+hiG88DChGPj2lEurbcTDDcjczugk+J9c52xB5WpqT8RnUC051Hgn Q9wX8PS3N5Y9QQiESurI22cRqQaocFF6JYwdCWwj8LyhOm6J2OsEfF1n0E7+AJtoEaqa 0Z4dEMEa8scDuT6o8Dk4lKMxy9MWPjNg/I7Wmwhi0f5jfbudnmOSqnPyuvDF1EWummL5 tbi1LdBgPhVnvgaTp8ve9MSzAAT9m6pZT2lkAV249dOLl8tdr2tI6Vj4IqgM0ZDbcEsN 61tSs9CI1XIGwXaBr/FVgukmlUolLzUCtguX1sYY0LCfAVgTTRsdsfOUedtPpfDN57Tg YS8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jBb4+HeQcA7+p7IQ/8Oh3pgTz2/8tbD12Acl64Nt8xU=; fh=ncOPkQLJDrnRpjUTNVG9Iqt/Dw+eF8lOZJtmRKpgL38=; b=XDn+XXVKUb6Ir2Kn4ZbDn2uV2FCLaKTl4R2hhhLfiNFZAmKxALTJTFBo2UUa0fcUqJ Mk2/l2LQpYj8KGDey+M1x9vNLKg55VjvYhut+RWWRbModIoOHhn5+IWcql80VPruAUrq znC9Od6OX1SDTG9aC2BvM+/x4ISGYwFjpmfE4iOSU2xZpAPEPTwMN63ATD7GnyTSCO8L ZZtE7qSNDyI6NPrxJn+RQuZFpERZuKPrZScya4/Sy+u7H74bGRuiJjm8adJ8AWYFpBeg eS5+cAKIUgKcsnOHad6g14A5gJ4gPtOIWt7JSf2XNDMhvc3Swg4hLH3we/GHV6sSO7/j uo4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ee6SY7Cs; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-216229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f72ce54b9si155988066b.633.2024.06.16.03.02.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 03:02:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-216229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ee6SY7Cs; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-216229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4E93F1F21313 for ; Sun, 16 Jun 2024 10:02:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02D99186E2F; Sun, 16 Jun 2024 10:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ee6SY7Cs" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 26D6138FB9 for ; Sun, 16 Jun 2024 10:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718532172; cv=none; b=BsyAlWuksxoMRp317zMQNvZ6lOSA6racX1crjYToYIBrnrEgR3tlO8WaCjSUTlLgzz4jSEzV19NY/ZuWrxsuiOjoFPIplofJoGKg+sp8U5qLodnQOmGhM9N5sRqItE5CqLAYMpozeU+aG7MFdxc1ixAb2Si15LgKAqtyzYBClnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718532172; c=relaxed/simple; bh=yXIjGttonwU+6Q+ZK3eNhYRfgLvdtg0GGxDoUfkvkao=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WMJuWeHkMtGvQo72YwqBod18bwk6emT1siKAmryKCmoLwIDWouPshCFXwgDlVNkmUEPkON6qP9Uf1CpNDrMj7jrV9Me3r0FSZNfWWN8kRQ5bV13GyCrxzoivKJY05KVMxZL4rj4y2qSKpiu1h8WAgX2NW4BX36IZOPhQiLyhUMA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ee6SY7Cs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F451C2BBFC; Sun, 16 Jun 2024 10:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718532171; bh=yXIjGttonwU+6Q+ZK3eNhYRfgLvdtg0GGxDoUfkvkao=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ee6SY7CsDK/d/l6Bi0U8xO8VqTxqZWceN9Nwa/fl4SymAl51HTqtdZ6qYmdRnKsDj L23L0Fu4VksdsePOMxV9vPN/NVAx7Pm+ps1XyMS39iHN2LwxSpKg769hg2XGP7ra+H nkLbdwrrX1p5idxjZz32fS6m6zJ6dlnyxDrwhDCg= Date: Sun, 16 Jun 2024 12:02:48 +0200 From: Greg KH To: Zijun Hu Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size Message-ID: <2024061609-breezy-magnitude-8edf@gregkh> References: <1718531655-29761-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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1718531655-29761-1-git-send-email-quic_zijuhu@quicinc.com> On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote: > Kernel API devm_krealloc() calls alloc_dr() with wrong argument > @total_new_size, and it will cause more memory to be allocated > than required, fixed by using @new_size as alloc_dr()'s argument. > > Fixes: f82485722e5d ("devres: provide devm_krealloc()") > Signed-off-by: Zijun Hu > --- > drivers/base/devres.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/base/devres.c b/drivers/base/devres.c > index 3df0025d12aa..1cf87ddf1f55 100644 > --- a/drivers/base/devres.c > +++ b/drivers/base/devres.c > @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp) > * taking the lock as most probably the caller uses GFP_KERNEL. > */ > new_dr = alloc_dr(devm_kmalloc_release, > - total_new_size, gfp, dev_to_node(dev)); > + new_size, gfp, dev_to_node(dev)); Wait, are you sure? Did you properly test this? What is the actual savings and how do you handle the fact that you are now not allocating the space reserved for the devres structure itself? thanks, greg k-h