Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5817220ybc; Wed, 27 Nov 2019 09:53:11 -0800 (PST) X-Google-Smtp-Source: APXvYqxi7ELtsqOF14qwvCRzJUi2jqV5hqN4Y2VY6r78iu9B4t8OEqmP5lmAXjCAJdpW5hsUHTda X-Received: by 2002:a05:6402:12d1:: with SMTP id k17mr33412971edx.188.1574877190993; Wed, 27 Nov 2019 09:53:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574877190; cv=none; d=google.com; s=arc-20160816; b=Rzy38pCD6Sb/LC7GxHwYcBcG34oLTJEHf/1xoKSvpDOBPTH4KdVfc3phL1UcegMDAG nQDJln8Qzp2S60aykHD/k1Ha2xWyphHbG3/MHZhzWYjgFmUjiCkj2+ooKPXAN4JHMT/G ar3g+XAgmUqfhbmWOcjFXYJ4ZNWprd764HsGKoZstkW6h0QJl+yHBv2lrFVv0l7mqKK8 S5q3tmbmaEVoUMiX8nXfzS3IVZzkyzQqoEUBh/hmub2+rtvrhrpAuXLAQQfK4BKqs5Q9 3KoKjtXlyIzp2dqgcjPm25CEiqZWx8stHiCbLLNjQkouEGNBDt+FLTOJfxpXjKNdZh2+ D+dA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=CVqM3XyMgumqJ3SCUSrKi+gH3fLBN/ajp7m/rX9qNj4=; b=dlcOrlQVyAYeY6jj3QACvGFxO7qMPVhvsbZI6AnVk8G8rWGnV+lUY9hP4CNV8hBtez a/z2eHotpUZLQZIP80mxktN3FWFxIGtM3J9iQyACJy5X97vSNZi06gqXOftPYC2iXCzx cpgM/cIpvpDUmpNF7dgqCQNDuLOrJhrXJKiY/Jpz8kol+bvHaPdQ8gEKYSbm3trM6Wn7 dDrH2DelFjikPu1LBh7h3h6auTKXZQwDOo9oxjdgGKJBj1u208vs9Xg3oP0denPclXMu WTGPyU2QsNX8y1Rhas+FMzO9gi5M5rQT07n3AeHAucaPNHzQ9tvUjBv5AEJVeHErxwPS hj8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="nN3U/3Ec"; 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 la17si10172751ejb.433.2019.11.27.09.52.47; Wed, 27 Nov 2019 09:53:10 -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="nN3U/3Ec"; 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 S1727287AbfK0RvH (ORCPT + 99 others); Wed, 27 Nov 2019 12:51:07 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:37710 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbfK0RvF (ORCPT ); Wed, 27 Nov 2019 12:51:05 -0500 Received: by mail-io1-f67.google.com with SMTP id k24so15203627ioc.4 for ; Wed, 27 Nov 2019 09:51:05 -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:mime-version :content-transfer-encoding; bh=CVqM3XyMgumqJ3SCUSrKi+gH3fLBN/ajp7m/rX9qNj4=; b=nN3U/3EcuU16psD8wY25vqnduQZh2jv6Yu+vYujZXF1lWxDlnWhaCxMsMIryFWP69N nWQDglF4GS59DSP9fBmpZBA22fTbu1grsTShquz4RSATnmJ4kw2607W15VRbEbaJiuvL xiIQS3BgvCXvWoh7LYPSTG7Khj32X2POwzt+zh4fhBInmLFksXDORTeQV972qLXW+9te AkzicMyrwmXg3cw9bN4z0qImGtsGovGp7gzwx91m5NCnn9GgoLrVDTHsg95vPhJS5B/X d1v+LelJGh6V9PLskS5KutLdpNyo7vK4yN4ApYakgiBEdD316mVgZNdEuRjoTNHjkMVD xW0g== 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:mime-version :content-transfer-encoding; bh=CVqM3XyMgumqJ3SCUSrKi+gH3fLBN/ajp7m/rX9qNj4=; b=QrSlm26hvh8mq8a4rkvvqGRG8JBJLzuCRAfqL78gnkmh+b1rialwFwCSrOm5tuuwUF oPa0OSfRi3Qfaf1VzjRX6XqMpMXY0NSUTDoR9x4AG4NFtZidWs3RRJUUyGptiI/IuTrO AuQT887Uhfm7lSDQjPx+AcnT+L/ue0nyJaK5wRomQykyTcIhNZxBc1snNd6iYAwEnWJw xmna6RMBUYsx1j4YpwY8XaGx8NXEl8U95hEDbUG/hKlZKkriOQl4IFvQCUzRQTRRIlh6 UQ0OpOkgusbgNfhK/5xLDOHvmOng1Hqkp42E9+6u44dxSlNX1x31AjW3pAXnDTqMe0DY K13w== X-Gm-Message-State: APjAAAWUsV1SKGfugqflcQOCS1m2aZPuCQAKyAlkPBoCYN2pBMXQY7Yw 3aq8vJdj+x/9nL+kjEm+NJ4= X-Received: by 2002:a6b:c982:: with SMTP id z124mr38750043iof.291.1574877065076; Wed, 27 Nov 2019 09:51:05 -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 k11sm4574351ilc.5.2019.11.27.09.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 09:51:04 -0800 (PST) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org Cc: linux@rasmusvillemoes.dk, greg@kroah.com, Jim Cromie Subject: [PATCH 07/16] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Wed, 27 Nov 2019 10:51:01 -0700 Message-Id: <20191127175102.1351520-1-jim.cromie@gmail.com> X-Mailer: git-send-email 2.23.0 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 handle "file foo.c:101-200" etc. 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 0e4783e11755..496c3da48e2b 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