[dpdk-dev] [PATCH v2 2/7] ethdev: add a link status textrepresentation

Stephen Hemminger stephen at networkplumber.org
Wed May 27 16:53:44 CEST 2020


On Wed, 27 May 2020 09:45:49 +0200
Morten Brørup <mb at smartsharesystems.com> wrote:

> void rte_eth_link_prepare_text(char *str, const struct rte_eth_link *const link)
> {
>     if (link.link_status == ETH_LINK_DOWN) {
>         str += sprintf(str, "Link down");
>     } else {
>         str += sprintf(str, "Link up at ");
>         if (link.link_speed == ETH_SPEED_NUM_UNKNOWN) {
>             str += sprintf("Unknown speed");
>         } else {
>             if (link.link_speed < ETH_SPEED_NUM_1G)
>                 str += sprintf(str, "%u Mbit/s", link.link_speed);
>             else if (link.link_speed == ETH_SPEED_NUM_2_5G)
>                 str += sprintf(str, "2.5 Gbit/s");
>             else
>                 str += sprintf(str, "%u Gbit/s", link.link_speed / 1000);
>             str += sprintf(str, " %cDX", link.link_duplex ? 'F' : 'H');
>             str += sprintf(str, " %s", link.link_autoneg ? "Autoneg" : "Fixed");
>         }
>     }
> }

Having a semi-standard link status text is good. This version of
the code needs work before it is ready.

Using sprintf() rather than snprintf() is going to upset the security folks.
The API must take string and length, or use asprintf();
You don't want to do last increment or Coverity will complain about useless assignment.


More information about the dev mailing list