Hi Stephen, > -----Original Message----- > From: Stephen Hemminger <[email protected]> > Sent: Wednesday, March 22, 2023 10:59 PM > To: Bing Zhao <[email protected]> > Cc: Slava Ovsiienko <[email protected]>; Matan Azrad > <[email protected]>; [email protected]; Raslan Darawsheh > <[email protected]>; [email protected] > Subject: Re: [PATCH v2] common/mlx5: fix the sysfs port name translation > > External email: Use caution opening links or attachments > > > On Wed, 22 Mar 2023 13:34:12 +0200 > Bing Zhao <[email protected]> wrote: > > > + > > + port_name = (char *)malloc(IF_NAMESIZE); > > + if (port_name == NULL) { > > + fclose(file); > > + rte_errno = ENOMEM; > > + return -rte_errno; > > + } > > + line_size = getline(&port_name, &port_name_size, file); > > This code is doing unnecessary extra work here. > From getline() man page:
Yes, I also checked the description of this interface before. The original purpose was to allocate / free the memory explicitly. This will be removed. > > If *lineptr is set to NULL before the call, then getline() will > allocate a buffer for storing the line. This buffer should be > freed by the user program even if getline() failed.

