Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4579501ybv; Tue, 25 Feb 2020 23:13:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzNay1F1K8SXhD0mhf+9RcGrv0bc8oF2/Xj6QlPhX5ubmbPflENc97JHX55P7OOUcYTj5og X-Received: by 2002:aca:b187:: with SMTP id a129mr2022800oif.175.1582701204424; Tue, 25 Feb 2020 23:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582701204; cv=none; d=google.com; s=arc-20160816; b=0+v+4FBsqinhSWLq32jSV/o9gJxhkzI5yRVNoL1VYpECQFaD3ckUxyi691e3M7jqA/ q4zKNxBRsj/kzoCfGS7pJdAOHNlpBIwYEH0DOlsve7QUOXbToSCE4qkNSXepRiVAoHfz 6xjk42+zGur4MB7Jo5cNVqJ9g8I/SPWsMVoVgFypZJGUB75Ugpjh/zcSA4kmy7S4Yr1D dRvIfY3otlANZB5F6O18bbYFdfNNQSAphi8PKfYWVd37X7RNuBC15WGA7xUub6ExO/Y0 NpN0dnczkffAGr5Jvi2b2W3MwGKh3S14m2gB6yfwZ0md5Ida4WizC3w0CG2qq/qWbySJ KSHw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=7OmgMtxbAHoP9QS/OL+mygnqgqfEl9CQdOa1vTVjZNI=; b=wVKzVjxzWxfCGJxBZ0GCuXz+KC0JCV9Df9nsZFs6bKX80ngn7F/eXyP77HrJVvOdAl JuvNv81GEOsUbM88CicJForQ6u0c46mEFmSiSQvFmLzMf5Awc7nfbfxVupCOxjb7IvFF JxVZEaUlDj3QHQv16uXGT4RyMdvEFPtq7fgqJGdjlYVGzY96UywiwvghDKCzP3zh+gpF NYyJpO9SFamvmnwe2VHqrnOpKWdb054t+NoYHy8NZdTZ6lmIHBuOKzya9+DjQHsDo64V gBme93xlHKSHt6CFbUuIaxfPyGm6eb3/2poGe+bxpi7DS8nTbZfnTCWb9Gvm5k52ODpn 5fXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xyZDqNdD; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si755757otm.221.2020.02.25.23.13.11; Tue, 25 Feb 2020 23:13:24 -0800 (PST) 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=@kernel.org header.s=default header.b=xyZDqNdD; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbgBZHLj (ORCPT + 99 others); Wed, 26 Feb 2020 02:11:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:43048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbgBZHLj (ORCPT ); Wed, 26 Feb 2020 02:11:39 -0500 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0CFC222C2; Wed, 26 Feb 2020 07:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582701098; bh=58RqZxjUH9atKjkoMOHsbmFPMrlnvz6rwgHUDYlVGD0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xyZDqNdDnaA5nD+cRo6i9yqYjrO5v79j3qCzq6tzWzpucG6ql5k2l14yovBL6nDau szxUdunZ/AQVM2M3NfLq+8eJj95BSjqGfTzlo4FPAyIhA55AFUqHtddL7BppTgw/B5 G7Xu7d7P6mFpIo1N8p8Vg17jTwOZeBYoZaEJFplw= Date: Wed, 26 Feb 2020 16:11:32 +0900 From: Masami Hiramatsu To: He Zhe Cc: , , , , , , , , , Subject: Re: [PATCH 2/2] perf: probe-file: Check return value of strlist__add Message-Id: <20200226161132.2aeea72b71d48e9988aa27d9@kernel.org> In-Reply-To: References: <1582641703-233485-1-git-send-email-zhe.he@windriver.com> <1582641703-233485-2-git-send-email-zhe.he@windriver.com> <20200226074906.0acb08b31d01c96c475da0cb@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 26 Feb 2020 10:49:19 +0800 He Zhe wrote: > > > On 2/26/20 6:49 AM, Masami Hiramatsu wrote: > > On Tue, 25 Feb 2020 22:41:43 +0800 > > wrote: > > > >> From: He Zhe > >> > >> strlist__add may fail with -ENOMEM or -EEXIST. Check it and give debugging > >> hint when necessary. > >> > >> Signed-off-by: He Zhe > >> --- > >> tools/perf/builtin-probe.c | 30 ++++++++++++++++-------------- > >> tools/perf/util/probe-file.c | 26 +++++++++++++++++++++----- > >> 2 files changed, 37 insertions(+), 19 deletions(-) > >> > >> diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c > >> index 26bc5923e6b5..8b4511c70fed 100644 > >> --- a/tools/perf/builtin-probe.c > >> +++ b/tools/perf/builtin-probe.c > >> @@ -442,24 +442,26 @@ static int perf_del_probe_events(struct strfilter *filter) > >> } > >> > >> ret = probe_file__get_events(kfd, filter, klist); > >> - if (ret == 0) { > >> - strlist__for_each_entry(ent, klist) > >> - pr_info("Removed event: %s\n", ent->s); > >> + if (ret < 0) > >> + goto out; > > No, this is ignored by design. > > Since probe_file__get_events() returns -ENOENT when no event is matched, > > this should be just ignored, and goto uprobe event matching. > > Thanks for pointing it out. However when strlist__add in probe_file__get_events > returns a -ENOMEM and we ignore that, though it happens not very likely, we > would miss some entries. So I add checks here and in probe_file__get_events to > give a heads-up in advance. If you are aware of -ENOMEM ( I guess in such case you'll see OOM killer sooner or later ), please just catch it. I mean if (ret == -ENOMEM) goto out; will be good. Thank you, > > And the same reason is for the checks below for probe_cache__load, > probe_cache__add_entry and probe_cache__scan_sdt. > > > Regards, > Zhe > > > > >> > >> - ret = probe_file__del_strlist(kfd, klist); > >> - if (ret < 0) > >> - goto error; > >> - } > >> + strlist__for_each_entry(ent, klist) > >> + pr_info("Removed event: %s\n", ent->s); > >> + > >> + ret = probe_file__del_strlist(kfd, klist); > >> + if (ret < 0) > >> + goto error; > >> > >> ret2 = probe_file__get_events(ufd, filter, ulist); > >> - if (ret2 == 0) { > >> - strlist__for_each_entry(ent, ulist) > >> - pr_info("Removed event: %s\n", ent->s); > >> + if (ret2 < 0) > >> + goto out; > > Ditto. > > > > Thank you, > > > >> > >> - ret2 = probe_file__del_strlist(ufd, ulist); > >> - if (ret2 < 0) > >> - goto error; > >> - } > >> + strlist__for_each_entry(ent, ulist) > >> + pr_info("Removed event: %s\n", ent->s); > >> + > >> + ret2 = probe_file__del_strlist(ufd, ulist); > >> + if (ret2 < 0) > >> + goto error; > >> > >> if (ret == -ENOENT && ret2 == -ENOENT) > >> pr_warning("\"%s\" does not hit any event.\n", str); > >> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c > >> index cf44c05f89c1..00f086cba88f 100644 > >> --- a/tools/perf/util/probe-file.c > >> +++ b/tools/perf/util/probe-file.c > >> @@ -307,10 +307,14 @@ int probe_file__get_events(int fd, struct strfilter *filter, > >> p = strchr(ent->s, ':'); > >> if ((p && strfilter__compare(filter, p + 1)) || > >> strfilter__compare(filter, ent->s)) { > >> - strlist__add(plist, ent->s); > >> - ret = 0; > >> + ret = strlist__add(plist, ent->s); > >> + if (ret < 0) { > >> + pr_debug("strlist__add failed (%d)\n", ret); > >> + goto out; > >> + } > >> } > >> } > >> +out: > >> strlist__delete(namelist); > >> > >> return ret; > >> @@ -517,7 +521,11 @@ static int probe_cache__load(struct probe_cache *pcache) > >> ret = -EINVAL; > >> goto out; > >> } > >> - strlist__add(entry->tevlist, buf); > >> + ret = strlist__add(entry->tevlist, buf); > >> + if (ret < 0) { > >> + pr_debug("strlist__add failed (%d)\n", ret); > >> + goto out; > >> + } > >> } > >> } > >> out: > >> @@ -678,7 +686,12 @@ int probe_cache__add_entry(struct probe_cache *pcache, > >> command = synthesize_probe_trace_command(&tevs[i]); > >> if (!command) > >> goto out_err; > >> - strlist__add(entry->tevlist, command); > >> + ret = strlist__add(entry->tevlist, command); > >> + if (ret < 0) { > >> + pr_debug("strlist__add failed (%d)\n", ret); > >> + goto out_err; > >> + } > >> + > >> free(command); > >> } > >> list_add_tail(&entry->node, &pcache->entries); > >> @@ -859,7 +872,10 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname) > >> break; > >> } > >> > >> - strlist__add(entry->tevlist, buf); > >> + ret = strlist__add(entry->tevlist, buf); > >> + if (ret < 0) > >> + pr_debug("strlist__add failed (%d)\n", ret); > >> + > >> free(buf); > >> entry = NULL; > >> } > >> -- > >> 2.24.1 > >> > > > -- Masami Hiramatsu