Received: by 2002:a25:9388:0:0:0:0:0 with SMTP id a8csp8990675ybm; Fri, 7 Jun 2019 03:00:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPqjgUkzuba9oTgnoWEp6JKm4nbSjq8vAgRTpoXsfcrgz/pRSph4bGLN5YrLZv57fA7cuS X-Received: by 2002:a17:902:724a:: with SMTP id c10mr1477203pll.298.1559901609108; Fri, 07 Jun 2019 03:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559901609; cv=none; d=google.com; s=arc-20160816; b=BT6P/JIyd4HnRUYUpHv3qd1DTs8ye/2rQfX+WdXzK2ZPpgxp0JRxvoZe9AlpCrUmt2 xu1tWRGLlbGTcZvQwtezVhzJWJXIqyNndwwUNmMfiERuIM+J0RGKvf7vfJEMQpskAn2l 9tgLpf7bS524R2Y3zikl7DcKd6RqTq4gvCXP6lC4GVvE0MhQN+c708duyAOPB6nliZjd k2HUBw00r5z2lxI3SSm2pms9Cj0E64o8OlHYMvt98wMm5dzq7Kt/yBkqQsIXBBEURjO9 JAhPSPn/smvTOAtBmjEeNOFHWYUYsc1YYFyTVKSIR8VTaqGgN4bNnC3mIqV2RNFCoxO6 TrXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=BkHOgQp9ZNT+w4r/aHTtr9WepEQUBdYdl9/a+tV9soA=; b=v2JrYdklS+CZxXGCEBBvy3c/Y6ai2ugbMXtr7RSsJpeozi0FrIC9JhLrQsi4RfRluo MrXLST3RfkWREAlyuINmTV7MCQIiXM+PsOm8YQCTVwrelwd1iqjYtwwDmEppcUPTGMSn Ocb343YRj02a9QolmANYIhkCTvpG++98c6cZL9oeouBcYO3lXI1u0qpzqqVXn70Q+K3v VIqiVq20jBKipchhOH4wtCxxdrGrw1HvK3lPxiD6aTwFUfYYLmfynGNF0V+17YG06ne3 tzuvTtSI/Go0KTSDmW5DeR3TMbYmVg8C0nOdDosbxSNFsk0pt99vF3OVPGH/s1Xo/U+B AGDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si1384686plb.402.2019.06.07.02.59.51; Fri, 07 Jun 2019 03:00: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727373AbfFGJKm (ORCPT + 99 others); Fri, 7 Jun 2019 05:10:42 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33609 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbfFGJKl (ORCPT ); Fri, 7 Jun 2019 05:10:41 -0400 Received: by mail-wr1-f66.google.com with SMTP id n9so1392716wru.0; Fri, 07 Jun 2019 02:10:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=BkHOgQp9ZNT+w4r/aHTtr9WepEQUBdYdl9/a+tV9soA=; b=AlyPNiy/nmOz7yw1lGihpnVVQlGuhUdDTiGQj68Z+FYXMh7V+EybfUX8bjNjlospLn iiY+OqQXAp/H4rCt7oralkYvo2GuwjsgNBk5Cf4TKceWap6ZBCrsmEwLQRSV/K+Y8Xkw k4G6Gx0YRVRXDOBNQnOm0haE9NtF1abDeds0MZyYpJVGjVtpEeDjdTUCgBh6pzZz7vY5 l9e0eIJHWJcDuZyauBxcHvhi+5tRrQkt6MUWMruSzq3YUU4MajDndRFNUDCh2YdOQ/Ky BWUuKTVdCEHFhVEEWSb02/9IJgFgNpklsZiL1Qdr5TB/blH1VO3LSC9aBKiiPlg3UAxo HASw== X-Gm-Message-State: APjAAAWEsu1n4Y7JUUhrzJK01p3TitlMqUMTftMxrbJnLwk3UQ7UwQJG 5L7zZjQBWOICB4ypXDOQfomWWl24 X-Received: by 2002:adf:ea8b:: with SMTP id s11mr18664982wrm.100.1559898639593; Fri, 07 Jun 2019 02:10:39 -0700 (PDT) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id 34sm1727277wre.32.2019.06.07.02.10.38 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 02:10:38 -0700 (PDT) Subject: Re: [PATCH] clk: fix a missing-free bug in clk_cpy_name() To: Gen Zhang , Stephen Boyd Cc: mturquette@baylibre.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190531011424.GA4374@zhanggen-UX430UQ> <20190605160043.GA4351@zhanggen-UX430UQ> <20190606201646.B4CC4206BB@mail.kernel.org> <20190607015258.GA2660@zhanggen-UX430UQ> From: Jiri Slaby Openpgp: preference=signencrypt Autocrypt: addr=jslaby@suse.cz; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckuc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3 qjNk1EEGyvioeycJhla0RjakKw5PoETbypxsBTXk5EyrSdD/I2Hez9YGW/RcI/WC8Y4Z/7FS ITZhASwaCOzy/vX2yC6iTx4AMFt+a6Z6uH/xGE8pG5NbGtd02r+m7SfuEDoG3Hs1iMGecPyV XxCVvSV6dwRQFc0UOZ1a6ywwCWfGOYqFnJvfSbUiCMV8bfRSWhnNQYLIuSv/nckyi8CzCYIg c21cfBvnwiSfWLZTTj1oWyj5a0PPgGOdgGoIvVjYXul3yXYeYOqbYjiC5t99JpEeIFupxIGV ciMk6t3pDrq7n7Vi/faqT+c4vnjazJi0UMfYnnAzYBa9+NkfW0w5W9Uy7kW/v7SffH/2yFiK 9HKkJqkN9xYEYaxtfl5pelF8idoxMZpTvCZY7jhnl2IemZCBMs6s338wS12Qro5WEAxV6cjD VSdmcD5l9plhKGLmgVNCTe8DPv81oDn9s0cIRLg9wNnDtj8aIiH8lBHwfUkpn32iv0uMV6Ae sLxhDWfOR4N+wu1gzXWgLel4drkCJcuYK5IL1qaZDcuGR8RPo3jbFO7Y Message-ID: Date: Fri, 7 Jun 2019 11:10:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190607015258.GA2660@zhanggen-UX430UQ> Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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