From patchwork Wed Jun 7 23:56:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 25126 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 6BF083252; Thu, 8 Jun 2017 01:56:34 +0200 (CEST) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id 58B3B2BB8 for ; Thu, 8 Jun 2017 01:56:24 +0200 (CEST) Received: by mail-wm0-f41.google.com with SMTP id d73so20748713wma.0 for ; Wed, 07 Jun 2017 16:56:24 -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=IMS9qsMlgwuiL04kp0ODvZtfYeRcgCjO9Hihm+8Gm6A=; b=gckkJN82pT2bKhwOd6Mxp6qh0iNxZHWPlg3XhSpl78xACvP9YJclrwePK/WdLeHRr6 m8hhCswnUznlaRd04NwVIW1+7x0wGXa229cvIa+SND0z9Ro/5opZgFxhs4e3a7p9kYwQ MRylnNtvM2bvGeQ8aTRGOTo84+AX3GjICPJ8sAj7WDqQZqXgp0MiMrJCj/VlHrjtKM3/ IaICWCh3/E1zYil7YqsYPMyaIARM2WWRlrrQCwmzEXx6jTA9BkU+R9tgTJe9cotGgfjR 9FdceGrd06n/ZWHLOVXcQPcx8GIX2+U3qhOJHPaJf0XyxNvyFfXfmVKL44T4iTw0UOTz +wMQ== 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=IMS9qsMlgwuiL04kp0ODvZtfYeRcgCjO9Hihm+8Gm6A=; b=CT+7fTvYmHVAMRiHBUozYE4veo1tUJS1YDpbHL0GV4JjfmGzZmHPu6qHW2miwqFoXV WTtxaT+JNPkQyyuzw2mO3Jc3EZM4U5oKYU+UNvV2m1YcE7ExbCzlguaJivIKW/FPFWW5 pne3FdcojJaKk5UVLuPnnmp89wbjWk1gGH2QebKargpMeHofVr9O5BNq2KCt7wIfGObH W5nspyn6YPj9b2mFh2mU7lSO+w+Z+lVLJn6IsjyLjCjw73G4nRR9Abq+85doy43HlbEQ HE85PVwz14yd15G8MwXrDViOcnDqBsIEHt0ifKfkLB0m4UPRdmMjFS1dYaiVHP6cq4hw mZLA== X-Gm-Message-State: AKS2vOwoshTIW2Z8AI21XPFQ52w3/XYpLam1ZEl2lziXlO454g1VHvQV 3XU01HBZOSKu+rnBPXY= X-Received: by 10.28.86.194 with SMTP id k185mr1390811wmb.35.1496879783720; Wed, 07 Jun 2017 16:56:23 -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 m40sm2624808wrm.4.2017.06.07.16.56.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:56:22 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 8 Jun 2017 01:56:02 +0200 Message-Id: <88e3fbcaffd62f58d816887d20b541c8e9fcba80.1496876810.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 381a0b6..d9d8f62 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); @@ -207,3 +209,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_ */