Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6966809ybi; Wed, 5 Jun 2019 09:05:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIg3iQ8f6/mVuQGKd1hq6Z8+OCsSDaeU3KXR69Mfn9/qrccvHKJCjOvPom6WEPuROz2KCW X-Received: by 2002:aa7:8e50:: with SMTP id d16mr40142463pfr.65.1559750706339; Wed, 05 Jun 2019 09:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559750706; cv=none; d=google.com; s=arc-20160816; b=u8F3l+vWmSwjFi4QC7iw3V2gprqBiqwf4ZCZaCl9SVmU+f4GtXWI0KCmX2fAaJQYBH b1O2dybeYXjP8cbLoJQKRIM2fzmG/7kPToBEddEhAVT0iszKvRt03PrEaL/9BBfugepP uP46skiYMHGbA3p882/bDAPACIYZLrEQCrUE74RQH6KmFOmuAEaalwYdNXbpuaiLp8Gu /NnQqvKNjzRn5WW2MMO3O00pzJZHO12rRPHSADONPQ4nFjvx9Tln3f798KljTBDvRlHd zraGhK+ZF9Rm+y2JLb6IK9GYAawizUa0rnaOlVP/2eyextXR2D4t2OTr95KX9ic1bbQN cumg== 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=+gmg8zF70tZqcuZYnBHWzWLmIsLYzqqZen+t6Z0irwY=; b=KuFEPUX7FppYZqsGqqti5dIYVKpo8qJwQ4gAcQynb5IgjqQWx3efKCCmuxup+jD73D 5Brz62vgG501ehgHbdziwCmWMF4S6rdRv+/JR3FOWdOkPQLW7PFxmpYCXgOYRfqbtapP WY+HjOtGMREY4fiwFff0Ehwf7Y1ljjO6YaDYjlVt0Xb9AEssZHNyC9TWDxYJG2bURgrg vMhuimRBKQT3SMUiCHtN1fkXvv8u0tX/KRaUFT2DURuCizxe3DZTv4Kuw4TSaAtpIe4l YPXjDCjKWEbwgppqdc9PHYIrWXclduu0veCK/a2A3S8NBQcdYdogjy6vslwISDKP/zSQ IZpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=n1nx20dx; 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 q17si12412117pgm.479.2019.06.05.09.04.46; Wed, 05 Jun 2019 09:05:06 -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=n1nx20dx; 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 S1728595AbfFEQAy (ORCPT + 99 others); Wed, 5 Jun 2019 12:00:54 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38866 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728280AbfFEQAy (ORCPT ); Wed, 5 Jun 2019 12:00:54 -0400 Received: by mail-wr1-f67.google.com with SMTP id d18so20031225wrs.5; Wed, 05 Jun 2019 09:00:52 -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=+gmg8zF70tZqcuZYnBHWzWLmIsLYzqqZen+t6Z0irwY=; b=n1nx20dxtXxPpRy++RZgyw0xB1v8ACLPAYMXerK6LrIxpO/PHaqSjPl8NLqKDUazsQ QaTGTwQfpXusLWWe8eGRu6PzVJsERMQMhPfbKnL2oSXa/6t0/yT8jG0h7dZnwH9MGKNh EN1kWENl/HXb/8Afldv4Ll4oteIfmkENRVAF4v/0uFY7vrh0kezWFHrTi5DHJw4ZbtYs u/2MQ5rmP5/9dDS4rFjhnZgxxIyniia2V20qQ5KxjWqQ9do0delzh2EOTs58RhiOqEKZ YVX/uhMmbEs6EAayybYDw9G9ruNeNqUN2/FKcaworYmlVj8hO5DUOWDDWzN5LUC0w/9n eqXw== 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=+gmg8zF70tZqcuZYnBHWzWLmIsLYzqqZen+t6Z0irwY=; b=krQ9IMt6oIv4E6ddAsVHYiET9Vp/+ZFdGFQfTlAW8jvuIgzX7iLkCTQ+NyLhpsaYrP jBZhvlRNX+3ayQXUkGV7bb9r2CC1NfvvsSjaPTb8thfPXBXS9ZU5HUtRwG6fdubNPTm0 zuX0MLklZw7+8BAUg7BNbQNjP2ZEt6zHbQux55rWBU56w9U7vPmyh0PvD+8HWKTIDqSt F1Aw1m+V+fkMM2xAp4gokRtDmtpuYuMSj3oAxmZ7exjcHkwHlJlPvVLCwZLIBtEEm4Iu U6BqUdnxvMXbwnxFIE1CySKc80vSDSR3NOLharYZb0/wLUxPzqeqp4LyYF+TXtunQDsF cV9Q== X-Gm-Message-State: APjAAAUaYGBocrLXyHBkiOq34pCPkEshm4b2CEZnEFYzM5Ymy/vZGVHP 9Rxvahmge9CHbnk2reKdeKk= X-Received: by 2002:adf:deca:: with SMTP id i10mr25624367wrn.313.1559750452348; Wed, 05 Jun 2019 09:00:52 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id s63sm12069359wme.17.2019.06.05.09.00.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 09:00:51 -0700 (PDT) Date: Thu, 6 Jun 2019 00:00:43 +0800 From: Gen Zhang To: Jiri Slaby Cc: mturquette@baylibre.com, sboyd@kernel.org, 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: <20190605160043.GA4351@zhanggen-UX430UQ> References: <20190531011424.GA4374@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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? Moreover, should 'parents[i].name' and 'parents[i].fw_name' be freed by kfree_const()? Thanks Gen > > thanks, > -- > js > suse labs