Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp113902ybi; Fri, 7 Jun 2019 05:10:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqysv/Mj4SFIgeREYRdCNPBV3Iv7ZW24hMU3hGygFVQgYAi0gvMOy9NEcP0L1X7LYGrIaWEt X-Received: by 2002:a17:902:20eb:: with SMTP id v40mr55081924plg.239.1559909409505; Fri, 07 Jun 2019 05:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559909409; cv=none; d=google.com; s=arc-20160816; b=04ZD4w4uoim3+GF+LUPQKmddyaZxVhEoQFjhcrGxCnXMIBZ9PxW/Isz5SoL0CYKB7F s5hDU+nQdtylQrvdJ07S9sK2glcZJ1IPBPHl37xJ/3AoMMacpPGLjz+mExGbfR/ZylwI qWuJY85moPXNLhFWsCjX3dClpZWG2hlH5ZaeEOrwIDtCI2Uji4OIVXp6L6r6fl8q28gs pAyEBU9U9kr906hs1THQnX0YunWgKCGGb/n0Ix6njXqKQMd9LjDmDzIs370buJUXrPOz XdBCx5FjWbqgUWujXlHUbRyWKLIkk2oxA/zpNIUiHhkr16Iph7FnMqDwpo5L8NLDm4zL TmLw== 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=/OaEJfBR0xsC2fNRDUtUonZ/nH//Pb0hepbkfyw3/RI=; b=iNTGKB2/PXcl1O6rf9GVwi1xIryamsUksof07wW0AU5bni+P92QnAqxkfveQvb09DL 2DwAqWQivVLTKgPL1Fckkcgl0ulwkZz+QykQQkACH7y7l5E+xnLYLIXFMync4ErZFWEl IvkvkZkhH2xkeX1WqJIEb/ccGveBzkFu38eVQxufygRydv2jODR15ewIvXlRbhZWCbn9 yEgAAXIkZHH0iEE6cmL0N7ws3GOEl+GXyapxaoivRzWkzhirrfCjgqyN/wpUJOarMC8q 2bxdnwxm1oewezuxwByYlRPOQ4M23Xyjpci7tiWCOTrSN4kcpRY2NhFdj6WKptu8JfpU VCYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Vd9U2BVx; 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 9si1628901pjy.36.2019.06.07.05.09.52; Fri, 07 Jun 2019 05:10:09 -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=Vd9U2BVx; 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 S1728477AbfFGMHa (ORCPT + 99 others); Fri, 7 Jun 2019 08:07:30 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43007 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727386AbfFGMHa (ORCPT ); Fri, 7 Jun 2019 08:07:30 -0400 Received: by mail-wr1-f68.google.com with SMTP id x17so1902036wrl.9; Fri, 07 Jun 2019 05:07:28 -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=/OaEJfBR0xsC2fNRDUtUonZ/nH//Pb0hepbkfyw3/RI=; b=Vd9U2BVxBdN4mlMul4jehfdsI+khyQ8bNYC+PbZUd+MLkJldq0QvPqlw67/TBgEj9a YisCswUD8lyWjT+ne+NbBXnB0880+Q22bXGI2ydtUN9nduFOqOQ/jbTnnVUPzTmcwn7h hCVLa+O8KOLJmFRB8X6lYdlYhQNDnwMLoE8hzkhT+SkuSzmxRDkQoAbJvOBvmx27pg/f 4WMav4+lrDRJnm/4dY9Sy1iLFnHWD+EwvWTMNrMXpyI0a6dWYI415XEBdVEeciUzBgfu Y9nuI3HvDTAir5TfDv7sTbHd9bJlKcm3F9cWjGcw7DAPTEkhyJR8PANVX06uYpYwVOLM j5LA== 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=/OaEJfBR0xsC2fNRDUtUonZ/nH//Pb0hepbkfyw3/RI=; b=Sf0GXxoLInMTiiMEqTzgNteUa80VdkoXd+IQBRbp092v1uoP4lydQeYW1Ongzi2wpA Wl/NXWwbA+Vl/nvTsDqH0Y9lqbtpLXVOMeQwpeLCFyZJdmkQuIslq8ezuMJQaKJ379zK 35MM7zlnvEeD0mlPvKcVDp6cqJxPr0VcS4gKhM0Y4N8GpIM7glr1qbroRVE39SgxAkw3 SnafJjZXljo6M2U6X+B0kvbmq7YR0NXYAZno4v8EnspPbSj2cfugNKbZ169/JBxg1GUX tztRgjc6vE0VJ02oioSSQBmvT+Mn01JHJa8GII97RMdtXvo4kGsY90uGtoGcftwYKnm4 XYEw== X-Gm-Message-State: APjAAAWwyFVaoA3VrDksDwNl6xzGjppZQRj+9dW74pm7AcbHASTHsuvF giKkFzvIxDZ7lhoYuhQ9DMA= X-Received: by 2002:adf:de8b:: with SMTP id w11mr9424156wrl.134.1559909248247; Fri, 07 Jun 2019 05:07:28 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id o3sm1543243wrv.94.2019.06.07.05.07.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 05:07:27 -0700 (PDT) Date: Fri, 7 Jun 2019 20:07:17 +0800 From: Gen Zhang To: Jiri Slaby Cc: Stephen Boyd , 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: <20190607120717.GA3109@zhanggen-UX430UQ> References: <20190531011424.GA4374@zhanggen-UX430UQ> <20190605160043.GA4351@zhanggen-UX430UQ> <20190606201646.B4CC4206BB@mail.kernel.org> <20190607015258.GA2660@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 Fri, Jun 07, 2019 at 11:10:37AM +0200, Jiri Slaby wrote: > On 07. 06. 19, 3:52, Gen Zhang wrote: > >>>>> @@ -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++? > > parent++ is done after the loop body. Or what do you mean? > > >>> 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()? :-( > > The second parameter (the source) is parent_data[i].*, not parents[i].* > (the destination). parent->fw_name and parent->name are properly freed > in the do {} while loop as parents[i].name and parents[i].fw_name, given > i hasn't changed yet. I am not sure what you mean at all. Are you > uncertain about the C code flow? > > thanks, > -- > js > suse labs Thanks your patient explainaton. I think I need some time to figure out this part of code. Thanks Gen