Hi Keller,
On Tue, Jul 18, 2017 at 08:40:59PM +0000, Keller, Jacob E wrote:
> > +int rtnl_link_info(struct interface *iface)
> > +{
> > + int fd, index;
> > +
> > + index = if_nametoindex(iface->name);
> > +
> > + if (index == 0) {
> > + pr_err("failed to get interface %s index: %m", iface->name);
> > + goto no_fd;
> > + }
> > +
> > + fd = rtnl_open();
> > + if (fd < 0)
> > + goto no_fd;
> > +
> > + if (rtnl_link_query(fd, index))
> > + goto no_info;
> > + if (rtnl_link_status(fd, NULL, iface->ts_iface))
> > + goto no_info;
> > +
> > + /* If we do not have a slave, then use our own interface name
> > + * as ts_iface
> > + */
> > + if (iface->ts_iface[0] == '\0')
> > + strncpy(iface->ts_iface, iface->name, MAX_IFNAME_SIZE);
> > +
>
> Seems like we're duplicating code here just to maintain a return value?
>
> > + rtnl_close(fd);
> > + return 0;
> > +
> > +no_info:
> > + rtnl_close(fd);
> > +no_fd:
> > + if (iface->ts_iface[0] == '\0')
> > + strncpy(iface->ts_iface, iface->name, MAX_IFNAME_SIZE);
> > +
> > + return -1;
> > +}
hmm, you are right, the code is a little clumsy, how about
fd = rtnl_open();
if (fd > 0 && ! rtnl_link_query(fd, index))
rtnl_link_status(fd, NULL, iface->ts_iface);
/* If we do not have a slave, then use our own interface name
* as ts_iface
*/
if (iface->ts_iface[0] == '\0')
strncpy(iface->ts_iface, iface->name, MAX_IFNAME_SIZE);
if (fd > 0) {
rtnl_close(fd);
return 0;
} else {
return -1;
}
Thanks
Hangbin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel