Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4880536pxj; Tue, 25 May 2021 19:54:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEh3AK3NNzI/j4wSdotq8xsjnzE7u7UtvwOc0P7jbt57GteIVBPhNgIO8Yc4I2a3phYZeT X-Received: by 2002:a17:906:6ada:: with SMTP id q26mr32895299ejs.237.1621997672818; Tue, 25 May 2021 19:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621997672; cv=none; d=google.com; s=arc-20160816; b=o/ruJeTdBUDlT5aMXbWJCYr7QAU6GUqpo5IcukK2m18j/KZSzzLFl27G89TwRVYsyU WB3FAjfVwbRO6gpv5YQO7p+pYkKGGAYH/nOUGW+KdHdlo1jnbtsHqnXieZl2SRdL95yO sen5G/8fdQj14hdltaKPHNcytTHjDBGeEe7C5CyqAODvWYIHwCtnWx3e3XQwq0RkcjkX 7HjCZ/AqRQmPHCTgP5iQSnEhxhzgdsl+eyYl683KQqnTszcYQ4OqewMlmBHY5fLyRv38 I27INyUryKCy+T3v8p4TnBk8IHsozOVBqiwumttvt3fv72pFR930TfS2hgZAe9Z7+AuC 22pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:ironport-sdr:ironport-sdr; bh=vqEkeQzDj0AFq729PchPMrGOgPmG75T3lGOTN+SRXqM=; b=dKjgJfZaCBEf3JyEv8PYwcl6YnFXJhdk7eTcXXGiNBpbU/qRec3auGIl1CrbEN+qPv lKgXq/pzITqgAKRvh+ADcFz5oKRfdNxj2XEpvnzUTciHWKNaKho0CPr9eX+IDhz+mYWa BMELbuHHUi3QiJjKhN1cJWxi4DHEL9AsSVR/d8raAdu88sksVCsM6SJPTsQTeJMC5Vm4 s4M2KTw0OLnsRVWV7Kq/zRKQN5cRCWzWAl3xRKWbEtlJDv2JA3scw2tK/tvqdPW0m4TX TDr1eXRMY7V42M5XDe1fDd5ZXKS6abEMoGw2Ar3EA9fjN76jZM6u7ugoJereFxkf9BN+ o2YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si16617484edz.104.2021.05.25.19.54.09; Tue, 25 May 2021 19:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbhEZBxK (ORCPT + 99 others); Tue, 25 May 2021 21:53:10 -0400 Received: from mga17.intel.com ([192.55.52.151]:29137 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231810AbhEZBxJ (ORCPT ); Tue, 25 May 2021 21:53:09 -0400 IronPort-SDR: jmPDnaOafe7uR54Ocf5WPX1PYem/OTtSnhWsCeeWSQH3b5gIGJswhNVwsP8hLHMSKa9EJ478qR 4Vmy7e4Iuv2w== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="182678540" X-IronPort-AV: E=Sophos;i="5.82,330,1613462400"; d="scan'208";a="182678540" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 18:51:39 -0700 IronPort-SDR: WwbU4BHYu2aAGkRs47Hm5MaSArW5f+T5U5ATlNnm23l8P/MWJX87QAf2bfFgPwuxN9aRr3sCMi Hfr8URtk/FAg== X-IronPort-AV: E=Sophos;i="5.82,330,1613462400"; d="scan'208";a="443710902" Received: from unknown (HELO [10.239.159.33]) ([10.239.159.33]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 18:51:36 -0700 Subject: Re: [PATCH v1 4/5] perf mem: Support record for hybrid platform From: "Jin, Yao" To: Jiri Olsa Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com References: <20210520070040.710-1-yao.jin@linux.intel.com> <20210520070040.710-5-yao.jin@linux.intel.com> <3d9e738d-b972-056b-d0bc-35ed1aaefbad@linux.intel.com> Message-ID: <6d6f1040-6c96-7d1d-c766-5fb0057e1cc4@linux.intel.com> Date: Wed, 26 May 2021 09:51:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiri, On 5/25/2021 3:39 PM, Jin, Yao wrote: > Hi Jiri, > >>>>       rec_argv = calloc(rec_argc + 1, sizeof(char *)); >>>>       if (!rec_argv) >>>>           return -1; >>>> +    /* >>>> +     * Save the allocated event name strings. >>>> +     */ >>>> +    rec_tmp = calloc(rec_argc + 1, sizeof(char *)); >>>> +    if (!rec_tmp) { >>>> +        free(rec_argv); >>>> +        return -1; >>>> +    } >>> >>> why not do strdup on all of them and always call free instead? >>> that would get rid of the rec_tmp and tmp_nr >>> >> >> That is also one method. Let me try it. >> > > If we do strdup on all of them, such as, > >     if (e->record) >         rec_argv[i++] = strdup("-W"); > >     rec_argv[i++] = strdup("-d"); > >     if (mem->phys_addr) >         rec_argv[i++] = strdup("--phys-data"); >     .... > > That looks too much strdup used here. So I choose to use a rec_tmp[] to record the allocated string > and free them before exit the function. > > Or we record the start index and end index in rec_argv[] for the allocated event string, use strdup > on them and call free before exit the function. > This method looks also not OK. The rec_argv[] is changed in cmd_record() for some complex command lines. For example, ./perf mem record -- ./memtest -R0d -b2000 -d64 -n100 Before cmd_record(), rec_argv[3] = "-e". After cmd_record(), rec_argv[3] = "-d64" Even we do strdup on all of rec_argv[], but the entries are probably changed in cmd_record(), so we can't free the entries at the end of __cmd_record(). Maybe we have to use the original way which just records the allocated event string to a temporary array and free the whole array at the end of __cmd_record(). What do you think? Thanks Jin Yao > What do you think? > > Thanks > Jin Yao