From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by dpdk.org (Postfix) with ESMTP id 8980C2716 for ; Fri, 15 May 2015 18:37:45 +0200 (CEST) Received: by pdea3 with SMTP id a3so15881472pde.2 for ; Fri, 15 May 2015 09:37:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7oL8htaYf1WByBewHpWE/js4nDbF3ApXHQWWjlqrLBo=; b=Lp712y//A93k5LUdo3UF2WC+3loSICDTdoNPZb6Le149tI94GKCQHdr2PG8gV6Hde5 /4DLvPHpqQzqqYBLdUiN4UBKiWnyDBfELuYEAFEjMca+hPhTNNWiFohEe2xuDnECAjRu qb6p5vEBCCQhecu6H6lOdfgT2lnL5/PKqQzl8JommTQ6Dy8RV/46nm4U9qZba1goAiSE J8FHDYupPkOw/LJ+7ggA7Vj0QBqqBdV8d9ZocT8RoJFH7Tv0a3B6yxJbuFwiQNu7sURq sh8tYamlJQQRyw2F9tz3QdvAge4RX0SzNGuwazj55kdWhjAKDknRHia/znZG7eHZa1EO B40A== X-Gm-Message-State: ALoCoQnTO9AGxUIq6BdlI1mtxDpEoVp+LGi4peon8fFYMDmtIkk4pA7neIdALy30cOB+64LGKLJ5 X-Received: by 10.70.43.10 with SMTP id s10mr19866832pdl.57.1431707864688; Fri, 15 May 2015 09:37:44 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id ho10sm2354198pbc.27.2015.05.15.09.37.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 May 2015 09:37:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Date: Fri, 15 May 2015 09:37:40 -0700 Message-Id: <1431707860-19562-1-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] eal devargs: don't call rte_log when not initialized 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: Fri, 15 May 2015 16:37:46 -0000 This problem was discovered when passing invalid PCI id to the blacklist API in devargs. Any failures in rte_devargs_add would cause a core dump because it would call rte_log() before the the EAL log environment was initailized. Rather than try and log just remove the messages and leave it up to the caller to check the return value. Most of the other failure possibilities are when malloc() fails, and if that happens any logging that used malloc() would also fail. This failure was not caught by the standalone tests to devargs because the tests are run after calling rte_eal_init (which is not how devargs is intended to be used). Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_devargs.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 615945e..ec56165 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -31,11 +31,15 @@ */ /* This file manages the list of devices and their arguments, as given - * by the user at startup */ + * by the user at startup + * + * Code here should not call rte_log since the EAL environment + * may not be initialized. + */ +#include #include -#include #include #include #include "eal_private.h" @@ -54,11 +58,8 @@ rte_eal_parse_devargs_str(const char *devargs_str, return -1; *drvname = strdup(devargs_str); - if (drvname == NULL) { - RTE_LOG(ERR, EAL, - "cannot allocate temp memory for driver name\n"); + if (drvname == NULL) return -1; - } /* set the first ',' to '\0' to split name and arguments */ sep = strchr(*drvname, ','); @@ -70,8 +71,6 @@ rte_eal_parse_devargs_str(const char *devargs_str, } if (*drvargs == NULL) { - RTE_LOG(ERR, EAL, - "cannot allocate temp memory for driver arguments\n"); free(*drvname); return -1; } @@ -88,10 +87,9 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) /* use malloc instead of rte_malloc as it's called early at init */ devargs = malloc(sizeof(*devargs)); - if (devargs == NULL) { - RTE_LOG(ERR, EAL, "cannot allocate devargs\n"); + if (devargs == NULL) goto fail; - } + memset(devargs, 0, sizeof(*devargs)); devargs->type = devtype; @@ -103,19 +101,17 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) case RTE_DEVTYPE_BLACKLISTED_PCI: /* try to parse pci identifier */ if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 && - eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0) { - RTE_LOG(ERR, EAL, "invalid PCI identifier <%s>\n", buf); + eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0) goto fail; - } + break; case RTE_DEVTYPE_VIRTUAL: /* save driver name */ ret = snprintf(devargs->virtual.drv_name, sizeof(devargs->virtual.drv_name), "%s", buf); - if (ret < 0 || ret >= (int)sizeof(devargs->virtual.drv_name)) { - RTE_LOG(ERR, EAL, "driver name too large: <%s>\n", buf); + if (ret < 0 || ret >= (int)sizeof(devargs->virtual.drv_name)) goto fail; - } + break; } -- 2.1.4