Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4165083pxj; Tue, 25 May 2021 01:42:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxPZzyW5kNVtXvzCggVFSxTU61DVZwfVv1VZs3v6mKLFznPUGxSZUBKsDCzAs7UmdBp9ce X-Received: by 2002:a17:906:c14c:: with SMTP id dp12mr27787376ejc.312.1621932168967; Tue, 25 May 2021 01:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621932168; cv=none; d=google.com; s=arc-20160816; b=YLpYr7NQ9sM2PTGW5+vRlsjDsOsZ3xJ28BepskL3P9yjT9bwQzOaVmKOOlZww97/KB 5KUwYO/VsN0jIvc3evg1HeDbnseC1XdXWAE20HvAszIMWdHMNRMtx34AIX4oyLJ/3Hlg 1WGrdDDIcKGtTMNTjiIHVWjz4NgwWOQgFcammKjSARQRrgYYHzmQoXwv5MNp56KO5CKb fcj/lApHRa8uIO8wTN+3uCDn9ZBCmHrZbJKo7AVW/T38Mxf6e5g6ky2cLh3js9gKinMr rCJCV4dLgKbKdYfdL4bd9NXhC6pGneDUysvYtZ7gB8PqxJ74lL3VMRQyHNbgYrjLMC9/ 8EnA== 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=97+saadlKMc0SjtCiisONHL2bMD+b38fDlDAVn3+0F8=; b=DfjgRfyag/Ql4zJtJLOSRZOSnZhgz7pUsUq1WLtCTfS+OpkapMV5BU2NxG1yIBEqvt iksgisyb1q5nMKqZEHLhs7RC1TKXcCtdQuI5FGPG6VbcQ06vpR7TK76kNoiEC8rOyNdi vMnFCVz7Uqw9t9ZmyjQeF1vSSh/RF9Pdks6NoqK1MmRShpSdfme9ceczoW8EIZth92cF Q+5eRIHL2a785x6kHaYYK+wB7Krh+yv0wKmhAjBIpU+jApDuVF102DgDVuMNpdpC6mIo GF5F3vB664XdGEvO4VuVLxpJFQsy4fq7ONmdtkOpHtvcMavvveM8GiFZcAJEkgbDnVL5 UCuA== 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 u10si15579491ejh.112.2021.05.25.01.42.26; Tue, 25 May 2021 01:42:48 -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 S232282AbhEYIKc (ORCPT + 99 others); Tue, 25 May 2021 04:10:32 -0400 Received: from mga18.intel.com ([134.134.136.126]:10049 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232027AbhEYIJI (ORCPT ); Tue, 25 May 2021 04:09:08 -0400 IronPort-SDR: 0GOsS9DYOEPEkX2KuRz7xvmklck6bdGXKCbzAvJIgUb0ijUSK8j+BdAiSBAHfm7oHNmNFTIEYs 9z0LsOdiSkyg== X-IronPort-AV: E=McAfee;i="6200,9189,9994"; a="189506523" X-IronPort-AV: E=Sophos;i="5.82,327,1613462400"; d="scan'208";a="189506523" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 00:39:45 -0700 IronPort-SDR: YmMP62HvLnsRDENhcuYbGX0IGcrKqlKQPGHYD0tYuzZh5nSZJkvW7v/E348GFtIWjn3wKW2SzO aGsISOFUentQ== X-IronPort-AV: E=Sophos;i="5.82,327,1613462400"; d="scan'208";a="442428432" Received: from unknown (HELO [10.239.159.33]) ([10.239.159.33]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 00:39:41 -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: Date: Tue, 25 May 2021 15:39:39 +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: <3d9e738d-b972-056b-d0bc-35ed1aaefbad@linux.intel.com> 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, >>>       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. What do you think? Thanks Jin Yao