On Mon, 13 May 2019 15:05:30 +0000, Maxim Mikityanskiy wrote:
> +     err = -EINVAL;
> +
> +     if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
> +             u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
> +
> +             if (check_addr_gen_mode(mode) < 0)
> +                     return -EINVAL;
> +             if (dev && check_stable_privacy(idev, dev_net(dev), mode) < 0)
> +                     return -EINVAL;
> +
> +             err = 0;
> +     }
> +
> +     if (tb[IFLA_INET6_TOKEN])
> +             err = 0;
> +
> +     return err;

While at it could you forgo the retval optimization?  Most of the time
it just leads to less readable code for no gain.

The normal way to write this code would be:

        if (!tb[IFLA_INET6_ADDR_GEN_MODE] && !tb[IFLA_INET6_TOKEN])
                return -EINVAL;

        if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
                u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);

                if (check_addr_gen_mode(mode) < 0)
                        return -EINVAL;
                if (dev && check_stable_privacy(idev, dev_net(dev), mode) < 0)
                        return -EINVAL;
        }

        return 0;

Reply via email to