From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id B4B9E6841 for ; Thu, 1 Jun 2017 12:09:11 +0200 (CEST) Received: by mail-wm0-f49.google.com with SMTP id b84so151966806wmh.0 for ; Thu, 01 Jun 2017 03:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=f+LFdBjE4o0RMsVma8xKmGHj1qH1Q2Ig0yE9kB77/xc=; b=2B3eMYzH+VqhbJz1ExjaxUb3Wnyx41l7HKY8bXb2L96aad99Mj4eKFT5ADr5FLt6fx yVM/ZesCr/H+w0EeTURwcBkJ5XqGP4vRZRG8Kxeq87RnBXxNHVmWTQngSmCiScoYi2Xq CD5kUpx8qa4Tt4n8Qz0q8Gbs7WjEjcCDaegdR7YS+x5goxM4cimX9Ya1ivc6cuZOf95S qv+Ur3KZtubMHMScEYlh/wtHg6EzxH2o8So4q+btvJLqc9XmNRMX5gOyc6eex6AKDmEJ WlPKCsbqCIPtyGrSBimUd5vcceYvSazrtVPvQBlZpeXhMb6Cg7YBmwLucBvRzs8xZqX0 AtxA== 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:in-reply-to:references; bh=f+LFdBjE4o0RMsVma8xKmGHj1qH1Q2Ig0yE9kB77/xc=; b=Pr5tBm28r+92w7VD1LiGYaqkU0NZjVfAI1XMpfsI6510jGTaRvvpQvPLjaYW2f79F3 eX6oV0wJMcLpQKSHIN+ozY2Ul2e6uNu1mq8npBlpap01dnca3IRCnddGuQIQAaIdlbRa YlKTOlZdlPH6SBnO/olIt4hoQ6Yk7ZSdLX1WW5FqVwWfbGtG5fmDtFmTCX1Yhbd2Q//v IKN8M8k+M20DyFrCNL3yLgORVnFM3jCs/kE3x/UbAxJl+rkFKV0uH9+OM/UHJbPgsGcI c+pe8+j31/oYgAX9YsQ1ufCIFFrT41A+Pswd3GDzmaBz81CxhhPaOF5q2ecD5C1tWnaK aWIg== X-Gm-Message-State: AODbwcDrLo418IJoenauyfVHJS/1BAS3atz6We5EOLmcXoPD4f7xdMjL hn6/+0lte9HgLCuGUjs= X-Received: by 10.28.26.133 with SMTP id a127mr1132554wma.11.1496311751059; Thu, 01 Jun 2017 03:09:11 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r10sm24305457wmd.9.2017.06.01.03.09.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 03:09:10 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 1 Jun 2017 12:08:52 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 2/9] bus: verify bus name on registration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2017 10:09:12 -0000 Verify that a bus name is legal. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++ lib/librte_eal/common/eal_private.h | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 4063897..bc3c6c6 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus) { RTE_VERIFY(bus); RTE_VERIFY(bus->name && strlen(bus->name)); + /* Its whole name should be comprised only of valid characters */ + RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name)); /* A bus should mandatorily have the scan implemented */ RTE_VERIFY(bus->scan); RTE_VERIFY(bus->probe); @@ -210,3 +212,14 @@ rte_bus_find_device(const struct rte_device *start, } return dev; } + +/* Validate a bus name. */ +size_t +rte_bus_name_valid(const char *name) +{ + size_t i = 0; + + while (isalnum(name[i]) || name[i] == '_') + i++; + return i; +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 6cacce0..6d2206a 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void); */ bool rte_eal_using_phys_addrs(void); +/* + * Validate a bus name. + * + * Counts the number of valid characters in a given name, + * starting from the beginning. + * A legal bus name is defined by the pattern: + * [:alnum:_]+ + * + * @param name + * bus name + * + * @return + * number of valid characters in name. + */ +size_t rte_bus_name_valid(const char *name); + #endif /* _EAL_PRIVATE_H_ */ -- 2.1.4