Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1626397pxv; Fri, 25 Jun 2021 18:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy914V2AG/IMla2nVfldEtghS4WJSEntaeMbgrJt2tT9/bAIDg3u3i+dFL4KVDTCuKZ6FRw X-Received: by 2002:a17:907:728d:: with SMTP id dt13mr14153023ejc.390.1624671250647; Fri, 25 Jun 2021 18:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624671250; cv=none; d=google.com; s=arc-20160816; b=v2HWApw9WWX5RmvRTisCW+fNdwI5Udp4I3TB9BOU5qbVaOckwKDcWzWOqSB0iptxey C2A4KfJ2mCjDo6+HNSI8b2TXLd9qUey6U8qAJf9LXb0+qWNStdRDPn2Egi/KpJkkLud0 dZhW7Ehg4SrICJthWm1j2rcCcI6CckgMfP7PY/NGm9GCLKIC1Jal7GSbnpJtOp+at45E 2ptvsrqizUM0zYnvWXQitx+aX2oGRaxNsguCVZdSKmqHX+BeG4t6vDsolpGofL3MEwrc g2r6YjIaSIJqqcwP6eh52/0cO4LW0f2GYHRLeSwgFFUYwC0YCN57UBcuPJnklaUqbvt0 ygxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=gLiRsOnujBMYWHTJNTxrtEIszvaaUsa0JgSuFIK/+vc=; b=KYbo31lPJb6jyd9TnKAxoxNpOzVin97BPZoSTW0tYtpoHJK8F7nfRxeU6C4wDHrHlt Z93evzWlLO/cQe0FTkny/zkDTg/7fwP94gveANmicyC9SPOC5BgaF5+WWh6p6uQL7/cq 1iv819KktxCGPXyqaWSdi2ItKBZEm4UGgOPuJ4AhGPRDIGfMSLFbj+UT8PF7YFzqvkvm zFA0KCEM2l1+3fJXjrXfRQW4I0EvtHmuqUzhZsvrJsqEZYbDB10mDHMr8MsTq1mKpsED IatdvTWVOLM+IqsHgkcr63zsJBmlku1vh5KpwdEX29tryNebARVB8GgoLOFNcf8JATwR 3sXw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si7380590edc.300.2021.06.25.18.33.47; Fri, 25 Jun 2021 18:34:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbhFZBfM (ORCPT + 99 others); Fri, 25 Jun 2021 21:35:12 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:5081 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbhFZBfL (ORCPT ); Fri, 25 Jun 2021 21:35:11 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GBbpG09ggzXlCG; Sat, 26 Jun 2021 09:27:34 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 26 Jun 2021 09:32:47 +0800 Received: from [127.0.0.1] (10.174.179.0) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 26 Jun 2021 09:32:47 +0800 Subject: Re: [PATCH 1/1] clk: tegra: tegra124-emc: Fix possible memory leak To: Stephen Boyd , Dmitry Osipenko , Jonathan Hunter , Michael Turquette , Peter De Schrijver , Prashant Gaikwad , Thierry Reding , linux-clk , linux-kernel , linux-tegra References: <20210617082759.1008-1-thunder.leizhen@huawei.com> <162466387362.3259633.2364843071785127818@swboyd.mtv.corp.google.com> From: "Leizhen (ThunderTown)" Message-ID: Date: Sat, 26 Jun 2021 09:32:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <162466387362.3259633.2364843071785127818@swboyd.mtv.corp.google.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.0] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 original >> memory is not released. In this case, the original "timings" scale should >> be maintained. >> >> Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes") >> 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 original 100-byte memory needs to be expanded to 200 bytes. If the memory allocation fails, a non-null pointer is returned. People must think they've applied for it and continue to use it, the end result is memory crashed. I don't think the kernel needs to be different from libc's realloc(). The implementation of __do_krealloc() illustrates this as well: /* If the object still fits, repoison it precisely. */ if (ks >= new_size) { p = kasan_krealloc((void *)p, new_size, flags); return (void *)p; } ret = kmalloc_track_caller(new_size, flags); //enlarge, allocate new memory if (ret && p) { memcpy(ret, kasan_reset_tag(p), ks); //copy the old content from 'p' to new memory 'ret' } return ret; //ret may be NULL, if kmalloc_track_caller() failed > > Reviewed-by: Stephen Boyd > > . >