On Fri, Jun 27, 2014 at 07:28:17PM +0200, Jiri Benc wrote:
> -/* returns the number matching that interface, or -1 on failure */
> -int config_create_interface(char *name, struct config *cfg)
> +struct interface *config_create_interface(char *name, struct config *cfg)
>  {
>       struct interface *iface;
> -     int i;
>  
> -     if (cfg->nports >= MAX_PORTS) {
> -             fprintf(stderr, "more than %d ports specified\n", MAX_PORTS);
> -             return -1;
> +     /* only create each interface once (by name) */
> +     STAILQ_FOREACH(iface, &cfg->interfaces, list) {
> +             if (0 == strncmp(name, iface->name, MAX_IFNAME_SIZE))
> +                     return iface;
>       }
>  
> -     iface = &cfg->iface[cfg->nports];
> -
> -     /* only create each interface once (by name) */
> -     for(i = 0; i < cfg->nports; i++) {
> -             if (0 == strncmp(name, cfg->iface[i].name, MAX_IFNAME_SIZE))
> -                     return i;
> +     iface = malloc(sizeof(struct interface));
> +     if (!iface) {
> +             fprintf(stderr, "cannot allocate memory for a port\n");
> +             return NULL;
>       }

Maybe better to clear iface, or use calloc.

Also, it would be nice form to free this when the program exists
normally. In that way, valgrind give you a perfect grade.

Otherwise, the series looks good to go.

Thanks,
Richard

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to