Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2266338ybg; Fri, 5 Jun 2020 09:32:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9AoZlEJzODXoEqfAcIDJFd5AaqQkFwBb8rIrTMM7rRot6uE7gYfsJHU/URlVJjsq2scQy X-Received: by 2002:a17:907:402e:: with SMTP id nr22mr8707788ejb.239.1591374743773; Fri, 05 Jun 2020 09:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591374743; cv=none; d=google.com; s=arc-20160816; b=aR8KzpuIb8GPNHDzmrQ363s8m7LpOwWw0Gbp5//wIjW8z1d19GDYTfBmExHuJ082j5 pLYObKMkNtysH1hr4oI4pmoPbOHljikdbDbIKfKceg9eLhu2eYJ40w3PIAMG76eCazBc 0IevD/m2I/8TaEmm6Vq60Uq6fFpi+/ZPfdWgfcHnqzWWfRwkLKKYpfwpiYosXHXCWiQe OAKOHl1FpIY/qjQ98VJkdZNrBe5rkRS1rOzzHS7NfhnKEpkRZHj1kSw/iS+aJbpP3GGD L3KHDrDHt37Y1zdCRaO0P4QgW+NnnjW+fmSrEV/AJ7viZkpOVXh2TUm0LPvuWBGyY/LM IxiQ== 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:date:subject:cc:to:from :dkim-signature; bh=h0TqppIn6BuRHaNOgh5AvgWTO95AAjy++fKL00K6NjM=; b=J69Oz0tD9W0fnsPyko0n2w6/3UgIa4OaKYanm1oHZuj4UpoytQKO/nrCAJU6PRlgyw N3ujI65vg9010F3kcSau5t4tsAk54d9Jrgnld1CDM5PC73j2nEK0DzjAn4Sz76sRfF4u c7LGjrFJde4YrHUBjmnCL23mtkRG1UfJy84xRm6bcSzfoI6JIsgQX0DeuG98MRdG16+x thSxCmrd/Z+vja8peMIiy2UJXuW51NQFYxUwN3/dWJEXwcMapdpWWYXE3Hut3CyHiLED 0dy8CmCpwGUJVbRyf50p+4sDZCY8RyNbiVfC4WXGJtnsdLU/N+h0qZzKSpgBVI3HPQOD E4TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="hj/801q0"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a63si3901218edf.135.2020.06.05.09.32.00; Fri, 05 Jun 2020 09:32:23 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="hj/801q0"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728622AbgFEQ2i (ORCPT + 99 others); Fri, 5 Jun 2020 12:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728530AbgFEQ1t (ORCPT ); Fri, 5 Jun 2020 12:27:49 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75235C08C5C4 for ; Fri, 5 Jun 2020 09:27:49 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id 69so8072887otv.2 for ; Fri, 05 Jun 2020 09:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h0TqppIn6BuRHaNOgh5AvgWTO95AAjy++fKL00K6NjM=; b=hj/801q0vd3JtRrTWASWK3loeGEI8BUp1dBrQehyCTrhSYQcY3OzL76dvXzSdtWMQm msFFu96s0A+bvbe+LYAffWzoJiuWZTTo8LT2IZ1dYtAX5FvF6oa9z1w9qHuUms5Ju0Zl fSsM3V58iGiIq6T16raITGmJcaPW/I8kpPAwr2zXWH52sHW6MIQ7p1jHT34I8+nU275u OpHnxpHJ9YI92dokvEUfUaXAIUJyl0QDmFp3YO+7qnqq+aerMYLth0XCuTHUGjcHNBZ7 z9ujlwKpmbjgMmbgKVFVTO/4qshgUrNM7SLG6+NAITvijGXqwwcWkhO1NW072K+utfm1 qZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h0TqppIn6BuRHaNOgh5AvgWTO95AAjy++fKL00K6NjM=; b=kAmQb/1ga7sP53pgBCjKRpcG5GUfNEMglazvsLdi/dUGY2HV0RIFk+CPeLgVy2K+7m ajGIACfn+qzKrSiPpQ3wYvFbKeDYU3se+OxIqRECIzTkrB2FlxB0jcX3DjSqrdozvs2f nFIImfHmlN7DDti4mf6iDUCs4xSXcM/i3+1Fq51oAkaPIDQIlg26dCX0+I3GcFmpZUFV 7Gq3c8rxWG8PuaZ6apSKXYvwFzKODch1yowmDZjiFfB5BlLHBFaJuCfAHmpM4qkHztto MkGRVV9MiAZ8l36nuNegeUm2ahQ1q/4R2sRQZHy+RKrIbeyNkXrx3zPlfcMiwc5Nk/nm 4k+Q== X-Gm-Message-State: AOAM531iKJg7UnXdY/GLh9uRD4QVFrCmmqZqrAtUyU/2ekDoPkmnKQ7Z GTftgzxyV3V3fPp4WKO5OH4= X-Received: by 2002:a9d:2253:: with SMTP id o77mr8129433ota.236.1591374468821; Fri, 05 Jun 2020 09:27:48 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:6ba0::aaac]) by smtp.googlemail.com with ESMTPSA id z13sm813894ooa.28.2020.06.05.09.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 09:27:47 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org, akpm@linuxfoundation.org, gregkh@linuxfoundation.org Cc: linux@rasmusvillemoes.dk, Jim Cromie Subject: [PATCH 08/16] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Fri, 5 Jun 2020 10:26:37 -0600 Message-Id: <20200605162645.289174-9-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200605162645.289174-1-jim.cromie@gmail.com> References: <20200605162645.289174-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org make the code-block reusable to later handle "file foo.c:101-200" etc. This should be a 90%+ code-move, with minimal adaptations; reindent, and scafolding. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 494856c04fa7..d43bc3547d3a 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -291,6 +291,39 @@ static inline int parse_lineno(const char *str, unsigned int *val) return 0; } +static int parse_linerange(struct ddebug_query *query, const char *first) +{ + char *last = strchr(first, '-'); + + if (query->first_lineno || query->last_lineno) { + pr_err("match-spec: line used 2x\n"); + return -EINVAL; + } + if (last) + *last++ = '\0'; + if (parse_lineno(first, &query->first_lineno) < 0) + return -EINVAL; + if (last) { + /* range - */ + if (parse_lineno(last, &query->last_lineno) < 0) + return -EINVAL; + + /* special case for last lineno not specified */ + if (query->last_lineno == 0) + query->last_lineno = UINT_MAX; + + if (query->last_lineno < query->first_lineno) { + pr_err("last-line:%d < 1st-line:%d\n", + query->last_lineno, + query->first_lineno); + return -EINVAL; + } + } else { + query->last_lineno = query->first_lineno; + } + return 0; +} + static int check_set(const char **dest, char *src, char *name) { int rc = 0; @@ -349,34 +382,8 @@ static int ddebug_parse_query(char *words[], int nwords, UNESCAPE_SPECIAL); rc = check_set(&query->format, words[i+1], "format"); } else if (!strcmp(words[i], "line")) { - char *first = words[i+1]; - char *last = strchr(first, '-'); - if (query->first_lineno || query->last_lineno) { - pr_err("match-spec: line used 2x\n"); - return -EINVAL; - } - if (last) - *last++ = '\0'; - if (parse_lineno(first, &query->first_lineno) < 0) + if (parse_linerange(query, words[i+1])) return -EINVAL; - if (last) { - /* range - */ - if (parse_lineno(last, &query->last_lineno) < 0) - return -EINVAL; - - /* special case for last lineno not specified */ - if (query->last_lineno == 0) - query->last_lineno = UINT_MAX; - - if (query->last_lineno < query->first_lineno) { - pr_err("last-line:%d < 1st-line:%d\n", - query->last_lineno, - query->first_lineno); - return -EINVAL; - } - } else { - query->last_lineno = query->first_lineno; - } } else { pr_err("unknown keyword \"%s\"\n", words[i]); return -EINVAL; -- 2.26.2