Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp313357imu; Mon, 5 Nov 2018 01:04:01 -0800 (PST) X-Google-Smtp-Source: AJdET5dnz/oGyGasKDsNGfrudbIja52QrH7EGFV7ZIKsHaAqNOygbHw+gh4nGhiyLXcBSEb+fR/G X-Received: by 2002:a63:960a:: with SMTP id c10mr19413252pge.106.1541408641711; Mon, 05 Nov 2018 01:04:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541408641; cv=none; d=google.com; s=arc-20160816; b=UMNyJrK46BSs+ji5NUYRPMBnstA8l/tg8AHOI3UJ2gBZPNj29VK+a2PcEfei9+5KR4 /FJ003iYIAjjHjLu+r0BZGod35RNDJ5qR7b6h+YPVH9H3R8Bkwoq73HgN83QEL4NLBrO ksIwckIkn77S5f2PEsjUPA4pDU/aFoHX0w7Br2BHJuPDqwc+kfj2TTXfEDxs3kTdtp47 s0+Zs8spItrOT1Txb6AD7WK/4ZACpCECYMApS3+HuLiXZMIswwEaadwn/hncknOnfI7d 3BHc/awljDa7XWpYuRGwpMuU7qxNoCnPtxAxdWL7zmGxLkn3fz9Y3ZxUJQcDCP/ES6b9 4yuA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rv55Fyks++vrxAheP/mmOzOahPTMHHLS7dxyXhc+kHc=; b=SohTTzyFhAMlNnQ3v1VfRzPXJ5AUjsFXDwEarhRFdr5qx6r+EEBQuFFkZTRC5BnFMa PenIPc/7AP0idjry4qBhGDO4aMYBCZgeDesZn4+NMsXR7wa26IDrFENEg/AlhroMbvff DFsMRBejeugkeX/fA50UobKaPrz9n4YEq/7iT1kLK4KcBIb9jpOX5Gj+5RLR4UF5lYsy L4+9uN/u0H9a2ZlqFmZw+wNfuFdLmXNZ0XvxqyegSgOi1V+IhqPboi4q7+DY+3D7ntXa Zl50k5sfsT0PebO89Yzb3dxNiDcFPZBXyloYui2s+eu0JFxEd6Lbw7K1Oti0TApEo9Qh 0sSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pcC5X0mT; 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 63-v6si20518353pfe.182.2018.11.05.01.03.45; Mon, 05 Nov 2018 01:04:01 -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=pcC5X0mT; 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 S1728850AbeKESUP (ORCPT + 99 others); Mon, 5 Nov 2018 13:20:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:50022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726228AbeKESUO (ORCPT ); Mon, 5 Nov 2018 13:20:14 -0500 Received: from localhost.localdomain (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 0856D20819; Mon, 5 Nov 2018 09:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541408494; bh=kvPU1QGPViKM90GlxOmNOjqH2CIuDPpvSXHvhno4gt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pcC5X0mTR3UXjGhvkbeVflkG5lIvYyUS1rk48RSvMKmqKA2pduEyhaaZ9jzPCdM71 9JYozltPxQdHFCVZdy6Mh0L8Xy+cWaT6x6Nz9VCeDuzw4q/8XqBP18QL6hzSVN7jhs 8P+t7i9hMDOFxhWl1D3/kNl35povp60HJzB8duns= From: Masami Hiramatsu To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Tom Zanussi , Ravi Bangoria Subject: [PATCH v2 03/12] tracing: Simplify creation and deletion of synthetic event Date: Mon, 5 Nov 2018 18:01:12 +0900 Message-Id: <154140847194.17322.17960275728005067803.stgit@devbox> X-Mailer: git-send-email 2.13.6 In-Reply-To: <154140838606.17322.15294184388075458777.stgit@devbox> References: <154140838606.17322.15294184388075458777.stgit@devbox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify creation and deletion code of synthetic event. Since the event_mutex and synth_event_mutex ordering issue is gone, we can skip existing event check when adding or deleting event, and some redundant code in error path. This changes release_all_synth_events() to abort the process when it hits any error and returns the error code. It succeeds only if it has no error. Signed-off-by: Masami Hiramatsu --- kernel/trace/trace_events_hist.c | 53 +++++++++++++------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 1670c65389fe..0feb7f460123 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1008,18 +1008,6 @@ struct hist_var_data { struct hist_trigger_data *hist_data; }; -static void add_or_delete_synth_event(struct synth_event *event, int delete) -{ - if (delete) - free_synth_event(event); - else { - if (!find_synth_event(event->name)) - list_add(&event->list, &synth_event_list); - else - free_synth_event(event); - } -} - static int create_synth_event(int argc, char **argv) { struct synth_field *field, *fields[SYNTH_FIELDS_MAX]; @@ -1052,15 +1040,16 @@ static int create_synth_event(int argc, char **argv) if (event) { if (delete_event) { if (event->ref) { - event = NULL; ret = -EBUSY; goto out; } - list_del(&event->list); - goto out; - } - event = NULL; - ret = -EEXIST; + ret = unregister_synth_event(event); + if (!ret) { + list_del(&event->list); + free_synth_event(event); + } + } else + ret = -EEXIST; goto out; } else if (delete_event) { ret = -ENOENT; @@ -1100,29 +1089,21 @@ static int create_synth_event(int argc, char **argv) event = NULL; goto err; } + ret = register_synth_event(event); + if (!ret) + list_add(&event->list, &synth_event_list); + else + free_synth_event(event); out: - if (event) { - if (delete_event) { - ret = unregister_synth_event(event); - add_or_delete_synth_event(event, !ret); - } else { - ret = register_synth_event(event); - add_or_delete_synth_event(event, ret); - } - } mutex_unlock(&synth_event_mutex); mutex_unlock(&event_mutex); return ret; err: - mutex_unlock(&synth_event_mutex); - mutex_unlock(&event_mutex); - for (i = 0; i < n_fields; i++) free_synth_field(fields[i]); - free_synth_event(event); - return ret; + goto out; } static int release_all_synth_events(void) @@ -1141,10 +1122,12 @@ static int release_all_synth_events(void) } list_for_each_entry_safe(event, e, &synth_event_list, list) { - list_del(&event->list); - ret = unregister_synth_event(event); - add_or_delete_synth_event(event, !ret); + if (!ret) { + list_del(&event->list); + free_synth_event(event); + } else + break; } mutex_unlock(&synth_event_mutex); mutex_unlock(&event_mutex);