Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8745047ybi; Thu, 6 Jun 2019 19:08:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+q6lrIVD6179LkLLKVaCeZTwr28Y0JnzPINLgmkuLMWiqVbnI09v5Wg1qNT1a8DY6yBOH X-Received: by 2002:a17:902:5ac9:: with SMTP id g9mr53658736plm.134.1559873308937; Thu, 06 Jun 2019 19:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559873308; cv=none; d=google.com; s=arc-20160816; b=NLl/X/erejyejw/PYNqVxlu/rSW6BkPo1RLKtvbJhY2OSsXtZjrQzhreLyL1ltkR1D uiTyTloXySw2wdDbR1uafpVWQ5cz/f7buiVXnezUckyGFIQrh9xWGKZ4Hr9EnG0/CQbf CAm4i685AgG2SLBKjhqIpyEhBOr+AxvkG1egM/7jQeNNDdO1+3gaFXFnocTSURFw9CWe n19VcE/CrZd+VG6KhhaRdZFGOv/xsSLKfvRfLrv5DyfUxwmQI0amk5ft78Ac/30p4zVf YV8ub0KnsiAfKyNYhM4iqM8ErD0NRNHpbNpNQwnI2tbzlWMid8gyRFJi/gVxsSmJMPMP C+vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HXbPnXaGhtf2NYvX8iWSqIWrGp6VGw0M5oS+kh5tYlw=; b=Ie8pLj/x7G2lGOUxvfIxhReG4BYWfauc/V+S2wuSmWraaXgCqpF+BaBV1QT7quulLD FcmneKZPJ2q45JWyzZ077+HjOsT26XanqkcFRTAk6jkwClR8U+BCyzpS4aKTOFbbHYXR BJfhGYtB5WEd2YJ7T7Tm8f91gh/ozM3Ic0xpjqiES2D9eOoAvxHmHnU+URZBWyS2ifop qbpA9ov/iFAlNQHgPpZO458BB318H3eqp6QQtJwDzTLOYjbDi/qdcliIpWXuTyHXgm9x /5MAappl76O+7ZcGR6VHmyKVhX+uJt1FiZ55L9e0hbGAjNwW3XXqlBUX34VEYAB+lwpL JJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="YhxM/LCl"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si621344plk.272.2019.06.06.19.08.13; Thu, 06 Jun 2019 19:08:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="YhxM/LCl"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727268AbfFGBxH (ORCPT + 99 others); Thu, 6 Jun 2019 21:53:07 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41832 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725784AbfFGBxH (ORCPT ); Thu, 6 Jun 2019 21:53:07 -0400 Received: by mail-wr1-f68.google.com with SMTP id c2so480396wrm.8; Thu, 06 Jun 2019 18:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HXbPnXaGhtf2NYvX8iWSqIWrGp6VGw0M5oS+kh5tYlw=; b=YhxM/LClRdhOXLrXGoyig8gM2kzYsJK3ClPUrSk8fcH08+R/FeaQGN1FzsJ1hEAI8V T1vIWi3coyHCm0EGClXmSsRPKJ6+G3iolZ8N0fHCOEMv9cWcTHMc1BrzkKI/ralknloR k/5zPimvlBj2OBt220R2UcWK0Mm+zjpX2SJ+U/xQczafReLc2mxhm5dNg016YBqEg79K nvgIrZ1hLvrUvDw79HGU/P5PqOecyyLi76Kq7qsux4ttza1LsVLMXbB96s6+OtSS4Rb+ EOkhBBbnbsntBs24oiEX1Xxv9rlsaipyvWRM0r+qLh3b84RETMzMuxYYwK7qk//72BVV ruSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HXbPnXaGhtf2NYvX8iWSqIWrGp6VGw0M5oS+kh5tYlw=; b=ZORfoHD30cO27nLyvOMCKzhhRKQvJBRMTNGgG3R3+ggSE6BYRvt2VMZBjRcWvL0Y7k 2aqxfc7yqh1omdplmMgeioans1+IZiF7eN4dAOjFo7AG4rTIDRsEBAueCzq1W7pwVJxh hiIzJtMSaZLgU+OvFHUetQPftb1mVCgGmb3CdENIA3nw/V3uKNjjIHtEb6hh6Web2qgb q5vVZ+1XWZJmQ5pm7fiUPTjw3Xem4H8xuDXw4I4xLzLlIt28QrUUkM2eW2g7Uit0Rsjf FMNMihqBdkrYqkDMYm0vT+XNrpKtDHy2CAHB7sbwrf2qnLuJaZDlG1mS2t5+IwQORwVb y1xg== X-Gm-Message-State: APjAAAVUB7vV/IS2TFjr+RML/9HnwPTrzEcRdzoovx4S8z5zXB6fmuMZ 4tixiZQLBH8f/6JL9FMuXH0= X-Received: by 2002:a5d:4904:: with SMTP id x4mr4866906wrq.337.1559872385508; Thu, 06 Jun 2019 18:53:05 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id s63sm544369wme.17.2019.06.06.18.53.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 18:53:04 -0700 (PDT) Date: Fri, 7 Jun 2019 09:52:58 +0800 From: Gen Zhang To: Stephen Boyd Cc: Jiri Slaby , mturquette@baylibre.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: fix a missing-free bug in clk_cpy_name() Message-ID: <20190607015258.GA2660@zhanggen-UX430UQ> References: <20190531011424.GA4374@zhanggen-UX430UQ> <20190605160043.GA4351@zhanggen-UX430UQ> <20190606201646.B4CC4206BB@mail.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190606201646.B4CC4206BB@mail.kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 06, 2019 at 01:16:45PM -0700, Stephen Boyd wrote: > Quoting Gen Zhang (2019-06-05 09:00:43) > > On Wed, Jun 05, 2019 at 08:38:00AM +0200, Jiri Slaby wrote: > > > On 31. 05. 19, 3:14, Gen Zhang wrote: > > > > In clk_cpy_name(), '*dst_p'('parent->name'and 'parent->fw_name') and > > > > 'dst' are allcoted by kstrdup_const(). According to doc: "Strings > > > > allocated by kstrdup_const should be freed by kfree_const". So > > > > 'parent->name', 'parent->fw_name' and 'dst' should be freed. > > > > > > > > Signed-off-by: Gen Zhang > > > > --- > > > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > > > > index aa51756..85c4d3f 100644 > > > > --- a/drivers/clk/clk.c > > > > +++ b/drivers/clk/clk.c > > > > @@ -3435,6 +3435,7 @@ static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist) > > > > if (!dst) > > > > return -ENOMEM; > > > > > > > > + kfree_const(dst); > > > > > > So you are now returning a freed pointer in dst_p? > > Thanks for your reply. I re-examined the code, and this kfree is > > incorrect and it should be deleted. > > > > > > > return 0; > > > > } > > > > > > > > @@ -3491,6 +3492,8 @@ static int clk_core_populate_parent_map(struct clk_core *core) > > > > kfree_const(parents[i].name); > > > > kfree_const(parents[i].fw_name); > > > > } while (--i >= 0); > > > > + kfree_const(parent->name); > > > > + kfree_const(parent->fw_name); > > > > > > Both of them were just freed in the loop above, no? > > for (i = 0, parent = parents; i < num_parents; i++, parent++) > > Is 'parent' the same as the one from the loop above? > > Yes. Did it change somehow? parent++? > > > > > Moreover, should 'parents[i].name' and 'parents[i].fw_name' be freed by > > kfree_const()? > > > > Yes? They're allocated with kstrdup_const() in clk_cpy_name(), or > they're NULL by virtue of the kcalloc and then kfree_const() does > nothing. I re-examined clk_cpy_name(). They are the second parameter of clk_cpy_name(). The first parameter is allocated, not the second one. So 'parent->name' and 'parent->fw_name' should be freed, not 'parents[i].name' or 'parents[i].fw_name'. Am I totally misunderstanding this clk_cpy_name()? :-( Thanks Gen > > I'm having a hard time following what this patch is trying to fix. It > looks unnecessary though so I'm going to drop it from the clk review > queue. >