From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id 6A5B67CFF for ; Wed, 24 May 2017 17:12:55 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id z52so56986608wrc.2 for ; Wed, 24 May 2017 08:12:55 -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=hAoUQyl6cgPf6xeWG0uKotjDCNXmMEFRS7aHB4sOAhQ=; b=tONK7UCjkoYsojtR5z3hCKV3UE7E/qsRWBLpVzOa6uLQH9Q3pEw9THq3h0agS9eNG7 Cga3p/1mBVSfUmho2pcTsx7+e2EUPs0LaCInxkL0Ir+n/aQHQwpLkPqYHD4Sl68/xILU 46TcvDLIRAErdVz0WCXg8FSTxtHucr/vJUPGGpjX3CeeJxURZ999EOwjp8RqVCbLLuJP Fm7vds3HtAFlejCgjccVhXCnX/cmamDg75v7R+T2Bx5WPJMClWA+2cH+ddhrFpT7GXZ7 7PiRMUYMi0okCS8n6abXVwtUTwx+wUIn/DOZJ22ZrQ+U187KV0pLlFDRO+gcMJalLxQN yxUw== 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=hAoUQyl6cgPf6xeWG0uKotjDCNXmMEFRS7aHB4sOAhQ=; b=guClUbl77s9CC1J20UGeZZz+EC6xR/WVEjdltw0PXE7ztC+LNejVm3svidmOPi1Uqc 3xBU9nmCMHJYp9N+D0n907T5QVs+Sl+zu1HelNlv/ABgPBBzo1mpG4haRiGj//ZiOBQw 13n7IJAuQ64FKw9virF+7VyG92i6xZ0CwhqeIzX1tZLFEfVFZVYKi84Nr9s1J/sxgl29 7g9gVWohp9I56+G5XipSDlBDqPTc5JYm9LwxMwDMmEHp691j14gZkr5jbctJn19aOo31 kllAKfNXv8a3XtUFMZV+ojS0ii+MEhqXV6apXe2E+OtAx6BDZk0TRLkjnfkGGiz4Kebj dGFA== X-Gm-Message-State: AODbwcCSXOgFnHC4eeKaM6bG5K6EQ4fGs770e0VQNbuN/cDv3MpgOxda fFqfI00If3X0MYTm X-Received: by 10.223.179.92 with SMTP id k28mr1071065wrd.118.1495638774779; Wed, 24 May 2017 08:12:54 -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 9sm5633351wmh.17.2017.05.24.08.12.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:12:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Jan Blunck , Stephen Hemminger , Maxime Coquelin , Jerin Jacob , David Marchand Date: Wed, 24 May 2017 17:12:34 +0200 Message-Id: <818ef5b17128ca0366646f194d5f1bfd31b6d987.1495629122.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 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: Wed, 24 May 2017 15:12:56 -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 b41ea86..8ef859a 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