From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by dpdk.org (Postfix) with ESMTP id A754B1DB1 for ; Mon, 7 Dec 2015 21:45:11 +0100 (CET) Received: by oiww189 with SMTP id w189so104622898oiw.3 for ; Mon, 07 Dec 2015 12:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pOa0uP6yxtfDgHNsP0MRBmYSJNkbVh+hd+j7mkKX0TM=; b=QeeMVEvd3FUoXOynAuXBW35V3E+YRfD9Ol4Mzo11TCUqQD/7DeH/R2alCcwtsjcK/s sKSFHISRGh0DAZkd2l1G/f7DCYtY2rsvOBP90MbyXtlnkwk99zqB6sjcT+5IaG+PXyKL TxB9zU+d1Jth7tAEy4K7kb2UnZ8/jBS6QSO7kcPw9hxobIBjy9dYEUrWP/QakmJ/Eddx C2OGl6hFMriQPb4pe5eJRbareWzZg3i2AxI/efivTJQazCGTDBbUgvjfg1nk/5JM6v79 Pprf2L3sbGgYPSxL5ewuDCoXhDXMLTvIWNjTkyTVQ5d9aYMN9C/36hW+krAeqQiYlcOd eikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=pOa0uP6yxtfDgHNsP0MRBmYSJNkbVh+hd+j7mkKX0TM=; b=UHbyh/LemKCvSAR1NARssK/QpdYHhqDf/DN0L++/ugUn1DZwPsWZ91QgiONwFIKpHI KisOGdLKaFmz8Der1wRxVB8HjXI9RkFQHN0GfFmD5VhHbGPUTMx071ypCH3884owdq4L LE94upa9/5AG4EOprJOHkvAmot/vTe4JSWZUoCamQxNinKSNfFzcu7GDHXTU9yUvejjl WjyJ3px0ssBdTfAUTIi/fmXUPtvZMGZ5upF3+vz/36AHw6Ln+wrKKyF8QvK5KLLVb7Va zB4J1ZgyWI57ZNcxG9OYKi41MAv/SMkQopVRsWQ69w/KrAFkXyqHUyXGPT7Sq5kl8Dta VmpQ== X-Gm-Message-State: ALoCoQkoyw/7Xx4yw6+3CWsX0Ew21N5RfpidgANKBwA418fnXj2vbRvlVffxYendYEb7O9yvQmEo MIME-Version: 1.0 X-Received: by 10.202.241.11 with SMTP id p11mr22736504oih.51.1449521110866; Mon, 07 Dec 2015 12:45:10 -0800 (PST) Received: by 10.76.153.5 with HTTP; Mon, 7 Dec 2015 12:45:10 -0800 (PST) In-Reply-To: <1449513365-22282-2-git-send-email-Kamil.Rytarowski@caviumnetworks.com> References: <1449507460-32038-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> <1449513365-22282-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> <1449513365-22282-2-git-send-email-Kamil.Rytarowski@caviumnetworks.com> Date: Mon, 7 Dec 2015 21:45:10 +0100 Message-ID: From: David Marchand To: Kamil Rytarowski Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v3 2/2] eal/linux: Add support for handling built-in kernel modules X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Dec 2015 20:45:12 -0000 On Mon, Dec 7, 2015 at 7:36 PM, Kamil Rytarowski < Kamil.Rytarowski@caviumnetworks.com> wrote: > Currently rte_eal_check_module() detects Linux kernel modules via reading > /proc/modules. Built-in ones aren't listed there and therefore they are not > being found by the script. > > Add support for checking built-in modules with parsing the sysfs files > > This commit obsoletes the /proc/modules parsing approach. > > Signed-off-by: Kamil Rytarowski > --- > lib/librte_eal/linuxapp/eal/eal.c | 32 +++++++++++++++++--------------- > 1 file changed, 17 insertions(+), 15 deletions(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal.c > b/lib/librte_eal/linuxapp/eal/eal.c > index 635ec36..539188f 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -52,6 +52,8 @@ > #if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) > #include > #endif > +#include > +#include > > #include > #include > @@ -901,27 +903,27 @@ int rte_eal_has_hugepages(void) > int > rte_eal_check_module(const char *module_name) > { > - char mod_name[30]; /* Any module names can be longer than 30 > bytes? */ > - int ret = 0; > - int n; > + char sysfs_mod_name[PATH_MAX]; > + struct stat st; > > if (NULL == module_name) > return -1; > > - FILE *fd = fopen("/proc/modules", "r"); > - if (NULL == fd) { > - RTE_LOG(ERR, EAL, "Open /proc/modules failed!" > - " error %i (%s)\n", errno, strerror(errno)); > + /* Check if there is sysfs mounted */ > + if (stat("/sys/module", &st) != 0) { > + RTE_LOG(DEBUG, EAL, "Open /sys/module failed: %s\n", > + strerror(errno)); > return -1; > } > Not sure making a difference between /sys/module and /sys/module/XXX presence really helps, but this is the same philosophy as how it was done before... So, ok let's go with this. > - while (!feof(fd)) { > - n = fscanf(fd, "%29s %*[^\n]", mod_name); > - if ((n == 1) && !strcmp(mod_name, module_name)) { > - ret = 1; > - break; > - } > + > + /* A module might be built-in, therefore try sysfs */ > + snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); > + if (stat(sysfs_mod_name, &st) != 0) { > + RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n", > + sysfs_mod_name, errno, strerror(errno)); > + return 0; > } > Please, add a check on snprintf return value. Even if this can't happen, if snprintf fails, stat would access a truncated or uninitialized (when < 0) path. With this fixed, you can add my ack. Thanks. -- David Marchand