Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp432347ybt; Sat, 13 Jun 2020 09:00:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+FI25aL9jc+CS0gajQ3kRYCrM4T6BB1aGWPfLkKCHYgcPWVUqwrByMWg5S/wszbgPLRco X-Received: by 2002:a17:906:ae5b:: with SMTP id lf27mr19110662ejb.156.1592064031725; Sat, 13 Jun 2020 09:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592064031; cv=none; d=google.com; s=arc-20160816; b=YRMfncK6qwlGsb7TW0mkieQp1ZlT2h/T732TXSiDt9hmrgF/ABQ7cOT6evnGfki1ta d6dgX966d/J2OS6vCj5LJI3Yh/5MTG/i6+aieiWDpJ78LTK/RN1Rtnjz/k/dZBzAxgcg KwC6++LuEgcrSmcEWuVtEkLJx5H5z3sIGp7phpJt4zR51l1qnLmHI3e0HCxJWWX8BSEX ug2R43/aXpy2cHDN4jdtXOHBF1CMQ0EGa/5moiqkc4n73Ixch3Uv7P0cFuVtzCNh1+qd ewhDOGsydJ8S0LO4tsj48xKyNm68Bia+x1Hs1tpB8MRHJVAZ0n/nH1Svg04Y1RlO2R06 Zlkw== 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=qfxcDoKXVRozj3fbz6wlrCLjQwfm6vOI61pB+sPfysk=; b=B3rhTZghtdt68cdCG7kSY/bQf/DqvosvqQckGX3pcpfG9+RdtpDoaSpeVwa6ahubLE 9mRnGDMvDn31v1EfATeEHYUYimUnztQhHhFlgZZ9VJPrsWM43XOZi9hgRAMtUNMEADzy ku3By/4Ehnb06oNupEk/y1sGHbpTzdGvjCOxdcd9vgJRbugUX3PsshPRzxheotY+e4wY JneFthQH3uMyIuHDwT+JDb35rwfj6IevtP21i5lTo5oqsyIFyzgYyOTfOdgo5n+qHNk+ yMLzWIa0QvievtC6Sm/SLyI7VBogxJGdqcEmAUKMKp0tmuQkenA5vLECKuASjYT3oyXr p7aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Bl+z6fqU; 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 gt26si5873801ejb.750.2020.06.13.09.00.09; Sat, 13 Jun 2020 09:00:31 -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=Bl+z6fqU; 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 S1726577AbgFMP6P (ORCPT + 99 others); Sat, 13 Jun 2020 11:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726552AbgFMP6L (ORCPT ); Sat, 13 Jun 2020 11:58:11 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 002FFC08C5C1 for ; Sat, 13 Jun 2020 08:58:10 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id v13so9757078otp.4 for ; Sat, 13 Jun 2020 08:58:10 -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=qfxcDoKXVRozj3fbz6wlrCLjQwfm6vOI61pB+sPfysk=; b=Bl+z6fqUM78VHCJnQiHtfiV3SQ5cIEDe201Lhgrs8CLBNZn7ivjkIPmuZ5oBmHlA5p 4mUAsQzcUUC/nR64mtLS8+Hdi7IfdwJiuw/43RMj8Sbm51xEhSHpjCUF3YaqkvL+UH2w D5NHVmrJAv4Wi/81QD3usP1RlW/MC5JhZ1ZTJ3Q+8d5Li+IP5DRXuOVxVwxdXVjT+1ff kHK86HwtlCA8AYu6n18NAsaQohWLyZqQha6UeS8zd0HW5/rmP1cbDJLnHL+QOtyNHbmg TySC/FH6hqGoQm+alatBzvPQ0wanG1ssYfvCqtAN+gXEWUjCs73xg2MlouN3POzwTcZL OWkg== 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=qfxcDoKXVRozj3fbz6wlrCLjQwfm6vOI61pB+sPfysk=; b=A1zJcGusZjMPj9PX0H4KSPNjzqLKBUYomtfoQ93tgH0Ib6jvjfsXa5Re5XUHIvwDC+ VkIvk78NdBNKHcVHCUIE+lQGYL7ukyhHlVI0DZffr9Q0bUTsCpYtKqcQtkqWF4ABGc7D SYk+1N3zkZdEljmL3++aqkcN1NYcAhkMOKct/g2jZVC3+oMPQ+HW93K5fluLkuuMIqVi CO2MxdN2llZrJ9YySfWBc828rrKxTeDupADNDT+2HpSWpyGbpTBH/0E1rxSPM8xkvoXM kWwAPYKtvoCbRkmti/IcQ85HCrRR8Es/l7Zh3LiWGYLxq471QsG29HZrjNIK8d027Gpv tjag== X-Gm-Message-State: AOAM533Az1oMN1j6FLSJYMICNqpe5bUalD5DOQnt0vX1Qwx9X55yqnwT UDBvPV9loi6xVKXmpUN0TbeqifMJYIc= X-Received: by 2002:a9d:8ac:: with SMTP id 41mr14789552otf.210.1592063890364; Sat, 13 Jun 2020 08:58:10 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:6ba0::aaac]) by smtp.googlemail.com with ESMTPSA id 53sm2105565otv.22.2020.06.13.08.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2020 08:58:09 -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 v2 10/24] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Sat, 13 Jun 2020 09:57:24 -0600 Message-Id: <20200613155738.2249399-11-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200613155738.2249399-1-jim.cromie@gmail.com> References: <20200613155738.2249399-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. --- 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 20b712652ee4..f87a7bef4204 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.26.2