[systemd-devel] Trouble with speed/mode in .link files - RESOLVED/PATCH

Lennart Poettering lennart at poettering.net
Thu Jan 4 12:19:36 UTC 2018


On Mi, 03.01.18 15:32, Bruce A. Johnson (bjohnson at blueridgenetworks.com) wrote:

> My problem seems to be a bug in ethtool-util.c's set_slinksettings().
> The base parameters were not being copied into the ethtool_link_settings
> request, so they were all zero and ioctl didn't like that.  I've pasted
> the patch below.  Please let me know if there is anything else I need to
> do to get this to the right person.

Could you submit this as PR on github please? This makes review much
easier! Thanks!

>                  __u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
> -        } ecmd = {
> -                .req.cmd = ETHTOOL_SLINKSETTINGS,
> -        };
> +        } ecmd;
>          unsigned int offset;
>          int r;
>  
>          if (u->base.cmd != ETHTOOL_GLINKSETTINGS || u->base.link_mode_masks_nwords <= 0)
>                  return -EINVAL;
>  
> +        memset(&ecmd, sizeof(ecmd), 0);
> +        memcpy(&ecmd.req, &u->base, sizeof(ecmd.req));
> +        ecmd.req.cmd = ETHTOOL_SLINKSETTINGS;

We genereally pefer initialization at declaration time instead of
explicit memset(), as this tends to provide nicer code. Hence, please
keep at least the zero-initialization in the declaratin above.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list