Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3096778pxv; Sun, 27 Jun 2021 18:55:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx77JtGNoJpOXJPifg6DSIUEKH2ROE1g0TSNO6UA543+aCsTy8hGuJ/qxF49cGx86weN2u X-Received: by 2002:a02:230d:: with SMTP id u13mr20368070jau.138.1624845303259; Sun, 27 Jun 2021 18:55:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624845303; cv=none; d=google.com; s=arc-20160816; b=YzBied4xp+Ha7Maa2tyYJyCjOUX3ePDjcd/f22aee5jbKocf8zR2xaUPSfRWGAYAjD VMdNR1znpUNg3c/053BPjHqzn+oLE9nKlOl+9jjqg1R1XlUJK1nhWvnYQGBvpe1IQCgd 1wzD1oRCytYiA/65Ah1A5aacsVhjGsQPZBFKlFm3FgmLGuGfiCWlAqKUaHyOLF28P56j IiLgYivmULWMKxqJYfP2E9dUDCuj4uiFK5o/YWGpb7cPl/XMBz4HdJSWPNXXLAJ03W+S FE+HdmCR2KwcsSJtDjHW9FQcy0LCppHd5Si9MYKkKxwHN9yQ/OdTg6bjI+RIVrso0S0P 4EcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:date:to:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=PH3Wfds3qlqovZiqXx5NqnOb1Jxi5bkmiAFNLQPEDKo=; b=H4f3UtzhP2c8bxWNJz4rbi1perUvtBTdZLWhV+6yR2CTG8bEok0/JyT+//p4EDB+v8 NHJqz0o7/wVp8zfLV+4hI2BBswmxDIfzIsJxctwkZbYfXlLKWHLoBbBWybiD977AdGXx ZR8KW+FSt18GHttIXNH13NcQMCDt5fWsWqOPzWFHOAV8nyHPZkC0rl7MZWZ2lZIXbg8L /COKJNGyaE2X8qhh0uyuWAzdLRdKaPtMr/bHbl1Q/Kyq4xD5FXrhUcrKAEaaioPh40tH d+cV8NvLvz07/xDnIkCaxAXiZjTEBk68/GZsRnlw74R/02zNT8BxF67XidF6iew7DXbD MB2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dTdeiFBf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o22si7626852jat.17.2021.06.27.18.54.51; Sun, 27 Jun 2021 18:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dTdeiFBf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231981AbhF1BzX (ORCPT + 99 others); Sun, 27 Jun 2021 21:55:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:45698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231678AbhF1BzW (ORCPT ); Sun, 27 Jun 2021 21:55:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7991061A36; Mon, 28 Jun 2021 01:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624845177; bh=YpYR08RUmtU3O4t9HgUXI0T0FWV5Il28adXJQeOZYOo=; h=In-Reply-To:References:Subject:From:To:Date:From; b=dTdeiFBfjtn0ZmPPtAeczAHJIaVRHrN1cmnrVZSSwQM/64zCH8F9enDftxzWOjJL0 B1x39j+sg0ehQ/8P32IRvFKw91lQ55HC3587ufZFleGcN4CrFIJyGFLkLjwfuTeZgs C47mUd/Dm8rr0FJ5nAYkvpQLZK6VD9w+simUAIgJuK4T76JssVDqxnTYOsCvudEG9q jtG1dQfv4BQ0SjKBrpAv+NuQI0CiVzP4qmZ7KjS1yk/o7QJw2moU2juqof/l9kbNz0 1wa2qhExOoGwcSVL9LDLWl0PAKkFkI0oNb7pPpkQNiDovdQ05ly1LWMLzNcG62whWU yS7ebNlxs9tIw== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <5eb50fd9-1de9-cc61-6443-d84999e22803@gmail.com> References: <20210617082759.1008-1-thunder.leizhen@huawei.com> <162466387362.3259633.2364843071785127818@swboyd.mtv.corp.google.com> <162483744494.3259633.12565750309559171999@swboyd.mtv.corp.google.com> <5eb50fd9-1de9-cc61-6443-d84999e22803@gmail.com> Subject: Re: [PATCH 1/1] clk: tegra: tegra124-emc: Fix possible memory leak From: Stephen Boyd To: Dmitry Osipenko , Jonathan Hunter , Leizhen (ThunderTown) , Michael Turquette , Peter De Schrijver , Prashant Gaikwad , Thierry Reding , linux-clk , linux-kernel , linux-tegra Date: Sun, 27 Jun 2021 18:52:56 -0700 Message-ID: <162484517623.3259633.1405371294577745182@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Dmitry Osipenko (2021-06-27 17:29:20) > 28.06.2021 02:44, Stephen Boyd =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > Quoting Leizhen (ThunderTown) (2021-06-25 18:32:46) > >> > >> > >> On 2021/6/26 7:31, Stephen Boyd wrote: > >>> Quoting Zhen Lei (2021-06-17 01:27:59) > >>>> When krealloc() fails to expand the memory and returns NULL, the ori= ginal > >>>> memory is not released. In this case, the original "timings" scale s= hould > >>>> be maintained. > >>>> > >>>> Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes") >=20 > The memory is still not released on error and this is not the only one > place in that code which doesn't release memory on error. >=20 > All this code is executed only once during early kernel boot, perhaps > not really worthwhile fixing it or at least this should be done properly. >=20 > >>>> Signed-off-by: Zhen Lei > >>>> --- > >>> > >>> Looks correct, but when does krealloc() return NULL? My read of the > >>> kerneldoc is that it would return the original memory if the new > >>> allocation "failed". > >> > >> That must be the wrong description in the document. For example, the o= riginal > >=20 > > Can you fix the kernel doc then? > >=20 >=20 > The doc is clearly saying that it returns NULL, am I missing something? >=20 > * Return: pointer to the allocated memory or %NULL in case of error See the paragraph * The contents of the object pointed to are preserved up to the * lesser of the new and old sizes (__GFP_ZERO flag is effectively ignored)= .=20 which confused me into thinking the memory that is being reallocated is guaranteed to be preserved so it would be returned if the larger size failed. I suppose there's nothing to fix in the kernel-doc, just my understanding of that paragraph. Maybe it should say The __GFP_ZERO flag is effectively ignored as the contents of the objected pointed to @p are preserved up to the lesser of the @new_size and old size.