From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by dpdk.org (Postfix) with ESMTP id 75F7B7CB9 for ; Wed, 24 May 2017 18:16:06 +0200 (CEST) Received: by mail-wr0-f174.google.com with SMTP id w50so58061858wrc.0 for ; Wed, 24 May 2017 09:16:06 -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=Vt32bYh0hrgwB+gHKORf7txmn9YZ14YrTNfhxtvcQ/VDh5JJaQyBo//U1ou4EklZrU +sAZTCtmJCqdWwYAICkSWpHJ31aJtOPWa479KlxyAv8YNlLxQe2hX9W+DeaelkGAig++ RYKzVccHs+qmx+dy2iOTofDfbQ0hs0B4fN7ZbVvkCG55iknpJkG1kSDIUWvmn4ymS4OA GpJZ2XtmKy/ASqXb7Ww6HkYdO2TUAUNzYCnwGuc4UoASHfKP0LqwL1r452J/nS//LC8c RokTweMBxwbPeTMX1sGKmcpnERxgoiAWzdYd1wdym0yL4iG3pdIVfYBJ+fAlwT+wUGOO XWqw== 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=GZJ2q0C3dTB6MQOnHzCdWZts8d7gHSh2gMXI+utfhTcwWupt0hXG0d7+FIJoMqC5U5 kT/B6/uuSCQuGHOItiaHv316z2X93Sgp6ZGyBmsILOW+ACIMx6LIFqdiLprJ8K4JYcll GWIlUFWOnYePKDv2jmPFV4z2i7crxx81wt0JkwovZNgfw61J7AJGCUw2hRRltAy193RM APGXLEjxX/RuDtRnHoALt32PEXFMfHiDHnI/inm4wtig2imGIEHMpbeFcAuBg4dNOUfz ga3e8yjlw+gVTISHIvntKDZXKgugUQl6igH2jl6c12a1AA9rBXsfPlj549AE75HcsQvg LJdw== X-Gm-Message-State: AODbwcDiyj6e4gJE+mOVpgzHHEAvf6BDedu0MURwnhe+612X7Qe5DluC t9XmUpPDG3ctvCta+Rg= X-Received: by 10.223.136.71 with SMTP id e7mr19272571wre.73.1495642565766; Wed, 24 May 2017 09:16:05 -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 l7sm7783055wrc.52.2017.05.24.09.16.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 09:16:04 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 24 May 2017 18:15:45 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 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 16:16:07 -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