Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8587665ybi; Thu, 6 Jun 2019 15:19:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyR54FmW7YGgTlOhXB5ubaUn6EohrCs2FJzi223rRu8ZUaKBJ+53vxN9BRgIK6SrPKg7nUl X-Received: by 2002:a17:902:a5c5:: with SMTP id t5mr53488478plq.288.1559859572869; Thu, 06 Jun 2019 15:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559859572; cv=none; d=google.com; s=arc-20160816; b=VD2dmoEcYTfpjB0Uaa9c2GKHPgZhh+e2rU1P6hzf2fncNZqhSxXdAT6mUAduf5Ungt NEUc0rW18mRjLUNfcHZsXL1jp2IOs3b03PjJsmVNnw2f6PkBdt/mvxOSBv4GWLwA+Lh0 jV4PGok9g6+AAgKZxNSIxqyPrqZgLvTheRu0eSOYl6aNOUZpamGrPteZps6MT0x49EKj dl61KJaHb32Uc3QOWItRKkzv78enOsrcQmsa50HhCvUg4OJUnjuxCeOtayF9WqNOK7y4 pteGWs13NR2EtqMFCz7SDAJ9d7OffVnZVDeKopveifUzn8L5l+XXRl86yRTPwiCtN4sB UogQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:user-agent:cc:subject :from:to:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=q11jND2nq014+QRGeYE/1Q9fBc70L3QI4f9AmjnxP/I=; b=UhXVKCfc5IfAEFlu5nb4Q7M9Bi1WHsJVPMu70r3U2qUlga9iAoDPcgMyB9xAUiw3JV WMsZ0IVCAu9sAJj7omWySXF1YaivEWd6JLO2FjTU1SQxWnwHuc+kTqkwcslmNSxJHqRw PyKzBlESt6t8WDuohUiL9uWaS9sQMxynvoG3UQmzmKg7YrZmWzWnowbJ/sW2LGJDY/am AptwzVZ64MQ42ym5LiCCOq2ryW5I3vbYpTEaXjC9L5mWsn4E8aIsbfNcFsn/AuEmWcbd i8Q+ys7VKwSK+z/ZM/idvUL8lZnonoW8my7OWRoSV9IyRVUYs5ULzuiDv30yH1WR+as+ cgDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=auni+q2M; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si258848pgv.105.2019.06.06.15.19.16; Thu, 06 Jun 2019 15:19:32 -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=@kernel.org header.s=default header.b=auni+q2M; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727703AbfFFUQt (ORCPT + 99 others); Thu, 6 Jun 2019 16:16:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:53506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbfFFUQr (ORCPT ); Thu, 6 Jun 2019 16:16:47 -0400 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B4CC4206BB; Thu, 6 Jun 2019 20:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559852206; bh=dtO+5DakYD+OBjmih0j/tzf4TsEgQw8kAWSobV34pos=; h=In-Reply-To:References:To:From:Subject:Cc:Date:From; b=auni+q2MkEs6XpdIx4TVt3rGKVBpTISGYV2lWzplv/HgVbnBkbp+TWJaf1JO/ZbFh sLQaF2cKycyi5+/vb5dOZUwEoYfrbPEXQ7I7HcjVaoqTg/hgvjcaoZi0B7cYf2mxbY vAGlb05B3a4l5vjuwDPvHqrHs18xVWrZOxVNatf4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190605160043.GA4351@zhanggen-UX430UQ> References: <20190531011424.GA4374@zhanggen-UX430UQ> <20190605160043.GA4351@zhanggen-UX430UQ> To: Gen Zhang , Jiri Slaby From: Stephen Boyd Subject: Re: [PATCH] clk: fix a missing-free bug in clk_cpy_name() Cc: mturquette@baylibre.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org User-Agent: alot/0.8.1 Date: Thu, 06 Jun 2019 13:16:45 -0700 Message-Id: <20190606201646.B4CC4206BB@mail.kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=20 > > > allocated by kstrdup_const should be freed by kfree_const". So=20 > > > 'parent->name', 'parent->fw_name' and 'dst' should be freed. > > >=20 > > > 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, con= st char *src, bool must_exist) > > > if (!dst) > > > return -ENOMEM; > > > =20 > > > + kfree_const(dst); > >=20 > > So you are now returning a freed pointer in dst_p? > Thanks for your reply. I re-examined the code, and this kfree is=20 > incorrect and it should be deleted. > >=20 > > > return 0; > > > } > > > =20 > > > @@ -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 >=3D 0); > > > + kfree_const(parent->name); > > > + kfree_const(parent->fw_name); > >=20 > > Both of them were just freed in the loop above, no? > for (i =3D 0, parent =3D parents; i < num_parents; i++, parent++) > Is 'parent' the same as the one from the loop above? Yes. Did it change somehow? >=20 > Moreover, should 'parents[i].name' and 'parents[i].fw_name' be freed by > kfree_const()? >=20 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'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.