Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2200540ybl; Thu, 5 Dec 2019 13:53:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxJeTCEmtOypPISVCoOhH8d6qCf1SATVi9elwKh7Wg3UbXgm+ioeyJsnSbAJvOVR6PCOBRN X-Received: by 2002:aca:b588:: with SMTP id e130mr9208245oif.169.1575582800900; Thu, 05 Dec 2019 13:53:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575582800; cv=none; d=google.com; s=arc-20160816; b=sMO4YX1A+wQX7wdSTVdTHwx9op9LtTg4IRjunGvANOkB1kwYd+g+TW5HnYmW571TvP 8n/FhJO874w0JKolkjVUVYX6kRKqFmAJT9veJdjC8qvMztWrABgjnjF3FhyY6V7asQwt TNHOEFNz+TzE5+nRnmAMtelUCUrHyyyNjIkTZpRH5pa4d19qrTrZVUoukPGvTAyGXB60 DfWJAUvrDPiv1BcsOi5JzvzI/1YtawlmH3Wdunwv34cXUIdGs8qrHoqH5RT4NBwx0mZy hPHe7B2PlVsSmrU629vmTwKxjerAAM5M7vS/VGbx+v29920CTYioQ54ytRUkbnOdvYRM 6MfA== 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=czlw2v1n44KvBNP8Ri+2G2naF0l2P1nitiHJyK13A/U=; b=Bq0g9mFk6JnAfHNaCpIqUhWrAoxzu9dMxuC3c77MMKIOtQxBZLLiTuED5vIhxJaQJT WuGb/X4aXEs9k44efJfObaxv2W1XRR5vywsUMTUkCuAs0fqrwfQkbz0hJYQbu2YtS44o FGStTJ3Ypj18GZRs5kFQxHCf3BRUO6zlSxVFSOpKljL6yP6siH3emLp5Z9A2BOnt9DjQ EFRbuAPsmv8ruLzM+jmEMNRgq0IXMZHYOLwiU4L7GY4fY/RvAUiaJiJB7ZmmRMpjsoKo bM5U+TAX8QDquNBMbfKno3GbolY5E6KxPTuPTlpFgJX8q+YtEk+jf6d2zdt2DZtbvhiQ GL/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u9EJ3E9o; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si5631842oie.196.2019.12.05.13.53.08; Thu, 05 Dec 2019 13:53:20 -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=@gmail.com header.s=20161025 header.b=u9EJ3E9o; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387423AbfLEVwT (ORCPT + 99 others); Thu, 5 Dec 2019 16:52:19 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:46358 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387408AbfLEVwP (ORCPT ); Thu, 5 Dec 2019 16:52:15 -0500 Received: by mail-il1-f195.google.com with SMTP id t17so4346304ilm.13 for ; Thu, 05 Dec 2019 13:52:14 -0800 (PST) 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=czlw2v1n44KvBNP8Ri+2G2naF0l2P1nitiHJyK13A/U=; b=u9EJ3E9o639t3kAnoadfidXpqM8i75hfWT/AjwGATRRAXqt+vgdXk3o6NMYjSSYRIO xdwWxq03v4+d3jx34V3lISTR0LB0c2glrCVbECdHrw9m8GF352a38IelDwX7LGhaHqsj VNRwnDtMXjcdjn5G4f5Rms2R0e5BWp1xeoWgpUH+PKInJfVoIkgfYm7exfaCK+tCuw6b 8JM3h7CVakZaAQR/REWv0ug+A8PV/FN73Hh0DYGMXtkLD8RMvu/0ZfkiHIxfzNz1atIV DrByREG8pAGzwYSNsLUQvMOTWdIIf4lDdWjWoxkY+tl7+4vZIwWhw7EqmGsHtoD6F4oI 4JgQ== 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=czlw2v1n44KvBNP8Ri+2G2naF0l2P1nitiHJyK13A/U=; b=sQr8a6BhfsJpm0bCsLAdV8hrFAZ37MjLM2iUtuGGo4ZqsrXiBzidTdIw7xWDls20/Q RBv1dwb5+NilzTVUPHcd7exc4U3kfU1mM1HJif++NlAv8GlFmozMRrynykDIeFWKYOtX DQtDeTKY0iTGl6uk3j20RMPXPUWgi31FXCxD9fu+abMCDndT9G4b5g02G0Ndx69qURio OKtxwFRi0oFmwKYxO4SHn0xCAxofMp+NvkiUHt+6EFFRw2g47FX3rnKsl/0a26nKJz8W h1TDBC+pivag8hw6lgvF1c54NLF2fpGWqKhliX4koNjiYH3Nxva0XxklAUUW/uAhq2mx fhxQ== X-Gm-Message-State: APjAAAVKx3b1sRWE+rjtGbLNhkGCrsYW05C7LuEOYh3ba5p62ub7uA/W HXWa7WHUKYGVYaYfGKzU05vPUylUlgc= X-Received: by 2002:a92:5c8a:: with SMTP id d10mr11686219ilg.137.1575582734406; Thu, 05 Dec 2019 13:52:14 -0800 (PST) Received: from localhost.localdomain (c-24-9-77-57.hsd1.co.comcast.net. [24.9.77.57]) by smtp.googlemail.com with ESMTPSA id n22sm740184iog.14.2019.12.05.13.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 13:52:13 -0800 (PST) From: Jim Cromie To: jbaron@akamai.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: linux@rasmusvillemoes.dk, Jim Cromie Subject: [PATCH 07/18] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Thu, 5 Dec 2019 14:51:38 -0700 Message-Id: <20191205215151.421926-8-jim.cromie@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191205215151.421926-1-jim.cromie@gmail.com> References: <20191205215151.421926-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 maybe fixes for compile, behavior. 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 49cb24948e12..f0cf90e672b8 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -292,6 +292,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; @@ -350,34 +383,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.23.0