Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1042840iog; Fri, 24 Jun 2022 22:32:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v0fQMRTf7ibgAckAmxmE+Fj7F8oNHKmm+DLY3SsnAWjlQFTlTRP21OqZ7UcTcYs1kzILAu X-Received: by 2002:a17:907:2cc3:b0:722:e993:c420 with SMTP id hg3-20020a1709072cc300b00722e993c420mr2342308ejc.145.1656135148995; Fri, 24 Jun 2022 22:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656135148; cv=none; d=google.com; s=arc-20160816; b=CbJvnxybXzxNs8Srv7lhggiigryU+wzNHr/ZYAfX6NKvMriAcXbnzuNSWuMwAMomG4 tUf4pBYPV1gOyXkxncto4asXYSKxsPoqSxo7Pxez8ud4I5hLBYsv+NOQC+x5SkeSSJo5 vG7huIkVxF0DwirI/YmWXMhQw+F3LcbgL2/2LVMVWJ9awpI3ONNSFHGvMRuOrFkJL49a IRCyio1TW2ZJ0ZXDHjkDijb7XT3sKtqQgXtk8AZgaCgCX99OlEJ5WDbeNBObfFR+PRKb IelhEkhKzwLBKqWyxDk0wqjUTHZZgazkafFwXsmvzWNPaivQMLj79UcaphevGteub9qx 8K/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=olh/t8bBvdypCRtDpfeOgA30mVxtptEkmVnsLVjMzDc=; b=xsCk/lHihHrUcISFr7GsmaGB+ZnD6KeBjLfumgv/b4x7Wed4FSfOsFD0xS94MhwevU gYHHFGjjy54gxlnOLoHVbm/1/lP+cEiiS67+8gPXf9zI9jAWLfBxi8yQfkjGYQBuIzYU jnuKqjj5GQwwGcDey5KS4Ic9uuiKAWVcmCEC6kn6arjKVpw5MmIDQqBDfpppkbHe5UtO PDTobnqk99YWja9Eg5IpALz1OVapnr40CWLYZuMq4XlpTXdeOSCdfwduL5WxoCiRBG06 d1LefLugu25rJXmhzMfLFI/Yo3RyboeNFZM4Jaq3YQ5JgAuruc8dhNarjWP8/kLsghHi Oi1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@maquefel.me header.s=mail header.b="Bp/ICzPW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170906278300b006f379d6f423si4781247ejc.582.2022.06.24.22.32.03; Fri, 24 Jun 2022 22:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@maquefel.me header.s=mail header.b="Bp/ICzPW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbiFYF2Z (ORCPT + 99 others); Sat, 25 Jun 2022 01:28:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbiFYF2Y (ORCPT ); Sat, 25 Jun 2022 01:28:24 -0400 Received: from forward500j.mail.yandex.net (forward500j.mail.yandex.net [5.45.198.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55D4CB492; Fri, 24 Jun 2022 22:28:20 -0700 (PDT) Received: from sas1-0e0150e31af0.qloud-c.yandex.net (sas1-0e0150e31af0.qloud-c.yandex.net [IPv6:2a02:6b8:c14:392a:0:640:e01:50e3]) by forward500j.mail.yandex.net (Yandex) with ESMTP id 18D446CB7324; Sat, 25 Jun 2022 08:28:18 +0300 (MSK) Received: from sas2-e7f6fb703652.qloud-c.yandex.net (sas2-e7f6fb703652.qloud-c.yandex.net [2a02:6b8:c14:4fa6:0:640:e7f6:fb70]) by sas1-0e0150e31af0.qloud-c.yandex.net (mxback/Yandex) with ESMTP id lMAl9z8mXq-SGfGlZik; Sat, 25 Jun 2022 08:28:18 +0300 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1656134898; bh=olh/t8bBvdypCRtDpfeOgA30mVxtptEkmVnsLVjMzDc=; h=In-Reply-To:Subject:Cc:To:From:References:Date:Message-ID; b=Bp/ICzPWzLMY/gyXracYUUPZjyK9jzgM+dU+ClK8GBSj4ff43N/t2tDIg7Hvn7ow5 utFRQA1pzsRFajGPBt3QMKTxR1jNxhiv0UgbL1ARXc1yBFN17rSfRlGVvGgAUqJw1n Q2rTefMzib1Tws59ZSND0T12UFKfojGaeTjOfMqs= Authentication-Results: sas1-0e0150e31af0.qloud-c.yandex.net; dkim=pass header.i=@maquefel.me Received: by sas2-e7f6fb703652.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id G8teebH6cY-SEN46qGX; Sat, 25 Jun 2022 08:28:15 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Date: Sat, 25 Jun 2022 08:28:13 +0300 From: Nikita Shubin To: Arnaldo Carvalho de Melo Cc: Atish Patra , Anup Patel , =?UTF-8?B?Sm/Do28gTcOhcmlv?= Domingos , linux@yadro.com, Nikita Shubin , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v4 2/5] perf tools riscv: Add support for get_cpuid_str function Message-ID: <20220625082813.3b70727c@redslave.neermore.group> In-Reply-To: References: <20220624160117.3206-1-nikita.shubin@maquefel.me> <20220624160117.3206-3-nikita.shubin@maquefel.me> X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Arnaldo! On Fri, 24 Jun 2022 13:32:20 -0300 Arnaldo Carvalho de Melo wrote: > > + if (mimpid) > > + free(mimpid); > > just use: > > > free(mvendorid); > free(marchid); > free(mimpid); > > fewer lines, free() accepts NULL. > > > + > > + return cpuid; > > +} > > + > > +int get_cpuid(char *buffer, size_t sz) > > +{ > > + char *cpuid = _get_cpuid(); > > + > > + if (sz < strlen(cpuid)) { > > + free(cpuid); > > + return -EINVAL; > > + } > > + > > + scnprintf(buffer, sz, "%s", cpuid); > > You're leaking cpuid here. Agree with both. Thank you for pointing it out. > > > + return 0; > > +} > > + > > +char * > > +get_cpuid_str(struct perf_pmu *pmu __maybe_unused) > > +{ > > + return _get_cpuid(); > > +} > > -- > > 2.35.1 >