From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A182DA00C5; Mon, 6 Jul 2020 23:24:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D66ED1D98C; Mon, 6 Jul 2020 23:24:31 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id C31131D987 for ; Mon, 6 Jul 2020 23:24:29 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id d4so18971871pgk.4 for ; Mon, 06 Jul 2020 14:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NzLp5nOAL42jBcFx1x+uITqhVMyI0bS17wE5H69sSmE=; b=MNJ9bYFnAFgfC+PONEqiR+hqdqKh2bx/PBq9IWvYKVpasdvm5QgvW6bRK5Ii7VaMsg NsUiTlLz7092RsNfeUjDk2FXWKnq/cz/57hCbL8THxaLYFIDHYVzyJjMyVQ4CHd+VSLW knqA6wQZ/CBpTdPC1qL69HbdxMQdSPb1KV94Og8CwPFAJ3RiO4xlQD7i/jU2pumNneCT NaRKMw9ngvNdpuM9fwlmJRdu1kHziDh/PgBSd8rVtyhUNdUktUOdkOQ6urtF1bFVvd+u SRQ5d5c7qBB8olayYX2Lu2Zj1bWyBMRuz7j9q31sBW8t8zA5fJvKNVvSMUmPyT9krep3 qMpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NzLp5nOAL42jBcFx1x+uITqhVMyI0bS17wE5H69sSmE=; b=cuHFUNxD3+xGzsSteivz7ymiuGBVHIpS2T738pLIc/zxyQiypS9q/mW3rmkjoIxFEy Pa+RUN+O+qmVqoP0z/TxVJXl7/8tbB/wHtVAMuxzqiTj8ZGMWNJwVDeBBSsqcOCHWcfT RDCf4wvbdqb/JjsUHGkfviPxDCQUDYY1jmCBZthgcEczJPHhGxNWU6vxxHkpzwz4mVFk U8m4iZV/w6NBekIghGtihcstSECKRU4QlsTRUZAqGPkwaqAuSI9PdprB0ClIsdbYqsAG iX+pWOA0l6RNvZTTbMKtrTLYmbCrMDdTpQnvfk7agC1q9a4RwIHVZnR7nzq7UTwG7uxe 78Mw== X-Gm-Message-State: AOAM530S6z5LRdR/gprrXxVITJmZTNt4J/MoaZFNGaOMsi8LEu6jAdJG ZBMrM/pxXpPeMNAN8lXX2qhwXA== X-Google-Smtp-Source: ABdhPJz/SRRWDghL//k8eMFJRFiGc8GNUYfNSMe1q/jwF7fRSlTcEeWPJljYcj1+A2V2xUkCH55ZlQ== X-Received: by 2002:a65:52c2:: with SMTP id z2mr43277569pgp.419.1594070668785; Mon, 06 Jul 2020 14:24:28 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n11sm19682014pgm.1.2020.07.06.14.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 14:24:28 -0700 (PDT) Date: Mon, 6 Jul 2020 14:24:19 -0700 From: Stephen Hemminger To: Ivan Dyukov Cc: dev@dpdk.org, v.kuramshin@samsung.com, thomas@monjalon.net, david.marchand@redhat.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, wei.zhao1@intel.com, jia.guo@intel.com, beilei.xing@intel.com, qiming.yang@intel.com, wenzhuo.lu@intel.com, mb@smartsharesystems.com, nicolas.chautru@intel.com, bruce.richardson@intel.com, konstantin.ananyev@intel.com, cristian.dumitrescu@intel.com, radu.nicolau@intel.com, akhil.goyal@nxp.com, declan.doherty@intel.com, skori@marvell.com, pbhagavatula@marvell.com, jerinj@marvell.com, kirankumark@marvell.com, david.hunt@intel.com, anatoly.burakov@intel.com, xiaoyun.li@intel.com, jingjing.wu@intel.com, john.mcnamara@intel.com, jasvinder.singh@intel.com, byron.marohn@intel.com, yipeng1.wang@intel.com Message-ID: <20200706142419.5f4c5f18@hermes.lan> In-Reply-To: <20200706203743.29416-3-i.dyukov@samsung.com> References: <20200427095737.11082-1-i.dyukov@samsung.com> <20200706203743.29416-1-i.dyukov@samsung.com> <20200706203743.29416-3-i.dyukov@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v6 02/25] ethdev: add a link status text representation 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" On Mon, 6 Jul 2020 23:37:16 +0300 Ivan Dyukov wrote: > static int > +rte_eth_link_strf_parser(char *str, size_t len, const char *const fmt, > + struct rte_eth_link *link) The link arg should be const. > +{ > + size_t offset = 0; > + const char *fmt_cur = fmt; > + char *str_cur = str; > + double gbits = (double)link->link_speed / 1000.; > + static const char AUTONEG_STR[] = "Autoneg"; > + static const char FIXED_STR[] = "Fixed"; > + static const char FDX_STR[] = "FDX"; > + static const char HDX_STR[] = "HDX"; > + static const char UNKNOWN_STR[] = "Unknown"; > + static const char UP_STR[] = "Up"; > + static const char DOWN_STR[] = "Down"; Why are these UPPER_CASE_CONSTANTS? That does not match DPDK style. > + > + char gbits_str[20]; > + char mbits_str[20]; > + /* preformat complex formatting to easily concatinate it further */ Blank line between declaration and code. > + snprintf(mbits_str, 20, "%u", link->link_speed); > + snprintf(gbits_str, 20, "%.1f", gbits); Use sizeof(mbits_str) which is safer and matches what youare doing. > + /* init str before formatting */ > + str[0] = 0; > + while (*fmt_cur) { > + /* check str bounds */ > + if (offset > (len - 1)) { > + str[len - 1] = '\0'; > + return -1; > + } > + if (*fmt_cur == '%') { > + /* set null terminator to current position, > + * it's required for strlcat > + */ > + *str_cur = '\0'; > + switch (*++fmt_cur) { > + /* Speed in Mbits/s */ > + case 'M': > + if (link->link_speed == > + ETH_SPEED_NUM_UNKNOWN) > + offset = strlcat(str, UNKNOWN_STR, > + len); > + else > + offset = strlcat(str, mbits_str, len); > + break; > + /* Speed in Gbits/s */ > + case 'G': > + if (link->link_speed == > + ETH_SPEED_NUM_UNKNOWN) > + offset = strlcat(str, UNKNOWN_STR, > + len); > + else > + offset = strlcat(str, gbits_str, len); > + break; > + /* Link status */ > + case 'S': > + offset = strlcat(str, link->link_status ? > + UP_STR : DOWN_STR, len); > + break; > + /* Link autoneg */ > + case 'A': > + offset = strlcat(str, link->link_autoneg ? > + AUTONEG_STR : FIXED_STR, len); > + break; > + /* Link duplex */ > + case 'D': > + offset = strlcat(str, link->link_duplex ? > + FDX_STR : HDX_STR, len); > + break; > + /* Error cases */ > + default: > + return -1; > + > + } > + if (offset > (len - 1)) > + return -1; > + > + str_cur = str + offset; > + } else { > + *str_cur++ = *fmt_cur; > + offset++; > + } > + fmt_cur++; > + } > + *str_cur = '\0'; > + return offset; > +} > + > +int > +rte_eth_link_printf(const char *const fmt, > + struct rte_eth_link *link) > +{ > + char text[200]; > + int ret; > + ret = rte_eth_link_strf(text, 200, fmt, link); Blank line tween declaration and code. > + if (ret > 0) > + printf("%s", text); > + return ret; > +}